lkml.org 
[lkml]   [2013]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 12/20] scripts/gdb: Add helper and convenience function to look up tasks
Date
Add the helper task_by_pid that can look up a task by its PID. Also
export it as a convenience function.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
scripts/gdb/task.py | 29 +++++++++++++++++++++++++++++
scripts/gdb/vmlinux-gdb.py | 1 +
2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/scripts/gdb/task.py b/scripts/gdb/task.py
index 6b73dbf..fe42eb0 100644
--- a/scripts/gdb/task.py
+++ b/scripts/gdb/task.py
@@ -33,3 +33,32 @@ def for_each_task(func, arg = None):
task_ptr_type, "thread_group")
if t == g:
break
+
+def get_task_by_pid(pid):
+ def match_pid(t, arg):
+ if int(t['pid']) == arg['pid']:
+ arg['task'] = t
+
+ arg = { 'pid': pid, 'task': None }
+ for_each_task(match_pid, arg)
+
+ return arg['task']
+
+
+class LxTaskByPidFunc(gdb.Function):
+ __doc__ = "Find Linux task by PID and return the task_struct variable.\n" \
+ "\n" \
+ "$lx_task_by_pid(PID): Given PID, iterate over all tasks of the target and\n" \
+ "return that task_struct variable which PID matches."
+
+ def __init__(self):
+ super(LxTaskByPidFunc, self).__init__("lx_task_by_pid")
+
+ def invoke(self, pid):
+ task = get_task_by_pid(pid)
+ if task:
+ return task.dereference()
+ else:
+ raise gdb.GdbError("No task of PID " + str(pid))
+
+LxTaskByPidFunc()
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py
index 4a5685b..e1c5dbc 100644
--- a/scripts/gdb/vmlinux-gdb.py
+++ b/scripts/gdb/vmlinux-gdb.py
@@ -25,3 +25,4 @@ else:
import symbols
import module
import dmesg
+ import task
--
1.7.3.4


\
 
 \ /
  Last update: 2013-01-29 15:21    [W:0.151 / U:0.112 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site