mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 14:21:47 +00:00
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>
This commit is contained in:
parent
54e2289a34
commit
fffb944c4e
@ -19,31 +19,20 @@ from linux import cpus, utils
|
|||||||
module_type = utils.CachedType("struct module")
|
module_type = utils.CachedType("struct module")
|
||||||
|
|
||||||
|
|
||||||
class ModuleList:
|
def module_list():
|
||||||
def __init__(self):
|
|
||||||
global module_type
|
global module_type
|
||||||
self.module_ptr_type = module_type.get_type().pointer()
|
module_ptr_type = module_type.get_type().pointer()
|
||||||
modules = gdb.parse_and_eval("modules")
|
modules = gdb.parse_and_eval("modules")
|
||||||
self.curr_entry = modules['next']
|
entry = modules['next']
|
||||||
self.end_of_list = modules.address
|
end_of_list = modules.address
|
||||||
|
|
||||||
def __iter__(self):
|
while entry != end_of_list:
|
||||||
return self
|
yield utils.container_of(entry, module_ptr_type, "list")
|
||||||
|
entry = entry['next']
|
||||||
def __next__(self):
|
|
||||||
entry = self.curr_entry
|
|
||||||
if entry != self.end_of_list:
|
|
||||||
self.curr_entry = entry['next']
|
|
||||||
return utils.container_of(entry, self.module_ptr_type, "list")
|
|
||||||
else:
|
|
||||||
raise StopIteration
|
|
||||||
|
|
||||||
def next(self):
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
|
|
||||||
def find_module_by_name(name):
|
def find_module_by_name(name):
|
||||||
for module in ModuleList():
|
for module in module_list():
|
||||||
if module['name'].string() == name:
|
if module['name'].string() == name:
|
||||||
return module
|
return module
|
||||||
return None
|
return None
|
||||||
@ -83,7 +72,7 @@ class LxLsmod(gdb.Command):
|
|||||||
"Address{0} Module Size Used by\n".format(
|
"Address{0} Module Size Used by\n".format(
|
||||||
" " if utils.get_long_type().sizeof == 8 else ""))
|
" " if utils.get_long_type().sizeof == 8 else ""))
|
||||||
|
|
||||||
for module in ModuleList():
|
for module in module_list():
|
||||||
ref = 0
|
ref = 0
|
||||||
module_refptr = module['refptr']
|
module_refptr = module['refptr']
|
||||||
for cpu in cpus.CpuList("cpu_possible_mask"):
|
for cpu in cpus.CpuList("cpu_possible_mask"):
|
||||||
|
@ -133,7 +133,7 @@ lx-symbols command."""
|
|||||||
gdb.execute("symbol-file vmlinux")
|
gdb.execute("symbol-file vmlinux")
|
||||||
|
|
||||||
self.loaded_modules = []
|
self.loaded_modules = []
|
||||||
module_list = modules.ModuleList()
|
module_list = modules.module_list()
|
||||||
if not module_list:
|
if not module_list:
|
||||||
gdb.write("no modules found\n")
|
gdb.write("no modules found\n")
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user