config.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # SPDX-License-Identifier: GPL-2.0
  2. #
  3. # Copyright 2019 Google LLC.
  4. import gdb
  5. import zlib
  6. from linux import utils
  7. class LxConfigDump(gdb.Command):
  8. """Output kernel config to the filename specified as the command
  9. argument. Equivalent to 'zcat /proc/config.gz > config.txt' on
  10. a running target"""
  11. def __init__(self):
  12. super(LxConfigDump, self).__init__("lx-configdump", gdb.COMMAND_DATA,
  13. gdb.COMPLETE_FILENAME)
  14. def invoke(self, arg, from_tty):
  15. if len(arg) == 0:
  16. filename = "config.txt"
  17. else:
  18. filename = arg
  19. try:
  20. py_config_ptr = gdb.parse_and_eval("&kernel_config_data")
  21. py_config_ptr_end = gdb.parse_and_eval("&kernel_config_data_end")
  22. py_config_size = py_config_ptr_end - py_config_ptr
  23. except gdb.error as e:
  24. raise gdb.GdbError("Can't find config, enable CONFIG_IKCONFIG?")
  25. inf = gdb.inferiors()[0]
  26. zconfig_buf = utils.read_memoryview(inf, py_config_ptr,
  27. py_config_size).tobytes()
  28. config_buf = zlib.decompress(zconfig_buf, 16)
  29. with open(filename, 'wb') as f:
  30. f.write(config_buf)
  31. gdb.write("Dumped config to " + filename + "\n")
  32. LxConfigDump()