Commit Graph

923 Commits

Author SHA1 Message Date
9959862154 Core: Widen any sub-64-bit context field instead of special-casing xdp_md
Reading a context field narrower than a register was hardcoded to
struct_xdp_md's i32 fields in three places that had to agree with each other:
the destination alloca in allocation_pass, the zext in load_ctx_field, and
the store in assign_pass. struct pt_regs' cs and ss are 2 bytes, so a second
special case would have been needed.

Replace all three with the general rule: a context field is loaded at its
natural width and zero-extended to i64, so its destination is i64.
allocation_pass gains the same context discriminator load_ctx_field uses
(a context argument has no alloca of its own), so non-context field reads,
which go through load_struct_field and bpf_probe_read_kernel, keep their
natural width and are untouched.

struct_xdp_md's generated IR is byte-identical, as is every other vmlinux/xdp
test program's; the only diff in the whole corpus remains the four new globals
from the previous commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 05:09:45 +05:30
4ff3ce26c6 Core: Emit nested CO-RE access strings for anonymous members
A field lifted out of an anonymous member needs an access string that walks
into that member, so `struct pt_regs.cs` is `llvm.pt_regs:0:136$0:17:0`
(member 0 of anonymous member 17) rather than the flat `$0:<index>` form.
This is byte-for-byte what clang emits for the equivalent C, verified against
`__builtin_preserve_access_index(ctx->cs)` on a struct with the same shape,
and the indices and offsets agree with `bpftool btf dump file
/sys/kernel/btf/vmlinux`.

Only fields carrying an access path take the new path; every other field
keeps the existing flat and indexed/array forms unchanged. The only .ll diff
across all vmlinux/xdp test programs is four brand new globals for cs, csx,
ss and ssx. No pre-existing relocation string changes.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 04:59:08 +05:30
f2ec70759e Core: Flatten anonymous struct/union members during vmlinux parsing
On this kernel `struct pt_regs` wraps `cs` and `ss` in anonymous unions.
ctypes lifts those names onto the parent class, exactly as C does, but the
parser only walked the top-level `_fields_`, so `cs` and `ss` were unknown to
the compiler and `ctx.cs` blew up.

Register the members of an anonymous member as fields of the parent, one
level deep, taking the ABSOLUTE offset ctypes reports on the parent (no
arithmetic) and recording the access path (anonymous member index, member
index). The anonymous member itself stays registered as before.

Deliberately conservative: only scalar ctypes members are flattened. Nested
vmlinux structs (`fred_cs`, `fred_ss`) and bitfields are skipped with a
warning rather than half-registered, and a flattened member never overwrites
an existing top-level field of the same name. Overlapping members are kept as
distinct fields, since `cs` and `csx` both legitimately live at offset 136.

Flattened fields are not yet emitted: IR generation and DWARF generation skip
them, and critically they do not consume a top-level field index, so existing
CO-RE names are untouched. Every vmlinux/xdp test program still compiles to a
byte-identical .ll. Entirely inert for any struct without `_anonymous_`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 04:54:17 +05:30
aa51d123de Core: Add an optional CO-RE access path to Field
Carries the chain of member indices from the enclosing struct down to a
field, so a field that does not sit at the top level of the struct can still
describe where it lives. Defaults to None, which keeps meaning "this field is
a plain top-level member".

Pure data, nothing reads it yet, generated IR is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 04:48:06 +05:30
ce222afa65 Core: Make vmlinux field lookups agree on one source of truth
has_field() consulted hasattr() on the ctypes class while get_field_type()
indexed the parsed members dict. For any member ctypes exposes but the
vmlinux parser never registered, has_field() said True and get_field_type()
then died with a raw KeyError.

Both now consult the parsed members dict, and a lookup that misses raises a
ValueError that distinguishes "no such field" from "field exists in
vmlinux.py but the parser does not support it yet".

get_field_index() additionally derives the index from the ctypes _fields_
list (the C declaration order) instead of the insertion order of the parsed
members dict, so it no longer depends on the two happening to coincide.

No change to generated IR: every vmlinux/xdp test program compiles to a
byte-identical .ll.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 04:43:49 +05:30
c2de7dad96 Temporarily ignore deprecation warnings for vmlinux.py 2026-05-27 14:53:54 +05:30
d1bb0191c9 Merge pull request #84 from pythonbpf/testing-framework
Automated testing framework which will give us regression and coverage reports, meant to run in a GH Action and locally
2026-04-25 23:02:00 +05:30
01ddffb619 Tests: Enable vmlinux requirement for verifier tests 2026-04-25 22:47:44 +05:30
1670814261 Tests: Remove unnecessary context from test_config 2026-04-25 20:22:57 +05:30
3c977fb240 Tests: Remove tomli from pyproject.toml 2026-04-25 20:15:22 +05:30
9103e44711 Tests: Remove unnecessary stuff from README 2026-04-25 20:13:17 +05:30
35b492054c Tests: Remove unnecessary _all_cases from conftest 2026-04-25 20:10:27 +05:30
48fa8aec3f Tests: USe namedtuple to pass verifier output for asserts 2026-04-25 18:54:25 +05:30
145e930389 Tests: Fix prefix set naming in test collector 2026-04-25 18:21:42 +05:30
5ec86be7dd Tests: Use full import path in test collector 2026-04-25 18:07:40 +05:30
56db0d3738 Tests: Remove unnecessary version check from test collector 2026-04-25 17:59:59 +05:30
1d555ddd47 Tests: Add tests/README.md
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 19:35:08 +05:30
ee444447b9 Tests: Add tests/__init__.py and pythonpath config
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 19:34:47 +05:30
da57911122 Tests: Add automated testing framework with coverage support
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 19:33:43 +05:30
0498885f71 Merge pull request #82 from pythonbpf/compilation-context
PythonBPF: Add Compilation Context to allow parallel compilation of multiple jobs
2026-03-29 10:02:10 +02:00
3f4f95115f Core: Pass compilation_context to _prepare_expr_args as it calls eval_expr 2026-03-29 13:28:38 +05:30
f2b9767098 Core: Fix args in helper/printk_formatter 2026-03-29 13:11:44 +05:30
0e087b9ea5 Core: Revert unnecessary changes to allocation_pass 2026-03-29 02:48:16 +05:30
ccbdfee9de Core: Remove unsused args in assign_pass 2026-03-29 02:44:42 +05:30
61bca6bad9 Core: Fix global pass to divide internal functions 2026-03-29 02:40:55 +05:30
305a8ba9e3 Core: Fix unnecessary args and changes in maps pass 2026-03-29 01:36:46 +05:30
bdcfe47601 Core: Fix unnecessary arg in structs/structs_pass 2026-03-28 20:44:07 +05:30
3396d84e26 Core: Fix incompatible logic in helper/helper_utils 2026-03-28 19:58:26 +05:30
c22911daaf Core: FIx inconsistent compilation_context usage in helper/printk_formatter 2026-03-28 19:02:16 +05:30
c04e32bd24 Core: Remove spurious comments from functions_pass 2026-03-28 12:15:41 +05:30
b7f917c3c2 Merge pull request #83 from pythonbpf/dependabot/github_actions/actions-985357984d
build(deps): bump the actions group with 2 updates
2026-03-07 14:11:31 +05:30
b025ae7158 build(deps): bump the actions group with 2 updates
Bumps the actions group with 2 updates: [actions/upload-artifact](https://github.com/actions/upload-artifact) and [actions/download-artifact](https://github.com/actions/download-artifact).


Updates `actions/upload-artifact` from 6 to 7
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v6...v7)

Updates `actions/download-artifact` from 7 to 8
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v7...v8)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
- dependency-name: actions/download-artifact
  dependency-version: '8'
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-02 11:45:33 +00:00
ec4a6852ec PythonBPF: Add Compilation Context to allow parallel compilation of multiple bpf programs 2026-02-21 18:59:33 +05:30
45d85c416f BCC-Examples: Fix returns in disksnoop.py 2026-01-29 22:33:07 +05:30
cb18ab67d9 docs: Add docs badge to README 2026-01-29 12:06:22 +05:30
d1872bc868 docs: Add readthedocs workflow file 2026-01-29 11:58:31 +05:30
2c2ed473d8 Merge pull request #80 from pythonbpf/copilot/create-documentation-project
Add comprehensive Sphinx documentation with MyST-Parser
2026-01-29 11:38:44 +05:30
b6ecec9889 docs: Format requirements 2026-01-29 11:37:50 +05:30
4f56f8c426 docs: Exclude README.md from toctree 2026-01-29 11:35:24 +05:30
3bff930e98 docs: Include cross-references to BCC-Examples 2026-01-29 11:31:25 +05:30
036830c200 docs: Fix API reference 2026-01-29 03:13:49 +05:30
aded125cba docs: Fix helpers and maps guide 2026-01-29 02:54:46 +05:30
581269e52b docs: Fix user-guide/compilation 2026-01-28 16:34:48 +05:30
8bfd998863 docs: Fix user-guide/bpf-structs 2026-01-28 04:12:35 +05:30
a31ef3997a docs: Fix user-guide/maps.md 2026-01-27 12:59:22 +05:30
217e760e98 docs: Fix decorators page in user-guide 2026-01-27 02:16:03 +05:30
06c81ae55e docs: fix TC section in decorators 2026-01-27 01:58:06 +05:30
9131d044dc docs: fix user-guide index 2026-01-26 08:45:56 +05:30
2840a5c101 docs: fix common issues section of quickstart 2026-01-25 13:31:21 +05:30
9ff33229a0 docs: fix type hints misconception in quickstart 2026-01-25 13:25:45 +05:30