Skip to content

Commit 8bd210c

Browse files
add debug info storage on assignment_info.py dataclass
1 parent 7bf6f9c commit 8bd210c

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
lines changed

pythonbpf/expr/vmlinux_registry.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def handle_attribute(cls, expr, local_sym_tab, module, builder):
3939
)
4040
return None
4141

42+
@classmethod
43+
def get_struct_debug_info(cls, name):
44+
if cls._handler is None:
45+
return False
46+
return cls._handler.get_struct_debug_info(name)
47+
4248
@classmethod
4349
def is_vmlinux_struct(cls, name):
4450
"""Check if a name refers to a vmlinux struct"""

pythonbpf/functions/function_debug_info.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
import llvmlite.ir as ir
44

5+
from pythonbpf.debuginfo import DebugInfoGenerator
6+
from pythonbpf.expr import VmlinuxHandlerRegistry
7+
58

69
def generate_function_debug_info(
710
func_node: ast.FunctionDef, module: ir.Module, func: ir.Function
811
):
12+
generator = DebugInfoGenerator(module)
13+
leading_argument = func_node.args.args[0]
14+
leading_argument_name = leading_argument.arg
15+
# TODO: add ctypes handling as well here
16+
print(leading_argument.arg, leading_argument.annotation.id)
17+
context_debug_info = VmlinuxHandlerRegistry.get_struct_debug_info(
18+
name=leading_argument.annotation.id
19+
)
20+
print(context_debug_info)
921
pass

pythonbpf/vmlinux_parser/assignment_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ class AssignmentInfo:
3333
# Value is a tuple that contains the global variable representing that field
3434
# along with all the information about that field as a Field type.
3535
members: Optional[Dict[str, tuple[ir.GlobalVariable, Field]]] # For structs.
36+
debug_info: Any

pythonbpf/vmlinux_parser/import_detector.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def process_vmlinux_assign(node, module, assignments: dict[str, AssignmentInfo])
148148
pointer_level=None,
149149
signature=None,
150150
members=None,
151+
debug_info=None,
151152
)
152153
logger.info(
153154
f"Added assignment: {target_name} = {node.value.value!r} of type {type(node.value.value)}"

pythonbpf/vmlinux_parser/ir_gen/ir_generation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ def struct_processor(self, struct, processing_stack=None):
7373
)
7474

7575
# Generate IR first to populate field names
76-
self.generated_debug_info.append(
77-
(struct, self.gen_ir(struct, self.generated_debug_info))
78-
)
76+
struct_debug_info = self.gen_ir(struct, self.generated_debug_info)
77+
self.generated_debug_info.append((struct, struct_debug_info))
7978

8079
# Fill the assignments dictionary with struct information
8180
if struct.name not in self.assignments:
@@ -105,6 +104,7 @@ def struct_processor(self, struct, processing_stack=None):
105104
pointer_level=None,
106105
signature=None,
107106
members=members_dict,
107+
debug_info=struct_debug_info,
108108
)
109109
logger.info(f"Added struct assignment info for {struct.name}")
110110

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import logging
2+
from typing import Any
3+
24
from llvmlite import ir
35

46
from pythonbpf.local_symbol import LocalSymbol
@@ -40,6 +42,15 @@ def is_vmlinux_enum(self, name):
4042
and self.vmlinux_symtab[name].value_type == AssignmentType.CONSTANT
4143
)
4244

45+
def get_struct_debug_info(self, name: str) -> Any:
46+
if (
47+
name in self.vmlinux_symtab
48+
and self.vmlinux_symtab[name].value_type == AssignmentType.STRUCT
49+
):
50+
return self.vmlinux_symtab[name].debug_info
51+
else:
52+
raise ValueError(f"{name} is not a vmlinux struct type")
53+
4354
def get_vmlinux_struct_type(self, name):
4455
"""Check if name is a vmlinux struct type"""
4556
if (

0 commit comments

Comments
 (0)