Add the internal helper get_module_by_name to obtain the module
structure corresponding to the given name. Also export this service as a
convenience function.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
---
 scripts/gdb/module.py      |   30 ++++++++++++++++++++++++++++++
 scripts/gdb/vmlinux-gdb.py |    1 +
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/scripts/gdb/module.py b/scripts/gdb/module.py
index 01b23df..e309c0a 100644
--- a/scripts/gdb/module.py
+++ b/scripts/gdb/module.py
@@ -26,3 +26,33 @@ def for_each_module(func, arg = None):
                module = container_of(entry, module_ptr_type, "list")
                func(module, arg)
                entry = entry['next']
+
+def find_module_by_name(name):
+       def match_name(module, arg):
+               if module['name'].string() == arg['name']:
+                       arg['module'] = module
+
+       arg = { 'name': name, 'module': None }
+       for_each_module(match_name, arg)
+
+       return arg['module']
+
+
+class LxModule(gdb.Function):
+       __doc__ = "Find module by name and return the module variable.\n" \
+                 "\n" \
+                 "$lx_module(MODULE): Given the name MODULE, iterate over all 
loaded modules of\n" \
+                 "the target and return that module variable which MODULE 
matches."
+
+       def __init__(self):
+               super(LxModule, self).__init__("lx_module")
+
+       def invoke(self, mod_name):
+               mod_name = mod_name.string()
+               module = find_module_by_name(mod_name)
+               if module:
+                       return module.dereference()
+               else:
+                       raise gdb.GdbError("Unable to find MODULE " + mod_name)
+
+LxModule()
diff --git a/scripts/gdb/vmlinux-gdb.py b/scripts/gdb/vmlinux-gdb.py
index 3553b7d..2a466a0 100644
--- a/scripts/gdb/vmlinux-gdb.py
+++ b/scripts/gdb/vmlinux-gdb.py
@@ -23,3 +23,4 @@ if gdb_version < "7.1":
 else:
        import utils
        import symbols
+       import module
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to