Skip to content

Commit 516b7c5

Browse files
committed
Reduce false positives of module_has_debuginfo()
The module_has_debuginfo() function is heuristic and only checks the first symbol to see whether drgn knows of it. Let's increase this to the first 5 symbols (truly, just a magic number) which eliminates some observed false positives in the wild. I'm willing to do this somewhat scattershot approach beacuse we're not far from switching to drgn's new Module API. This will allow us to drop this heuristic function and just query the Module API for the status of the debuginfo file. Orabug: 37894875 Signed-off-by: Stephen Brennan <[email protected]>
1 parent 498e05f commit 516b7c5

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drgn_tools/module.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,13 @@ def module_symbols(module: Object) -> List[Tuple[str, Object]]:
450450
return syms
451451

452452

453-
def _first_kallsyms_symbol(module: Object) -> Optional[int]:
453+
def _first_kallsyms_symbols(module: Object, count: int) -> List[int]:
454454
try:
455455
ks = module.kallsyms
456456
except AttributeError:
457457
ks = module
458-
if ks.num_symtab >= 2:
459-
return int(ks.symtab[1].st_value)
460-
return None
458+
end = min(count + 1, ks.num_symtab)
459+
return [int(ks.symtab[i].st_value) for i in range(1, end)]
461460

462461

463462
def module_has_debuginfo(module: Object) -> bool:
@@ -471,14 +470,14 @@ def module_has_debuginfo(module: Object) -> bool:
471470
"""
472471
if module.prog_.cache.get("using_ctf"):
473472
return True
474-
fst = _first_kallsyms_symbol(module)
475-
if not fst:
476-
return False
477-
try:
478-
module.prog_.symbol(fst)
479-
return True
480-
except LookupError:
481-
return False
473+
addrs = _first_kallsyms_symbols(module, 5)
474+
for addr in addrs:
475+
try:
476+
module.prog_.symbol(addr)
477+
return True
478+
except LookupError:
479+
pass
480+
return False
482481

483482

484483
def _elf_sym_to_symbol(name: str, obj: Object) -> Symbol:

0 commit comments

Comments
 (0)