History

scripts/gdb: add io resource readers

Provide iomem_resource and ioports_resource printers and command hooks It can be quite interesting to halt the kernel as it's booting and check to see this list as it is being populated. It should be useful in the event that a kernel is not booting, you can identify what memory resources have been registered

Kieran Bingham committed 10 years ago

Commit e7165a21 parent 74627cf1 file · +57 −0Browse files

Unified · Split

scripts/gdb/linux/proc.py+57−0
@@ -39,3 +39,60 @@ class LxVersion(gdb.Command): · 38 unmodified lines
3939 gdb.write(gdb.parse_and_eval("linux_banner").string())
4040
4141 LxVersion()
42+
43+
44+# Resource Structure Printers
45+# /proc/iomem
46+# /proc/ioports
47+
48+def get_resources(resource, depth):
49+ while resource:
50+ yield resource, depth
51+
52+ child = resource['child']
53+ if child:
54+ for res, deep in get_resources(child, depth + 1):
55+ yield res, deep
56+
57+ resource = resource['sibling']
58+
59+
60+def show_lx_resources(resource_str):
61+ resource = gdb.parse_and_eval(resource_str)
62+ width = 4 if resource['end'] < 0x10000 else 8
63+ # Iterate straight to the first child
64+ for res, depth in get_resources(resource['child'], 0):
65+ start = int(res['start'])
66+ end = int(res['end'])
67+ gdb.write(" " * depth * 2 +
68+ "{0:0{1}x}-".format(start, width) +
69+ "{0:0{1}x} : ".format(end, width) +
70+ res['name'].string() + "\n")
71+
72+
73+class LxIOMem(gdb.Command):
74+ """Identify the IO memory resource locations defined by the kernel
75+
76+Equivalent to cat /proc/iomem on a running target"""
77+
78+ def __init__(self):
79+ super(LxIOMem, self).__init__("lx-iomem", gdb.COMMAND_DATA)
80+
81+ def invoke(self, arg, from_tty):
82+ return show_lx_resources("iomem_resource")
83+
84+LxIOMem()
85+
86+
87+class LxIOPorts(gdb.Command):
88+ """Identify the IO port resource locations defined by the kernel
89+
90+Equivalent to cat /proc/ioports on a running target"""
91+
92+ def __init__(self):
93+ super(LxIOPorts, self).__init__("lx-ioports", gdb.COMMAND_DATA)
94+
95+ def invoke(self, arg, from_tty):
96+ return show_lx_resources("ioport_resource")
97+
98+LxIOPorts()