Skip to content

Commit

Permalink
scripts/gdb: convert ModuleList to generator function
Browse files Browse the repository at this point in the history
Analogously to the task list, convert the module list to a generator
function.  It noticeably simplifies the code.

Signed-off-by: Jan Kiszka <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Jason Wessel <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ben Widawsky <[email protected]>
Cc: Borislav Petkov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
jan-kiszka authored and torvalds committed Feb 17, 2015
1 parent 54e2289 commit fffb944
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
33 changes: 11 additions & 22 deletions scripts/gdb/linux/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,20 @@
module_type = utils.CachedType("struct module")


class ModuleList:
def __init__(self):
global module_type
self.module_ptr_type = module_type.get_type().pointer()
modules = gdb.parse_and_eval("modules")
self.curr_entry = modules['next']
self.end_of_list = modules.address

def __iter__(self):
return self

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 module_list():
global module_type
module_ptr_type = module_type.get_type().pointer()
modules = gdb.parse_and_eval("modules")
entry = modules['next']
end_of_list = modules.address

def next(self):
return self.__next__()
while entry != end_of_list:
yield utils.container_of(entry, module_ptr_type, "list")
entry = entry['next']


def find_module_by_name(name):
for module in ModuleList():
for module in module_list():
if module['name'].string() == name:
return module
return None
Expand Down Expand Up @@ -83,7 +72,7 @@ def invoke(self, arg, from_tty):
"Address{0} Module Size Used by\n".format(
" " if utils.get_long_type().sizeof == 8 else ""))

for module in ModuleList():
for module in module_list():
ref = 0
module_refptr = module['refptr']
for cpu in cpus.CpuList("cpu_possible_mask"):
Expand Down
2 changes: 1 addition & 1 deletion scripts/gdb/linux/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def load_all_symbols(self):
gdb.execute("symbol-file vmlinux")

self.loaded_modules = []
module_list = modules.ModuleList()
module_list = modules.module_list()
if not module_list:
gdb.write("no modules found\n")
else:
Expand Down

0 comments on commit fffb944

Please sign in to comment.