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 .maps import maps_proc
|
||||||
from .structs import structs_proc
|
from .structs import structs_proc
|
||||||
from .globals_pass import globals_processing
|
from .globals_pass import globals_processing
|
||||||
from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum
|
from .debuginfo import DW_LANG_C11, DwarfBehaviorEnum, DebugInfoGenerator
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import inspect
|
import inspect
|
||||||
@ -60,32 +60,14 @@ def compile_to_ir(filename: str, output: str, loglevel=logging.WARNING):
|
|||||||
module.triple = "bpf"
|
module.triple = "bpf"
|
||||||
|
|
||||||
if not hasattr(module, "_debug_compile_unit"):
|
if not hasattr(module, "_debug_compile_unit"):
|
||||||
module._file_metadata = module.add_debug_info(
|
debug_generator = DebugInfoGenerator(module)
|
||||||
"DIFile",
|
debug_generator.generate_file_metadata(filename, os.path.dirname(filename))
|
||||||
{ # type: ignore
|
debug_generator.generate_debug_cu(DW_LANG_C11,
|
||||||
"filename": filename,
|
f"PythonBPF {VERSION}",
|
||||||
"directory": os.path.dirname(filename),
|
True # TODO: This is probably not true
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
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
|
# 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.
|
# be required for kprobes.
|
||||||
"runtimeVersion": 0,
|
, True)
|
||||||
"emissionKind": 1,
|
|
||||||
"splitDebugInlining": False,
|
|
||||||
"nameTableKind": 0,
|
|
||||||
},
|
|
||||||
is_distinct=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
module.add_named_metadata("llvm.dbg.cu", module._debug_compile_unit) # type: ignore
|
|
||||||
|
|
||||||
processor(source, filename, module)
|
processor(source, filename, module)
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,32 @@ class DebugInfoGenerator:
|
|||||||
self.module = module
|
self.module = module
|
||||||
self._type_cache = {} # Cache for common debug types
|
self._type_cache = {} # Cache for common debug types
|
||||||
|
|
||||||
|
def generate_file_metadata(self, filename, dirname):
|
||||||
|
self.module._file_metadata = self.module.add_debug_info(
|
||||||
|
"DIFile",
|
||||||
|
{ # type: ignore
|
||||||
|
"filename": filename,
|
||||||
|
"directory": dirname,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def generate_debug_cu(self, language, producer: str, is_optimized: bool, is_distinct: bool):
|
||||||
|
self.module._debug_compile_unit = self.module.add_debug_info(
|
||||||
|
"DICompileUnit",
|
||||||
|
{ # type: ignore
|
||||||
|
"language": language,
|
||||||
|
"file": self.module._file_metadata, # type: ignore
|
||||||
|
"producer": producer,
|
||||||
|
"isOptimized": is_optimized,
|
||||||
|
"runtimeVersion": 0,
|
||||||
|
"emissionKind": 1,
|
||||||
|
"splitDebugInlining": False,
|
||||||
|
"nameTableKind": 0,
|
||||||
|
},
|
||||||
|
is_distinct=is_distinct,
|
||||||
|
)
|
||||||
|
self.module.add_named_metadata("llvm.dbg.cu", self.module._debug_compile_unit) # type: ignore
|
||||||
|
|
||||||
def get_basic_type(self, name: str, size: int, encoding: int) -> Any:
|
def get_basic_type(self, name: str, size: int, encoding: int) -> Any:
|
||||||
"""Get or create a basic type with caching"""
|
"""Get or create a basic type with caching"""
|
||||||
key = (name, size, encoding)
|
key = (name, size, encoding)
|
||||||
|
|||||||
Reference in New Issue
Block a user