Commit fffb944c4e6d3882a7a15c494bd4cde36c68c39c

Authored by Jan Kiszka
Committed by Linus Torvalds
1 parent 54e2289a34

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>

Showing 2 changed files with 12 additions and 23 deletions Side-by-side Diff

scripts/gdb/linux/modules.py
... ... @@ -19,31 +19,20 @@
19 19 module_type = utils.CachedType("struct module")
20 20  
21 21  
22   -class ModuleList:
23   - def __init__(self):
24   - global module_type
25   - self.module_ptr_type = module_type.get_type().pointer()
26   - modules = gdb.parse_and_eval("modules")
27   - self.curr_entry = modules['next']
28   - self.end_of_list = modules.address
  22 +def module_list():
  23 + global module_type
  24 + module_ptr_type = module_type.get_type().pointer()
  25 + modules = gdb.parse_and_eval("modules")
  26 + entry = modules['next']
  27 + end_of_list = modules.address
29 28  
30   - def __iter__(self):
31   - return self
  29 + while entry != end_of_list:
  30 + yield utils.container_of(entry, module_ptr_type, "list")
  31 + entry = entry['next']
32 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 33  
41   - def next(self):
42   - return self.__next__()
43   -
44   -
45 34 def find_module_by_name(name):
46   - for module in ModuleList():
  35 + for module in module_list():
47 36 if module['name'].string() == name:
48 37 return module
49 38 return None
... ... @@ -83,7 +72,7 @@
83 72 "Address{0} Module Size Used by\n".format(
84 73 " " if utils.get_long_type().sizeof == 8 else ""))
85 74  
86   - for module in ModuleList():
  75 + for module in module_list():
87 76 ref = 0
88 77 module_refptr = module['refptr']
89 78 for cpu in cpus.CpuList("cpu_possible_mask"):
scripts/gdb/linux/symbols.py
... ... @@ -133,7 +133,7 @@
133 133 gdb.execute("symbol-file vmlinux")
134 134  
135 135 self.loaded_modules = []
136   - module_list = modules.ModuleList()
  136 + module_list = modules.module_list()
137 137 if not module_list:
138 138 gdb.write("no modules found\n")
139 139 else: