Skip to content

Commit 3ee7b3f

Browse files
jan-kiszkatorvalds
authored andcommitted
scripts/gdb: add infrastructure
This provides the basic infrastructure to load kernel-specific python helper scripts when debugging the kernel in gdb. The loading mechanism is based on gdb loading for <objfile>-gdb.py when opening <objfile>. Therefore, this places a corresponding link to the main helper script into the output directory that contains vmlinux. The main scripts will pull in submodules containing Linux specific gdb commands and functions. To avoid polluting the source directory with compiled python modules, we link to them from the object directory. Due to gdb.parse_and_eval and string redirection for gdb.execute, we depend on gdb >= 7.2. This feature is enabled via CONFIG_GDB_SCRIPTS. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Acked-by: Michal Marek <mmarek@suse.cz> [kbuild stuff] 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>
1 parent 0445f01 commit 3ee7b3f

6 files changed

Lines changed: 51 additions & 1 deletion

File tree

‎Makefile‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,9 @@ ifdef CONFIG_SAMPLES
926926
endif
927927
ifdef CONFIG_BUILD_DOCSRC
928928
$(Q)$(MAKE) $(build)=Documentation
929+
endif
930+
ifdef CONFIG_GDB_SCRIPTS
931+
$(Q)ln -fsn `cd $(srctree) && /bin/pwd`/scripts/gdb/vmlinux-gdb.py
929932
endif
930933
+$(call if_changed,link-vmlinux)
931934

@@ -1181,7 +1184,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
11811184
Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
11821185
signing_key.priv signing_key.x509 x509.genkey \
11831186
extra_certificates signing_key.x509.keyid \
1184-
signing_key.x509.signer
1187+
signing_key.x509.signer vmlinux-gdb.py
11851188

11861189
# clean - Delete most, but leave enough to build external modules
11871190
#

‎lib/Kconfig.debug‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,17 @@ config DEBUG_INFO_DWARF4
167167
But it significantly improves the success of resolving
168168
variables in gdb on optimized code.
169169

170+
config GDB_SCRIPTS
171+
bool "Provide GDB scripts for kernel debugging"
172+
depends on DEBUG_INFO
173+
help
174+
This creates the required links to GDB helper scripts in the
175+
build directory. If you load vmlinux into gdb, the helper
176+
scripts will be automatically imported by gdb as well, and
177+
additional functions are available to analyze a Linux kernel
178+
instance. See Documentation/gdb-kernel-debugging.txt for further
179+
details.
180+
170181
config ENABLE_WARN_DEPRECATED
171182
bool "Enable __deprecated logic"
172183
default y

‎scripts/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ subdir-$(CONFIG_MODVERSIONS) += genksyms
3636
subdir-y += mod
3737
subdir-$(CONFIG_SECURITY_SELINUX) += selinux
3838
subdir-$(CONFIG_DTC) += dtc
39+
subdir-$(CONFIG_GDB_SCRIPTS) += gdb
3940

4041
# Let clean descend into subdirs
4142
subdir- += basic kconfig package

‎scripts/gdb/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
subdir-y := linux

‎scripts/gdb/linux/Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
always := gdb-scripts
2+
3+
SRCTREE := $(shell cd $(srctree) && /bin/pwd)
4+
5+
$(obj)/gdb-scripts:
6+
ifneq ($(KBUILD_SRC),)
7+
$(Q)ln -fsn $(SRCTREE)/$(obj)/*.py $(objtree)/$(obj)
8+
endif
9+
@:
10+
11+
clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py)

‎scripts/gdb/vmlinux-gdb.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# gdb helper commands and functions for Linux kernel debugging
3+
#
4+
# loader module
5+
#
6+
# Copyright (c) Siemens AG, 2012, 2013
7+
#
8+
# Authors:
9+
# Jan Kiszka <jan.kiszka@siemens.com>
10+
#
11+
# This work is licensed under the terms of the GNU GPL version 2.
12+
#
13+
14+
import os
15+
16+
sys.path.insert(0, os.path.dirname(__file__) + "/scripts/gdb")
17+
18+
try:
19+
gdb.parse_and_eval("0")
20+
gdb.execute("", to_string=True)
21+
except:
22+
gdb.write("NOTE: gdb 7.2 or later required for Linux helper scripts to "
23+
"work.\n")

0 commit comments

Comments
 (0)