diff options
Diffstat (limited to 'scripts/gdb/linux/modules.py')
-rw-r--r-- | scripts/gdb/linux/modules.py | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/scripts/gdb/linux/modules.py b/scripts/gdb/linux/modules.py index 2dbf6796ce4f..6d497229d026 100644 --- a/scripts/gdb/linux/modules.py +++ b/scripts/gdb/linux/modules.py | |||
@@ -19,31 +19,20 @@ from linux import cpus, utils | |||
19 | module_type = utils.CachedType("struct module") | 19 | module_type = utils.CachedType("struct module") |
20 | 20 | ||
21 | 21 | ||
22 | class ModuleList: | 22 | def module_list(): |
23 | def __init__(self): | 23 | global module_type |
24 | global module_type | 24 | module_ptr_type = module_type.get_type().pointer() |
25 | self.module_ptr_type = module_type.get_type().pointer() | 25 | modules = gdb.parse_and_eval("modules") |
26 | modules = gdb.parse_and_eval("modules") | 26 | entry = modules['next'] |
27 | self.curr_entry = modules['next'] | 27 | end_of_list = modules.address |
28 | self.end_of_list = modules.address | ||
29 | |||
30 | def __iter__(self): | ||
31 | return self | ||
32 | |||
33 | def __next__(self): | ||
34 | entry = self.curr_entry | ||
35 | if entry != self.end_of_list: | ||
36 | self.curr_entry = entry['next'] | ||
37 | return utils.container_of(entry, self.module_ptr_type, "list") | ||
38 | else: | ||
39 | raise StopIteration | ||
40 | 28 | ||
41 | def next(self): | 29 | while entry != end_of_list: |
42 | return self.__next__() | 30 | yield utils.container_of(entry, module_ptr_type, "list") |
31 | entry = entry['next'] | ||
43 | 32 | ||
44 | 33 | ||
45 | def find_module_by_name(name): | 34 | def find_module_by_name(name): |
46 | for module in ModuleList(): | 35 | for module in module_list(): |
47 | if module['name'].string() == name: | 36 | if module['name'].string() == name: |
48 | return module | 37 | return module |
49 | return None | 38 | return None |
@@ -83,7 +72,7 @@ class LxLsmod(gdb.Command): | |||
83 | "Address{0} Module Size Used by\n".format( | 72 | "Address{0} Module Size Used by\n".format( |
84 | " " if utils.get_long_type().sizeof == 8 else "")) | 73 | " " if utils.get_long_type().sizeof == 8 else "")) |
85 | 74 | ||
86 | for module in ModuleList(): | 75 | for module in module_list(): |
87 | ref = 0 | 76 | ref = 0 |
88 | module_refptr = module['refptr'] | 77 | module_refptr = module['refptr'] |
89 | for cpu in cpus.CpuList("cpu_possible_mask"): | 78 | for cpu in cpus.CpuList("cpu_possible_mask"): |