From 44c6ceda275c4c63112d8b23f7bb6e63c8016557 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Wed, 5 Nov 2025 17:44:29 +0530 Subject: [PATCH] fix context debug info repetition circular reference error --- pythonbpf/functions/function_debug_info.py | 11 +++++++++++ tests/failing_tests/vmlinux/i32_test.py | 13 ++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pythonbpf/functions/function_debug_info.py b/pythonbpf/functions/function_debug_info.py index e22e9ad..985eb92 100644 --- a/pythonbpf/functions/function_debug_info.py +++ b/pythonbpf/functions/function_debug_info.py @@ -49,16 +49,27 @@ def generate_function_debug_info( "The first argument should always be a pointer to a struct or a void pointer" ) context_debug_info = VmlinuxHandlerRegistry.get_struct_debug_info(annotation.id) + + # Create pointer to context this must be created fresh for each function + # to avoid circular reference issues when the same struct is used in multiple functions pointer_to_context_debug_info = generator.create_pointer_type( context_debug_info, 64 ) + + # Create subroutine type - also fresh for each function subroutine_type = generator.create_subroutine_type( return_type, pointer_to_context_debug_info ) + + # Create local variable - fresh for each function with unique name context_local_variable = generator.create_local_variable_debug_info( leading_argument_name, 1, pointer_to_context_debug_info ) + retained_nodes = [context_local_variable] + logger.info(f"Generating debug info for function {func_node.name}") + + # Create subprogram with is_distinct=True to ensure each function gets unique debug info subprogram_debug_info = generator.create_subprogram( func_node.name, subroutine_type, retained_nodes ) diff --git a/tests/failing_tests/vmlinux/i32_test.py b/tests/failing_tests/vmlinux/i32_test.py index cff9f0a..737d9c5 100644 --- a/tests/failing_tests/vmlinux/i32_test.py +++ b/tests/failing_tests/vmlinux/i32_test.py @@ -3,6 +3,12 @@ from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile from vmlinux import struct_xdp_md from vmlinux import XDP_PASS +@bpf +@section("xdp") +def print_xdp_dat2a(ct2x: struct_xdp_md) -> c_int64: + data = ct2x.data # 32-bit field: packet start pointer + print(f"ct2x->data = {data}") + return c_int64(XDP_PASS) @bpf @section("xdp") @@ -12,13 +18,6 @@ def print_xdp_data(ctx: struct_xdp_md) -> c_int64: print(f"ctx->data = {something}") return c_int64(XDP_PASS) -@bpf -@section("xdp") -def print_xdp_dat2a(ct2x: struct_xdp_md) -> c_int64: - data = ct2x.data # 32-bit field: packet start pointer - print(f"ct2x->data = {data}") - return c_int64(XDP_PASS) - @bpf @bpfglobal def LICENSE() -> str: