Skip to content

Commit 7083f47

Browse files
committed
module_has_debuginfo: avoid heuristic for DWARF
The heuristic approach for detecting whether DWARF debuginfo is loaded for kernel modules proved to be even less reliable than previously expected. For instance, on some kernel versions, over half of kernel modules are wrongly detected as "missing" debuginfo. To avoid this causing problems in corelens, let's add the less elegant, but obvious solution. Keep track of which modules we've loaded debuginfo, and consult this set first. Fall back to heuristic detection in case we did not record that we had loaded debuginfo. This is unlikely, given that the common use cases of drgn-tools (corelens and the CLI) both rely on the APIs here to load debuginfo. Orabug: 37894875 Signed-off-by: Stephen Brennan <[email protected]>
1 parent 516b7c5 commit 7083f47

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drgn_tools/module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ def module_has_debuginfo(module: Object) -> bool:
470470
"""
471471
if module.prog_.cache.get("using_ctf"):
472472
return True
473+
# The common case for DWARF is that we record which modules' debuginfo we
474+
# load as we do it. Then we can easily check the name in the cache.
475+
name = module.name.string_().decode().replace("-", "_")
476+
if name in module.prog_.cache.get("drgn-tools-loaded-mods", set()):
477+
return True
478+
# Otherwise, fallback to a heuristic. TODO: drgn 0.0.31 use the module API
479+
# for this.
473480
addrs = _first_kallsyms_symbols(module, 5)
474481
for addr in addrs:
475482
try:
@@ -883,6 +890,7 @@ def load_debuginfo(
883890
info = fetch_debuginfo(release, [name]).get(name)
884891
if info:
885892
self.obj.prog_.load_debug_info([info])
893+
self.obj.prog_.cache.setdefault("drgn-tools-loaded-mods", set()).add(name)
886894
else:
887895
raise FileNotFoundError("Could not find debuginfo for module")
888896

@@ -1107,6 +1115,7 @@ def load_module_debuginfo(
11071115
)
11081116

11091117
prog.load_debug_info(to_load)
1118+
prog.cache.setdefault("drgn-tools-loaded-mods", set()).update(found_set)
11101119

11111120

11121121
def ensure_debuginfo(prog: Program, modules: List[str]) -> Optional[str]:

0 commit comments

Comments
 (0)