mmap #8

Merged
mathieu merged 22 commits from mmap into master 2024-02-11 15:29:59 +01:00
Showing only changes of commit b352eab798 - Show all commits

View File

@ -184,18 +184,19 @@ class ListDumpCmd(gdb.Command):
"list_dump", gdb.COMMAND_USER
)
def _print_list(self, val):
def _print_list(self, val, next_name):
"""Walk through the linked list.
We will simply follow the 'next' pointers until we encounter the HEAD again
"""
idx = 0
head = val
thread_ptr = val
result = ""
while thread_ptr != 0 and (idx == 0 or thread_ptr != head):
result += gdb.execute('p *({}){}'.format(str(thread_ptr.type),thread_ptr), to_string=True)
thread_ptr = thread_ptr["next"]
result += gdb.execute('p *({}){}'.format(str(thread_ptr.type),
thread_ptr), to_string=True)
thread_ptr = thread_ptr[next_name]
idx += 1
result = ("Found a Linked List with %d items:" % idx) + "\n" + result
return result
@ -209,17 +210,21 @@ class ListDumpCmd(gdb.Command):
# We can pass args here and use Python CLI utilities like argparse
# to do argument parsing
print("Args Passed: %s" % args)
if args:
ptr_val = gdb.parse_and_eval(args)
else:
ptr_val = gdb.parse_and_eval("currentThread")
thread_name = "currentThread"
next_name = "next"
if(args):
args_arr = args.split()
thread_name = args_arr[0]
if(len(args_arr) >= 2):
next_name = args_arr[1]
ptr_val = gdb.parse_and_eval(thread_name)
try:
ptr_val["next"]
ptr_val[next_name]
except:
print("Expected pointer argument with a next field")
print("Expected pointer argument with a %s field" % next_name)
return
print(self._print_list(ptr_val))
print(self._print_list(ptr_val, next_name))
register_pretty_printer(None, CustomPrettyPrinterLocator(), replace=True)