drgn.helpers.linux.kconfig: clean up exception if CONFIG_IKCONFIG=n

get_kconfig() on a system with CONFIG_IKCONFIG=n produces a traceback like
this:

  >>> get_kconfig(prog)
  Traceback (most recent call last):
    File "/home/osandov/repos/drgn/drgn/helpers/linux/kconfig.py", line 40, in get_kconfig
      start = prog.symbol("kernel_config_data").address
  LookupError: could not find symbol with name 'kernel_config_data'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/home/osandov/repos/drgn/drgn/helpers/linux/kconfig.py", line 47, in get_kconfig
      kernel_config_data = prog["kernel_config_data"]
  KeyError: 'kernel_config_data'

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "<console>", line 1, in <module>
    File "/home/osandov/repos/drgn/drgn/helpers/linux/kconfig.py", line 49, in get_kconfig
      raise LookupError(
  LookupError: kernel configuration data not found; kernel must be compiled with CONFIG_IKCONFIG

The original exceptions are unnecessary noise; use raise ... from None to
suppress them so that it looks like this instead:

  >>> get_kconfig(prog)
  Traceback (most recent call last):
    File "<console>", line 1, in <module>
    File "/home/osandov/repos/drgn/drgn/helpers/linux/kconfig.py", line 49, in get_kconfig
      raise LookupError(
  LookupError: kernel configuration data not found; kernel must be compiled with CONFIG_IKCONFIG

Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2022-10-18 16:25:14 -07:00
parent e6f1aa563f
commit 72f1db7968

View File

@ -48,7 +48,7 @@ def get_kconfig(prog: Program) -> Mapping[str, str]:
except KeyError:
raise LookupError(
"kernel configuration data not found; kernel must be compiled with CONFIG_IKCONFIG"
)
) from None
# The data is delimited by the magic strings "IKCFG_ST" and "IKCFG_ED"
# plus a NUL byte.
start = kernel_config_data.address_ + 8 # type: ignore[operator]