Skip to content

Commit 7bf6f9c

Browse files
add function_debug_info.py and format
1 parent a1fe2ed commit 7bf6f9c

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

pythonbpf/assign_pass.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ def handle_variable_assignment(
152152
if val_type != var_type:
153153
if isinstance(val_type, Field):
154154
logger.info("Handling assignment to struct field")
155-
#TODO: handling only ctype struct fields for now. Handle other stuff too later.
155+
# TODO: handling only ctype struct fields for now. Handle other stuff too later.
156156
if var_type == ctypes_to_ir(val_type.type.__name__):
157157
builder.store(val, var_ptr)
158158
logger.info(f"Assigned ctype struct field to {var_name}")
159159
return True
160-
logger.error(f"Failed to assign ctype struct field to {var_name}: {val_type} != {var_type}")
160+
logger.error(
161+
f"Failed to assign ctype struct field to {var_name}: {val_type} != {var_type}"
162+
)
161163
return False
162164
elif isinstance(val_type, ir.IntType) and isinstance(var_type, ir.IntType):
163165
# Allow implicit int widening
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ast
2+
3+
import llvmlite.ir as ir
4+
5+
6+
def generate_function_debug_info(
7+
func_node: ast.FunctionDef, module: ir.Module, func: ir.Function
8+
):
9+
pass

pythonbpf/functions/functions_pass.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
create_targets_and_rvals,
2424
LocalSymbol,
2525
)
26-
26+
from .function_debug_info import generate_function_debug_info
2727
from .return_utils import handle_none_return, handle_xdp_return, is_xdp_name
2828
from .function_metadata import get_probe_string, is_global_function, infer_return_type
2929

@@ -440,14 +440,17 @@ def func_proc(tree, module, chunks, map_sym_tab, structs_sym_tab):
440440
func_type = get_probe_string(func_node)
441441
logger.info(f"Found probe_string of {func_node.name}: {func_type}")
442442

443-
process_bpf_chunk(
443+
func = process_bpf_chunk(
444444
func_node,
445445
module,
446446
ctypes_to_ir(infer_return_type(func_node)),
447447
map_sym_tab,
448448
structs_sym_tab,
449449
)
450450

451+
logger.info(f"Generating Debug Info for Function {func_node.name}")
452+
generate_function_debug_info(func_node, module, func)
453+
451454

452455
# TODO: WIP, for string assignment to fixed-size arrays
453456
def assign_string_to_array(builder, target_array_ptr, source_string_ptr, array_length):

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def handle_vmlinux_struct_field(
8888
)
8989
builder.function.args[0].type = ir.PointerType(ir.IntType(64))
9090
print(builder.function.args[0])
91-
field_ptr = self.load_ctx_field(builder, builder.function.args[0], globvar_ir)
91+
field_ptr = self.load_ctx_field(
92+
builder, builder.function.args[0], globvar_ir
93+
)
9294
print(field_ptr)
9395
# Return pointer to field and field type
9496
return field_ptr, field_data
@@ -112,9 +114,9 @@ def load_ctx_field(builder, ctx_arg, offset_global):
112114
# Load the offset value
113115
offset = builder.load(offset_global)
114116

115-
# Ensure ctx_arg is treated as i8* (byte pointer)
116-
# i8_type = ir.IntType(8)
117-
i8_ptr_type = ir.PointerType()
117+
# # Ensure ctx_arg is treated as i8* (byte pointer)
118+
# # i8_type = ir.IntType(8)
119+
# i8_ptr_type = ir.PointerType()
118120

119121
# Cast ctx_arg to i8* if it isn't already
120122
# if str(ctx_arg.type) != str(i8_ptr_type):
@@ -133,7 +135,7 @@ def load_ctx_field(builder, ctx_arg, offset_global):
133135
module = builder.function.module
134136

135137
try:
136-
passthrough_fn = module.globals.get('llvm.bpf.passthrough.p0.p0')
138+
passthrough_fn = module.globals.get("llvm.bpf.passthrough.p0.p0")
137139
if passthrough_fn is None:
138140
raise KeyError
139141
except (KeyError, AttributeError):
@@ -144,14 +146,12 @@ def load_ctx_field(builder, ctx_arg, offset_global):
144146
passthrough_fn = ir.Function(
145147
module,
146148
passthrough_type,
147-
name='llvm.bpf.passthrough.p0.p0',
149+
name="llvm.bpf.passthrough.p0.p0",
148150
)
149151

150152
# Call passthrough to satisfy BPF verifier
151153
verified_ptr = builder.call(
152-
passthrough_fn,
153-
[ir.Constant(ir.IntType(32), 0), field_ptr],
154-
tail=True
154+
passthrough_fn, [ir.Constant(ir.IntType(32), 0), field_ptr], tail=True
155155
)
156156

157157
# Bitcast to i64* (assuming field is 64-bit, adjust if needed)
@@ -163,7 +163,6 @@ def load_ctx_field(builder, ctx_arg, offset_global):
163163

164164
return value
165165

166-
167166
def has_field(self, struct_name, field_name):
168167
"""Check if a vmlinux struct has a specific field"""
169168
if self.is_vmlinux_struct(struct_name):

0 commit comments

Comments
 (0)