Skip to content

Commit 9de20b2

Browse files
Merge pull request #3 from varun-r-mallya/expt
dwarf constant handling
2 parents daa3982 + e038575 commit 9de20b2

File tree

4 files changed

+782
-36
lines changed

4 files changed

+782
-36
lines changed

examples/execve2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
def last() -> HashMap:
1010
return HashMap(key_type=c_uint64, value_type=c_uint64, max_entries=1)
1111

12-
1312
@bpf
1413
@section("tracepoint/syscalls/sys_enter_execve")
1514
def hello(ctx: c_void_p) -> c_int32:

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)])

0 commit comments

Comments
 (0)