mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
members generated with wrong size calc for arrays
This commit is contained in:
@ -111,7 +111,7 @@ class DebugInfoGenerator:
|
|||||||
"name": name,
|
"name": name,
|
||||||
"file": self.module._file_metadata,
|
"file": self.module._file_metadata,
|
||||||
"baseType": base_type,
|
"baseType": base_type,
|
||||||
"size": getattr(base_type, "size", type_size),
|
"size": type_size,
|
||||||
"offset": offset,
|
"offset": offset,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@ -59,7 +59,7 @@ def _get_field_debug_type(
|
|||||||
generator: DebugInfoGenerator,
|
generator: DebugInfoGenerator,
|
||||||
parent_struct: DependencyNode,
|
parent_struct: DependencyNode,
|
||||||
generated_debug_info: List[Tuple[DependencyNode, Any]]
|
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.
|
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 field.ctype_complex_type is not None:
|
||||||
if issubclass(field.ctype_complex_type, ctypes.Array):
|
if issubclass(field.ctype_complex_type, ctypes.Array):
|
||||||
# Handle array types
|
# Handle array types
|
||||||
element_type = _get_basic_debug_type(field.containing_type, generator)
|
element_type, base_type_size = _get_basic_debug_type(field.containing_type, generator)
|
||||||
return generator.create_array_type(element_type, field.type_size)
|
return generator.create_array_type(element_type, field.type_size), field.type_size * base_type_size
|
||||||
elif issubclass(field.ctype_complex_type, ctypes._Pointer):
|
elif issubclass(field.ctype_complex_type, ctypes._Pointer):
|
||||||
# Handle pointer types
|
# Handle pointer types
|
||||||
pointee_type = _get_basic_debug_type(field.containing_type, generator)
|
pointee_type, _ = _get_basic_debug_type(field.containing_type, generator)
|
||||||
return generator.create_pointer_type(pointee_type)
|
return generator.create_pointer_type(pointee_type), 64
|
||||||
|
|
||||||
# Handle other vmlinux types (nested structs)
|
# Handle other vmlinux types (nested structs)
|
||||||
if field.type.__module__ == "vmlinux":
|
if field.type.__module__ == "vmlinux":
|
||||||
@ -93,13 +93,13 @@ def _get_field_debug_type(
|
|||||||
for existing_struct, debug_info in generated_debug_info:
|
for existing_struct, debug_info in generated_debug_info:
|
||||||
if existing_struct.name == struct_name:
|
if existing_struct.name == struct_name:
|
||||||
# Use existing debug info
|
# Use existing debug info
|
||||||
return debug_info
|
return debug_info, existing_struct.__sizeof__()
|
||||||
|
|
||||||
# If not found, create a forward declaration
|
# If not found, create a forward declaration
|
||||||
# This will be completed when the actual struct is processed
|
# This will be completed when the actual struct is processed
|
||||||
logger.warning("Forward declaration in struct created")
|
logger.warning("Forward declaration in struct created")
|
||||||
forward_type = generator.create_struct_type([], 0, is_distinct=True)
|
forward_type = generator.create_struct_type([], 0, is_distinct=True)
|
||||||
return forward_type
|
return forward_type, 0
|
||||||
|
|
||||||
# Handle basic C types
|
# Handle basic C types
|
||||||
return _get_basic_debug_type(field.type, generator)
|
return _get_basic_debug_type(field.type, generator)
|
||||||
|
|||||||
@ -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.maps import HashMap
|
||||||
from pythonbpf.helper import XDP_PASS
|
from pythonbpf.helper import XDP_PASS
|
||||||
from vmlinux import TASK_COMM_LEN # noqa: F401
|
from vmlinux import TASK_COMM_LEN # noqa: F401
|
||||||
from vmlinux import struct_xdp_md
|
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
|
from ctypes import c_int64
|
||||||
|
|
||||||
# Instructions to how to run this program
|
# Instructions to how to run this program
|
||||||
@ -26,3 +26,4 @@ def LICENSE() -> str:
|
|||||||
|
|
||||||
|
|
||||||
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
|
compile_to_ir("xdp_pass.py", "xdp_pass.ll")
|
||||||
|
compile()
|
||||||
|
|||||||
Reference in New Issue
Block a user