Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jan Kiszka and committed by
Linus Torvalds
fffb944c 54e2289a

+12 -23
+11 -22
scripts/gdb/linux/modules.py
··· 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 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 - 41 - def next(self): 42 - return self.__next__() 29 + while entry != end_of_list: 30 + yield utils.container_of(entry, module_ptr_type, "list") 31 + entry = entry['next'] 43 32 44 33 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 ··· 72 83 "Address{0} Module Size Used by\n".format( 73 84 " " if utils.get_long_type().sizeof == 8 else "")) 74 85 75 - for module in ModuleList(): 86 + for module in module_list(): 76 87 ref = 0 77 88 module_refptr = module['refptr'] 78 89 for cpu in cpus.CpuList("cpu_possible_mask"):
+1 -1
scripts/gdb/linux/symbols.py
··· 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: