3 Provide access to kernel_table data.
4 Copyright 2014 Cray Inc. All Rights Reserved
7 from pykdump.API import *
12 """Provide access to the crash kernel_table.
14 The data is collected by parsing the output of the 'help -k' command.
18 """Extract kernel data from crash.
20 Initialize the table of kernel information by parsing the output
21 of the 'help -k' command. This only extracts selected data.
23 Each item extracted is made available as an instance attribute.
26 # crash 'help -k' doesn't use prefixes on numbers, so we must
27 # know what number base is in use for each numeric field.
28 decFields = ('cpus', 'NR_CPUS', 'kernel_NR_CPUS')
30 hexFields = ('flags', 'stext', 'etext', 'stext_init', 'etext_init',
31 'init_begin', 'init_end', 'end', 'module_list', 'kernel_module')
33 expected_key_count = len(decFields) + len(hexFields)
35 for line in exec_crash_command('help -k').splitlines():
38 # (PER_CPU_OFF|SMP|KMOD_V2|KALLSYMS_V2|NO_DWARF_UNWIND|DWARF_UNWIND_MEMORY|DWARF_UNWIND_MODULES)
39 # stext: ffffffff810001f0
40 # etext: ffffffff813915b5
41 # stext_init: ffffffff8170b000
42 # etext_init: ffffffff81740b65
43 # init_begin: ffffffff816f9000
44 # init_end: ffffffff81796000
45 # end: ffffffff818cf000
47 # cpus_override: (null)
48 # NR_CPUS: 4096 (compiled-in to this version of crash)
50 # ikconfig_flags: 1 (IKCONFIG_AVAIL)
53 # highest_irq: (unused/undetermined)
54 # module_list: ffffffffa05c96e0
55 # kernel_module: ffffffff81684630
59 # Only use the first value after the field name and
60 # only for selected fields.
62 if len(parts) < 2: continue
63 key = parts[0].rstrip(':')
65 self.__dict__[key] = int(parts[1],10)
66 elif key in hexFields:
67 self.__dict__[key] = int(parts[1],16)
69 # If some versions of crash or the kernel don't have all the
70 # fields, this check code may need to be removed or modified.
71 if len(self.__dict__.keys()) != expected_key_count:
72 raise crashlib.cid.ParseError(
73 'Expected {:d}, but parsed {:d} entries.'.format(
74 expected_key_count, len(self.__dict__.keys())))
76 # --------------------------------------------------------------------------
78 # Create a shared instances.
80 crashlib.cid.krntbl = KernelInfo()