Skip to content

Commit 896dadd

Browse files
change debug_compile_unit addition location
1 parent 12bca3c commit 896dadd

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

pythonbpf/codegen.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .functions_pass import func_proc
55
from .maps_pass import maps_proc
66
from .globals_pass import globals_processing
7+
import os
78

89

910
def find_bpf_chunks(tree):
@@ -41,7 +42,27 @@ def compile_to_ir(filename: str, output: str):
4142
module.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
4243
module.triple = "bpf"
4344

45+
if not hasattr(module, '_debug_compile_unit'):
46+
module._file_metadata = module.add_debug_info("DIFile", { # type: ignore
47+
"filename": filename,
48+
"directory": os.path.dirname(filename)
49+
})
50+
51+
module._debug_compile_unit = module.add_debug_info("DICompileUnit", { # type: ignore
52+
"language": 29, # DW_LANG_C11
53+
"file": module._file_metadata, # type: ignore
54+
"producer": "PythonBPF DSL Compiler",
55+
"isOptimized": True,
56+
"runtimeVersion": 0,
57+
"emissionKind": 1,
58+
"splitDebugInlining": False,
59+
"nameTableKind": 0
60+
}, is_distinct=True)
61+
62+
module.add_named_metadata("llvm.dbg.cu", module._debug_compile_unit) # type: ignore
63+
4464
processor(source, filename, module)
65+
4566
wchar_size = module.add_metadata([ir.Constant(ir.IntType(32), 1),
4667
"wchar_size",
4768
ir.Constant(ir.IntType(32), 4)])

pythonbpf/maps_pass.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,7 @@ def create_bpf_map(module, map_name, map_params):
4848

4949
def create_map_debug_info(module, map_global, map_name, map_params):
5050
"""Generate debug information metadata for BPF map"""
51-
file_metadata = module
52-
# Get or create compile unit (you may already have this)
53-
if not hasattr(module, '_debug_compile_unit'):
54-
# Create file metadata
55-
file_metadata = module.add_debug_info("DIFile", {
56-
"filename": "generated.bpf.c", # Adjust as needed
57-
"directory": "/generated", # Adjust as needed
58-
})
59-
60-
# Create compile unit
61-
module._debug_compile_unit = module.add_debug_info("DICompileUnit", {
62-
"language": 12, # DW_LANG_C11
63-
"file": file_metadata,
64-
"producer": "PythonBPF DSL Compiler",
65-
"isOptimized": True,
66-
"runtimeVersion": 0,
67-
"emissionKind": 1,
68-
"splitDebugInlining": False,
69-
"nameTableKind": 0
70-
}, is_distinct=True)
71-
72-
module.add_named_metadata("llvm.dbg.cu", module._debug_compile_unit)
73-
51+
file_metadata = module._file_metadata
7452
compile_unit = module._debug_compile_unit
7553

7654
# Create basic type for unsigned int (32-bit)

0 commit comments

Comments
 (0)