diff --git a/pythonbpf/debuginfo/debug_info_generator.py b/pythonbpf/debuginfo/debug_info_generator.py index e9703db..1848ecc 100644 --- a/pythonbpf/debuginfo/debug_info_generator.py +++ b/pythonbpf/debuginfo/debug_info_generator.py @@ -111,7 +111,7 @@ class DebugInfoGenerator: "name": name, "file": self.module._file_metadata, "baseType": base_type, - "size": getattr(base_type, "size", type_size), + "size": type_size, "offset": offset, }, ) diff --git a/pythonbpf/vmlinux_parser/ir_gen/debug_info_gen.py b/pythonbpf/vmlinux_parser/ir_gen/debug_info_gen.py index ab0bf46..15b21c5 100644 --- a/pythonbpf/vmlinux_parser/ir_gen/debug_info_gen.py +++ b/pythonbpf/vmlinux_parser/ir_gen/debug_info_gen.py @@ -59,7 +59,7 @@ def _get_field_debug_type( generator: DebugInfoGenerator, parent_struct: DependencyNode, generated_debug_info: List[Tuple[DependencyNode, Any]] -) -> Any: +) -> tuple[Any, int]: """ Determine the appropriate debug type for a field based on its Python/ctypes type. @@ -77,12 +77,12 @@ def _get_field_debug_type( if field.ctype_complex_type is not None: if issubclass(field.ctype_complex_type, ctypes.Array): # Handle array types - element_type = _get_basic_debug_type(field.containing_type, generator) - return generator.create_array_type(element_type, field.type_size) + element_type, base_type_size = _get_basic_debug_type(field.containing_type, generator) + return generator.create_array_type(element_type, field.type_size), field.type_size * base_type_size elif issubclass(field.ctype_complex_type, ctypes._Pointer): # Handle pointer types - pointee_type = _get_basic_debug_type(field.containing_type, generator) - return generator.create_pointer_type(pointee_type) + pointee_type, _ = _get_basic_debug_type(field.containing_type, generator) + return generator.create_pointer_type(pointee_type), 64 # Handle other vmlinux types (nested structs) if field.type.__module__ == "vmlinux": @@ -93,13 +93,13 @@ def _get_field_debug_type( for existing_struct, debug_info in generated_debug_info: if existing_struct.name == struct_name: # Use existing debug info - return debug_info + return debug_info, existing_struct.__sizeof__() # If not found, create a forward declaration # This will be completed when the actual struct is processed logger.warning("Forward declaration in struct created") forward_type = generator.create_struct_type([], 0, is_distinct=True) - return forward_type + return forward_type, 0 # Handle basic C types return _get_basic_debug_type(field.type, generator) diff --git a/tests/passing_tests/vmlinux/xdp_pass.py b/tests/passing_tests/vmlinux/xdp_pass.py index 484784b..4ba2fea 100644 --- a/tests/passing_tests/vmlinux/xdp_pass.py +++ b/tests/passing_tests/vmlinux/xdp_pass.py @@ -1,9 +1,9 @@ -from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir +from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir, compile from pythonbpf.maps import HashMap from pythonbpf.helper import XDP_PASS from vmlinux import TASK_COMM_LEN # noqa: F401 from vmlinux import struct_xdp_md -# from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401 +from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401 from ctypes import c_int64 # Instructions to how to run this program @@ -26,3 +26,4 @@ def LICENSE() -> str: compile_to_ir("xdp_pass.py", "xdp_pass.ll") +compile()