aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/gdb
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2015-02-17 16:46:52 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-17 17:34:53 -0500
commit82b41e3d6113291258c65281144bce946553dfed (patch)
tree864930d353e36989bf5c7c5d378e5eb39cac25d9 /scripts/gdb
parentbe02a1862304b126cd6ba4f347fa5db59460a776 (diff)
scripts/gdb: add automatic symbol reloading on module insertion
This installs a silent breakpoint on the do_init_module function. The breakpoint handler will try to load symbols from the module files found during lx-symbols execution. This way, breakpoints can be set to module initialization functions, and there is no need to explicitly call lx-symbols after (re-)loading a module. 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>
Diffstat (limited to 'scripts/gdb')
-rw-r--r--scripts/gdb/linux/symbols.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/scripts/gdb/linux/symbols.py b/scripts/gdb/linux/symbols.py
index bd21a9624428..139841fa7f70 100644
--- a/scripts/gdb/linux/symbols.py
+++ b/scripts/gdb/linux/symbols.py
@@ -19,6 +19,30 @@ import string
19from linux import modules, utils 19from linux import modules, utils
20 20
21 21
22if hasattr(gdb, 'Breakpoint'):
23 class LoadModuleBreakpoint(gdb.Breakpoint):
24 def __init__(self, spec, gdb_command):
25 super(LoadModuleBreakpoint, self).__init__(spec, internal=True)
26 self.silent = True
27 self.gdb_command = gdb_command
28
29 def stop(self):
30 module = gdb.parse_and_eval("mod")
31 module_name = module['name'].string()
32 cmd = self.gdb_command
33
34 # enforce update if object file is not found
35 cmd.module_files_updated = False
36
37 if module_name in cmd.loaded_modules:
38 gdb.write("refreshing all symbols to reload module "
39 "'{0}'\n".format(module_name))
40 cmd.load_all_symbols()
41 else:
42 cmd.load_module_symbols(module)
43 return False
44
45
22class LxSymbols(gdb.Command): 46class LxSymbols(gdb.Command):
23 """(Re-)load symbols of Linux kernel and currently loaded modules. 47 """(Re-)load symbols of Linux kernel and currently loaded modules.
24 48
@@ -30,6 +54,8 @@ lx-symbols command."""
30 module_paths = [] 54 module_paths = []
31 module_files = [] 55 module_files = []
32 module_files_updated = False 56 module_files_updated = False
57 loaded_modules = []
58 breakpoint = None
33 59
34 def __init__(self): 60 def __init__(self):
35 super(LxSymbols, self).__init__("lx-symbols", gdb.COMMAND_FILES, 61 super(LxSymbols, self).__init__("lx-symbols", gdb.COMMAND_FILES,
@@ -87,6 +113,8 @@ lx-symbols command."""
87 addr=module_addr, 113 addr=module_addr,
88 sections=self._section_arguments(module)) 114 sections=self._section_arguments(module))
89 gdb.execute(cmdline, to_string=True) 115 gdb.execute(cmdline, to_string=True)
116 if not module_name in self.loaded_modules:
117 self.loaded_modules.append(module_name)
90 else: 118 else:
91 gdb.write("no module object found for '{0}'\n".format(module_name)) 119 gdb.write("no module object found for '{0}'\n".format(module_name))
92 120
@@ -104,6 +132,7 @@ lx-symbols command."""
104 gdb.execute("symbol-file", to_string=True) 132 gdb.execute("symbol-file", to_string=True)
105 gdb.execute("symbol-file vmlinux") 133 gdb.execute("symbol-file vmlinux")
106 134
135 self.loaded_modules = []
107 module_list = modules.ModuleList() 136 module_list = modules.ModuleList()
108 if not module_list: 137 if not module_list:
109 gdb.write("no modules found\n") 138 gdb.write("no modules found\n")
@@ -123,5 +152,15 @@ lx-symbols command."""
123 152
124 self.load_all_symbols() 153 self.load_all_symbols()
125 154
155 if hasattr(gdb, 'Breakpoint'):
156 if not self.breakpoint is None:
157 self.breakpoint.delete()
158 self.breakpoint = None
159 self.breakpoint = LoadModuleBreakpoint(
160 "kernel/module.c:do_init_module", self)
161 else:
162 gdb.write("Note: symbol update on module loading not supported "
163 "with this gdb version\n")
164
126 165
127LxSymbols() 166LxSymbols()