mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
format chore and pre commit hook addition
This commit is contained in:
@ -4,7 +4,7 @@ Provides utilities for generating DWARF/BTF debug information
|
||||
"""
|
||||
|
||||
from . import dwarf_constants as dc
|
||||
from typing import Dict, Any, List, Optional, Union
|
||||
from typing import Any, List
|
||||
|
||||
|
||||
class DebugInfoGenerator:
|
||||
@ -16,11 +16,9 @@ class DebugInfoGenerator:
|
||||
"""Get or create a basic type with caching"""
|
||||
key = (name, size, encoding)
|
||||
if key not in self._type_cache:
|
||||
self._type_cache[key] = self.module.add_debug_info("DIBasicType", {
|
||||
"name": name,
|
||||
"size": size,
|
||||
"encoding": encoding
|
||||
})
|
||||
self._type_cache[key] = self.module.add_debug_info(
|
||||
"DIBasicType", {"name": name, "size": size, "encoding": encoding}
|
||||
)
|
||||
return self._type_cache[key]
|
||||
|
||||
def get_uint32_type(self) -> Any:
|
||||
@ -33,21 +31,23 @@ class DebugInfoGenerator:
|
||||
|
||||
def create_pointer_type(self, base_type: Any, size: int = 64) -> Any:
|
||||
"""Create a pointer type to the given base type"""
|
||||
return self.module.add_debug_info("DIDerivedType", {
|
||||
"tag": dc.DW_TAG_pointer_type,
|
||||
"baseType": base_type,
|
||||
"size": size
|
||||
})
|
||||
return self.module.add_debug_info(
|
||||
"DIDerivedType",
|
||||
{"tag": dc.DW_TAG_pointer_type, "baseType": base_type, "size": size},
|
||||
)
|
||||
|
||||
def create_array_type(self, base_type: Any, count: int) -> Any:
|
||||
"""Create an array type of the given base type with specified count"""
|
||||
subrange = self.module.add_debug_info("DISubrange", {"count": count})
|
||||
return self.module.add_debug_info("DICompositeType", {
|
||||
"tag": dc.DW_TAG_array_type,
|
||||
"baseType": base_type,
|
||||
"size": self._compute_array_size(base_type, count),
|
||||
"elements": [subrange]
|
||||
})
|
||||
return self.module.add_debug_info(
|
||||
"DICompositeType",
|
||||
{
|
||||
"tag": dc.DW_TAG_array_type,
|
||||
"baseType": base_type,
|
||||
"size": self._compute_array_size(base_type, count),
|
||||
"elements": [subrange],
|
||||
},
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _compute_array_size(base_type: Any, count: int) -> int:
|
||||
@ -57,36 +57,51 @@ class DebugInfoGenerator:
|
||||
|
||||
def create_struct_member(self, name: str, base_type: Any, offset: int) -> Any:
|
||||
"""Create a struct member with the given name, type, and offset"""
|
||||
return self.module.add_debug_info("DIDerivedType", {
|
||||
"tag": dc.DW_TAG_member,
|
||||
"name": name,
|
||||
"file": self.module._file_metadata,
|
||||
"baseType": base_type,
|
||||
"size": getattr(base_type, "size", 64),
|
||||
"offset": offset
|
||||
})
|
||||
return self.module.add_debug_info(
|
||||
"DIDerivedType",
|
||||
{
|
||||
"tag": dc.DW_TAG_member,
|
||||
"name": name,
|
||||
"file": self.module._file_metadata,
|
||||
"baseType": base_type,
|
||||
"size": getattr(base_type, "size", 64),
|
||||
"offset": offset,
|
||||
},
|
||||
)
|
||||
|
||||
def create_struct_type(self, members: List[Any], size: int, is_distinct: bool) -> Any:
|
||||
def create_struct_type(
|
||||
self, members: List[Any], size: int, is_distinct: bool
|
||||
) -> Any:
|
||||
"""Create a struct type with the given members and size"""
|
||||
return self.module.add_debug_info("DICompositeType", {
|
||||
"tag": dc.DW_TAG_structure_type,
|
||||
"file": self.module._file_metadata,
|
||||
"size": size,
|
||||
"elements": members,
|
||||
}, is_distinct=is_distinct)
|
||||
return self.module.add_debug_info(
|
||||
"DICompositeType",
|
||||
{
|
||||
"tag": dc.DW_TAG_structure_type,
|
||||
"file": self.module._file_metadata,
|
||||
"size": size,
|
||||
"elements": members,
|
||||
},
|
||||
is_distinct=is_distinct,
|
||||
)
|
||||
|
||||
def create_global_var_debug_info(self, name: str, var_type: Any, is_local: bool = False) -> Any:
|
||||
def create_global_var_debug_info(
|
||||
self, name: str, var_type: Any, is_local: bool = False
|
||||
) -> Any:
|
||||
"""Create debug info for a global variable"""
|
||||
global_var = self.module.add_debug_info("DIGlobalVariable", {
|
||||
"name": name,
|
||||
"scope": self.module._debug_compile_unit,
|
||||
"file": self.module._file_metadata,
|
||||
"type": var_type,
|
||||
"isLocal": is_local,
|
||||
"isDefinition": True
|
||||
}, is_distinct=True)
|
||||
global_var = self.module.add_debug_info(
|
||||
"DIGlobalVariable",
|
||||
{
|
||||
"name": name,
|
||||
"scope": self.module._debug_compile_unit,
|
||||
"file": self.module._file_metadata,
|
||||
"type": var_type,
|
||||
"isLocal": is_local,
|
||||
"isDefinition": True,
|
||||
},
|
||||
is_distinct=True,
|
||||
)
|
||||
|
||||
return self.module.add_debug_info("DIGlobalVariableExpression", {
|
||||
"var": global_var,
|
||||
"expr": self.module.add_debug_info("DIExpression", {})
|
||||
})
|
||||
return self.module.add_debug_info(
|
||||
"DIGlobalVariableExpression",
|
||||
{"var": global_var, "expr": self.module.add_debug_info("DIExpression", {})},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user