Skip to content

Commit

Permalink
scripts/gdb: add task iteration class
Browse files Browse the repository at this point in the history
This class allows to iterate over all tasks of the target.

Signed-off-by: Jan Kiszka <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Jason Wessel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Borislav Petkov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jan-kiszka authored and torvalds committed Feb 17, 2015
1 parent ae7dbaa commit 7704d58
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/gdb/linux/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# gdb helper commands and functions for Linux kernel debugging
#
# task & thread tools
#
# Copyright (c) Siemens AG, 2011-2013
#
# Authors:
# Jan Kiszka <[email protected]>
#
# This work is licensed under the terms of the GNU GPL version 2.
#

import gdb

from linux import utils


task_type = utils.CachedType("struct task_struct")


class TaskList:
def __init__(self):
global task_type
self.task_ptr_type = task_type.get_type().pointer()
self.init_task = gdb.parse_and_eval("init_task")
self.curr_group = self.init_task.address
self.curr_task = None

def __iter__(self):
return self

def next(self):
t = self.curr_task
if not t or t == self.curr_group:
self.curr_group = \
utils.container_of(self.curr_group['tasks']['next'],
self.task_ptr_type, "tasks")
if self.curr_group == self.init_task.address:
raise StopIteration
t = self.curr_task = self.curr_group
else:
self.curr_task = \
utils.container_of(t['thread_group']['next'],
self.task_ptr_type, "thread_group")
return t

0 comments on commit 7704d58

Please sign in to comment.