Skip to content

Commit 44c6ced

Browse files
fix context debug info repetition circular reference error
1 parent 2685d0a commit 44c6ced

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

pythonbpf/functions/function_debug_info.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,27 @@ def generate_function_debug_info(
4949
"The first argument should always be a pointer to a struct or a void pointer"
5050
)
5151
context_debug_info = VmlinuxHandlerRegistry.get_struct_debug_info(annotation.id)
52+
53+
# Create pointer to context this must be created fresh for each function
54+
# to avoid circular reference issues when the same struct is used in multiple functions
5255
pointer_to_context_debug_info = generator.create_pointer_type(
5356
context_debug_info, 64
5457
)
58+
59+
# Create subroutine type - also fresh for each function
5560
subroutine_type = generator.create_subroutine_type(
5661
return_type, pointer_to_context_debug_info
5762
)
63+
64+
# Create local variable - fresh for each function with unique name
5865
context_local_variable = generator.create_local_variable_debug_info(
5966
leading_argument_name, 1, pointer_to_context_debug_info
6067
)
68+
6169
retained_nodes = [context_local_variable]
70+
logger.info(f"Generating debug info for function {func_node.name}")
71+
72+
# Create subprogram with is_distinct=True to ensure each function gets unique debug info
6273
subprogram_debug_info = generator.create_subprogram(
6374
func_node.name, subroutine_type, retained_nodes
6475
)

tests/failing_tests/vmlinux/i32_test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
from vmlinux import struct_xdp_md
44
from vmlinux import XDP_PASS
55

6+
@bpf
7+
@section("xdp")
8+
def print_xdp_dat2a(ct2x: struct_xdp_md) -> c_int64:
9+
data = ct2x.data # 32-bit field: packet start pointer
10+
print(f"ct2x->data = {data}")
11+
return c_int64(XDP_PASS)
612

713
@bpf
814
@section("xdp")
@@ -12,13 +18,6 @@ def print_xdp_data(ctx: struct_xdp_md) -> c_int64:
1218
print(f"ctx->data = {something}")
1319
return c_int64(XDP_PASS)
1420

15-
@bpf
16-
@section("xdp")
17-
def print_xdp_dat2a(ct2x: struct_xdp_md) -> c_int64:
18-
data = ct2x.data # 32-bit field: packet start pointer
19-
print(f"ct2x->data = {data}")
20-
return c_int64(XDP_PASS)
21-
2221
@bpf
2322
@bpfglobal
2423
def LICENSE() -> str:

0 commit comments

Comments
 (0)