aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/gdb/linux/modules.py
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2015-02-17 16:47:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-17 17:34:55 -0500
commitfffb944c4e6d3882a7a15c494bd4cde36c68c39c (patch)
tree801f69e1d2721cb1e0b49f46b48d32e55beae2f3 /scripts/gdb/linux/modules.py
parent54e2289a34e13d956acb841a00c3a6f06aced3f9 (diff)
scripts/gdb: convert ModuleList to generator function
Analogously to the task list, convert the module list to a generator function. It noticeably simplifies the code. 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/linux/modules.py')
-rw-r--r--scripts/gdb/linux/modules.py33
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
19module_type = utils.CachedType("struct module") 19module_type = utils.CachedType("struct module")
20 20
21 21
22class ModuleList: 22def 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
45def find_module_by_name(name): 34def 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"):