Skip to content

Commit e7165a2

Browse files
kbinghamtorvalds
authored andcommitted
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 Link: http://lkml.kernel.org/r/f0a6b9fa9c92af4d7ed2e7343ccc84150e9c6fc5.1462865983.git.jan.kiszka@siemens.com Signed-off-by: Kieran Bingham <kieran.bingham@linaro.org> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 74627cf commit e7165a2

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎scripts/gdb/linux/proc.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,60 @@ def invoke(self, arg, from_tty):
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()

0 commit comments

Comments
 (0)