diff options
| author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2015-02-17 16:47:41 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-17 17:34:54 -0500 |
| commit | 54e2289a34e13d956acb841a00c3a6f06aced3f9 (patch) | |
| tree | 3c5c97fca93b00e4e1e5d48494f321c1cd41c38d /scripts/gdb | |
| parent | 2478a8a15ccaddd68e84bb8791cd468f636673e9 (diff) | |
scripts/gdb: use a generator instead of iterator for task list
The iterator does not return any task_struct from the thread_group list
because the first condition in the 'if not t or ...' will only be the
first time None.
Instead of keeping track of the state ourself in the next() function, we
fall back using Python's generator.
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Ben Widawsky <ben@bwidawsk.net>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/gdb')
| -rw-r--r-- | scripts/gdb/linux/tasks.py | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/scripts/gdb/linux/tasks.py b/scripts/gdb/linux/tasks.py index 0008e75f1c4f..e2037d9bb7eb 100644 --- a/scripts/gdb/linux/tasks.py +++ b/scripts/gdb/linux/tasks.py | |||
| @@ -18,38 +18,28 @@ from linux import utils | |||
| 18 | 18 | ||
| 19 | task_type = utils.CachedType("struct task_struct") | 19 | task_type = utils.CachedType("struct task_struct") |
| 20 | 20 | ||
| 21 | 21 | def task_lists(): | |
| 22 | class TaskList: | 22 | global task_type |
| 23 | def __init__(self): | 23 | task_ptr_type = task_type.get_type().pointer() |
| 24 | global task_type | 24 | init_task = gdb.parse_and_eval("init_task").address |
| 25 | self.task_ptr_type = task_type.get_type().pointer() | 25 | t = g = init_task |
| 26 | self.init_task = gdb.parse_and_eval("init_task") | 26 | |
| 27 | self.curr_group = self.init_task.address | 27 | while True: |
| 28 | self.curr_task = None | 28 | while True: |
| 29 | 29 | yield t | |
| 30 | def __iter__(self): | 30 | |
| 31 | return self | 31 | t = utils.container_of(t['thread_group']['next'], |
| 32 | 32 | task_ptr_type, "thread_group") | |
| 33 | def __next__(self): | 33 | if t == g: |
| 34 | t = self.curr_task | 34 | break |
| 35 | if not t or t == self.curr_group: | 35 | |
| 36 | self.curr_group = \ | 36 | t = g = utils.container_of(g['tasks']['next'], |
| 37 | utils.container_of(self.curr_group['tasks']['next'], | 37 | task_ptr_type, "tasks") |
| 38 | self.task_ptr_type, "tasks") | 38 | if t == init_task: |
| 39 | if self.curr_group == self.init_task.address: | 39 | return |
| 40 | raise StopIteration | ||
| 41 | t = self.curr_task = self.curr_group | ||
| 42 | else: | ||
| 43 | self.curr_task = \ | ||
| 44 | utils.container_of(t['thread_group']['next'], | ||
| 45 | self.task_ptr_type, "thread_group") | ||
| 46 | return t | ||
| 47 | |||
| 48 | def next(self): | ||
| 49 | return self.__next__() | ||
| 50 | 40 | ||
| 51 | def get_task_by_pid(pid): | 41 | def get_task_by_pid(pid): |
| 52 | for task in TaskList(): | 42 | for task in task_lists(): |
| 53 | if int(task['pid']) == pid: | 43 | if int(task['pid']) == pid: |
| 54 | return task | 44 | return task |
| 55 | return None | 45 | return None |
