GDB: add cmd for Phy Mem state

This commit is contained in:
Mathieu Maret 2021-04-09 20:46:49 +02:00
parent 8c0c61c099
commit 1d1ed1ef60

View File

@ -60,7 +60,7 @@ class KthreadListDumpCmd(gdb.Command):
head = val
kthread_ptr = val
result = ""
while kthread_ptr != 0 and (idx == 0 or kthread_ptr != head) :
while kthread_ptr != 0 and (idx == 0 or kthread_ptr != head):
result += "\n%d: %s" % (idx, KthreadPrettyPrinter(kthread_ptr).to_string())
kthread_ptr = kthread_ptr["next"]
idx += 1
@ -86,6 +86,56 @@ class KthreadListDumpCmd(gdb.Command):
print(self._kthread_list_to_str(kthread_ptr_val))
class PhyMemDescListDumpCmd(gdb.Command):
"""Prints the memDesc list"""
def __init__(self):
super(PhyMemDescListDumpCmd, self).__init__(
"phyMem_list_dump", gdb.COMMAND_USER)
def _phy_memDesc_lit_to_str(self, val):
result = ""
idx = 0
head = val
memDesc_ptr = val
prevAddr = None
printBegin = True
memAddrs = []
while memDesc_ptr != 0 and (idx == 0 or memDesc_ptr != head):
memAddrs.append(int(memDesc_ptr["phy_addr"]))
memDesc_ptr = memDesc_ptr["next"]
idx += 1
memAddrs.sort()
for currAddr in memAddrs:
if printBegin:
prevAddr = currAddr
result += "[0x%x" % prevAddr
printBegin = False
if currAddr > prevAddr + 4096:
result += "->0x%x[\n[0x%x" % ((prevAddr+4096), currAddr)
prevAddr = currAddr
if prevAddr:
result += "->0x%x[\n" % (prevAddr+4096)
result = ("Found a List with %d memDesc:\n" % idx) + result
return result
def complete(self, text, word):
return gdb.COMPLETE_SYMBOL
def invoke(self, args, from_tty):
if args:
desc = gdb.parse_and_eval(args)
else:
desc = gdb.parse_and_eval("freePage")
if str(desc.type) != "struct memDesc *":
print("Expected pointer argument of type (struct memDesc *)")
return
print(self._phy_memDesc_lit_to_str(desc))
register_pretty_printer(None, CustomPrettyPrinterLocator(), replace=True)
KthreadListDumpCmd()
PhyMemDescListDumpCmd()