mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
move debug cu generation to debug module
This commit is contained in:
@ -5,7 +5,7 @@ from .functions_pass import func_proc
|
||||
from .maps import maps_proc
|
||||
from .structs import structs_proc
|
||||
from .globals_pass import globals_processing
|
||||
from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum
|
||||
from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum, DebugInfoGenerator
|
||||
import os
|
||||
import subprocess
|
||||
import inspect
|
||||
@ -60,32 +60,14 @@ def compile_to_ir(filename: str, output: str, loglevel=logging.WARNING):
|
||||
module.triple = "bpf"
|
||||
|
||||
if not hasattr(module, "_debug_compile_unit"):
|
||||
module._file_metadata = module.add_debug_info(
|
||||
"DIFile",
|
||||
{ # type: ignore
|
||||
"filename": filename,
|
||||
"directory": os.path.dirname(filename),
|
||||
},
|
||||
)
|
||||
|
||||
module._debug_compile_unit = module.add_debug_info(
|
||||
"DICompileUnit",
|
||||
{ # type: ignore
|
||||
"language": DW_LANG_C11,
|
||||
"file": module._file_metadata, # type: ignore
|
||||
"producer": f"PythonBPF {VERSION}",
|
||||
"isOptimized": True, # TODO: This is probably not true
|
||||
# TODO: add a global field here that keeps track of all the globals. Works without it, but I think it might
|
||||
# be required for kprobes.
|
||||
"runtimeVersion": 0,
|
||||
"emissionKind": 1,
|
||||
"splitDebugInlining": False,
|
||||
"nameTableKind": 0,
|
||||
},
|
||||
is_distinct=True,
|
||||
)
|
||||
|
||||
module.add_named_metadata("llvm.dbg.cu", module._debug_compile_unit) # type: ignore
|
||||
debug_generator = DebugInfoGenerator(module)
|
||||
debug_generator.generate_file_metadata(filename, os.path.dirname(filename))
|
||||
debug_generator.generate_debug_cu(DW_LANG_C11,
|
||||
f"PythonBPF {VERSION}",
|
||||
True # TODO: This is probably not true
|
||||
# TODO: add a global field here that keeps track of all the globals. Works without it, but I think it might
|
||||
# be required for kprobes.
|
||||
, True)
|
||||
|
||||
processor(source, filename, module)
|
||||
|
||||
@ -147,7 +129,7 @@ def compile(loglevel=logging.WARNING) -> bool:
|
||||
|
||||
success = True
|
||||
success = (
|
||||
compile_to_ir(str(caller_file), str(ll_file), loglevel=loglevel) and success
|
||||
compile_to_ir(str(caller_file), str(ll_file), loglevel=loglevel) and success
|
||||
)
|
||||
|
||||
success = bool(
|
||||
@ -174,7 +156,7 @@ def BPF(loglevel=logging.WARNING) -> BpfProgram:
|
||||
caller_frame = inspect.stack()[1]
|
||||
src = inspect.getsource(caller_frame.frame)
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w+", delete=True, suffix=".py"
|
||||
mode="w+", delete=True, suffix=".py"
|
||||
) as f, tempfile.NamedTemporaryFile(
|
||||
mode="w+", delete=True, suffix=".ll"
|
||||
) as inter, tempfile.NamedTemporaryFile(
|
||||
|
||||
Reference in New Issue
Block a user