From 1d1ed1ef60cd989aff6830dea31c9700582c6c5c Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Fri, 9 Apr 2021 20:46:49 +0200 Subject: [PATCH] GDB: add cmd for Phy Mem state --- custom_gdb_extension.py | 54 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/custom_gdb_extension.py b/custom_gdb_extension.py index 0341750..0c22a2d 100644 --- a/custom_gdb_extension.py +++ b/custom_gdb_extension.py @@ -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()