Skip to content

Commit 95a986e

Browse files
Core: Give each function its own context DILocalVariable
add_debug_info caches nodes by operands, so a second program with a same-named context of the same vmlinux type got the first one's variable, already scoped to the first function. Scoping it again made a metadata cycle that llvmlite recursed on forever.
1 parent d992493 commit 95a986e

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎pythonbpf/debuginfo/debug_info_generator.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
from . import dwarf_constants as dc
7+
from llvmlite.ir.values import DIValue
78
from typing import Any, List
89

910

@@ -227,14 +228,25 @@ def create_local_variable_debug_info(
227228
Example:
228229
!DILocalVariable(name: "ctx", arg: 1, file: !3, line: 20, type: !7)
229230
"""
230-
return self.module.add_debug_info(
231-
"DILocalVariable",
231+
# Not through add_debug_info, which returns a cached node for equal
232+
# operands: a second function with the same parameter name would get
233+
# the first one's node, already scoped to the first function by
234+
# add_scope_to_local_variable. Scoping it again makes a metadata cycle
235+
# that llvmlite recurses on forever when it hashes the next node.
236+
operands = self.module._fix_di_operands(
232237
{
233238
"name": name,
234239
"arg": arg,
235240
"file": self.module._file_metadata,
236241
"type": var_type,
237-
},
242+
}.items()
243+
)
244+
return DIValue(
245+
self.module,
246+
False,
247+
"DILocalVariable",
248+
sorted(operands),
249+
name=str(len(self.module.metadata)),
238250
)
239251

240252
def add_scope_to_local_variable(self, local_variable_debug_info, scope_value):

0 commit comments

Comments
 (0)