88
99
1010class DebugInfoGenerator :
11+ """
12+ Generator for DWARF/BTF debug information in LLVM IR modules.
13+
14+ This class provides methods to create debug metadata for BPF programs,
15+ including types, structs, globals, and compilation units.
16+ """
17+
1118 def __init__ (self , module ):
19+ """
20+ Initialize the debug info generator.
21+
22+ Args:
23+ module: LLVM IR module to attach debug info to
24+ """
1225 self .module = module
1326 self ._type_cache = {} # Cache for common debug types
1427
1528 def generate_file_metadata (self , filename , dirname ):
29+ """
30+ Generate file metadata for debug info.
31+
32+ Args:
33+ filename: Name of the source file
34+ dirname: Directory containing the source file
35+ """
1636 self .module ._file_metadata = self .module .add_debug_info (
1737 "DIFile" ,
1838 { # type: ignore
@@ -24,6 +44,15 @@ def generate_file_metadata(self, filename, dirname):
2444 def generate_debug_cu (
2545 self , language , producer : str , is_optimized : bool , is_distinct : bool
2646 ):
47+ """
48+ Generate debug compile unit metadata.
49+
50+ Args:
51+ language: DWARF language code (e.g., DW_LANG_C11)
52+ producer: Compiler/producer string
53+ is_optimized: Whether the code is optimized
54+ is_distinct: Whether the compile unit should be distinct
55+ """
2756 self .module ._debug_compile_unit = self .module .add_debug_info (
2857 "DICompileUnit" ,
2958 { # type: ignore
@@ -83,6 +112,16 @@ def create_array_type(self, base_type: Any, count: int) -> Any:
83112
84113 @staticmethod
85114 def _compute_array_size (base_type : Any , count : int ) -> int :
115+ """
116+ Compute the size of an array in bits.
117+
118+ Args:
119+ base_type: The base type of the array
120+ count: Number of elements in the array
121+
122+ Returns:
123+ Total size in bits
124+ """
86125 # Extract size from base_type if possible
87126 # For simplicity, assuming base_type has a size attribute
88127 return getattr (base_type , "size" , 32 ) * count
0 commit comments