Skip to content

Commit 423d2cd

Browse files
committed
libdrgn: dwarf_index: rework file reporting
Currently, the interface between the DWARF index, libdwfl, and the code which finds and reports vmlinux/kernel modules is spaghetti. The DWARF index tracks Dwfl_Modules via their userdata. However, despite conceptually being owned by the DWARF index, the reporting code reports the Dwfl_Modules and sets up the userdata. These Dwfl_Modules and drgn_dwfl_module_userdatas are messy to track and pass between the layers. This reworks the architecture so that the DWARF index owns the Dwfl instance and files are reported to the DWARF index; the DWARF index takes care of reporting to libdwfl internally. In addition to making the interface for the reporter much cleaner, this improves a few things as a side-effect: - We now deduplicate on build ID in addition to path. - We now skip searching for vmlinux and/or kernel modules if they were already indexed. - We now support compressed ELF files via libdwelf. - We can now load default debug info at the same time as additional debug info.
1 parent 91265c3 commit 423d2cd

14 files changed

+1832
-1144
lines changed

docs/api_reference.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -266,33 +266,33 @@ Programs
266266

267267
:param int pid: Process ID.
268268

269-
.. method:: load_debug_info(paths)
269+
.. method:: load_debug_info(paths, default=False)
270270

271271
Load debugging information for a list of executable or library files.
272272

273-
If an error is encountered while loading any file, no new debugging
274-
information is loaded.
275-
276273
Note that this is parallelized, so it is usually faster to load
277274
multiple files at once rather than one by one.
278275

279276
:param paths: Paths of binary files.
280277
:type paths: Iterable[str, bytes, or os.PathLike]
278+
:param bool default: Also load debugging information which can
279+
automatically be determined from the program.
280+
281+
For the Linux kernel, this tries to load ``vmlinux`` and any loaded
282+
kernel modules from a few standard locations.
283+
284+
For userspace programs, this tries to load the executable and any
285+
loaded libraries.
286+
:raises MissingDebugInfoError: if debugging information was not
287+
available for some files; other files with debugging information
288+
are still loaded
281289

282290
.. method:: load_default_debug_info()
283291

284292
Load debugging information which can automatically be determined from
285293
the program.
286294

287-
For the Linux kernel, this tries to load ``vmlinux`` and any loaded
288-
kernel modules from a few standard locations.
289-
290-
For userspace programs, this tries to load the executable and any
291-
loaded libraries.
292-
293-
:raises MissingDebugInfoError: if debugging information was not
294-
available for some files; other files with debugging information
295-
are still loaded if this is raised
295+
This is equivalent to ``load_debug_info([], True)``.
296296

297297
.. attribute:: cache
298298

drgn/internal/cli.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,11 @@ def main() -> None:
8585
prog.set_pid(args.pid or os.getpid())
8686
else:
8787
prog.set_kernel()
88-
if args.default_symbols:
89-
try:
90-
prog.load_default_debug_info()
91-
except drgn.MissingDebugInfoError as e:
92-
if not args.quiet:
93-
print(str(e), file=sys.stderr)
94-
if args.symbols:
95-
try:
96-
prog.load_debug_info(args.symbols)
97-
except (drgn.MissingDebugInfoError, OSError) as e:
98-
if not args.quiet:
99-
print(e, file=sys.stderr)
88+
try:
89+
prog.load_debug_info(args.symbols or [], args.default_symbols)
90+
except drgn.MissingDebugInfoError as e:
91+
if not args.quiet:
92+
print(str(e), file=sys.stderr)
10093

10194
init_globals: Dict[str, Any] = {'prog': prog}
10295
if args.script:

libdrgn/drgn.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,16 +1117,15 @@ struct drgn_error *drgn_program_set_kernel(struct drgn_program *prog);
11171117
*/
11181118
struct drgn_error *drgn_program_set_pid(struct drgn_program *prog, pid_t pid);
11191119

1120-
/** Load debugging information for a list of executable or library files. */
1121-
struct drgn_error *drgn_program_load_debug_info(struct drgn_program *prog,
1122-
const char **paths, size_t n);
1123-
11241120
/**
1125-
* Load debugging information which can automatically be determined from the
1126-
* program.
1121+
* Load debugging information for a list of executable or library files.
1122+
*
1123+
* @param[in] load_default Whether to also load debugging information which can
1124+
* automatically be determined from the program.
11271125
*/
1128-
struct drgn_error *
1129-
drgn_program_load_default_debug_info(struct drgn_program *prog);
1126+
struct drgn_error *drgn_program_load_debug_info(struct drgn_program *prog,
1127+
const char **paths, size_t n,
1128+
bool load_default);
11301129

11311130
/**
11321131
* Create a @ref drgn_program from a core dump file.

0 commit comments

Comments
 (0)