tasks.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #
  2. # gdb helper commands and functions for Linux kernel debugging
  3. #
  4. # task & thread tools
  5. #
  6. # Copyright (c) Siemens AG, 2011-2013
  7. #
  8. # Authors:
  9. # Jan Kiszka <jan.kiszka@siemens.com>
  10. #
  11. # This work is licensed under the terms of the GNU GPL version 2.
  12. #
  13. import gdb
  14. from linux import utils
  15. task_type = utils.CachedType("struct task_struct")
  16. class TaskList:
  17. def __init__(self):
  18. global task_type
  19. self.task_ptr_type = task_type.get_type().pointer()
  20. self.init_task = gdb.parse_and_eval("init_task")
  21. self.curr_group = self.init_task.address
  22. self.curr_task = None
  23. def __iter__(self):
  24. return self
  25. def next(self):
  26. t = self.curr_task
  27. if not t or t == self.curr_group:
  28. self.curr_group = \
  29. utils.container_of(self.curr_group['tasks']['next'],
  30. self.task_ptr_type, "tasks")
  31. if self.curr_group == self.init_task.address:
  32. raise StopIteration
  33. t = self.curr_task = self.curr_group
  34. else:
  35. self.curr_task = \
  36. utils.container_of(t['thread_group']['next'],
  37. self.task_ptr_type, "thread_group")
  38. return t