Skip to content

Commit

Permalink
libdrgn: better error reporting of unsupported libkdumpfile format
Browse files Browse the repository at this point in the history
Return DRGN_ERROR_INVALID_ARGUMENT with a reasonable error message if
libkdumpfile cannot open a file.

The error output currently looks something like:

Traceback (most recent call last):
  File "/research/bin/drgn", line 33, in <module>
    sys.exit(load_entry_point('drgn', 'console_scripts', 'drgn')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/research/src/drgn/drgn/cli.py", line 264, in _main
    prog.set_core_dump(args.core)
Exception: kdump_set_number_attr(KDUMP_ATTR_FILE_FD): File #0: Unknown file format

Replace it with this:

error: file #0: Unknown file format

This is similar to the error message when trying to open a file that is
neither KDUMP nor ELF:

error: not an ELF core file

Signed-off-by: Petr Tesarik <[email protected]>
  • Loading branch information
ptesarik authored and osandov committed Nov 29, 2023
1 parent 3cda725 commit 4054a68
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libdrgn/kdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ struct drgn_error *drgn_program_set_kdump(struct drgn_program *prog)
}

ks = kdump_set_number_attr(ctx, KDUMP_ATTR_FILE_FD, prog->core_fd);
if (ks == KDUMP_ERR_NOTIMPL) {
err = drgn_error_format(DRGN_ERROR_INVALID_ARGUMENT,
"%s", kdump_get_err(ctx));
goto err;
}
if (ks != KDUMP_OK) {
err = drgn_error_format(DRGN_ERROR_OTHER,
"kdump_set_number_attr(KDUMP_ATTR_FILE_FD): %s",
Expand Down

0 comments on commit 4054a68

Please sign in to comment.