Skip to content

Commit 1b4272b

Browse files
members generated with wrong size calc for arrays
1 parent 101183c commit 1b4272b

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

pythonbpf/debuginfo/debug_info_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def create_struct_member_vmlinux(self, name: str, base_type_with_size: Any, offs
111111
"name": name,
112112
"file": self.module._file_metadata,
113113
"baseType": base_type,
114-
"size": getattr(base_type, "size", type_size),
114+
"size": type_size,
115115
"offset": offset,
116116
},
117117
)

pythonbpf/vmlinux_parser/ir_gen/debug_info_gen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _get_field_debug_type(
5959
generator: DebugInfoGenerator,
6060
parent_struct: DependencyNode,
6161
generated_debug_info: List[Tuple[DependencyNode, Any]]
62-
) -> Any:
62+
) -> tuple[Any, int]:
6363
"""
6464
Determine the appropriate debug type for a field based on its Python/ctypes type.
6565
@@ -77,12 +77,12 @@ def _get_field_debug_type(
7777
if field.ctype_complex_type is not None:
7878
if issubclass(field.ctype_complex_type, ctypes.Array):
7979
# Handle array types
80-
element_type = _get_basic_debug_type(field.containing_type, generator)
81-
return generator.create_array_type(element_type, field.type_size)
80+
element_type, base_type_size = _get_basic_debug_type(field.containing_type, generator)
81+
return generator.create_array_type(element_type, field.type_size), field.type_size * base_type_size
8282
elif issubclass(field.ctype_complex_type, ctypes._Pointer):
8383
# Handle pointer types
84-
pointee_type = _get_basic_debug_type(field.containing_type, generator)
85-
return generator.create_pointer_type(pointee_type)
84+
pointee_type, _ = _get_basic_debug_type(field.containing_type, generator)
85+
return generator.create_pointer_type(pointee_type), 64
8686

8787
# Handle other vmlinux types (nested structs)
8888
if field.type.__module__ == "vmlinux":
@@ -93,13 +93,13 @@ def _get_field_debug_type(
9393
for existing_struct, debug_info in generated_debug_info:
9494
if existing_struct.name == struct_name:
9595
# Use existing debug info
96-
return debug_info
96+
return debug_info, existing_struct.__sizeof__()
9797

9898
# If not found, create a forward declaration
9999
# This will be completed when the actual struct is processed
100100
logger.warning("Forward declaration in struct created")
101101
forward_type = generator.create_struct_type([], 0, is_distinct=True)
102-
return forward_type
102+
return forward_type, 0
103103

104104
# Handle basic C types
105105
return _get_basic_debug_type(field.type, generator)

tests/passing_tests/vmlinux/xdp_pass.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir
1+
from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir, compile
22
from pythonbpf.maps import HashMap
33
from pythonbpf.helper import XDP_PASS
44
from vmlinux import TASK_COMM_LEN # noqa: F401
55
from vmlinux import struct_xdp_md
6-
# from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
6+
from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
77
from ctypes import c_int64
88

99
# Instructions to how to run this program
@@ -26,3 +26,4 @@ def LICENSE() -> str:
2626

2727

2828
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
29+
compile()

0 commit comments

Comments
 (0)