diff options
Diffstat (limited to 'scripts/gdb/linux/tasks.py')
-rw-r--r-- | scripts/gdb/linux/tasks.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/gdb/linux/tasks.py b/scripts/gdb/linux/tasks.py index cd259846ab4b..13bb97cd3312 100644 --- a/scripts/gdb/linux/tasks.py +++ b/scripts/gdb/linux/tasks.py | |||
@@ -44,3 +44,30 @@ class TaskList: | |||
44 | utils.container_of(t['thread_group']['next'], | 44 | utils.container_of(t['thread_group']['next'], |
45 | self.task_ptr_type, "thread_group") | 45 | self.task_ptr_type, "thread_group") |
46 | return t | 46 | return t |
47 | |||
48 | |||
49 | def get_task_by_pid(pid): | ||
50 | for task in TaskList(): | ||
51 | if int(task['pid']) == pid: | ||
52 | return task | ||
53 | return None | ||
54 | |||
55 | |||
56 | class LxTaskByPidFunc(gdb.Function): | ||
57 | """Find Linux task by PID and return the task_struct variable. | ||
58 | |||
59 | $lx_task_by_pid(PID): Given PID, iterate over all tasks of the target and | ||
60 | return that task_struct variable which PID matches.""" | ||
61 | |||
62 | def __init__(self): | ||
63 | super(LxTaskByPidFunc, self).__init__("lx_task_by_pid") | ||
64 | |||
65 | def invoke(self, pid): | ||
66 | task = get_task_by_pid(pid) | ||
67 | if task: | ||
68 | return task.dereference() | ||
69 | else: | ||
70 | raise gdb.GdbError("No task of PID " + str(pid)) | ||
71 | |||
72 | |||
73 | LxTaskByPidFunc() | ||