@@ -345,7 +345,9 @@ def _get_debuginfo_paths(
345345 return paths
346346
347347
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 ]:
349351 replace_pat = re .compile (r"[_-]" )
350352 for search_dir in paths :
351353 if "lib/modules" in str (search_dir ) and mod != "vmlinux" :
@@ -379,6 +381,32 @@ def _find_debuginfo(paths: List[Path], mod: str) -> Optional[Path]:
379381 candidate = search_dir / f"{ name_alt } { ext } "
380382 if candidate .exists ():
381383 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+
382410 return None
383411
384412
@@ -428,7 +456,7 @@ def find_debuginfo(
428456 if dinfo_path :
429457 user_paths .append (dinfo_path )
430458 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 )
432460
433461
434462# Mapping of kernel version (without release) to the UEK major version. The
0 commit comments