|
|
@ -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() |
|
|
|
|