mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add DI subprogram to make CO-RE work fully.
This commit is contained in:
@ -222,15 +222,44 @@ class DebugInfoGenerator:
|
|||||||
"""
|
"""
|
||||||
Add scope information to an existing local variable debug info object.
|
Add scope information to an existing local variable debug info object.
|
||||||
"""
|
"""
|
||||||
#TODO: this is a workaround a flaw in the debug info generation. Fix this if possible in the future.
|
# TODO: this is a workaround a flaw in the debug info generation. Fix this if possible in the future.
|
||||||
# We should not be touching llvmlite's internals like this.
|
# We should not be touching llvmlite's internals like this.
|
||||||
if hasattr(local_variable_debug_info, 'operands'):
|
if hasattr(local_variable_debug_info, "operands"):
|
||||||
# LLVM metadata operands is a tuple, so we need to rebuild it
|
# LLVM metadata operands is a tuple, so we need to rebuild it
|
||||||
existing_operands = local_variable_debug_info.operands
|
existing_operands = local_variable_debug_info.operands
|
||||||
|
|
||||||
# Convert tuple to list, add scope, convert back to tuple
|
# Convert tuple to list, add scope, convert back to tuple
|
||||||
operands_list = list(existing_operands)
|
operands_list = list(existing_operands)
|
||||||
operands_list.append(('scope', scope_value))
|
operands_list.append(("scope", scope_value))
|
||||||
|
|
||||||
# Reassign the new tuple
|
# Reassign the new tuple
|
||||||
local_variable_debug_info.operands = tuple(operands_list)
|
local_variable_debug_info.operands = tuple(operands_list)
|
||||||
|
|
||||||
|
def create_subprogram(
|
||||||
|
self, name: str, subroutine_type: Any, retained_nodes: List[Any]
|
||||||
|
) -> Any:
|
||||||
|
"""
|
||||||
|
Create a DISubprogram for a function.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Function name
|
||||||
|
subroutine_type: DISubroutineType for the function signature
|
||||||
|
retained_nodes: List of DILocalVariable nodes for function parameters/variables
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
DISubprogram metadata
|
||||||
|
"""
|
||||||
|
return self.module.add_debug_info(
|
||||||
|
"DISubprogram",
|
||||||
|
{
|
||||||
|
"name": name,
|
||||||
|
"scope": self.module._file_metadata,
|
||||||
|
"file": self.module._file_metadata,
|
||||||
|
"type": subroutine_type,
|
||||||
|
# "flags": dc.DW_FLAG_Prototyped | dc.DW_FLAG_AllCallsDescribed,
|
||||||
|
# "spFlags": dc.DW_SPFLAG_Definition | dc.DW_SPFLAG_Optimized,
|
||||||
|
"unit": self.module._debug_compile_unit,
|
||||||
|
"retainedNodes": retained_nodes,
|
||||||
|
},
|
||||||
|
is_distinct=True,
|
||||||
|
)
|
||||||
|
|||||||
@ -58,9 +58,15 @@ def generate_function_debug_info(
|
|||||||
context_local_variable = generator.create_local_variable_debug_info(
|
context_local_variable = generator.create_local_variable_debug_info(
|
||||||
leading_argument_name, 1, pointer_to_context_debug_info
|
leading_argument_name, 1, pointer_to_context_debug_info
|
||||||
)
|
)
|
||||||
|
retained_nodes = [context_local_variable]
|
||||||
|
print("function name", func_node.name)
|
||||||
|
subprogram_debug_info = generator.create_subprogram(
|
||||||
|
func_node.name, subroutine_type, retained_nodes
|
||||||
|
)
|
||||||
|
generator.add_scope_to_local_variable(
|
||||||
|
context_local_variable, subprogram_debug_info
|
||||||
|
)
|
||||||
|
func.set_metadata("dbg", subprogram_debug_info)
|
||||||
|
|
||||||
# following is just a test.
|
|
||||||
generator.add_scope_to_local_variable(context_local_variable, module._file_metadata)
|
|
||||||
print(context_local_variable)
|
|
||||||
else:
|
else:
|
||||||
logger.error(f"Invalid annotation type for argument '{leading_argument_name}'")
|
logger.error(f"Invalid annotation type for argument '{leading_argument_name}'")
|
||||||
|
|||||||
Reference in New Issue
Block a user