@@ -345,7 +345,9 @@ def _get_debuginfo_paths(
345
345
return paths
346
346
347
347
348
- def _find_debuginfo (paths : List [Path ], mod : str ) -> Optional [Path ]:
348
+ def _find_debuginfo (
349
+ prog_or_release : Union ["Program" , str ], paths : List [Path ], mod : str
350
+ ) -> Optional [Path ]:
349
351
replace_pat = re .compile (r"[_-]" )
350
352
for search_dir in paths :
351
353
if "lib/modules" in str (search_dir ) and mod != "vmlinux" :
@@ -379,6 +381,32 @@ def _find_debuginfo(paths: List[Path], mod: str) -> Optional[Path]:
379
381
candidate = search_dir / f"{ name_alt } { ext } "
380
382
if candidate .exists ():
381
383
return candidate
384
+
385
+ if mod == "vmlinux" :
386
+ # On some distributions (e.g., Ubuntu), vmlinux may not reside in the modules directory.
387
+ # Search common locations for vmlinux, as referenced in:
388
+ # https://github.com/anakryiko/retsnoop/blob/389e2c9ddfc686ee048b063ce0c17b94b55398d2/src/retsnoop.c#L59-L67
389
+
390
+ if isinstance (prog_or_release , str ):
391
+ release = prog_or_release
392
+ else :
393
+ # Assume to be a program, without explicitly using the name
394
+ prog = prog_or_release
395
+ release = prog ["UTS_RELEASE" ].string_ ().decode ()
396
+
397
+ locations = [
398
+ f"/boot/vmlinux-{ release } " ,
399
+ f"/lib/modules/{ release } /vmlinux-{ release } " ,
400
+ f"/lib/modules/{ release } /build/vmlinux" ,
401
+ f"/usr/lib/modules/{ release } /kernel/vmlinux" ,
402
+ f"/usr/lib/debug/boot/vmlinux-{ release } " ,
403
+ f"/usr/lib/debug/boot/vmlinux-{ release } .debug" ,
404
+ f"/usr/lib/debug/lib/modules/{ release } /vmlinux" ,
405
+ ]
406
+ for loc in locations :
407
+ if os .path .exists (loc ):
408
+ return Path (loc )
409
+
382
410
return None
383
411
384
412
@@ -428,7 +456,7 @@ def find_debuginfo(
428
456
if dinfo_path :
429
457
user_paths .append (dinfo_path )
430
458
paths = _get_debuginfo_paths (prog_or_release , dinfo_path = user_paths )
431
- return _find_debuginfo (paths , mod )
459
+ return _find_debuginfo (prog_or_release , paths , mod )
432
460
433
461
434
462
# Mapping of kernel version (without release) to the UEK major version. The
0 commit comments