lkml.org 
[lkml]   [2013]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 06/20] scripts/gdb: Add internal helper and convenience function to look up a module
Date
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.kiszka@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


\
 
 \ /
  Last update: 2013-01-29 14:21    [W:0.799 / U:1.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site