Browse Source

Add gdb custom commands

master
Mathieu Maret 12 months ago
parent
commit
1f1f017224
  1. 44
      custom_gdb_extension.py
  2. 1
      debug.gdb

44
custom_gdb_extension.py

@ -0,0 +1,44 @@
class KthreadListDumpCmd(gdb.Command):
"""Prints the kthread list"""
def __init__(self):
super(KthreadListDumpCmd, self).__init__(
"kthread_list_dump", gdb.COMMAND_USER
)
def _kthread_list_to_str(self, val):
"""Walk through the Kthread list.
We will simply follow the 'next' pointers until we encounter the HEAD again
"""
idx = 0
head = val
kthread_ptr = val
result = ""
while kthread_ptr != 0 and (idx == 0 or kthread_ptr != head) :
name = kthread_ptr["name"]
result += "\n%d: Addr: 0x%x, name: %s" % (idx, kthread_ptr, name)
kthread_ptr = kthread_ptr["next"]
idx += 1
result = ("Found a Linked List with %d kthread:" % idx) + result
return result
def complete(self, text, word):
# We expect the argument passed to be a symbol so fallback to the
# internal tab-completion handler for symbols
return gdb.COMPLETE_SYMBOL
def invoke(self, args, from_tty):
# We can pass args here and use Python CLI utilities like argparse
# to do argument parsing
print("Args Passed: %s" % args)
kthread_ptr_val = gdb.parse_and_eval(args)
if str(kthread_ptr_val.type) != "struct kthread *":
print("Expected pointer argument of type (struct kthread *)")
return
print(self._kthread_list_to_str(kthread_ptr_val))
KthreadListDumpCmd()

1
debug.gdb

@ -1,2 +1,3 @@
add-symbol-file kernel.sym
source custom_gdb_extension.py
target remote | qemu-system-i386 -S -gdb stdio -kernel kernel
Loading…
Cancel
Save