Skip to content

Commit 3bf85e7

Browse files
add DI subprogram to make CO-RE work fully.
1 parent 73f7c80 commit 3bf85e7

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

pythonbpf/debuginfo/debug_info_generator.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,44 @@ def add_scope_to_local_variable(self, local_variable_debug_info, scope_value):
222222
"""
223223
Add scope information to an existing local variable debug info object.
224224
"""
225-
#TODO: this is a workaround a flaw in the debug info generation. Fix this if possible in the future.
225+
# TODO: this is a workaround a flaw in the debug info generation. Fix this if possible in the future.
226226
# We should not be touching llvmlite's internals like this.
227-
if hasattr(local_variable_debug_info, 'operands'):
227+
if hasattr(local_variable_debug_info, "operands"):
228228
# LLVM metadata operands is a tuple, so we need to rebuild it
229229
existing_operands = local_variable_debug_info.operands
230230

231231
# Convert tuple to list, add scope, convert back to tuple
232232
operands_list = list(existing_operands)
233-
operands_list.append(('scope', scope_value))
233+
operands_list.append(("scope", scope_value))
234234

235235
# Reassign the new tuple
236-
local_variable_debug_info.operands = tuple(operands_list)
236+
local_variable_debug_info.operands = tuple(operands_list)
237+
238+
def create_subprogram(
239+
self, name: str, subroutine_type: Any, retained_nodes: List[Any]
240+
) -> Any:
241+
"""
242+
Create a DISubprogram for a function.
243+
244+
Args:
245+
name: Function name
246+
subroutine_type: DISubroutineType for the function signature
247+
retained_nodes: List of DILocalVariable nodes for function parameters/variables
248+
249+
Returns:
250+
DISubprogram metadata
251+
"""
252+
return self.module.add_debug_info(
253+
"DISubprogram",
254+
{
255+
"name": name,
256+
"scope": self.module._file_metadata,
257+
"file": self.module._file_metadata,
258+
"type": subroutine_type,
259+
# "flags": dc.DW_FLAG_Prototyped | dc.DW_FLAG_AllCallsDescribed,
260+
# "spFlags": dc.DW_SPFLAG_Definition | dc.DW_SPFLAG_Optimized,
261+
"unit": self.module._debug_compile_unit,
262+
"retainedNodes": retained_nodes,
263+
},
264+
is_distinct=True,
265+
)

pythonbpf/functions/function_debug_info.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ def generate_function_debug_info(
5858
context_local_variable = generator.create_local_variable_debug_info(
5959
leading_argument_name, 1, pointer_to_context_debug_info
6060
)
61+
retained_nodes = [context_local_variable]
62+
print("function name", func_node.name)
63+
subprogram_debug_info = generator.create_subprogram(
64+
func_node.name, subroutine_type, retained_nodes
65+
)
66+
generator.add_scope_to_local_variable(
67+
context_local_variable, subprogram_debug_info
68+
)
69+
func.set_metadata("dbg", subprogram_debug_info)
6170

62-
# following is just a test.
63-
generator.add_scope_to_local_variable(context_local_variable, module._file_metadata)
64-
print(context_local_variable)
6571
else:
6672
logger.error(f"Invalid annotation type for argument '{leading_argument_name}'")

0 commit comments

Comments
 (0)