modules.py 896 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # gdb helper commands and functions for Linux kernel debugging
  3. #
  4. # module tools
  5. #
  6. # Copyright (c) Siemens AG, 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. module_type = utils.CachedType("struct module")
  16. class ModuleList:
  17. def __init__(self):
  18. global module_type
  19. self.module_ptr_type = module_type.get_type().pointer()
  20. modules = gdb.parse_and_eval("modules")
  21. self.curr_entry = modules['next']
  22. self.end_of_list = modules.address
  23. def __iter__(self):
  24. return self
  25. def next(self):
  26. entry = self.curr_entry
  27. if entry != self.end_of_list:
  28. self.curr_entry = entry['next']
  29. return utils.container_of(entry, self.module_ptr_type, "list")
  30. else:
  31. raise StopIteration