Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 #
0003 # Copyright 2019 Google LLC.
0004 
0005 import gdb
0006 import zlib
0007 
0008 from linux import utils
0009 
0010 
0011 class LxConfigDump(gdb.Command):
0012     """Output kernel config to the filename specified as the command
0013        argument. Equivalent to 'zcat /proc/config.gz > config.txt' on
0014        a running target"""
0015 
0016     def __init__(self):
0017         super(LxConfigDump, self).__init__("lx-configdump", gdb.COMMAND_DATA,
0018                                            gdb.COMPLETE_FILENAME)
0019 
0020     def invoke(self, arg, from_tty):
0021         if len(arg) == 0:
0022             filename = "config.txt"
0023         else:
0024             filename = arg
0025 
0026         try:
0027             py_config_ptr = gdb.parse_and_eval("&kernel_config_data")
0028             py_config_ptr_end = gdb.parse_and_eval("&kernel_config_data_end")
0029             py_config_size = py_config_ptr_end - py_config_ptr
0030         except gdb.error as e:
0031             raise gdb.GdbError("Can't find config, enable CONFIG_IKCONFIG?")
0032 
0033         inf = gdb.inferiors()[0]
0034         zconfig_buf = utils.read_memoryview(inf, py_config_ptr,
0035                                             py_config_size).tobytes()
0036 
0037         config_buf = zlib.decompress(zconfig_buf, 16)
0038         with open(filename, 'wb') as f:
0039             f.write(config_buf)
0040 
0041         gdb.write("Dumped config to " + filename + "\n")
0042 
0043 
0044 LxConfigDump()