kgdb, kdb proposed merge for 2.6.34
Subsystems (17)
Jason Wessel
maintainercover kgdb, kdb proposed merge for 2.6.34
Patch set 1 of 3 - The kdb / kgdb merge
This is 3rd and hopefully final kgdb/kdb series originally posted in December 2009. The next version will hopefully be a pull request to Linus, depending on any further feedback from the community.
Thank you very much to everyone who provided feedback on the prior patch sets, as well as to Martin Hicks for some code contributions which have been folded into the series.
This patch set is stable, and there are several people in the community making use of the patches.
You can preview the documetation at:
http://kernel.org/pub/linux/kernel/people/jwessel/kdb/
In total there are presently 43 patches, but they have been broken up into three separate series.
1) 28 patches - The kdb core
2) 7 patches - The debug core kms hooks
3) 8 patches - Early debugging capability with kdb & kgdb
Differences in the V3 patch set:
* The ARM hooks were dropped and implemented another way by RMK
* X86 hw breakpoint regression patches were merged in 2.6.33-rc7
* All the NR_CPUS arrays were factored out of the kdb shell
* The kdb init was divided into an early and late section to allow extended commands definitions to use kernel memory allocator
* The KMS debugger API function names were updated for consistency
* Several minor bugs fixed in the kdb shell with the pager
* The early debug series was added to kgdb-next
* Allows early hardware breakpoints and trap on X86
* Allows kgdb and kdb over the EHCI USB Debug Port
* Allows kdb debugging in conjunction with earlyprintk=vga
Differences in the V2 patch set:
* All the code is now in linux-next via kgdb-next
* 6 different build breakages were repaired around different .config options not compiling
* kms / kdb / kgdb was built tested as kernel modules
* The kdb core was split into 2 patches, 1 for the core, and one for all the files touched outside the kdb core
* kdb_seq_printf added to eliminate the duplicate meminfo commands in procfs
* kdb breakpoint code refactored to remove unused globals and struct members
* Fixed the possibility to loop infinitely in the kdb md command
* Cleaned up the kdb kernel/modules.c patch
* Removed the unused kdb report helper function in kernel/sched.c
* HW instruction and data access breakpoints implementation completed
* The kdb keyboard code no longer modifies include/linux/keyboard.h
* The kernel_probe_read and kernel_probe_write were cleaned up for blackfin
* The blackfin arch specific kgdb implementation was cleaned up and merged
* The debug core now turns off tracing while the kernel debugger is active
* New in the series is a command for kdb called ftdump, which allows dumping the ftrace buffer
* kdb will automatically set the correct number of rows on the display via the information from the vt_console when using kms
* There is preliminary documentation for kdb and kms
* The drm hacks patch is still a hack, but cleaned up and using macros
The acks were added for the blackfin, sparc and sh arch specific code by the respective maintainers.
-- From v1 patch set --
Back in May 2009 an initial kdb prototype was posted to lkml as an RFC to see if there was sufficient interest to merge kdb and kgdb together.
There was enough interest to continue on with the project, and it is now in a state where further work can occur to review, and hopefully merge the code into a future kernel.
If this is the first time you have heard about kgdb or kdb, you might consider taking a look at the presentation slides from LPC 2009.
http://kgdb.wiki.kernel.org/index.php/Main_Page#Linux_Plumbers_Conference_presentation_2009
The code included in this series does not include any of the USB code referenced in the presentation.
Several changes have occurred since the original prototype was posted. All of the architectures using the kgdb core today have had the functions implemented to make use of the kdb shell. This list includes x86, arm, ppc, mips, sh, sparc, and blackfin. The proposed atomic kernel modesetting project now has an initial implementation for the intel i915 driver, and it should be possible to add atomic mode setting hooks for any other video driver which makes use of builtin kernel mode setting. All the dead code and functions that were not previously implemented in the RFC have been removed or implemented.
The directory of the kernel debugger changed as well. All the kernel debugger pieces, the debug core, gdbstub and kdb now live under kernel/debug.
While the patch set may be slightly large, it is broken down into logical, incremental functionality. Only the first 12 patches are needed to see kdb in action on a serial port which has a kgdboc driver for example.
It is important to understand that this work was directly derived from the original kdb, and the intent is to deprecate the out of tree kdb and move all its functionality to this code base. This version of kdb is completely wired into the debug core and the kgdboc polled I/O model using the same API used by the gdbstub (which people call kgdb).
The kdb front end in this patch series works a little differently than if you were to take the original kdb patch set from:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
In the kernel .config you should enable the following options:
CONFIG_KGDB=yCONFIG_KGDB_SERIAL_CONSOLE=yCONFIG_KGDB_LOW_LEVEL_TRAP=yCONFIG_KGDB_KDB=yCONFIG_KDB_KEYBOARD=y
To use kdb with a serial port you would use the kgdb/kgdboc way of doing things. You would used a kernel command line with:
console=ttyS0,115200 kgdboc=ttyS0 kgdbwait
That will get you access to kdb just after the console has been registered. If you want to use the keyboard, you could use the following (NOTE it is kbd and not kdb, kbd is short for keyboard):
console=tty0 kgdboc=kbd kgdbwait
You can also use the keyboard and or serial console:
console=ttyS0,115200 console=tty0 kgdboc=kbd,ttyS0
In terms of breaking into the debugger after the system is up, you must use the sysrq-g sequence. That means you could run:
echo g > /proc/sysrq-trigger
Or you can use the SysRq key on your key board. On a typical laptop you might have to do the following:
press and hold ALT -- You will be holding this the whole time
press and hold FN
press and release the key with the SysRq label
release FN
press and release g
release ALT
Once you are in kdb you can run help to see a limited list of commands.
You can also still connect gdb or re-enter kdb without leaving the exception state, if you are using a serial port. To get out of kgdb mode you can type "$3#33", or to get into kgdb mode from kdb, you can type "kgdb".
Quoted 1 line
From gdb you can issue commands to the kdb front end, via gdb's
monitor command. For instance you could issue "monitor lsmod". Allowing the gdb monitor extension was certainly another motivation behind the prototype.
Included among the kdb patches are some kgdb specific fixes for the next kernel merge window, and if kdb were to not make the cut, these patches will be split out of the series. Anything too ugly for a possible merge is also a candidate to get removed from the series.
Thanks,
Jason.
You can find the development branch for this here:
http://git.kernel.org/?p=linux/kernel/git/jwessel/linux-2.6-kgdb.git;a=shortlog;h=kdb-merge
---
Jason Wessel (28):
Move kernel/kgdb.c to kernel/debug/debug_core.c
Separate the gdbstub from the debug core
kgdb: eliminate kgdb_wait(), all cpus enter the same way
kgdb,sparc: Add in kgdb_arch_set_pc for sparc
kgdb,sh: update superh kgdb exception handling
kgdb,blackfin: Add in kgdb_arch_set_pc for blackfin
kdb: core for kgdb back end (1 of 2)
kdb: core for kgdb back end (2 of 2)
kgdb: core changes to support kdb
kgdb,8250,pl011: Return immediately from console poll
sh,sh-sci: Use NO_POLL_CHAR in the SCIF polled console code sparc,sunzilog: Add console polling support for sunzilog serial driver
kgdb: gdb "monitor" -> kdb passthrough
kgdboc,keyboard: Keyboard driver for kdb with kgdb
kgdb,docs: Update the kgdb docs to include kdb
kgdb: remove post_primary_code references
x86,kgdb: Add low level debug hook
powerpc,kgdb: Introduce low level trap catching
mips,kgdb: kdb low level trap catch and stack trace
kgdb: Add the ability to schedule a breakpoint via a tasklet kgdboc,kdb: Allow kdb to work on a non open console port
printk,kdb: capture printk() when in kdb shell
keyboard, input: Add hook to input to allow low level event clear debug_core,kdb: Allow the debug core to process a recursive debug entry
MAINTAINERS: update kgdb, kdb, and debug_core info kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop() kgdbts,sh: Add in breakpoint pc offset for superh
debug_core: Turn off tracing while in the debugger
Documentation/DocBook/kgdb.tmpl | 640 ++++++-- Documentation/kernel-parameters.txt | 15 +- MAINTAINERS | 6 +- arch/arm/include/asm/kmap_types.h | 1 + arch/arm/kernel/kgdb.c | 5 + arch/blackfin/kernel/kgdb.c | 5 + arch/mips/include/asm/kgdb.h | 2 + arch/mips/kernel/kgdb.c | 27 +- arch/mips/kernel/traps.c | 13 + arch/powerpc/include/asm/kmap_types.h | 1 + arch/powerpc/kernel/kgdb.c | 12 +- arch/powerpc/kernel/traps.c | 7 + arch/sh/kernel/kgdb.c | 14 +- arch/sparc/kernel/kgdb_32.c | 6 + arch/sparc/kernel/kgdb_64.c | 6 + arch/x86/include/asm/kgdb.h | 3 + arch/x86/kernel/kgdb.c | 56 +- arch/x86/kernel/traps.c | 6 + drivers/char/Makefile | 1 + drivers/char/kdb_keyboard.c | 204 +++ drivers/char/kdb_keyboard.h | 143 ++ drivers/char/keyboard.c | 29 +- drivers/input/input.c | 15 + drivers/misc/kgdbts.c | 6 + drivers/serial/8250.c | 4 +- drivers/serial/amba-pl011.c | 6 +- drivers/serial/kgdboc.c | 88 +- drivers/serial/sh-sci.c | 6 +- drivers/serial/sunzilog.c | 50 + fs/proc/internal.h | 4 +- fs/proc/meminfo.c | 15 +- fs/proc/mmu.c | 8 +- include/asm-generic/kmap_types.h | 3 +- include/linux/input.h | 10 + include/linux/kdb.h | 117 ++ include/linux/kgdb.h | 41 +- include/linux/serial_core.h | 1 + include/linux/swap.h | 2 + init/main.c | 2 + kernel/Makefile | 2 +- kernel/debug/Makefile | 7 + kernel/debug/debug_core.c | 966 +++++++++++ kernel/debug/debug_core.h | 81 + kernel/debug/gdbstub.c | 1022 ++++++++++++ kernel/debug/kdb/.gitignore | 1 + kernel/debug/kdb/Makefile | 24 + kernel/debug/kdb/kdb_bp.c | 564 +++++++ kernel/debug/kdb/kdb_bt.c | 210 +++ kernel/debug/kdb/kdb_cmds | 35 + kernel/debug/kdb/kdb_debugger.c | 169 ++ kernel/debug/kdb/kdb_io.c | 826 ++++++++++ kernel/debug/kdb/kdb_main.c | 2855 +++++++++++++++++++++++++++++++++ kernel/debug/kdb/kdb_private.h | 312 ++++ kernel/debug/kdb/kdb_support.c | 991 ++++++++++++ kernel/kallsyms.c | 21 + kernel/kgdb.c | 1763 -------------------- kernel/module.c | 4 + kernel/panic.c | 7 +- kernel/printk.c | 25 + kernel/sched.c | 7 +- kernel/signal.c | 40 + lib/Kconfig.kgdb | 24 +- mm/swapfile.c | 10 +- 63 files changed, 9528 insertions(+), 2018 deletions(-) create mode 100644 drivers/char/kdb_keyboard.c create mode 100644 drivers/char/kdb_keyboard.h create mode 100644 include/linux/kdb.h create mode 100644 kernel/debug/Makefile create mode 100644 kernel/debug/debug_core.c create mode 100644 kernel/debug/debug_core.h create mode 100644 kernel/debug/gdbstub.c create mode 100644 kernel/debug/kdb/.gitignore create mode 100644 kernel/debug/kdb/Makefile create mode 100644 kernel/debug/kdb/kdb_bp.c create mode 100644 kernel/debug/kdb/kdb_bt.c create mode 100644 kernel/debug/kdb/kdb_cmds create mode 100644 kernel/debug/kdb/kdb_debugger.c create mode 100644 kernel/debug/kdb/kdb_io.c create mode 100644 kernel/debug/kdb/kdb_main.c create mode 100644 kernel/debug/kdb/kdb_private.h create mode 100644 kernel/debug/kdb/kdb_support.c delete mode 100644 kernel/kgdb.c
Jason Wessel
maintainerPATCH 1/28 Move kernel/kgdb.c to kernel/debug/debug_core.c
Move kgdb.c in preparation for to separate the gdbstub from the debug core and exception handling.n
---
kernel/Makefile | 2 +-
kernel/debug/Makefile | 5 +++++
kernel/{kgdb.c => debug/debug_core.c} | 0
3 files changed, 6 insertions(+), 1 deletions(-)
create mode 100644 kernel/debug/Makefile
rename kernel/{kgdb.c => debug/debug_core.c} (100%)kernel/Makefile +1 -1
@@ -74,7 +74,7 @@ obj-$(CONFIG_AUDITSYSCALL) += auditsc.o obj-$(CONFIG_GCOV_KERNEL) += gcov/ obj-$(CONFIG_AUDIT_TREE) += audit_tree.o obj-$(CONFIG_KPROBES) += kprobes.o -obj-$(CONFIG_KGDB) += kgdb.o +obj-$(CONFIG_KGDB) += debug/ obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
kernel/debug/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the linux kernel debugger +# + +obj-$(CONFIG_KGDB) += debug_core.o
kernel/debug/debug_core.c renamed from kernel/kgdb.c +0 -0
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 2/28 Separate the gdbstub from the debug core
In reply to Jason WesselSplit the former kernel/kgdb.c into debug_core.c which contains the kernel debugger exception logic and to the gdbstub.c which contains the logic for allowing gdb to talk to the debug core.
This also created a private include file called debug_core.h which contains all the definitions to glue the debug_core to any other debugger connections.
--- include/linux/kgdb.h | 1 + kernel/debug/Makefile | 2 +- kernel/debug/debug_core.c | 992 ++------------------------------------------- kernel/debug/debug_core.h | 48 +++ kernel/debug/gdbstub.c | 939 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1028 insertions(+), 954 deletions(-) create mode 100644 kernel/debug/debug_core.h create mode 100644 kernel/debug/gdbstub.c
include/linux/kgdb.h +1 -0
@@ -264,6 +264,7 @@ extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);extern int kgdb_register_io_module (struct kgdb_io *local_kgdb_io_ops);extern void kgdb_unregister_io_module (struct kgdb_io *local_kgdb_io_ops); +extern struct kgdb_io *dbg_io_ops;extern int kgdb_hex2long (char **ptr,unsigned long *long_val);extern int kgdb_mem2hex (char *mem,char *buf,int count);
kernel/debug/Makefile +1 -1
@@ -2,4 +2,4 @@ # Makefile for the linux kernel debugger # -obj-$(CONFIG_KGDB) += debug_core.o +obj-$(CONFIG_KGDB) += debug_core.o gdbstub.o
kernel/debug/debug_core.c +39 -953
1,190 lines not on this page · raw message
kernel/debug/debug_core.h new file +48 -0
48 lines not on this page · raw message
kernel/debug/gdbstub.c new file +939 -0
939 lines not on this page · raw message
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 3/28 kgdb: eliminate kgdb_wait(), all cpus enter the same way
In reply to Jason WesselThis is a kgdb architectural change to have all the cpus (master or slave) enter the same function.
A cpu that hits an exception (wants to be the master cpu) will call kgdb_handle_exception() from the trap handler and then invoke a kgdb_roundup_cpu() to synchronize the other cpus and bring them into the kgdb_handle_exception() as well.
A slave cpu will enter kgdb_handle_exception() from the kgdb_nmicallback() and set the exception state to note that the processor is a slave.
Previously the salve cpu would have called kgdb_wait(). This change allows the debug core to change cpus without resuming the system in order to inspect arch specific cpu information.
--- kernel/debug/debug_core.c | 158 +++++++++++++++++++++----------------------- kernel/debug/debug_core.h | 7 ++ 2 files changed, 82 insertions(+), 83 deletions(-)
kernel/debug/debug_core.c +75 -83
@@ -215,49 +215,6 @@ void __weak kgdb_disable_hw_debug(struct pt_regs *regs) }/* -* CPU debug state control: -*/ - -#ifdef CONFIG_SMP -static void kgdb_wait (struct pt_regs *regs) -{ -unsigned long flags; -int cpu; - -local_irq_save (flags); - cpu =raw_smp_processor_id (); - kgdb_info[cpu].debuggerinfo = regs; - kgdb_info[cpu].task = current; -/* -* Make sure the above info reaches the primary CPU before -* our cpu_in_kgdb[] flag setting does: -*/ -smp_wmb (); -atomic_set (&cpu_in_kgdb[cpu],1 ); - -/* Disable any cpu specific hw breakpoints */ -kgdb_disable_hw_debug (regs); - -/* Wait till primary CPU is done with debugging */ -while (atomic_read (&passive_cpu_wait[cpu])) -cpu_relax (); - - kgdb_info[cpu].debuggerinfo =NULL ; - kgdb_info[cpu].task =NULL ; - -/* fix up hardware debug registers on local cpu */ -if (arch_kgdb_ops.correct_hw_break) - arch_kgdb_ops.correct_hw_break (); - -/* Signal the primary CPU that we are done: */ -atomic_set (&cpu_in_kgdb[cpu],0 ); -touch_softlockup_watchdog_sync (); -clocksource_touch_watchdog (); -local_irq_restore (flags); -} -#endif - -/* * Some architectures need cache flushes when we set/clear a * breakpoint: */
@@ -486,34 +443,12 @@ static int kgdb_reenter_check(struct kgdb_state *ks)return 1 ; } -/* -* kgdb_handle_exception() - main entry point from a kernel exception -* -* Locking hierarchy: -* interface locks, if any (begin_session) -* kgdb lock (kgdb_active) -*/ -int -kgdb_handle_exception (int evector,int signo,int ecode,struct pt_regs *regs) +static int kgdb_cpu_enter (struct kgdb_state *ks,struct pt_regs *regs) { -struct kgdb_state kgdb_var; -struct kgdb_state *ks = &kgdb_var;unsigned long flags;int sstep_tries =100 ;int error =0 ;int i, cpu; - - ks->cpu =raw_smp_processor_id (); - ks->ex_vector = evector; - ks->signo = signo; - ks->ex_vector = evector; - ks->err_code = ecode; - ks->kgdb_usethreadid =0 ; - ks->linux_regs = regs; - -if (kgdb_reenter_check (ks)) -return 0 ;/* Ouch, double exception ! */ - acquirelock:/* * Interrupts will be restored by the 'trap return' code, except when
@@ -521,13 +456,42 @@ acquirelock:*/ local_irq_save (flags); - cpu =raw_smp_processor_id (); + cpu = ks->cpu; + kgdb_info[cpu].debuggerinfo = regs; + kgdb_info[cpu].task = current; +/* +* Make sure the above info reaches the primary CPU before +* our cpu_in_kgdb[] flag setting does: +*/ +smp_wmb (); +atomic_set (&cpu_in_kgdb[cpu],1 );/* -* Acquire the kgdb_active lock: +* CPU will loop if it is a slave or request to become a kgdb +* master cpu and acquire the kgdb_active lock: */ -while (atomic_cmpxchg (&kgdb_active,-1 , cpu) !=-1 ) +while (1 ) { +if (kgdb_info[cpu].exception_state &DCPU_WANT_MASTER ) { +if (atomic_cmpxchg (&kgdb_active,-1 , cpu) == cpu) +break ; + }else if (kgdb_info[cpu].exception_state &DCPU_IS_SLAVE ) { +if (!atomic_read (&passive_cpu_wait[cpu])) + goto return_normal; + }else { +return_normal: +/* Return to normal operation by executing any +* hw breakpoint fixup. +*/ +if (arch_kgdb_ops.correct_hw_break) + arch_kgdb_ops.correct_hw_break (); +atomic_set (&cpu_in_kgdb[cpu],0 ); +touch_softlockup_watchdog_sync (); +clocksource_touch_watchdog (); +local_irq_restore (flags); +return 0 ; + }cpu_relax (); + }/* * For single stepping, try to only enter on the processor
@@ -561,9 +525,6 @@ acquirelock:if (dbg_io_ops->pre_exception) dbg_io_ops->pre_exception (); - kgdb_info[ks->cpu].debuggerinfo = ks->linux_regs; - kgdb_info[ks->cpu].task = current; -kgdb_disable_hw_debug (ks->linux_regs);/*
@@ -575,12 +536,6 @@ acquirelock:atomic_set (&passive_cpu_wait[i],1 ); } -/* -* spin_lock code is good enough as a barrier so we don't -* need one here: -*/ -atomic_set (&cpu_in_kgdb[ks->cpu],1 ); -#ifdef CONFIG_SMP /* Signal the other CPUs to enter kgdb_wait() */ if ((!kgdb_single_step) && kgdb_do_roundup)
@@ -612,8 +567,6 @@ acquirelock:if (dbg_io_ops->post_exception) dbg_io_ops->post_exception (); - kgdb_info[ks->cpu].debuggerinfo =NULL ; - kgdb_info[ks->cpu].task =NULL ;atomic_set (&cpu_in_kgdb[ks->cpu],0 );if (!kgdb_single_step) {
@@ -646,13 +599,52 @@ kgdb_restore:return error; } +/* +* kgdb_handle_exception() - main entry point from a kernel exception +* +* Locking hierarchy: +* interface locks, if any (begin_session) +* kgdb lock (kgdb_active) +*/ +int +kgdb_handle_exception (int evector,int signo,int ecode,struct pt_regs *regs) +{ +struct kgdb_state kgdb_var; +struct kgdb_state *ks = &kgdb_var; +int ret; + + ks->cpu =raw_smp_processor_id (); + ks->ex_vector = evector; + ks->signo = signo; + ks->ex_vector = evector; + ks->err_code = ecode; + ks->kgdb_usethreadid =0 ; + ks->linux_regs = regs; + +if (kgdb_reenter_check (ks)) +return 0 ;/* Ouch, double exception ! */ + kgdb_info[ks->cpu].exception_state |=DCPU_WANT_MASTER ; + ret =kgdb_cpu_enter (ks, regs); + kgdb_info[ks->cpu].exception_state &= ~DCPU_WANT_MASTER ; +return ret; +} +int kgdb_nmicallback (int cpu,void *regs) {#ifdef CONFIG_SMP +struct kgdb_state kgdb_var; +struct kgdb_state *ks = &kgdb_var; + +memset (ks,0 ,sizeof (struct kgdb_state )); + ks->cpu = cpu; + ks->linux_regs = regs; +if (!atomic_read (&cpu_in_kgdb[cpu]) && -atomic_read (&kgdb_active) != cpu && -atomic_read (&cpu_in_kgdb[atomic_read (&kgdb_active)])) { -kgdb_wait ((struct pt_regs *)regs); +atomic_read (&kgdb_active) !=-1 && +atomic_read (&kgdb_active) != cpu) { + kgdb_info[cpu].exception_state |=DCPU_IS_SLAVE ; +kgdb_cpu_enter (ks, regs); + kgdb_info[cpu].exception_state &= ~DCPU_IS_SLAVE ;return 0 ; }#endif
kernel/debug/debug_core.h +7 -0
@@ -28,9 +28,16 @@ struct kgdb_state {struct pt_regs *linux_regs; }; +/* Exception state values */ +#define DCPU_WANT_MASTER 0x1/* Waiting to become a master kgdb cpu */ +#define DCPU_NEXT_MASTER 0x2/* Transition from one master cpu to another */ +#define DCPU_IS_SLAVE 0x4/* Slave cpu enter exception */ +#define DCPU_SSTEP 0x8/* CPU is single stepping */ +struct debuggerinfo_struct {void *debuggerinfo;struct task_struct *task; +int exception_state; };extern struct debuggerinfo_struct kgdb_info[];
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 4/28 kgdb,sparc: Add in kgdb_arch_set_pc for sparc
In reply to Jason WesselThe new debug core api requires all architectures that use to debug core to implement a function to set the program counter.
--- arch/sparc/kernel/kgdb_32.c | 6 ++++++ arch/sparc/kernel/kgdb_64.c | 6 ++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
arch/sparc/kernel/kgdb_32.c +6 -0
@@ -158,6 +158,12 @@ void kgdb_arch_exit(void) { } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long ip) +{ + regs->pc = ip; + regs->npc = regs->pc +4 ; +} +struct kgdb_arch arch_kgdb_ops = {/* Breakpoint instruction: ta 0x7d */ .gdb_bpt_instr = {0x91 ,0xd0 ,0x20 ,0x7d },
arch/sparc/kernel/kgdb_64.c +6 -0
@@ -180,6 +180,12 @@ void kgdb_arch_exit(void) { } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long ip) +{ + regs->tpc = ip; + regs->tnpc = regs->tpc +4 ; +} +struct kgdb_arch arch_kgdb_ops = {/* Breakpoint instruction: ta 0x72 */ .gdb_bpt_instr = {0x91 ,0xd0 ,0x20 ,0x72 },
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 5/28 kgdb,sh: update superh kgdb exception handling
In reply to Jason WesselImplement kgdb_arch_pc() which adjusts the pc if it needs to be adjusted after a software breakpoint trap.
Implement kgdb_arch_set_pc() which is a new required function in the kgdb debug core.
When processing a single step return zero in the error exception field so that the debug core can distinguish between a single step trap and a breakpoint trap generically.
--- arch/sh/kernel/kgdb.c | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
arch/sh/kernel/kgdb.c +13 -1
@@ -237,6 +237,18 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,return -1 ; } +unsigned long kgdb_arch_pc (int exception,struct pt_regs *regs) +{ +if (exception ==60 ) +return instruction_pointer (regs) -2 ; +return instruction_pointer (regs); +} + +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long ip) +{ + regs->pc = ip; +} +/* * The primary entry points for the kgdb debug trap table entries. */
@@ -247,7 +259,7 @@ BUILD_TRAP_HANDLER(singlestep)local_irq_save (flags); regs->pc -=instruction_size (__raw_readw (regs->pc -4 )); -kgdb_handle_exception (vec >>2 ,SIGTRAP ,0 , regs); +kgdb_handle_exception (0 ,SIGTRAP ,0 , regs);local_irq_restore (flags); }
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 6/28 kgdb,blackfin: Add in kgdb_arch_set_pc for blackfin
In reply to Jason WesselThe new debug core api requires all architectures that use to debug core to implement a function to set the program counter.
--- arch/blackfin/kernel/kgdb.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
arch/blackfin/kernel/kgdb.c +5 -0
@@ -439,6 +439,11 @@ int kgdb_validate_break_address(unsigned long addr)return -EFAULT ; } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long ip) +{ + regs->retx = ip; +} +int kgdb_arch_init (void ) { kgdb_single_step =0 ;
Signature · 1 line
1.6.4.rc1
Re: [PATCH 06/28] kgdb,blackfin: Add in kgdb_arch_set_pc for blackfin
Quoted 4 lines · Jason Wessel
The new debug core api requires all architectures that use to debug core to implement a function to set the program counter.
CC Mike Frysinger <[email protected]>
sorry, thought i Acked-by this already ...
-mike
Jason Wessel
maintainerPATCH 7/28 kdb: core for kgdb back end (1 of 2)
In reply to Jason WesselThis patch contains only the kdb core. Because the change set was large, it was split. The next patch in the series includes the instrumentation into the core kernel which are mainly helper functions for kdb.
This work is directly derived from kdb v4.4 found at:
ftp://oss.sgi.com/projects/kdb/download/v4.4/
The kdb internals have been re-organized to make them mostly platform independent and to connect everything to the debug core which is used by gdbstub (which has long been known as kgdb).
The original version of kdb was 58,000 lines worth of changes to support x86. From that implementation only the kdb shell, and basic commands for memory access, runcontrol, lsmod, and dmesg where carried forward.
This is a generic implementation which aims to cover all the current architectures using the kgdb core: ppc, arm, x86, mips, sparc, sh and blackfin. More archictectures can be added by implementing the architecture specific kgdb functions.
[[email protected]: Compile fix with hugepages enabled]
[[email protected]: Clean breakpoint code renaming kdba_ -> kdb_] [[email protected]: fix new line after printing registers] [[email protected]: Remove the concept of global vs. local breakpoints] [[email protected]: Rework kdb_si_swapinfo to use more generic name] [[email protected]: fix the information dump macros, remove 'arch' from the names]
--- include/linux/kdb.h | 110 ++ kernel/debug/Makefile | 4 +- kernel/debug/kdb/.gitignore | 1 + kernel/debug/kdb/Makefile | 24 + kernel/debug/kdb/kdb_bp.c | 564 ++++++++ kernel/debug/kdb/kdb_bt.c | 208 +++ kernel/debug/kdb/kdb_cmds | 35 + kernel/debug/kdb/kdb_debugger.c | 159 +++ kernel/debug/kdb/kdb_io.c | 789 +++++++++++ kernel/debug/kdb/kdb_main.c | 2851 +++++++++++++++++++++++++++++++++++++++ kernel/debug/kdb/kdb_private.h | 314 +++++ kernel/debug/kdb/kdb_support.c | 991 ++++++++++++++ 12 files changed, 6049 insertions(+), 1 deletions(-) create mode 100644 include/linux/kdb.h create mode 100644 kernel/debug/kdb/.gitignore create mode 100644 kernel/debug/kdb/Makefile create mode 100644 kernel/debug/kdb/kdb_bp.c create mode 100644 kernel/debug/kdb/kdb_bt.c create mode 100644 kernel/debug/kdb/kdb_cmds create mode 100644 kernel/debug/kdb/kdb_debugger.c create mode 100644 kernel/debug/kdb/kdb_io.c create mode 100644 kernel/debug/kdb/kdb_main.c create mode 100644 kernel/debug/kdb/kdb_private.h create mode 100644 kernel/debug/kdb/kdb_support.c
include/linux/kdb.h new file +110 -0
@@ -0,0 +1,110 @@ +#ifndef _KDB_H +#define _KDB_H + +/* +* Kernel Debugger Architecture Independent Global Headers +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file "COPYING" in the main directory of this archive +* for more details. +* +* Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved. +* Copyright (C) 2000 Stephane Eranian <[email protected]> +* Copyright (C) 2009 Jason Wessel <[email protected]> +*/ + +#ifdef CONFIG_KGDB_KDB +#include <linux/init.h> +#include <linux/sched.h> +#include <asm/atomic.h> + +#define KDB_POLL_FUNC_MAX 5 + +/* +* kdb_initial_cpu is initialized to -1, and is set to the cpu +* number whenever the kernel debugger is entered. +*/ +extern int kdb_initial_cpu; +extern atomic_t kdb_event; + +/* +* kdb_diemsg +* +* Contains a pointer to the last string supplied to the +* kernel 'die' panic function. +*/ +extern const char *kdb_diemsg; + +#define KDB_FLAG_EARLYKDB (1 << 0)/* set from boot parameter kdb=early */ +#define KDB_FLAG_CATASTROPHIC (1 << 1)/* A catastrophic event has occurred */ +#define KDB_FLAG_CMD_INTERRUPT (1 << 2)/* Previous command was interrupted */ +#define KDB_FLAG_NOIPI (1 << 3)/* Do not send IPIs */ +#define KDB_FLAG_ONLY_DO_DUMP (1 << 4)/* Only do a dump, used when +* kdb is off */ +#define KDB_FLAG_NO_CONSOLE (1 << 5)/* No console is available, +* kdb is disabled */ +#define KDB_FLAG_NO_VT_CONSOLE (1 << 6)/* No VT console is available, do +* not use keyboard */ +#define KDB_FLAG_NO_I8042 (1 << 7)/* No i8042 chip is available, do +* not use keyboard */ + +extern int kdb_flags;/* Global flags, see kdb_state for per cpu state */ + +extern void kdb_save_flags (void ); +extern void kdb_restore_flags (void ); + +#define KDB_FLAG (flag) (kdb_flags & KDB_FLAG_##flag) +#define KDB_FLAG_SET (flag) ((void)(kdb_flags |= KDB_FLAG_##flag)) +#define KDB_FLAG_CLEAR (flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag)) + +/* +* External entry point for the kernel debugger. The pt_regs +* at the time of entry are supplied along with the reason for +* entry to the kernel debugger. +*/ + +typedef enum { +KDB_REASON_ENTER =1 ,/* KDB_ENTER() trap/fault - regs valid */ +KDB_REASON_ENTER_SLAVE ,/* KDB_ENTER_SLAVE() trap/fault - regs valid */ +KDB_REASON_BREAK ,/* Breakpoint inst. - regs valid */ +KDB_REASON_DEBUG ,/* Debug Fault - regs valid */ +KDB_REASON_OOPS ,/* Kernel Oops - regs valid */ +KDB_REASON_SWITCH ,/* CPU switch - regs valid*/ +KDB_REASON_KEYBOARD ,/* Keyboard entry - regs valid */ +KDB_REASON_NMI ,/* Non-maskable interrupt; regs valid */ +KDB_REASON_RECURSE ,/* Recursive entry to kdb; +* regs probably valid */ +KDB_REASON_SSTEP ,/* Single Step trap. - regs valid */ +}kdb_reason_t ; + +extern int kdb_printf (const char *, ...) + __attribute__ ((format (printf,1 ,2 ))); +typedef int (*kdb_printf_t )(const char *, ...) + __attribute__ ((format (printf,1 ,2 ))); + +extern void kdb_init (int level); + +/* Access to kdb specific polling devices */ +typedef int (*get_char_func )(void ); +extern get_char_func kdb_poll_funcs[]; +extern int kdb_get_kbd_char (void ); + +static inline +int kdb_process_cpu (const struct task_struct *p) +{ +unsigned int cpu =task_thread_info (p)->cpu; +if (cpu >num_possible_cpus ()) + cpu =0 ; +return cpu; +} + +#else /* ! CONFIG_KGDB_KDB */ +#define kdb_printf (...) +#define kdb_init (x) +#endif /* CONFIG_KGDB_KDB */ +enum { +KDB_NOT_INITIALIZED , +KDB_INIT_EARLY , +KDB_INIT_FULL , +}; +#endif /* !_KDB_H */
kernel/debug/Makefile +3 -1
@@ -2,4 +2,6 @@ # Makefile for the linux kernel debugger # -obj-$(CONFIG_KGDB) += debug_core.o gdbstub.o +obj-$(CONFIG_KGDB) += debug_core.o gdbstub.o +obj-$(CONFIG_KGDB_KDB) += kdb/ +
kernel/debug/kdb/.gitignore new file +1 -0
@@ -0,0 +1 @@ +gen-kdb_cmds.c
kernel/debug/kdb/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +# This file is subject to the terms and conditions of the GNU General Public +# License. See the file "COPYING" in the main directory of this archive +# for more details. +# +# Copyright (c) 1999-2004 Silicon Graphics, Inc. All Rights Reserved. +# Copyright (c) 2009 Wind River Systems, Inc. All Rights Reserved. +# + +CCVERSION := $(shell $(CC) -v 2>&1 | sed -ne '$$p') +obj-y := kdb_io.o kdb_main.o kdb_support.o kdb_bt.o gen-kdb_cmds.o kdb_bp.o kdb_debugger.o + +clean-files := gen-kdb_cmds.c + +quiet_cmd_gen-kdb = GENKDB $@ + cmd_gen-kdb = $(AWK) 'BEGIN {print "\#include <linux/stddef.h>"; print "\#include <linux/init.h>"} \ + /^\#/{next} \ + /^[ \t]*$$/{next} \ + {gsub(/"/, "\\\"", $$0); \ + print "static __initdata char kdb_cmd" cmds++ "[] = \"" $$0 "\\n\";"} \ + END {print "extern char *kdb_cmds[]; char __initdata *kdb_cmds[] = {"; for (i = 0; i < cmds; ++i) {print " kdb_cmd" i ","}; print(" NULL\n};");}' \ + $(filter-out %/Makefile,$^) > $@# + +$(obj)/gen-kdb_cmds.c: $(src)/kdb_cmds $(src)/Makefile + $(call cmd,gen-kdb)
kernel/debug/kdb/kdb_bp.c new file +564 -0
564 lines not on this page · raw message
kernel/debug/kdb/kdb_bt.c new file +208 -0
208 lines not on this page · raw message
kernel/debug/kdb/kdb_cmds new file +35 -0
@@ -0,0 +1,35 @@ +# Initial commands for kdb, alter to suit your needs. +# These commands are executed in kdb_init() context, no SMP, no +# processes. Commands that require process data (including stack or +# registers) are not reliable this early. set and bp commands should +# be safe. Global breakpoint commands affect each cpu as it is booted. + +# Standard debugging information for first level support, just type archkdb +# or archkdbcpu or archkdbshort at the kdb prompt. + +defcmd dumpcommon "" "Common kdb debugging" + set BTAPROMPT 0 + set LINES 10000 + -summary + -cpu + -ps + -dmesg 600 + -bt +endefcmd + +defcmd dumpall "" "First line debugging" + set BTSYMARG 1 + set BTARGS 9 + pid R + -dumpcommon + -bta +endefcmd + +defcmd dumpcpu "" "Same as dumpall but only tasks on cpus" + set BTSYMARG 1 + set BTARGS 9 + pid R + -dumpcommon + -btc +endefcmd +
kernel/debug/kdb/kdb_debugger.c new file +159 -0
159 lines not on this page · raw message
kernel/debug/kdb/kdb_io.c new file +789 -0
789 lines not on this page · raw message
kernel/debug/kdb/kdb_main.c new file +2851 -0
1,102 lines not on this page · raw message
kernel/debug/kdb/kdb_private.h new file +314 -0
314 lines not on this page · raw message
kernel/debug/kdb/kdb_support.c new file +991 -0
991 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.6.4.rc1
Part of the diff is not shown here. View the raw message.
Jason Wessel
maintainerPATCH 8/28 kdb: core for kgdb back end (2 of 2)
In reply to Jason WesselThis patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
--- arch/arm/include/asm/kmap_types.h | 1 + arch/powerpc/include/asm/kmap_types.h | 1 + fs/proc/internal.h | 4 +- fs/proc/meminfo.c | 15 ++++++++++-- fs/proc/mmu.c | 8 ++++-- include/asm-generic/kmap_types.h | 3 +- include/linux/swap.h | 2 + init/main.c | 2 + kernel/kallsyms.c | 21 +++++++++++++++++ kernel/module.c | 4 +++ kernel/printk.c | 16 +++++++++++++ kernel/sched.c | 7 ++++- kernel/signal.c | 40 +++++++++++++++++++++++++++++++++ mm/swapfile.c | 10 ++++++- 14 files changed, 121 insertions(+), 13 deletions(-)
arch/arm/include/asm/kmap_types.h +1 -0
@@ -19,6 +19,7 @@ enum km_type {KM_SOFTIRQ0 ,KM_SOFTIRQ1 ,KM_L2_CACHE , +KM_KDB , KM_TYPE_NR };
arch/powerpc/include/asm/kmap_types.h +1 -0
@@ -26,6 +26,7 @@ enum km_type {KM_SOFTIRQ1 ,KM_PPC_SYNC_PAGE ,KM_PPC_SYNC_ICACHE , +KM_KDB , KM_TYPE_NR };
fs/proc/internal.h +2 -2
@@ -32,11 +32,11 @@ extern struct mm_struct *mm_for_maps(struct task_struct *);#ifdef CONFIG_MMU #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START) -extern void get_vmalloc_info (struct vmalloc_info *vmi); +extern void get_vmalloc_info (struct vmalloc_info *vmi,int lock);#else #define VMALLOC_TOTAL 0UL -#define get_vmalloc_info (vmi) \ +#define get_vmalloc_info (vmi, lock) \ do { \ (vmi)->used = 0; \ (vmi)->largest_chunk = 0; \
fs/proc/meminfo.c +12 -3
@@ -10,6 +10,7 @@#include <linux/seq_file.h> #include <linux/swap.h> #include <linux/vmstat.h> +#include <linux/kdb.h> #include <asm/atomic.h> #include <asm/page.h> #include <asm/pgtable.h>
@@ -19,7 +20,7 @@ void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) { } -static int meminfo_proc_show (struct seq_file *m,void *v) +int _meminfo_proc_show (struct seq_file *m,void *v,int lock) {struct sysinfo i;unsigned long committed;
@@ -34,7 +35,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)*/ #define K (x) ((x) << (PAGE_SHIFT - 10))si_meminfo (&i); -si_swapinfo (&i); +if (lock) +si_swapinfo (&i); +else +__si_swapinfo (&i); committed =percpu_counter_read_positive (&vm_committed_as); allowed = ((totalram_pages -hugetlb_total_pages ()) * sysctl_overcommit_ratio /100 ) + total_swap_pages;
@@ -44,7 +48,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)if (cached <0 ) cached =0 ; -get_vmalloc_info (&vmi); +get_vmalloc_info (&vmi, lock);for (lru =LRU_BASE ; lru <NR_LRU_LISTS ; lru++) pages[lru] =global_page_state (NR_LRU_BASE + lru);
@@ -161,6 +165,11 @@ static int meminfo_proc_show(struct seq_file *m, void *v)#undef K } +static int meminfo_proc_show (struct seq_file *m,void *v) +{ +return _meminfo_proc_show (m, v,1 ); +} +static int meminfo_proc_open (struct inode *inode,struct file *file) {return single_open (file, meminfo_proc_show,NULL );
fs/proc/mmu.c +5 -3
@@ -14,7 +14,7 @@#include <asm/pgtable.h> #include "internal.h" -void get_vmalloc_info (struct vmalloc_info *vmi) +void get_vmalloc_info (struct vmalloc_info *vmi,int lock) {struct vm_struct *vma;unsigned long free_area_size;
@@ -30,7 +30,8 @@ void get_vmalloc_info(struct vmalloc_info *vmi) prev_end =VMALLOC_START ; -read_lock (&vmlist_lock); +if (lock) +read_lock (&vmlist_lock);for (vma = vmlist; vma; vma = vma->next) {unsigned long addr = (unsigned long ) vma->addr;
@@ -55,6 +56,7 @@ void get_vmalloc_info(struct vmalloc_info *vmi)if (VMALLOC_END - prev_end > vmi->largest_chunk) vmi->largest_chunk =VMALLOC_END - prev_end; -read_unlock (&vmlist_lock); +if (lock) +read_unlock (&vmlist_lock); } }
include/asm-generic/kmap_types.h +2 -1
@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY, KMAP_D(16) KM_IRQ_PTE, KMAP_D(17) KM_NMI, KMAP_D(18) KM_NMI_PTE, -KMAP_D(19) KM_TYPE_NR +KMAP_D(19) KM_KDB, +KMAP_D(20) KM_TYPE_NR };#undef KMAP_D
include/linux/swap.h +2 -0
@@ -312,6 +312,7 @@ extern struct page *swapin_readahead(swp_entry_t, gfp_t,/* linux/mm/swapfile.c */ extern long nr_swap_pages;extern long total_swap_pages; +extern void __si_swapinfo (struct sysinfo *);extern void si_swapinfo (struct sysinfo *);extern swp_entry_t get_swap_page (void );extern swp_entry_t get_swap_page_of_type (int );
@@ -377,6 +378,7 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)#define si_swapinfo (val) \ do { (val)->freeswap = (val)->totalswap = 0; } while (0) +#define __si_swapinfo (val) si_swapinfo(val)/* only sparc can not include linux/pagemap.h in this file * so leave page_cache_release and release_pages undeclared... */ #define free_page_and_swap_cache (page) \
init/main.c +2 -0
@@ -63,6 +63,7 @@#include <linux/sched.h> #include <linux/signal.h> #include <linux/idr.h> +#include <linux/kdb.h> #include <linux/ftrace.h> #include <linux/async.h> #include <linux/kmemcheck.h>
@@ -659,6 +660,7 @@ asmlinkage void __init start_kernel(void)key_init ();radix_tree_init ();security_init (); +kdb_init (KDB_INIT_FULL );vfs_caches_init (totalram_pages);signals_init ();/* rootfs populating might need page-writeback */
kernel/kallsyms.c +21 -0
@@ -16,6 +16,7 @@#include <linux/init.h> #include <linux/seq_file.h> #include <linux/fs.h> +#include <linux/kdb.h> #include <linux/err.h> #include <linux/proc_fs.h> #include <linux/sched.h> /* for cond_resched */
@@ -515,6 +516,26 @@ static int kallsyms_open(struct inode *inode, struct file *file)return ret; } +#ifdef CONFIG_KGDB_KDB +const char *kdb_walk_kallsyms (loff_t *pos) +{ +static struct kallsym_iter kdb_walk_kallsyms_iter; +if (*pos ==0 ) { +memset (&kdb_walk_kallsyms_iter,0 , +sizeof (kdb_walk_kallsyms_iter)); +reset_iter (&kdb_walk_kallsyms_iter,0 ); + } +while (1 ) { +if (!update_iter (&kdb_walk_kallsyms_iter, *pos)) +return NULL ; + ++*pos; +/* Some debugging symbols have no name. Ignore them. */ +if (kdb_walk_kallsyms_iter.name[0 ]) +return kdb_walk_kallsyms_iter.name; + } +} +#endif /* CONFIG_KGDB_KDB */ +static const struct file_operations kallsyms_operations = { .open = kallsyms_open, .read = seq_read,
kernel/module.c +4 -0
@@ -79,6 +79,10 @@ EXPORT_TRACEPOINT_SYMBOL(module_get);DEFINE_MUTEX (module_mutex);EXPORT_SYMBOL_GPL (module_mutex);static LIST_HEAD (modules); +#ifdef CONFIG_KGDB_KDB +struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ +#endif /* CONFIG_KGDB_KDB */ +/* Block module loading/unloading? */ int modules_disabled =0 ;
kernel/printk.c +16 -0
@@ -420,6 +420,22 @@ SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)return do_syslog (type, buf, len); } +#ifdef CONFIG_KGDB_KDB +/* kdb dmesg command needs access to the syslog buffer. do_syslog() +* uses locks so it cannot be used during debugging. Just tell kdb +* where the start and end of the physical and logical logs are. This +* is equivalent to do_syslog(3). +*/ +void kdb_syslog_data (char *syslog_data[4 ]) +{ + syslog_data[0 ] = log_buf; + syslog_data[1 ] = log_buf + log_buf_len; + syslog_data[2 ] = log_buf + log_end - + (logged_chars < log_buf_len ? logged_chars : log_buf_len); + syslog_data[3 ] = log_buf + log_end; +} +#endif /* CONFIG_KGDB_KDB */ +/* * Call the console drivers on a range of log_buf */
kernel/sched.c +5 -2
@@ -9802,9 +9802,9 @@ void normalize_rt_tasks(void)#endif /* CONFIG_MAGIC_SYSRQ */ -#ifdef CONFIG_IA64 +#if defined(CONFIG_IA64 ) || defined(CONFIG_KGDB_KDB )/* -* These functions are only useful for the IA64 MCA handling. +* These functions are only useful for the IA64 MCA handling, or kdb. * * They can only be called when the whole system has been * stopped - every CPU needs to be quiescent, and no scheduling
@@ -9824,6 +9824,9 @@ struct task_struct *curr_task(int cpu) return cpu_curr(cpu); } +#endif /* defined(CONFIG_IA64) || defined(CONFIG_KGDB_KDB) */ + +#ifdef CONFIG_IA64 /** * set_curr_task - set the current task for a given cpu. * @cpu: the processor in question.
kernel/signal.c +40 -0
@@ -2718,3 +2718,43 @@ void __init signals_init(void) { sigqueue_cachep =KMEM_CACHE (sigqueue,SLAB_PANIC ); } + +#ifdef CONFIG_KGDB_KDB +#include <linux/kdb.h> +/* +* kdb_send_sig_info - Allows kdb to send signals without exposing +* signal internals. This function checks if the required locks are +* available before calling the main signal code, to avoid kdb +* deadlocks. +*/ +void +kdb_send_sig_info (struct task_struct *t,struct siginfo *info) +{ +static struct task_struct *kdb_prev_t; +int sig, new_t; +if (!spin_trylock (&t->sighand->siglock)) { +kdb_printf ("Can't do kill command now.\n" +"The sigmask lock is held somewhere else in " +"kernel, try again later\n" ); +return ; + } +spin_unlock (&t->sighand->siglock); + new_t = kdb_prev_t != t; + kdb_prev_t = t; +if (t->state !=TASK_RUNNING && new_t) { +kdb_printf ("Process is not RUNNING, sending a signal from " +"kdb risks deadlock\n" +"on the run queue locks. " +"The signal has _not_ been sent.\n" +"Reissue the kill command if you want to risk " +"the deadlock.\n" ); +return ; + } + sig = info->si_signo; +if (send_sig_info (sig, info, t)) +kdb_printf ("Fail to deliver Signal %d to process %d.\n" , + sig, t->pid); +else +kdb_printf ("Signal %d is sent to process %d.\n" , sig, t->pid); +} +#endif /* CONFIG_KGDB_KDB */
mm/swapfile.c +8 -2
@@ -13,6 +13,7 @@#include <linux/swap.h> #include <linux/vmalloc.h> #include <linux/pagemap.h> +#include <linux/kdb.h> #include <linux/namei.h> #include <linux/shm.h> #include <linux/blkdev.h>
@@ -2056,12 +2057,11 @@ out:return error; } -void si_swapinfo (struct sysinfo *val) +void __si_swapinfo (struct sysinfo *val) {unsigned int type;unsigned long nr_to_be_unused =0 ; -spin_lock (&swap_lock);for (type =0 ; type < nr_swapfiles; type++) {struct swap_info_struct *si = swap_info[type];
@@ -2070,6 +2070,12 @@ void si_swapinfo(struct sysinfo *val) } val->freeswap = nr_swap_pages + nr_to_be_unused; val->totalswap = total_swap_pages + nr_to_be_unused; +} + +void si_swapinfo (struct sysinfo *val) +{ +spin_lock (&swap_lock); +__si_swapinfo (val);spin_unlock (&swap_lock); }
Signature · 7 lines
1.6.4.rc1 ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 3 lines · Jason Wessel
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
You know this dropping the locks from vmalloc_info and swap_info is down right ugly, and I don't believe it is safe. That code was not designed to run while the write_lock is held.
How does kdb build if NOMMU is set?
Similarly with si_swapinfo. What makes it safe to run the code without it's locks. Safe as in no null pointer deferences or other nasties.
I am not impressed with the mess you make of meminfo_proc_show. That looks like a maintenance hazard if I ever saw one. An innocent change to get some additional info (that happens to take a lock) will cause kdb to deadlock.
The weird magic include of kdb.h in fs/proc/meminfo.c is also ugly.
Eric
Quoted 360 lines
fs/proc/internal.h +2
-2@@ -32,11 +32,11 @@ extern struct mm_struct *mm_for_maps(struct task_struct *);#ifdef CONFIG_MMU #define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START) -extern void get_vmalloc_info (struct vmalloc_info *vmi); +extern void get_vmalloc_info (struct vmalloc_info *vmi,int lock);#else #define VMALLOC_TOTAL 0UL -#define get_vmalloc_info (vmi) \ +#define get_vmalloc_info (vmi, lock) \ do { \ (vmi)->used = 0; \ (vmi)->largest_chunk = 0; \fs/proc/meminfo.c +12
-3@@ -10,6 +10,7 @@#include <linux/seq_file.h> #include <linux/swap.h> #include <linux/vmstat.h> +#include <linux/kdb.h> #include <asm/atomic.h> #include <asm/page.h> #include <asm/pgtable.h> @@ -19,7 +20,7 @@ void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) { } -static int meminfo_proc_show (struct seq_file *m,void *v) +int _meminfo_proc_show (struct seq_file *m,void *v,int lock) {struct sysinfo i;unsigned long committed;@@ -34,7 +35,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)*/ #define K (x) ((x) << (PAGE_SHIFT - 10))si_meminfo (&i); -si_swapinfo (&i); +if (lock) +si_swapinfo (&i); +else +__si_swapinfo (&i); committed =percpu_counter_read_positive (&vm_committed_as); allowed = ((totalram_pages -hugetlb_total_pages ()) * sysctl_overcommit_ratio /100 ) + total_swap_pages;@@ -44,7 +48,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)if (cached <0 ) cached =0 ; -get_vmalloc_info (&vmi); +get_vmalloc_info (&vmi, lock);for (lru =LRU_BASE ; lru <NR_LRU_LISTS ; lru++) pages[lru] =global_page_state (NR_LRU_BASE + lru);@@ -161,6 +165,11 @@ static int meminfo_proc_show(struct seq_file *m, void *v)#undef K } +static int meminfo_proc_show (struct seq_file *m,void *v) +{ +return _meminfo_proc_show (m, v,1 ); +} +static int meminfo_proc_open (struct inode *inode,struct file *file) {return single_open (file, meminfo_proc_show,NULL );fs/proc/mmu.c +5
-3@@ -14,7 +14,7 @@#include <asm/pgtable.h> #include "internal.h" -void get_vmalloc_info (struct vmalloc_info *vmi) +void get_vmalloc_info (struct vmalloc_info *vmi,int lock) {struct vm_struct *vma;unsigned long free_area_size;@@ -30,7 +30,8 @@ void get_vmalloc_info(struct vmalloc_info *vmi) prev_end =VMALLOC_START ; -read_lock (&vmlist_lock); +if (lock) +read_lock (&vmlist_lock);for (vma = vmlist; vma; vma = vma->next) {unsigned long addr = (unsigned long ) vma->addr;@@ -55,6 +56,7 @@ void get_vmalloc_info(struct vmalloc_info *vmi)if (VMALLOC_END - prev_end > vmi->largest_chunk) vmi->largest_chunk =VMALLOC_END - prev_end; -read_unlock (&vmlist_lock); +if (lock) +read_unlock (&vmlist_lock); } }include/asm-generic/kmap_types.h +2
-1@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY, KMAP_D(16) KM_IRQ_PTE, KMAP_D(17) KM_NMI, KMAP_D(18) KM_NMI_PTE, -KMAP_D(19) KM_TYPE_NR +KMAP_D(19) KM_KDB, +KMAP_D(20) KM_TYPE_NR };#undef KMAP_Dinclude/linux/swap.h +2
-0@@ -312,6 +312,7 @@ extern struct page *swapin_readahead(swp_entry_t, gfp_t,/* linux/mm/swapfile.c */ extern long nr_swap_pages;extern long total_swap_pages; +extern void __si_swapinfo (struct sysinfo *);extern void si_swapinfo (struct sysinfo *);extern swp_entry_t get_swap_page (void );extern swp_entry_t get_swap_page_of_type (int );@@ -377,6 +378,7 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t ent)#define si_swapinfo (val) \ do { (val)->freeswap = (val)->totalswap = 0; } while (0) +#define __si_swapinfo (val) si_swapinfo(val)/* only sparc can not include linux/pagemap.h in this file * so leave page_cache_release and release_pages undeclared... */ #define free_page_and_swap_cache (page) \init/main.c +2
-0@@ -63,6 +63,7 @@#include <linux/sched.h> #include <linux/signal.h> #include <linux/idr.h> +#include <linux/kdb.h> #include <linux/ftrace.h> #include <linux/async.h> #include <linux/kmemcheck.h> @@ -659,6 +660,7 @@ asmlinkage void __init start_kernel(void)key_init ();radix_tree_init ();security_init (); +kdb_init (KDB_INIT_FULL );vfs_caches_init (totalram_pages);signals_init ();/* rootfs populating might need page-writeback */ kernel/kallsyms.c +21
-0@@ -16,6 +16,7 @@#include <linux/init.h> #include <linux/seq_file.h> #include <linux/fs.h> +#include <linux/kdb.h> #include <linux/err.h> #include <linux/proc_fs.h> #include <linux/sched.h> /* for cond_resched */ @@ -515,6 +516,26 @@ static int kallsyms_open(struct inode *inode, struct file *file)return ret; } +#ifdef CONFIG_KGDB_KDB +const char *kdb_walk_kallsyms (loff_t *pos) +{ +static struct kallsym_iter kdb_walk_kallsyms_iter; +if (*pos ==0 ) { +memset (&kdb_walk_kallsyms_iter,0 , +sizeof (kdb_walk_kallsyms_iter)); +reset_iter (&kdb_walk_kallsyms_iter,0 ); + } +while (1 ) { +if (!update_iter (&kdb_walk_kallsyms_iter, *pos)) +return NULL ; + ++*pos; +/* Some debugging symbols have no name. Ignore them. */ +if (kdb_walk_kallsyms_iter.name[0 ]) +return kdb_walk_kallsyms_iter.name; + } +} +#endif /* CONFIG_KGDB_KDB */ +static const struct file_operations kallsyms_operations = { .open = kallsyms_open, .read = seq_read,kernel/module.c +4
-0@@ -79,6 +79,10 @@ EXPORT_TRACEPOINT_SYMBOL(module_get);DEFINE_MUTEX (module_mutex);EXPORT_SYMBOL_GPL (module_mutex);static LIST_HEAD (modules); +#ifdef CONFIG_KGDB_KDB +struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ +#endif /* CONFIG_KGDB_KDB */ +/* Block module loading/unloading? */ int modules_disabled =0 ;kernel/printk.c +16
-0@@ -420,6 +420,22 @@ SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)return do_syslog (type, buf, len); } +#ifdef CONFIG_KGDB_KDB +/* kdb dmesg command needs access to the syslog buffer. do_syslog() +* uses locks so it cannot be used during debugging. Just tell kdb +* where the start and end of the physical and logical logs are. This +* is equivalent to do_syslog(3). +*/ +void kdb_syslog_data (char *syslog_data[4 ]) +{ + syslog_data[0 ] = log_buf; + syslog_data[1 ] = log_buf + log_buf_len; + syslog_data[2 ] = log_buf + log_end - + (logged_chars < log_buf_len ? logged_chars : log_buf_len); + syslog_data[3 ] = log_buf + log_end; +} +#endif /* CONFIG_KGDB_KDB */ +/* * Call the console drivers on a range of log_buf */ kernel/sched.c +5
-2@@ -9802,9 +9802,9 @@ void normalize_rt_tasks(void)#endif /* CONFIG_MAGIC_SYSRQ */ -#ifdef CONFIG_IA64 +#if defined(CONFIG_IA64 ) || defined(CONFIG_KGDB_KDB )/* -* These functions are only useful for the IA64 MCA handling. +* These functions are only useful for the IA64 MCA handling, or kdb. * * They can only be called when the whole system has been * stopped - every CPU needs to be quiescent, and no scheduling @@ -9824,6 +9824,9 @@ struct task_struct *curr_task(int cpu) return cpu_curr(cpu); } +#endif /* defined(CONFIG_IA64) || defined(CONFIG_KGDB_KDB) */ + +#ifdef CONFIG_IA64 /** * set_curr_task - set the current task for a given cpu. * @cpu: the processor in question. kernel/signal.c +40
-0@@ -2718,3 +2718,43 @@ void __init signals_init(void) { sigqueue_cachep =KMEM_CACHE (sigqueue,SLAB_PANIC ); } + +#ifdef CONFIG_KGDB_KDB +#include <linux/kdb.h> +/* +* kdb_send_sig_info - Allows kdb to send signals without exposing +* signal internals. This function checks if the required locks are +* available before calling the main signal code, to avoid kdb +* deadlocks. +*/ +void +kdb_send_sig_info (struct task_struct *t,struct siginfo *info) +{ +static struct task_struct *kdb_prev_t; +int sig, new_t; +if (!spin_trylock (&t->sighand->siglock)) { +kdb_printf ("Can't do kill command now.\n" +"The sigmask lock is held somewhere else in " +"kernel, try again later\n" ); +return ; + } +spin_unlock (&t->sighand->siglock); + new_t = kdb_prev_t != t; + kdb_prev_t = t; +if (t->state !=TASK_RUNNING && new_t) { +kdb_printf ("Process is not RUNNING, sending a signal from " +"kdb risks deadlock\n" +"on the run queue locks. " +"The signal has _not_ been sent.\n" +"Reissue the kill command if you want to risk " +"the deadlock.\n" ); +return ; + } + sig = info->si_signo; +if (send_sig_info (sig, info, t)) +kdb_printf ("Fail to deliver Signal %d to process %d.\n" , + sig, t->pid); +else +kdb_printf ("Signal %d is sent to process %d.\n" , sig, t->pid); +} +#endif /* CONFIG_KGDB_KDB */ mm/swapfile.c +8
-2@@ -13,6 +13,7 @@#include <linux/swap.h> #include <linux/vmalloc.h> #include <linux/pagemap.h> +#include <linux/kdb.h> #include <linux/namei.h> #include <linux/shm.h> #include <linux/blkdev.h> @@ -2056,12 +2057,11 @@ out:return error; } -void si_swapinfo (struct sysinfo *val) +void __si_swapinfo (struct sysinfo *val) {unsigned int type;unsigned long nr_to_be_unused =0 ; -spin_lock (&swap_lock);for (type =0 ; type < nr_swapfiles; type++) {struct swap_info_struct *si = swap_info[type];@@ -2070,6 +2070,12 @@ void si_swapinfo(struct sysinfo *val) } val->freeswap = nr_swap_pages + nr_to_be_unused; val->totalswap = total_swap_pages + nr_to_be_unused; +} + +void si_swapinfo (struct sysinfo *val) +{ +spin_lock (&swap_lock); +__si_swapinfo (val);spin_unlock (&swap_lock); }Signature · 7 lines
1.6.4.rc1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Jason Wessel
maintainerRe: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 12 lines · Eric W. Biederman
Quoted 4 lines · Jason Wessel
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
You know this dropping the locks from
vmalloc_infoandswap_infois down right ugly, and I don't believe it is safe. That code was not designed to run while thewrite_lockis held.
Perhaps we can find some middle ground. I don't mind simply not allowing the information to be queried from kdb if the locks are not available.
Which is less ugly you, making the swap_lock global or adding a function to query it?
Quoted 2 lines
How does kdb build if NOMMU is set?
I did not see a kernel config option called NOMMU.
Can you point me to a kernel config that uses this? Or is it the case
that it is something like "# CONFIG_MMU is not set"?
Perhaps we just set kdb to work only when CONFIG_MMU is enabled? It is hard to say it works or not without a kernel configuration, file system and hardware to test it with.
Quoted 5 lines
Similarly with
si_swapinfo. What makes it safe to run the code without it's locks. Safe as in no null pointer deferences or other nasties.
It looks to me like the original kdb took the approach of calling the setjmp() longjmp() and if there was any kind of fault, it long jumped back to the original context. Obviously that doesn't solve any kind of problem with a list loop.
As I mentioned earlier, I think we should check for the lock and if it isn't available you don't get to execute the function, else a separate function has to be written that does the same thing safely. I do not see any value in making a separate function to safely print the information at this time. If you want to probe around, consider using a gdb macro.
Quoted 6 lines
I am not impressed with the mess you make of
meminfo_proc_show. That looks like a maintenance hazard if I ever saw one. An innocent change to get some additional info (that happens to take a lock) will cause kdb to deadlock.
This code goes away if we expose a way to check for the lock.
Jason.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 14 lines · Jason Wessel
Quoted 12 lines · Eric W. Biederman
Quoted 4 lines · Jason Wessel
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
You know this dropping the locks from
vmalloc_infoandswap_infois down right ugly, and I don't believe it is safe. That code was not designed to run while thewrite_lockis held.
Quoted 6 lines
Perhaps we can find some middle ground. I don't mind simply not allowing the information to be queried from kdb if the locks are not available.
Which is less ugly you, making the
swap_lockglobal or adding a function to query it?
My recommendation would be to simply drop the swap_info and meminfo information for now, and have kdb do what is good at.
Skimming through the history of the discussion it appears Christoph Hellwig asked you to do something about these bits on the first review.
From a maintenance point of view anything where you have to know which locks a function will take is fragile. It is entirely too easy to create a change that is fine in it's normal context but breaks kdb.
Alt-sysrq already allows capturing that kind of information, without any thorny maintenance issues. By contrast kdb appears to be a much larger and inferior tool.
Eric
Jason Wessel
maintainerRe: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 23 lines · Eric W. Biederman
Quoted 20 lines · Jason Wessel
Quoted 4 lines · Eric W. Biederman
Jason Wessel <[email protected]> writes:
Quoted 10 lines
Quoted 5 lines
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
You know this dropping the locks from
vmalloc_infoandswap_infois down right ugly, and I don't believe it is safe. That code was not designed to run while thewrite_lockis held.Perhaps we can find some middle ground. I don't mind simply not allowing the information to be queried from kdb if the locks are not available.
Quoted 7 lines
Quoted 3 lines
Which is less ugly you, making the
swap_lockglobal or adding a function to query it?My recommendation would be to simply drop the
swap_infoand meminfo information for now, and have kdb do what is good at.
I have no objection to dropping this for now.
Quoted 5 lines
Skimming through the history of the discussion it appears Christoph Hellwig asked you to do something about these bits on the first review.
If you are referring to the statement from the RFC patch:
"Patch 1 still containes a lot random junk. E.g. all those meminfo and whatever hooks aren't required for a very basic kernel debugger"
Most of that was restructured in that code base vs what you have taken a look at and we are down to a handful of instrumentation points.
Quoted 5 lines
From a maintenance point of view anything where you have to know which locks a function will take is fragile. It is entirely too easy to create a change that is fine in it's normal context but breaks kdb.
Sure, but that is life for kdb in the current state. You either make safe query macros or create something to call helper functions to inspect code. Either way it is maintenance.
Quoted 2 lines
Alt-sysrq already allows capturing that kind of information, without any thorny maintenance issues.
Alt-sysrq cannot be called from all the same contexts that you can invoke kdb. The maintenance issue you speak of is avoided because of the points you can actually invoke a sysrq. Certainly you are not going to be able to call Alt-sysrq, in an nmi as well as a number of other contexts.
Quoted 4 lines
By contrast kdb appears to be a much larger
and inferior tool.
I am not certain as to what comparison you are trying to draw here. If you are only using kdb to obtain meminfo and swapinfo, sure I buy your
argument. If you are using kdb to modify, inspect memory and execute
back traces at certain places then I think this is not an apples to apples comparison.
I'll post a new version of the patch with the hooks you asked about stripped out. The commands will also get removed from the kdb command shell.
Thanks,
Jason.
Jason Wessel
maintainerRe: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 3 lines · Jason Wessel
I'll post a new version of the patch with the hooks you asked about stripped out. The commands will also get removed from the kdb command shell.
Thanks for your comments Eric.
The summary of the clean up is as follows because some of the kdb core had to be touched in order to properly remove this.
fs/proc/internal.h | 4 +- fs/proc/meminfo.c | 15 +-------- fs/proc/mmu.c | 8 +---- include/linux/swap.h | 2 - kernel/debug/kdb/kdb_main.c | 13 +++----- kernel/debug/kdb/kdb_private.h | 12 ------- kernel/debug/kdb/kdb_support.c | 65 ----------------------------------------- mm/swapfile.c | 10 +----- 8 files changed, 15 insertions(+), 114 deletions(-)
Below is the new version of the basic kernel core kdb modifications. If you have further comments, please let me know. I would also be happy to add an ack if you approve of the new patch.
Thanks,
Jason.
---
From: Jason Wessel <[email protected]>
Subject: [PATCH] kdb: core for kgdb back end (2 of 2)
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
--- arch/arm/include/asm/kmap_types.h | 1 arch/powerpc/include/asm/kmap_types.h | 1 include/asm-generic/kmap_types.h | 3 +- init/main.c | 2 + kernel/kallsyms.c | 21 +++++++++++++++++ kernel/module.c | 4 +++ kernel/printk.c | 16 +++++++++++++ kernel/sched.c | 7 ++++- kernel/signal.c | 40 ++++++++++++++++++++++++++++++++++ 9 files changed, 92 insertions(+), 3 deletions(-)
arch/arm/include/asm/kmap_types.h +1 -0
@@ -19,6 +19,7 @@ enum km_type {KM_SOFTIRQ0 ,KM_SOFTIRQ1 ,KM_L2_CACHE , +KM_KDB , KM_TYPE_NR };
arch/powerpc/include/asm/kmap_types.h +1 -0
@@ -26,6 +26,7 @@ enum km_type {KM_SOFTIRQ1 ,KM_PPC_SYNC_PAGE ,KM_PPC_SYNC_ICACHE , +KM_KDB , KM_TYPE_NR };
include/asm-generic/kmap_types.h +2 -1
@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY, KMAP_D(16) KM_IRQ_PTE, KMAP_D(17) KM_NMI, KMAP_D(18) KM_NMI_PTE, -KMAP_D(19) KM_TYPE_NR +KMAP_D(19) KM_KDB, +KMAP_D(20) KM_TYPE_NR };#undef KMAP_D
init/main.c +2 -0
@@ -63,6 +63,7 @@#include <linux/sched.h> #include <linux/signal.h> #include <linux/idr.h> +#include <linux/kdb.h> #include <linux/ftrace.h> #include <linux/async.h> #include <linux/kmemcheck.h>
@@ -659,6 +660,7 @@ asmlinkage void __init start_kernel(voidkey_init ();radix_tree_init ();security_init (); +kdb_init (KDB_INIT_FULL );vfs_caches_init (totalram_pages);signals_init ();/* rootfs populating might need page-writeback */
kernel/kallsyms.c +21 -0
@@ -16,6 +16,7 @@#include <linux/init.h> #include <linux/seq_file.h> #include <linux/fs.h> +#include <linux/kdb.h> #include <linux/err.h> #include <linux/proc_fs.h> #include <linux/sched.h> /* for cond_resched */
@@ -515,6 +516,26 @@ static int kallsyms_open(struct inode *ireturn ret; } +#ifdef CONFIG_KGDB_KDB +const char *kdb_walk_kallsyms (loff_t *pos) +{ +static struct kallsym_iter kdb_walk_kallsyms_iter; +if (*pos ==0 ) { +memset (&kdb_walk_kallsyms_iter,0 , +sizeof (kdb_walk_kallsyms_iter)); +reset_iter (&kdb_walk_kallsyms_iter,0 ); + } +while (1 ) { +if (!update_iter (&kdb_walk_kallsyms_iter, *pos)) +return NULL ; + ++*pos; +/* Some debugging symbols have no name. Ignore them. */ +if (kdb_walk_kallsyms_iter.name[0 ]) +return kdb_walk_kallsyms_iter.name; + } +} +#endif /* CONFIG_KGDB_KDB */ +static const struct file_operations kallsyms_operations = { .open = kallsyms_open, .read = seq_read,
kernel/module.c +4 -0
@@ -79,6 +79,10 @@ EXPORT_TRACEPOINT_SYMBOL(module_get);DEFINE_MUTEX (module_mutex);EXPORT_SYMBOL_GPL (module_mutex);static LIST_HEAD (modules); +#ifdef CONFIG_KGDB_KDB +struct list_head *kdb_modules = &modules;/* kdb needs the list of modules */ +#endif /* CONFIG_KGDB_KDB */ +/* Block module loading/unloading? */ int modules_disabled =0 ;
kernel/printk.c +16 -0
@@ -420,6 +420,22 @@ SYSCALL_DEFINE3(syslog, int, type, charreturn do_syslog (type, buf, len); } +#ifdef CONFIG_KGDB_KDB +/* kdb dmesg command needs access to the syslog buffer. do_syslog() +* uses locks so it cannot be used during debugging. Just tell kdb +* where the start and end of the physical and logical logs are. This +* is equivalent to do_syslog(3). +*/ +void kdb_syslog_data (char *syslog_data[4 ]) +{ + syslog_data[0 ] = log_buf; + syslog_data[1 ] = log_buf + log_buf_len; + syslog_data[2 ] = log_buf + log_end - + (logged_chars < log_buf_len ? logged_chars : log_buf_len); + syslog_data[3 ] = log_buf + log_end; +} +#endif /* CONFIG_KGDB_KDB */ +/* * Call the console drivers on a range of log_buf */
kernel/sched.c +5 -2
@@ -9802,9 +9802,9 @@ void normalize_rt_tasks(void)#endif /* CONFIG_MAGIC_SYSRQ */ -#ifdef CONFIG_IA64 +#if defined(CONFIG_IA64 ) || defined(CONFIG_KGDB_KDB )/* -* These functions are only useful for the IA64 MCA handling. +* These functions are only useful for the IA64 MCA handling, or kdb. * * They can only be called when the whole system has been * stopped - every CPU needs to be quiescent, and no scheduling
@@ -9824,6 +9824,9 @@ struct task_struct *curr_task(int cpu) return cpu_curr(cpu); } +#endif /* defined(CONFIG_IA64) || defined(CONFIG_KGDB_KDB) */ + +#ifdef CONFIG_IA64 /** * set_curr_task - set the current task for a given cpu. * @cpu: the processor in question.
kernel/signal.c +40 -0
@@ -2718,3 +2718,43 @@ void __init signals_init(void) { sigqueue_cachep =KMEM_CACHE (sigqueue,SLAB_PANIC ); } + +#ifdef CONFIG_KGDB_KDB +#include <linux/kdb.h> +/* +* kdb_send_sig_info - Allows kdb to send signals without exposing +* signal internals. This function checks if the required locks are +* available before calling the main signal code, to avoid kdb +* deadlocks. +*/ +void +kdb_send_sig_info (struct task_struct *t,struct siginfo *info) +{ +static struct task_struct *kdb_prev_t; +int sig, new_t; +if (!spin_trylock (&t->sighand->siglock)) { +kdb_printf ("Can't do kill command now.\n" +"The sigmask lock is held somewhere else in " +"kernel, try again later\n" ); +return ; + } +spin_unlock (&t->sighand->siglock); + new_t = kdb_prev_t != t; + kdb_prev_t = t; +if (t->state !=TASK_RUNNING && new_t) { +kdb_printf ("Process is not RUNNING, sending a signal from " +"kdb risks deadlock\n" +"on the run queue locks. " +"The signal has _not_ been sent.\n" +"Reissue the kill command if you want to risk " +"the deadlock.\n" ); +return ; + } + sig = info->si_signo; +if (send_sig_info (sig, info, t)) +kdb_printf ("Fail to deliver Signal %d to process %d.\n" , + sig, t->pid); +else +kdb_printf ("Signal %d is sent to process %d.\n" , sig, t->pid); +} +#endif /* CONFIG_KGDB_KDB */
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Re: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
In reply to Jason WesselQuoted 9 lines · Jason Wessel
Quoted 8 lines · Eric W. Biederman
Quoted 4 lines · Jason Wessel
This patch contains the hooks and instrumentation into kernel which live outside the kernel/debug directory, which the kdb core will call to run commands like lsmod, dmesg, bt etc...
Quoted 8 lines
Quoted 4 lines
You know this dropping the locks from
vmalloc_infoandswap_infois down right ugly, and I don't believe it is safe. That code was not designed to run while thewrite_lockis held.Perhaps we can find some middle ground. I don't mind simply not allowing the information to be queried from kdb if the locks are not available.
IIRC the original KDB would stop all the cpus when entered, thus locking to avoid concurrent access to data
was not necessary when displaying kernel data structures. However, KDB user and developers were assumed to be aware that when KDB was entered the system context was in an indeterminate state particularly with respect to linked lists and other non-tabular data structures.
KDB code that displayed data structures which were kept in a non-table data structure (linked list, tree, etc.) was be required to both validate each pointer it tries to follow as well as ensure that it detects loops (either by terminating the list traversal after a certain number of elements or by allowing the KDB user to terminate the traversal with e.g. 'q').
Quoted 5 lines
It looks to me like the original kdb took the approach of calling the
setjmp()longjmp()and if there was any kind of fault, it long jumped back to the original context. Obviously that doesn't solve any kind of problem with a list loop.
Yes. The list loop was expected to be handled either by the display
code terminating after some number of traversal step or by the KDB user terminating the command via the keyboard (e.g. 'q' at a more-type prompt).
If the new KDB framework allows other cpus to continue to run while kdb data structure display commands are running, then much more care must be taken in the display command code to avoid inconsistent data causing loops or #PF.
scott
Jason Wessel
maintainerRe: [PATCH 08/28] kdb: core for kgdb back end (2 of 2)
Quoted 4 lines · Scott Lurndal
IIRC the original KDB would stop all the cpus when entered, thus locking to avoid concurrent access to data was not necessary when displaying kernel data structures.
Just because the system is "effectively frozen" does not mean you can safely walk a structure or call something that takes a lock.
One of the key points Eric and others have made is that they do not want some of this helper code in the kernel core, nor do they want alternate lock semantics while the kernel debugger is active. You can achieve the same sort of interrogation with a gdb helper macro. At some point kdb could be extended to have the same sort of functionality if someone finds they just cannot live without it.
Quoted 19 lines
However,
KDB user and developers were assumed to be aware that when KDB was entered the system context was in an indeterminate state particularly with respect to linked lists and other non-tabular data structures.KDB code that displayed data structures which were kept in a non-table data structure (linked list, tree, etc.) was be required to both validate each pointer it tries to follow as well as ensure that it detects loops (either by terminating the list traversal after a certain number of elements or by allowing the KDB user to terminate the traversal with e.g. 'q').
Quoted 5 lines
It looks to me like the original kdb took the approach of calling the
setjmp()longjmp()and if there was any kind of fault, it long jumped back to the original context. Obviously that doesn't solve any kind of problem with a list loop.
Quoted 5 lines
Yes. The list loop was expected to be handled either by the display
code terminating after some number of traversal step or by the KDB user terminating the command via the keyboard (e.g. 'q' at a more-type prompt).
The new kdb has a pager as well as abort operations, but it does not make use of setjmp() longjmp() to handle faults while executing other helper print code.
Quoted 6 lines
If the new KDB framework allows other cpus to continue to run while kdb data structure display commands are running, then much more care must be taken in the display command code to avoid inconsistent data causing loops or #PF.
In the new kdb. The system is fully stopped by the kernel debug core. There is the concept of the master CPU (the one running the debug shell) and the slave CPUs which are all the other cores. All the slaves spin in a control loop, and you may switch cpus with the kdb cpu command without exiting the debug context. The master can "trade places" with an online slave cpu.
Jason.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
Jason Wessel
maintainerPATCH 9/28 kgdb: core changes to support kdb
In reply to Jason WesselThese are the minimum changes to the kgdb core in order to enable an API to connect a new front end (kdb) to the debug core.
This patch introduces the dbg_kdb_mode variable controls where the user level I/O is routed. It will be routed to the gdbstub (kgdb) or to the kdb front end which is a simple shell available over the kgdboc connection.
You can switch back and forth between kdb or the gdb stub mode of operation dynamically. From gdb stub mode you can blindly type "$3#33", or from the kdb mode you can enter "kgdb" to switch to the gdb stub.
The logic in the debug core depends on kdb to look for the typical gdb connection sequences and return immediately with KGDB_PASS_EVENT if a gdb serial command sequence is detected. That should allow a reasonably seamless transition between kdb -> gdb without leaving the kernel exception state. The two gdb serial queries that kdb is responsible for detecting are the "?" and "qSupported" packets.
--- arch/arm/kernel/kgdb.c | 5 ++ arch/mips/kernel/kgdb.c | 5 ++ arch/powerpc/kernel/kgdb.c | 5 ++ arch/x86/kernel/kgdb.c | 5 ++ include/linux/kgdb.h | 11 ++++- kernel/debug/debug_core.c | 104 +++++++++++++++++++++++++++++++++++++------- kernel/debug/debug_core.h | 24 ++++++++++ kernel/debug/gdbstub.c | 36 +++++++++++++++ lib/Kconfig.kgdb | 6 +++ 9 files changed, 183 insertions(+), 18 deletions(-)
arch/arm/kernel/kgdb.c +5 -0
@@ -97,6 +97,11 @@ sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task) gdb_regs[_CPSR] = thread_regs->ARM_cpsr; } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc) +{ + regs->ARM_pc = pc; +} +static int compiled_break; int kgdb_arch_handle_exception(int exception_vector, int signo,
arch/mips/kernel/kgdb.c +5 -0
@@ -180,6 +180,11 @@ void sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *p) *(ptr++) = regs->cp0_epc; } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc) +{ + regs->cp0_epc = pc; +} +/* * Calls linux_debug_hook before the kernel dies. If KGDB is enabled, * then try to fall into the debugger
arch/powerpc/kernel/kgdb.c +5 -0
@@ -309,6 +309,11 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) (unsigned long)(((void *)gdb_regs) + NUMREGBYTES)); } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc) +{ + regs->nip = pc; +} +/* * This function does PowerPC specific procesing for interfacing to gdb. */
arch/x86/kernel/kgdb.c +5 -0
@@ -690,6 +690,11 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)return instruction_pointer (regs); } +void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long ip) +{ + regs->ip = ip; +} +struct kgdb_arch arch_kgdb_ops = {/* Breakpoint instruction: */ .gdb_bpt_instr = {0xcc },
include/linux/kgdb.h +9 -2
@@ -16,10 +16,12 @@#include <linux/serial_8250.h> #include <linux/linkage.h> #include <linux/init.h> -#include <asm/atomic.h> +#ifdef CONFIG_HAVE_ARCH_KGDB #include <asm/kgdb.h> +#endif +#ifdef CONFIG_KGDB struct pt_regs ;/**
@@ -262,6 +264,7 @@ extern struct kgdb_arch arch_kgdb_ops;extern unsigned long __weak kgdb_arch_pc (int exception,struct pt_regs *regs); +extern void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc);extern int kgdb_register_io_module (struct kgdb_io *local_kgdb_io_ops);extern void kgdb_unregister_io_module (struct kgdb_io *local_kgdb_io_ops);extern struct kgdb_io *dbg_io_ops;
@@ -279,5 +282,9 @@ extern int kgdb_nmicallback(int cpu, void *regs);extern int kgdb_single_step;extern atomic_t kgdb_active; - +#define in_dbg_master () \ + (raw_smp_processor_id() == atomic_read(&kgdb_active)) +#else /* ! CONFIG_KGDB */ +#define in_dbg_master () (0) +#endif /* ! CONFIG_KGDB */ #endif /* _KGDB_H_ */
kernel/debug/debug_core.c +88 -16
224 lines not on this page · raw message
kernel/debug/debug_core.h +24 -0
@@ -38,6 +38,8 @@ struct debuggerinfo_struct {void *debuggerinfo;struct task_struct *task;int exception_state; +int ret_state; +int irq_depth; };extern struct debuggerinfo_struct kgdb_info[];
@@ -47,9 +49,31 @@ extern int dbg_remove_all_break(void);extern int dbg_set_sw_break (unsigned long addr);extern int dbg_remove_sw_break (unsigned long addr);extern int dbg_activate_sw_breakpoints (void ); +extern int dbg_deactivate_sw_breakpoints (void ); + +/* polled character access to i/o module */ +extern int dbg_io_get_char (void ); + +/* stub return value for switching between the gdbstub and kdb */ +#define DBG_PASS_EVENT -12345 +/* Switch from one cpu to another */ +#define DBG_SWITCH_CPU_EVENT -123456 +extern int dbg_switch_cpu;/* gdbstub interface functions */ extern int gdb_serial_stub (struct kgdb_state *ks);extern void gdbstub_msg_write (const char *s,int len); +/* gdbstub functions used for kdb <-> gdbstub transition */ +extern int gdbstub_state (struct kgdb_state *ks,char *cmd); + +#ifdef CONFIG_KGDB_KDB +extern int kdb_stub (struct kgdb_state *ks); +#else /* ! CONFIG_KGDB_KDB */ +static inline int kdb_stub (struct kgdb_state *ks) +{ +return DBG_PASS_EVENT ; +} +#endif /* CONFIG_KGDB_KDB */ +#endif /* _DEBUG_CORE_H_ */
kernel/debug/gdbstub.c +36 -0
@@ -892,6 +892,13 @@ int gdb_serial_stub(struct kgdb_state *ks)case 'Z' :/* Break point set */ gdb_cmd_break (ks);break ; +#ifdef CONFIG_KGDB_KDB +case '3' :/* Escape into back into kdb */ +if (remcom_in_buffer[1 ] =='\0' ) { +gdb_cmd_detachkill (ks); +return DBG_PASS_EVENT ; + } +#endif case 'C' :/* Exception passing */ tmp =gdb_cmd_exception_pass (ks);if (tmp >0 )
@@ -937,3 +944,32 @@ kgdb_exit: error =1 ;return error; } + +int gdbstub_state (struct kgdb_state *ks,char *cmd) +{ +int error; + +switch (cmd[0 ]) { +case 'e' : + error =kgdb_arch_handle_exception (ks->ex_vector, + ks->signo, + ks->err_code, + remcom_in_buffer, + remcom_out_buffer, + ks->linux_regs); +return error; +case 's' : +case 'c' : +strcpy (remcom_in_buffer, cmd); +return 0 ; +case '?' : +gdb_cmd_status (ks); +break ; +case '\0' : +strcpy (remcom_out_buffer,"" ); +break ; + } + dbg_io_ops->write_char ('+' ); +put_packet (remcom_out_buffer); +return 0 ; +}
lib/Kconfig.kgdb +6 -0
@@ -57,4 +57,10 @@ config KGDB_TESTS_BOOT_STRING information about other strings you could use beyond the default of V1F100. +config KGDB_KDB + bool "KGDB_KDB: include kdb frontend for kgdb" + default n + help + KDB frontend for kernel + endif # KGDB
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 10/28 kgdb,8250,pl011: Return immediately from console poll
In reply to Jason WesselThe design of kdb required that every device that can provide input to kdb have a polling routine that exits immediately if there is no character available.
This is required in order to get the page scrolling mechanism working, it is also a reasonable requirement for future kgdb I/O drivers because that allows for the possibility of multiple input channels.
NO_POLL_CHAR will be the return code to the polling routine when ever there is no character available. There are several other console polling drivers which can be modified, but for the prototype only the 8250 and pl011 driver have been changed to make use of this.
--- drivers/serial/8250.c | 4 ++-- drivers/serial/amba-pl011.c | 6 +++--- include/linux/kdb.h | 1 + include/linux/serial_core.h | 1 + kernel/debug/debug_core.c | 2 ++ kernel/debug/gdbstub.c | 37 +++++++++++++++++++++++++++++++------ kernel/debug/kdb/kdb_debugger.c | 10 ++++++++++ 7 files changed, 50 insertions(+), 11 deletions(-)
drivers/serial/8250.c +2 -2
@@ -1895,8 +1895,8 @@ static int serial8250_get_poll_char(struct uart_port *port)struct uart_8250_port *up = (struct uart_8250_port *)port;unsigned char lsr =serial_inp (up,UART_LSR ); -while (!(lsr &UART_LSR_DR )) - lsr =serial_inp (up,UART_LSR ); +if (!(lsr &UART_LSR_DR )) +return NO_POLL_CHAR ;return serial_inp (up,UART_RX ); }
drivers/serial/amba-pl011.c +3 -3
@@ -335,9 +335,9 @@ static int pl010_get_poll_char(struct uart_port *port)struct uart_amba_port *uap = (struct uart_amba_port *)port;unsigned int status; -do { - status =readw (uap->port.membase + UART01x_FR); - }while (status & UART01x_FR_RXFE); + status =readw (uap->port.membase + UART01x_FR); +if (status & UART01x_FR_RXFE) +return NO_POLL_CHAR ;return readw (uap->port.membase + UART01x_DR); }
include/linux/kdb.h +1 -0
@@ -19,6 +19,7 @@#include <asm/atomic.h> #define KDB_POLL_FUNC_MAX 5 +extern int kdb_poll_idx;/* * kdb_initial_cpu is initialized to -1, and is set to the cpu
include/linux/serial_core.h +1 -0
@@ -246,6 +246,7 @@ struct uart_ops {#endif }; +#define NO_POLL_CHAR 0x00ff0000#define UART_CONFIG_TYPE (1 << 0)#define UART_CONFIG_IRQ (1 << 1)
kernel/debug/debug_core.c +2 -0
@@ -874,6 +874,8 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);int dbg_io_get_char (void ) {int ret = dbg_io_ops->read_char (); +if (ret ==NO_POLL_CHAR ) +return -1 ;if (!dbg_kdb_mode)return ret;if (ret ==127 )
kernel/debug/gdbstub.c +31 -6
@@ -30,6 +30,7 @@#include <linux/kernel.h> #include <linux/kgdb.h> +#include <linux/kdb.h> #include <linux/reboot.h> #include <linux/uaccess.h> #include <asm/cacheflush.h>
@@ -62,6 +63,30 @@ static int hex(char ch)return -1 ; } +#ifdef CONFIG_KGDB_KDB +static int gdbstub_read_wait (void ) +{ +int ret =-1 ; +int i; + +/* poll any additional I/O interfaces that are defined */ +while (ret <0 ) +for (i =0 ; kdb_poll_funcs[i] !=NULL ; i++) { + ret = kdb_poll_funcs[i](); +if (ret >0 ) +break ; + } +return ret; +} +#else +static int gdbstub_read_wait (void ) +{ +int ret = dbg_io_ops->read_char (); +while (ret ==NO_POLL_CHAR ) + ret = dbg_io_ops->read_char (); +return ret; +} +#endif /* scan for the sequence $<data>#<checksum> */ static void get_packet (char *buffer) {
@@ -75,7 +100,7 @@ static void get_packet(char *buffer)* Spin and wait around for the start character, ignore all * other characters: */ -while ((ch = (dbg_io_ops->read_char ())) !='$' ) +while ((ch = (gdbstub_read_wait ())) !='$' )/* nothing */ ; kgdb_connected =1 ;
@@ -88,7 +113,7 @@ static void get_packet(char *buffer)* now, read until a # or end of buffer is found: */ while (count < (BUFMAX -1 )) { - ch = dbg_io_ops->read_char (); + ch =gdbstub_read_wait ();if (ch =='#' )break ; checksum = checksum + ch;
@@ -98,8 +123,8 @@ static void get_packet(char *buffer) buffer[count] =0 ;if (ch =='#' ) { - xmitcsum =hex (dbg_io_ops->read_char ()) <<4 ; - xmitcsum +=hex (dbg_io_ops->read_char ()); + xmitcsum =hex (gdbstub_read_wait ()) <<4 ; + xmitcsum +=hex (gdbstub_read_wait ());if (checksum != xmitcsum)/* failed checksum */
@@ -144,10 +169,10 @@ static void put_packet(char *buffer) dbg_io_ops->flush ();/* Now see what we get in reply. */ - ch = dbg_io_ops->read_char (); + ch =gdbstub_read_wait ();if (ch ==3 ) - ch = dbg_io_ops->read_char (); + ch =gdbstub_read_wait ();/* If we get an ACK, we are done. */ if (ch =='+' )
kernel/debug/kdb/kdb_debugger.c +10 -0
@@ -20,7 +20,15 @@get_char_func kdb_poll_funcs[] = { dbg_io_get_char,NULL , +NULL , +NULL , +NULL , +NULL , }; +EXPORT_SYMBOL_GPL (kdb_poll_funcs); + +int kdb_poll_idx =1 ; +EXPORT_SYMBOL_GPL (kdb_poll_idx);int kdb_stub (struct kgdb_state *ks) {
@@ -85,6 +93,7 @@ int kdb_stub(struct kgdb_state *ks)kdb_bp_remove ();KDB_STATE_CLEAR (DOING_SS );KDB_STATE_CLEAR (DOING_SSB ); +KDB_STATE_SET (PAGER );/* zero out any offline cpu data */ for_each_present_cpu (i) {if (!cpu_online (i)) {
@@ -112,6 +121,7 @@ int kdb_stub(struct kgdb_state *ks) kdb_initial_cpu =-1 ; kdb_current_task =NULL ; kdb_current_regs =NULL ; +KDB_STATE_CLEAR (PAGER );kdbnearsym_cleanup ();if (error ==KDB_CMD_KGDB ) {if (KDB_STATE (DOING_KGDB ) ||KDB_STATE (DOING_KGDB2 )) {
Signature · 7 lines
1.6.4.rc1 ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev
Jason Wessel
maintainerPATCH 11/28 sh,sh-sci: Use NO_POLL_CHAR in the SCIF polled console code
In reply to Jason WesselThe sci_poll_get_char() needs to return immediately if there is no input from the chip to process, and must return a value of NO_POLL_CHAR.
This allows kgdboc to process multiple polled devices while kgdb is active.
--- drivers/serial/sh-sci.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/serial/sh-sci.c +5 -1
@@ -126,7 +126,11 @@ static int sci_poll_get_char(struct uart_port *port)handle_error (port);continue ; } - }while (!(status &SCxSR_RDxF (port))); +break ; + }while (1 ); + +if (!(status &SCxSR_RDxF (port))) +return NO_POLL_CHAR ; c =sci_in (port, SCxRDR);
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 12/28 sparc,sunzilog: Add console polling support for sunzilog serial driver
In reply to Jason WesselAllow kgdboc to work on sparc hardware with the Zilog serial chips.
--- drivers/serial/sunzilog.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-)
drivers/serial/sunzilog.c +50 -0
@@ -102,6 +102,8 @@ struct uart_sunzilog_port {#endif }; +static void sunzilog_putchar (struct uart_port *port,int ch); +#define ZILOG_CHANNEL_FROM_PORT (PORT ) ((struct zilog_channel __iomem *)((PORT)->membase))#define UART_ZILOG (PORT ) ((struct uart_sunzilog_port *)(PORT))
@@ -996,6 +998,50 @@ static int sunzilog_verify_port(struct uart_port *port, struct serial_struct *sereturn -EINVAL ; } +#ifdef CONFIG_CONSOLE_POLL +static int sunzilog_get_poll_char (struct uart_port *port) +{ +unsigned char ch, r1; +struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; +struct zilog_channel __iomem *channel + =ZILOG_CHANNEL_FROM_PORT (&up->port); + + + r1 =read_zsreg (channel,R1 ); +if (r1 & (PAR_ERR | Rx_OVR |CRC_ERR )) { +writeb (ERR_RES , &channel->control); +ZSDELAY (); +ZS_WSYNC (channel); + } + + ch =readb (&channel->control); +ZSDELAY (); + +/* This funny hack depends upon BRK_ABRT not interfering +* with the other bits we care about in R1. +*/ +if (ch &BRK_ABRT ) + r1 |=BRK_ABRT ; + +if (!(ch & Rx_CH_AV)) +return NO_POLL_CHAR ; + + ch =readb (&channel->data); +ZSDELAY (); + + ch &= up->parity_mask; +return ch; +} + +static void sunzilog_put_poll_char (struct uart_port *port, +unsigned char ch) +{ +struct uart_sunzilog_port *up = (struct uart_sunzilog_port *)port; + +sunzilog_putchar (&up->port, ch); +} +#endif /* CONFIG_CONSOLE_POLL */ +static struct uart_ops sunzilog_pops = { .tx_empty = sunzilog_tx_empty, .set_mctrl = sunzilog_set_mctrl,
@@ -1013,6 +1059,10 @@ static struct uart_ops sunzilog_pops = { .request_port = sunzilog_request_port, .config_port = sunzilog_config_port, .verify_port = sunzilog_verify_port, +#ifdef CONFIG_CONSOLE_POLL + .poll_get_char = sunzilog_get_poll_char, + .poll_put_char = sunzilog_put_poll_char, +#endif };static int uart_chip_count;
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 13/28 kgdb: gdb "monitor" -> kdb passthrough
In reply to Jason WesselOne of the driving forces behind integrating another front end (kdb) to the debug core is to allow front end commands to be accessible via gdb's monitor command. It is true that you could write gdb macros to get certain data, but you may want to just use gdb to access the commands that are available in the kdb front end.
This patch implements the Rcmd gdb stub packet. In gdb you access this with the "monitor" command. For instance you could type "monitor help", "monitor lsmod" or "monitor ps A" etc...
There is no error checking or command restrictions on what you can and cannot access at this point. Doing something like trying to set breakpoints with the monitor command is going to cause nothing but problems. Perhaps in the future only the commands that are actually known to work with the gdb monitor command will be available.
--- kernel/debug/debug_core.c | 2 +- kernel/debug/debug_core.h | 2 ++ kernel/debug/gdbstub.c | 22 ++++++++++++++++++++++ kernel/debug/kdb/kdb_io.c | 13 +++++++++---- kernel/debug/kdb/kdb_private.h | 1 - 5 files changed, 34 insertions(+), 6 deletions(-)
kernel/debug/debug_core.c +1 -1
@@ -82,7 +82,7 @@ static int kgdb_use_con;int dbg_switch_cpu;/* Use kdb or gdbserver mode */ -static int dbg_kdb_mode =1 ; +int dbg_kdb_mode =1 ;static int __init opt_kgdb_con (char *str) {
kernel/debug/debug_core.h +2 -0
@@ -66,9 +66,11 @@ extern void gdbstub_msg_write(const char *s, int len);/* gdbstub functions used for kdb <-> gdbstub transition */ extern int gdbstub_state (struct kgdb_state *ks,char *cmd); +extern int dbg_kdb_mode;#ifdef CONFIG_KGDB_KDB extern int kdb_stub (struct kgdb_state *ks); +extern int kdb_parse (const char *cmdstr);#else /* ! CONFIG_KGDB_KDB */ static inline int kdb_stub (struct kgdb_state *ks) {
kernel/debug/gdbstub.c +22 -0
@@ -201,6 +201,9 @@ void gdbstub_msg_write(const char *s, int len)int wcount;int i; +if (len ==0 ) + len =strlen (s); +/* 'O'utput */ gdbmsgbuf[0 ] ='O' ;
@@ -690,6 +693,25 @@ static void gdb_cmd_query(struct kgdb_state *ks)kgdb_mem2hex (tmpstr, remcom_out_buffer,strlen (tmpstr)); }break ; +#ifdef CONFIG_KGDB_KDB +case 'R' : +if (strncmp (remcom_in_buffer,"qRcmd," ,6 ) ==0 ) { +int len =strlen (remcom_in_buffer +6 ); + +if ((len %2 ) !=0 ) { +strcpy (remcom_out_buffer,"E01" ); +break ; + } +kgdb_hex2mem (remcom_in_buffer +6 , + remcom_out_buffer, len); + len = len /2 ; + remcom_out_buffer[len++] =0 ; + +kdb_parse (remcom_out_buffer); +strcpy (remcom_out_buffer,"OK" ); + } +break ; +#endif } }
kernel/debug/kdb/kdb_io.c +9 -4
@@ -21,6 +21,7 @@#include <linux/smp.h> #include <linux/nmi.h> #include <linux/delay.h> +#include <linux/kgdb.h> #include <linux/kdb.h> #include <linux/kallsyms.h> #include "kdb_private.h"
@@ -669,10 +670,14 @@ kdb_printit:* Write to all consoles. */ retlen =strlen (kdb_buffer); -while (c) { - c->write (c, kdb_buffer, retlen); -touch_nmi_watchdog (); - c = c->next; +if (!dbg_kdb_mode && kgdb_connected) { +gdbstub_msg_write (kdb_buffer, retlen); + }else { +while (c) { + c->write (c, kdb_buffer, retlen); +touch_nmi_watchdog (); + c = c->next; + } }if (logging) { saved_loglevel = console_loglevel;
kernel/debug/kdb/kdb_private.h +0 -1
@@ -254,7 +254,6 @@ extern unsigned long kdb_task_state(const struct task_struct *p, unsigned long mask);extern void kdb_ps_suppressed (void );extern void kdb_ps1 (const struct task_struct *p); -extern int kdb_parse (const char *cmdstr);extern void kdb_print_nameval (const char *name,unsigned long val);extern void kdb_send_sig_info (struct task_struct *p,struct siginfo *info);extern void kdb_meminfo_proc_show (void );
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 14/28 kgdboc,keyboard: Keyboard driver for kdb with kgdb
In reply to Jason WesselThis patch adds in the kdb PS/2 keyboard driver. This was mostly a direct port from the original kdb where I cleaned up the code against checkpatch.pl and added the glue to stitch it into kgdb.
This patch also enables early kdb debug via kgdbwait and the keyboard.
All the access to configure kdb using either a serial console or the keyboard is done via kgdboc.
If you want to use only the keyboard and want to break in early you would add to your kernel command arguments:
kgdboc=kbd kgdbwait
If you wanted serial and or the keyboard access you could use:
kgdboc=kbd,ttyS0
You can also configure kgdboc as a kernel module or at run time with the sysfs where you can activate and deactivate kgdb.
Turn it on:
echo kbd,ttyS0 > /sys/module/kgdboc/parameters/kgdboc
Turn it off:
echo "" > /sys/module/kgdboc/parameters/kgdboc
--- Documentation/kernel-parameters.txt | 8 +- drivers/char/Makefile | 1 + drivers/char/kdb_keyboard.c | 204 +++++++++++++++++++++++++++++++++++ drivers/char/kdb_keyboard.h | 143 ++++++++++++++++++++++++ drivers/serial/kgdboc.c | 61 +++++++++-- lib/Kconfig.kgdb | 7 ++ 6 files changed, 414 insertions(+), 10 deletions(-) create mode 100644 drivers/char/kdb_keyboard.c create mode 100644 drivers/char/kdb_keyboard.h
Documentation/kernel-parameters.txt +5 -3
@@ -1103,9 +1103,11 @@ and is between 256 and 4096 characters. It is defined in the file zone if it does not. kgdboc= [HW] kgdb over consoles. - Requires a tty driver that supports console polling. - (only serial supported for now) - Format: <serial_device>[,baud] + Requires a tty driver that supports console polling, + or a supported polling keyboard driver (non-usb). + Serial only format: <serial_device>[,baud] + keyboard only format: kbd + keyboard and serial format: kbd,<serial_device>[,baud] kmac= [MIPS] korina ethernet MAC address. Configure the RouterBoard 532 series on-chip
drivers/char/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS) += pty.o obj-$(CONFIG_UNIX98_PTYS) += pty.o obj-y += misc.o obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o +obj-$(CONFIG_KDB_KEYBOARD) += kdb_keyboard.o obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
drivers/char/kdb_keyboard.c new file +204 -0
204 lines not on this page · raw message
drivers/char/kdb_keyboard.h new file +143 -0
143 lines not on this page · raw message
drivers/serial/kgdboc.c +54 -7
117 lines not on this page · raw message
lib/Kconfig.kgdb +7 -0
@@ -63,4 +63,11 @@ config KGDB_KDB help KDB frontend for kernel +config KDB_KEYBOARD + bool "KGDB_KDB: keyboard as input device" + depends on VT && KGDB_KDB + default y + help + KDB can use a PS/2 type keyboard for an input device + endif # KGDB
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 15/28 kgdb,docs: Update the kgdb docs to include kdb
In reply to Jason WesselUpdate the kgdb docs to reflect the new directory structure and API.
Merge in the kdb shell information.
--- Documentation/DocBook/kgdb.tmpl | 640 ++++++++++++++++++++++++++--------- Documentation/kernel-parameters.txt | 7 +- include/linux/kgdb.h | 12 +- lib/Kconfig.kgdb | 2 +- 4 files changed, 495 insertions(+), 166 deletions(-)
Documentation/DocBook/kgdb.tmpl +477 -163
@@ -4,7 +4,7 @@ <book id="kgdbOnLinux"> <bookinfo> - <title>Using kgdb and the kgdb Internals</title> + <title>Using kgdb, kdb and the kernel debugger internals</title> <authorgroup> <author>
@@ -17,33 +17,8 @@ </affiliation> </author> </authorgroup> - - <authorgroup> - <author> - <firstname>Tom</firstname> - <surname>Rini</surname> - <affiliation> - <address> - <email>[email protected]</email> - </address> - </affiliation> - </author> - </authorgroup> - - <authorgroup> - <author> - <firstname>Amit S.</firstname> - <surname>Kale</surname> - <affiliation> - <address> - <email>[email protected]</email> - </address> - </affiliation> - </author> - </authorgroup> - <copyright> - <year>2008</year> + <year>2008,2010</year> <holder>Wind River Systems, Inc.</holder> </copyright> <copyright>
@@ -69,41 +44,76 @@ <chapter id="Introduction"> <title>Introduction</title> <para> - kgdb is a source level debugger for linux kernel. It is used along - with gdb to debug a linux kernel. The expectation is that gdb can - be used to "break in" to the kernel to inspect memory, variables - and look through call stack information similar to what an - application developer would use gdb for. It is possible to place - breakpoints in kernel code and perform some limited execution - stepping. + The kernel has two different debugger front ends (kdb and kgdb) + which interface to the debug core. It is possible to use either + of the debugger front ends and dynamically transition between them + if you configure the kernel properly at compile and runtime. + </para> + <para> + Kdb is simplistic shell style interface which you can use on a + system console with a keyboard or serial console. You can use it + to inspect memory, registers, process lists, dmesg, and even set + breakpoints to stop in a certain location. Kdb is not a source + level debugger, although you can set breakpoints and execute some + basic kernel run control. Kdb is mainly aimed at doing some + analysis to aid in development or diagnosing kernel problems. You + can access some symbols by name in kernel builtins or in kernel + modules if the code was built + with <symbol>CONFIG_KALLSYMS</symbol>. </para> <para> - Two machines are required for using kgdb. One of these machines is a - development machine and the other is a test machine. The kernel - to be debugged runs on the test machine. The development machine - runs an instance of gdb against the vmlinux file which contains - the symbols (not boot image such as bzImage, zImage, uImage...). - In gdb the developer specifies the connection parameters and - connects to kgdb. The type of connection a developer makes with - gdb depends on the availability of kgdb I/O modules compiled as - builtin's or kernel modules in the test machine's kernel. + Kgdb was intended to be used as a source level debugger for the + linux kernel. It is used along with gdb to debug a linux kernel. + The expectation is that gdb can be used to "break in" to the + kernel to inspect memory, variables and look through call stack + information similar to the way an application developer would use + gdb to debug an application. It is possible to place breakpoints + in kernel code and perform some limited execution stepping. + </para> + <para> + Two machines are required for using kgdb. One of these machines is + a development machine and the other is the target machine. The + kernel to be debugged runs on the target machine. The development + machine runs an instance of gdb against the vmlinux file which + contains the symbols (not boot image such as bzImage, zImage, + uImage...). In gdb the developer specifies the connection + parameters and connects to kgdb. The type of connection a + developer makes with gdb depends on the availability of kgdb I/O + modules compiled as builtins or kernel modules in the test + machine's kernel. </para> </chapter> <chapter id="CompilingAKernel"> - <title>Compiling a kernel</title> + <title>Compiling a kernel</title> + <para> + <itemizedlist> + <listitem><para>In order to enable compilation of kdb, you must first enable kgdb.</para></listitem> + <listitem><para>The kgdb test compile options are described in the kgdb test suite chapter.</para></listitem> + </itemizedlist> + </para> + <sect1 id="CompileKGDB"> + <title>Kernel config options for kgdb</title> <para> To enable <symbol>CONFIG_KGDB</symbol> you should first turn on "Prompt for development and/or incomplete code/drivers" (CONFIG_EXPERIMENTAL) in "General setup", then under the - "Kernel debugging" select "KGDB: kernel debugging with remote gdb". + "Kernel debugging" select "KGDB: kernel debugger". + </para> + <para> + While it is not a hard requirement that you have symbols in your + vmlinux file, gdb tends not to be very useful without the symbolic + data, so you will want to turn + on <symbol>CONFIG_DEBUG_INFO</symbol> which is called "Compile the + kernel with debug info" in the menu config. </para> <para> It is advised, but not required that you turn on the - CONFIG_FRAME_POINTER kernel option. This option inserts code to - into the compiled executable which saves the frame information in - registers or on the stack at different points which will allow a - debugger such as gdb to more accurately construct stack back traces - while debugging the kernel. + <symbol>CONFIG_FRAME_POINTER</symbol> kernel option which is called "Compile the + kernel with frame pointers" in the menu config. This option + inserts code to into the compiled executable which saves the frame + information in registers or on the stack at different points which + will allow a debugger such as gdb to more accurately construct + stack back traces while debugging the kernel. </para> <para> If the architecture that you are using supports the kernel option
@@ -116,38 +126,146 @@ this option. </para> <para> - Next you should choose one of more I/O drivers to interconnect debugging - host and debugged target. Early boot debugging requires a KGDB - I/O driver that supports early debugging and the driver must be - built into the kernel directly. Kgdb I/O driver configuration - takes place via kernel or module parameters, see following - chapter. + Next you should choose one of more I/O drivers to interconnect + debugging host and debugged target. Early boot debugging requires + a KGDB I/O driver that supports early debugging and the driver + must be built into the kernel directly. Kgdb I/O driver + configuration takes place via kernel or module parameters which + you can learn more about in the in the section that describes the + kernel parameter kgdboc. </para> - <para> - The kgdb test compile options are described in the kgdb test suite chapter. + <para>Here is an example set of .config to enable kgdb: + <itemizedlist> + <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> + <listitem><para>CONFIG_KGDB=y</para></listitem> + <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem> + </itemizedlist> </para> - + </sect1> + <sect1 id="CompileKDB"> + <title>Kernel config options for kdb</title> + <para>Kdb is quite a bit more complex than the simple gdbstub + sitting on top of the kernel's debug core. Kdb must implement an + shell, and also adds some helper functions in other parts of the + kernel, responsible for printing out interesting data such as what + you would see if you ran "lsmod", or "ps". In order to build kdb + into the kernel you follow the same steps as you would for kgdb. + </para> + <para>The main config option for kdb + is <symbol>CONFIG_KGDB_KDB</symbol> which is called "KGDB_KDB: + include kdb frontend for kgdb" in the menu config. In theory you + would have already also selected an I/O driver such as the + CONFIG_KGDB_SERIAL_CONSOLE interface if you plan on using kdb on a + serial port, when you were configuring kgdb. + </para> + <para>If you want to use a ps/2 style keyboard with kdb you would + select CONFIG_KDB_KEYBOARD which is called "KGDB_KDB: keyboard as + input device" in the menu config. This option really does do + anything for the gdb interface to kgdb it only works with kdb, + because it is not really meaningful to manually type in gdb + remote protocol commands. + </para> + <para>Here is an example set of .config to enable kdb: + <itemizedlist> + <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> + <listitem><para>CONFIG_KGDB=y</para></listitem> + <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem> + <listitem><para>CONFIG_KGDB_KDB=y</para></listitem> + <listitem><para>CONFIG_KDB_KEYBOARD=y</para></listitem> + </itemizedlist> + </para> + </sect1> </chapter> - <chapter id="EnableKGDB"> - <title>Enable kgdb for debugging</title> - <para> - In order to use kgdb you must activate it by passing configuration - information to one of the kgdb I/O drivers. If you do not pass any - configuration information kgdb will not do anything at all. Kgdb - will only actively hook up to the kernel trap hooks if a kgdb I/O - driver is loaded and configured. If you unconfigure a kgdb I/O - driver, kgdb will unregister all the kernel hook points. + <chapter id="kgdbKernelArgs"> + <title>Kernel Debugger Boot Arguments</title> + <para>This section will describe the various runtime kernel + parameters that affect the configuration of the kernel debugger. + The following chapter will cover using kdb and kgdb as well as + provide some examples of the configuration parameters.</para> + <sect1 id="kgdboc"> + <title>Kernel parameter: kgdboc</title> + <para>The kgdboc driver was originally an abbreviation meant to + stand for "kgdb over console". Today it is the primary mechanism + to configure how to communicate from gdb to kgdb as well as the + devices you want to use to interact with the kdb shell. </para> - <para> - All drivers can be reconfigured at run time, if - <symbol>CONFIG_SYSFS</symbol> and <symbol>CONFIG_MODULES</symbol> - are enabled, by echo'ing a new config string to - <constant>/sys/module/<driver>/parameter/<option></constant>. - The driver can be unconfigured by passing an empty string. You cannot - change the configuration while the debugger is attached. Make sure - to detach the debugger with the <constant>detach</constant> command - prior to trying unconfigure a kgdb I/O driver. + <para>For kgdb/gdb, kgdboc is designed to work with a single serial + port. It was meant to cover the circumstance where you wanted to + use a serial console as your primary console as well as using it to + perform kernel debugging. It is also possible to use kgdb on a + serial port which is not designated as a system console. Kgdboc + may be configured as a kernel built-in or a kernel module. You can + only make use of <constant>kgdbwait</constant> and early debugging + if you build kgdboc into the kernel as a builtins. + </para> + <sect2 id="kgdbocArgs"> + <title>kgdboc arguments</title> + <para>Usage: <constant>kgdboc=[kbd][[,]serial_device][,baud]</constant></para> + <para>You can configure kgdboc to use the keyboard, and or a serial device + depending on if you are using kdb and or kgdb, in one of the + following scenarios. + <orderedlist> + <listitem><para>kdb and kgdb over only a serial port</para> + <para><constant>kgdboc=<serial_device>[,baud]</constant></para> + <para>Example: <constant>kgdboc=ttyS0,115200</constant></para> + </listitem> + <listitem><para>kdb and kgdb with keyboard and a serial port</para> + <para><constant>kgdboc=kbd,<serial_device>[,baud]</constant></para> + <para>Example: <constant>kgdboc=kbd,ttyS0,115200</constant></para> + </listitem> + <listitem><para>kdb with a keyboard</para> + <para><constant>kgdboc=kbd</constant></para> + </listitem> + </orderedlist> + </para> + <para>You can configure kgdboc via sysfs or a module or kernel boot line + parameter depending on if you build with CONFIG_KGDBOC as a module + or built-in. + <orderedlist> + <listitem><para>From the module load or build-in</para> + <para>As a kernel argument: <constant>kgdboc=<tty-device>,[baud]</constant></para> + <para>As a kernel module: <constant>modprobe kgdboc kgdboc=<tty-device>,[baud]</constant></para> + <para>Here are two examples, the first for an x86 target using the + first serial port and the second for the ARM Versatile AB using the + second serial port. + <orderedlist> + <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> + <listitem><para><constant>kgdboc=ttyAMA1,115200</constant></para></listitem> + </orderedlist> + </para> + </listitem> + <listitem><para>From sysfs</para> + <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para> + <para>NOTE: You do not need to specify the baud if you are + configuring the console on tty which is already configured or + open.</para> + </listitem> + </orderedlist> + </para> + <para>NOTE: Kgdboc does not support interrupting the target via the + gdb remote protocol. You must manually send a sysrq-g unless you + have a proxy that splits console output to a terminal program. + A console proxy has a separate tcp port for the debugger and a separate + tcp port for the "human" console. The proxy can take care of sending + the sysrq-g for you. </para> + <para>When using kgdboc with no debugger proxy, you can end up + connecting the debugger for one of two entry points. If an + exception occurs after you have loaded kgdboc a message should + print on the console stating it is waiting for the debugger. In + case you disconnect your terminal program and then connect the + debugger in its place. If you want to interrupt the target system + and forcibly enter a debug session you have to issue a Sysrq + sequence and then type the letter <constant>g</constant>. Then + you disconnect the terminal session and connect gdb. Your options + if you don't like this are to hack gdb to send the sysrq-g for you + as well as on the initial connect, or to use a debugger proxy that + allows an unmodified gdb to do the debugging. + </para> + </sect2> + </sect1> <sect1 id="kgdbwait"> <title>Kernel parameter: kgdbwait</title> <para>
@@ -166,99 +284,193 @@ kgdb I/O driver as a kernel module kgdbwait will not do anything. </para> </sect1> - <sect1 id="kgdboc"> - <title>Kernel parameter: kgdboc</title> - <para> - The kgdboc driver was originally an abbreviation meant to stand for - "kgdb over console". Kgdboc is designed to work with a single - serial port. It was meant to cover the circumstance - where you wanted to use a serial console as your primary console as - well as using it to perform kernel debugging. Of course you can - also use kgdboc without assigning a console to the same port. + <sect1 id="kgdbcon"> + <title>Kernel parameter: kgdbcon</title> + <para> The kgdbcon feature allows you to see printk() messages + inside gdb while gdb is connected to the kernel. Kdb does not make + use of the kgdbcon feature. + </para> + <para>Kgdb supports using the gdb serial protocol to send console + messages to the debugger when the debugger is connected and running. + There are two ways to activate this feature. + <orderedlist> + <listitem><para>Activate with the kernel command line option:</para> + <para><constant>kgdbcon</constant></para> + </listitem> + <listitem><para>Use sysfs before configuring an io driver</para> + <para> + <constant>echo 1 > /sys/module/kgdb/parameters/kgdb_use_con</constant> + </para> + <para> + NOTE: If you do this after you configure the kgdb I/O driver, the + setting will not take effect until the next point the I/O is + reconfigured. + </para> + </listitem> + </orderedlist> + <para>IMPORTANT NOTE: You cannot use kgdboc + kgdbcon on a tty that is an + active system console IE: console=ttyS0,115200 kgdboc=ttyS0 kgdbcon + </para> + <para>It is possible to use this option with kgdboc on a tty that is not a system console. + </para> </para> - <sect2 id="UsingKgdboc"> - <title>Using kgdboc</title> - <para> - You can configure kgdboc via sysfs or a module or kernel boot line - parameter depending on if you build with CONFIG_KGDBOC as a module - or built-in. - <orderedlist> - <listitem><para>From the module load or build-in</para> - <para><constant>kgdboc=<tty-device>,[baud]</constant></para> + </sect1> + </chapter> + <chapter id="usingKDB"> + <title>Using kdb</title> <para> - The example here would be if your console port was typically ttyS0, you would use something like <constant>kgdboc=ttyS0,115200</constant> or on the ARM Versatile AB you would likely use <constant>kgdboc=ttyAMA0,115200</constant> + </para> + <sect1 id="quickKDBserial"> + <title>Quick start for kdb on a serial port</title> + <para>This is a quick example of how to use kdb</para> + <para><orderedlist> + <listitem><para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>console=ttyS0,115200 kgdboc=ttyS0,115200</constant></para></listitem> + </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted assuming your are using a serial port console: + <itemizedlist> + <listitem><para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist> </para> </listitem> - <listitem><para>From sysfs</para> - <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para> + <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para> + <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using minicom 2.2</para> + <para>Press: <constant>Control-a</constant></para> + <para>Press: <constant>f</constant></para> + <para>Press: <constant>g</constant></para> </listitem> - </orderedlist> - </para> - <para> - NOTE: Kgdboc does not support interrupting the target via the - gdb remote protocol. You must manually send a sysrq-g unless you - have a proxy that splits console output to a terminal problem and - has a separate port for the debugger to connect to that sends the - sysrq-g for you. + <listitem><para>When you have telneted to a terminal server that supports sending a remote break</para> + <para>Press: <constant>Control-]</constant></para> + <para>Type in:<constant>send break</constant></para> + <para>Press: <constant>Enter</constant></para> + <para>Press: <constant>g</constant></para> + </listitem> + </itemizedlist> + </listitem> + <listitem><para>From the kdb prompt you can run the "help" command to see a complete list of the commands that are available.</para> + <para>Some useful commands in kdb include: + <itemizedlist> + <listitem><para>lsmod -- Shows where kernel modules are loaded</para></listitem> + <listitem><para>ps -- Displays only the active processes</para></listitem> + <listitem><para>ps A -- Shows all the processes</para></listitem> + <listitem><para>summary -- Shows kernel version info and memory usage</para></listitem> + <listitem><para>bt -- Get a backtrace of the current process using dump_stack()</para></listitem> + <listitem><para>dmesg -- View the kernel syslog buffer</para></listitem> + <listitem><para>go -- Continue the system</para></listitem> + </itemizedlist> </para> - <para>When using kgdboc with no debugger proxy, you can end up - connecting the debugger for one of two entry points. If an - exception occurs after you have loaded kgdboc a message should print - on the console stating it is waiting for the debugger. In case you - disconnect your terminal program and then connect the debugger in - its place. If you want to interrupt the target system and forcibly - enter a debug session you have to issue a Sysrq sequence and then - type the letter <constant>g</constant>. Then you disconnect the - terminal session and connect gdb. Your options if you don't like - this are to hack gdb to send the sysrq-g for you as well as on the - initial connect, or to use a debugger proxy that allows an - unmodified gdb to do the debugging. + </listitem> + <listitem> + <para>When you are done using kdb you need to consider rebooting the system or using the "go" command to resuming normal kernel execution. If you have paused the kernel for a lengthy period of time, applications that rely on timely networking or anything to do with real wall clock time could get adversely affected, so you should take this into consideration when using the kernel debugger.</para> + </listitem> + </orderedlist></para> + </sect1> + <sect1 id="quickKDBkeyboard"> + <title>Quick start for kdb using a keyboard connected console</title> + <para>This is a quick example of how to use kdb with a keyboard</para> + <para><orderedlist> + <listitem><para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>kgdboc=kbd</constant></para></listitem> + </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted: + <itemizedlist> + <listitem><para><constant>echo kbd > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist> </para> - </sect2> + </listitem> + <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para> + <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using a laptop keyboard</para> + <para>Press and hold down: <constant>Alt</constant></para> + <para>Press and hold down: <constant>Fn</constant></para> + <para>Press and release the key with the label: <constant>SysRq</constant></para> + <para>Release: <constant>Fn</constant></para> + <para>Press and release: <constant>g</constant></para> + <para>Release: <constant>Alt</constant></para> + </listitem> + <listitem><para>Example using a PS/2 101 keyboard</para> + <para>Press and hold down: <constant>Alt</constant></para> + <para>Press and release the key with the label: <constant>SysRq</constant></para> + <para>Press and release: <constant>g</constant></para> + <para>Release: <constant>Alt</constant></para> + </listitem> + </itemizedlist> + </listitem> + <listitem> + <para>Now type in a kdb command such as "help", "dmesg", "bt" or "go" to continue kernel execution.</para> + </listitem> + </orderedlist></para> </sect1> - <sect1 id="kgdbcon"> - <title>Kernel parameter: kgdbcon</title> - <para> - Kgdb supports using the gdb serial protocol to send console messages - to the debugger when the debugger is connected and running. There - are two ways to activate this feature. + </chapter> + <chapter id="EnableKGDB"> + <title>Using kgdb / gdb</title> + <para>In order to use kgdb you must activate it by passing + configuration information to one of the kgdb I/O drivers. If you + do not pass any configuration information kgdb will not do anything + at all. Kgdb will only actively hook up to the kernel trap hooks + if a kgdb I/O driver is loaded and configured. If you unconfigure + a kgdb I/O driver, kgdb will unregister all the kernel hook points. + </para> + <para> All kgdb I/O drivers can be reconfigured at run time, if + <symbol>CONFIG_SYSFS</symbol> and <symbol>CONFIG_MODULES</symbol> + are enabled, by echo'ing a new config string to + <constant>/sys/module/<driver>/parameter/<option></constant>. + The driver can be unconfigured by passing an empty string. You cannot + change the configuration while the debugger is attached. Make sure + to detach the debugger with the <constant>detach</constant> command + prior to trying unconfigure a kgdb I/O driver. + </para> + <sect1 id="ConnectingGDB"> + <title>Connecting with gdb to a serial port</title> <orderedlist> - <listitem><para>Activate with the kernel command line option:</para> - <para><constant>kgdbcon</constant></para> + <listitem><para>Configure kgdboc</para> + <para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> + </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted: + <itemizedlist> + <listitem><para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist></para> </listitem> - <listitem><para>Use sysfs before configuring an io driver</para> - <para> - <constant>echo 1 > /sys/module/kgdb/parameters/kgdb_use_con</constant> - </para> - <para> - NOTE: If you do this after you configure the kgdb I/O driver, the - setting will not take effect until the next point the I/O is - reconfigured. - </para> + <listitem> + <para>Stop kernel execution (break into the debugger)</para> + <para>In order to connect to gdb to the via kgdboc the kernel must + first be stopped. There are several ways to stop the kernel which + include using kgdbwait as a boot argument, via a sysrq-g, or running + the kernel until it takes an an exception where it waits for the + debugger to attach. + <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using minicom 2.2</para> + <para>Press: <constant>Control-a</constant></para> + <para>Press: <constant>f</constant></para> + <para>Press: <constant>g</constant></para> </listitem> - </orderedlist> - </para> - <para> - IMPORTANT NOTE: Using this option with kgdb over the console - (kgdboc) is not supported. + <listitem><para>When you have telneted to a terminal server that supports sending a remote break</para> + <para>Press: <constant>Control-]</constant></para> + <para>Type in:<constant>send break</constant></para> + <para>Press: <constant>Enter</constant></para> + <para>Press: <constant>g</constant></para> + </listitem> + </itemizedlist> </para> - </sect1> - </chapter> - <chapter id="ConnectingGDB"> - <title>Connecting gdb</title> - <para> - If you are using kgdboc, you need to have used kgdbwait as a boot - argument, issued a sysrq-g, or the system you are going to debug - has already taken an exception and is waiting for the debugger to - attach before you can connect gdb. - </para> - <para> - If you are not using different kgdb I/O driver other than kgdboc, - you should be able to connect and the target will automatically - respond. - </para> + </listitem> + <listitem> + <para>Connect from from gdb</para> <para> - Example (using a serial port): + Example (using a directly connected port): </para> <programlisting> % gdb ./vmlinux
@@ -283,6 +495,82 @@ communications. You do this prior to issuing the <constant>target remote</constant> command by typing in: <constant>set debug remote 1</constant> </para> + </listitem> + </orderedlist> + <para>Remember if you continue in gdb, and need "break in" again, + you need to issue an other sysrq. It is easy to create an simple + entry point by putting a breakpoint at <constant>sys_sync</constant> + and then you can run "sync" from a shell or script to break into the + debugger.</para> + </sect1> + </chapter> + <chapter id="switchKdbKgdb"> + <title>kgdb and kdb interoperability</title> + <para>It is possible to transition between kdb and kgdb dynamically. + The debug core will remember which you used the last time and + automatically start in the same mode.</para> + <sect1> + <title>Switching between kdb and kgdb</title> + <sect2> + <title>Switching from kgdb to kdb</title> + <para> + There are two ways to switch from kgdb to kdb, you can use gdb to + issue a maintenance packet, or you can blindly type the command $3#33. + When ever kernel debugger stops in kgdb mode it will print the + message <constant>KGDB or $3#33 for KDB</constant>. It is important + to note, that you have to type the sequence correctly in one pass. + You cannot type a backspace or delete because kgdb will interpret + that as part of the debug stream. + <orderedlist> + <listitem><para>Change from kgdb to kdb by blindly typing:</para> + <para><constant>$3#33</constant></para></listitem> + <listitem><para>Change from kgdb to kdb with gdb</para> + <para><constant>maintenance packet 3</constant></para> + <para>NOTE: Now you must kill gdb</para></listitem> + </orderedlist> + </para> + </sect2> + <sect2> + <title>Change from kdb to kgdb</title> + <para>There are two ways you can change from kdb to kgdb. You can + manually enter kgdb mode by issuing the kgdb command from the kdb + shell prompt, or you can connect gdb while the kdb shell prompt is + active. The kdb shell looks for the typical first commands that gdb + would issue with the gdb remote protocol and if it sees one of those + commands it automatically changes into kgdb mode.</para> + <orderedlist> + <listitem><para>From kdb issue the command:</para> + <para><constant>kgdb</constant></para> + <para>Now disconnect your terminal program and connect gdb in its place</para></listitem> + <listitem><para>At the kdb prompt, disconnect the terminal program and connect gdb in its place.</para></listitem> + </orderedlist> + </sect2> + </sect1> + <sect1> + <title>Running kdb commands from gdb</title> + <para>It is possible to run a limited set of kdb commands from gdb, + using the gdb monitor command. You don't want to execute any of the + run control or breakpoint operations, because it can disrupt the + state of the kernel debugger. You should be using gdb for + breakpoints and run control operations if you have gdb connected. + The more useful commands to run are things like lsmod, dmesg, ps or + possibly some of the memory information. To see all the kdb + commands you can run <constant>monitor help</constant>.</para> + <para>Example: + <informalexample><programlisting> +(gdb) monitor ps +1 idle process (state I) and +27 sleeping system daemon (state M) processes suppressed, +use 'ps A' to see all. +Task Addr Pid Parent [*] cpu State Thread Command + +0xc78291d0 1 0 0 0 S 0xc7829404 init +0xc7954150 942 1 0 0 S 0xc7954384 dropbear +0xc78789c0 944 1 0 0 S 0xc7878bf4 sh +(gdb) + </programlisting></informalexample> + </para> + </sect1> </chapter> <chapter id="KGDBTestSuite"> <title>kgdb Test Suite</title>
@@ -309,22 +597,22 @@ </para> </chapter> <chapter id="CommonBackEndReq"> - <title>KGDB Internals</title> + <title>Kernel Debugger Internals</title> <sect1 id="kgdbArchitecture"> <title>Architecture Specifics</title> <para> - Kgdb is organized into three basic components: + The kernel debugger is organized into a number of components: <orderedlist> - <listitem><para>kgdb core</para> + <listitem><para>The debug core</para> <para> - The kgdb core is found in kernel/kgdb.c. It contains: + The debug core is found in kernel/debugger/debug_core.c. It contains: <itemizedlist> - <listitem><para>All the logic to implement the gdb serial protocol</para></listitem> <listitem><para>A generic OS exception handler which includes sync'ing the processors into a stopped state on an multi cpu system.</para></listitem> <listitem><para>The API to talk to the kgdb I/O drivers</para></listitem> <listitem><para>The API to make calls to the arch specific kgdb implementation</para></listitem> <listitem><para>The logic to perform safe memory reads and writes to memory while using the debugger</para></listitem> <listitem><para>A full implementation for software breakpoints unless overridden by the arch</para></listitem> + <listitem><para>The API to invoke either the kdb or kgdb frontend to the debug core.</para></listitem> </itemizedlist> </para> </listitem>
@@ -347,9 +635,31 @@ </itemizedlist> </para> </listitem> + <listitem><para>gdbstub frontend (aka kgdb)</para> + <para>The gdbstub is located in kernel/debug/gdbstub.c. It contains:</para> + <itemizedlist> + <listitem><para>All the logic to implement the gdb serial protocol</para></listitem> + </itemizedlist> + </listitem> + <listitem><para>kdb frontend</para> + <para>The kdb debugger shell is broken down into a number of + components. The kdb core is located in kernel/debug/kdb. There + are number of helper functions in some of the other kernel + components to make it possible for kdb to examine report + information about the kernel without taking locks that could + cause a kernel deadlock. The kdb core contains implements the following functionality.</para> + <itemizedlist> + <listitem><para>A simple shell</para></listitem> + <listitem><para>The kdb core command set</para></listitem> + <listitem><para>A registration API to register additional kdb shell commands.</para> + <para>A good example of a self contained kdb module is the "ftdump" command for dumping the ftrace buffer. See: kernel/trace/trace_kdb.c</para></listitem> + <listitem><para>The implementation for kdb_printf() which emit messages directly to I/O drivers, bypassing the kernel log.</para></listitem> + <listitem><para>SW / HW breakpoint management for the kdb shell</para></listitem> + </itemizedlist> + </listitem> <listitem><para>kgdb I/O driver</para> <para> - Each kgdb I/O driver has to provide an implemenation for the following: + Each kgdb I/O driver has to provide an implementation for the following: <itemizedlist> <listitem><para>configuration via builtin or module</para></listitem> <listitem><para>dynamic configuration and kgdb hook registration calls</para></listitem>
@@ -453,6 +763,10 @@ <itemizedlist> <listitem><para>Jason Wessel<email>[email protected]</email></para></listitem> </itemizedlist> + In Jan 2010 this document was updated to include kdb. + <itemizedlist> + <listitem><para>Jason Wessel<email>[email protected]</email></para></listitem> + </itemizedlist> </para> </chapter> </book>
Documentation/kernel-parameters.txt +6 -1
@@ -57,6 +57,7 @@ parameter is applicable: ISAPNP ISA PnP code is enabled. ISDN Appropriate ISDN support is enabled. JOY Appropriate joystick support is enabled. + KGDB Kernel debugger support is enabled. KVM Kernel Virtual Machine support is enabled. LIBATA Libata driver is enabled LP Printer support is enabled.
@@ -1102,13 +1103,17 @@ and is between 256 and 4096 characters. It is defined in the file use the HighMem zone if it exists, and the Normal zone if it does not. - kgdboc= [HW] kgdb over consoles. + kgdboc= [KGDB,HW] kgdb over consoles. Requires a tty driver that supports console polling, or a supported polling keyboard driver (non-usb). Serial only format: <serial_device>[,baud] keyboard only format: kbd keyboard and serial format: kbd,<serial_device>[,baud] + kgdbwait [KGDB] Stop kernel execution and enter the + kernel debugger at the earliest opportunity if + kgdb was configured on as a boot argument. + kmac= [MIPS] korina ethernet MAC address. Configure the RouterBoard 532 series on-chip Ethernet adapter MAC address.
include/linux/kgdb.h +11 -1
@@ -204,6 +204,17 @@ kgdb_arch_handle_exception(int vector, int signo, int err_code,*/ extern void kgdb_roundup_cpus (unsigned long flags); +/** +* kgdb_arch_set_pc - Generic call back to the program counter +* @regs: Current &struct pt_regs. +* @pc: The new value for the program counter +* +* This function handles updating the program counter and requires an +* architecture specific implementation. +*/ +extern void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc); + +/* Optional functions. */ extern int kgdb_validate_break_address (unsigned long addr);extern int kgdb_arch_set_breakpoint (unsigned long addr,char *saved_instr);
@@ -264,7 +275,6 @@ extern struct kgdb_arch arch_kgdb_ops;extern unsigned long __weak kgdb_arch_pc (int exception,struct pt_regs *regs); -extern void kgdb_arch_set_pc (struct pt_regs *regs,unsigned long pc);extern int kgdb_register_io_module (struct kgdb_io *local_kgdb_io_ops);extern void kgdb_unregister_io_module (struct kgdb_io *local_kgdb_io_ops);extern struct kgdb_io *dbg_io_ops;
lib/Kconfig.kgdb +1 -1
@@ -3,7 +3,7 @@ config HAVE_ARCH_KGDB bool menuconfig KGDB - bool "KGDB: kernel debugging with remote gdb" + bool "KGDB: kernel debugger" depends on HAVE_ARCH_KGDB depends on DEBUG_KERNEL && EXPERIMENTAL help
Signature · 1 line
1.6.4.rc1
Re: [PATCH 15/28] kgdb,docs: Update the kgdb docs to include kdb
Quoted 16 lines · Jason Wessel
Update the kgdb docs to reflect the new directory structure and API.
Merge in the kdb shell information.
Signed-off-by Jason Wessel <[email protected]>---
Documentation/kernel-parameters.txt +0
-1@@ -1102,13 +1103,17 @@ and is between 256 and 4096 characters. It is defined in the file use the HighMem zone if it exists, and the Normal zone if it does not. - kgdboc= [HW] kgdb over consoles.
Documentation/kernel-parameters.txt and is between 256 and 4096 characters. It is defined in the file · line 1115
Quoted 10 lines
Documentation/kernel-parameters.txt +4
-0+ kgdboc= [KGDB,HW] kgdb over consoles. Requires a tty driver that supports console polling, or a supported polling keyboard driver (non-usb). Serial only format: <serial_device>[,baud] keyboard only format: kbd keyboard and serial format: kbd,<serial_device>[,baud] + kgdbwait [KGDB] Stop kernel execution and enter the + kernel debugger at the earliest opportunity if + kgdb was configured on as a boot argument.
What does "kgdb was configured on as a boot argument" mean?
Quoted 4 lines
Documentation/kernel-parameters.txt +1
-0+ kmac= [MIPS] korina ethernet MAC address. Configure the RouterBoard 532 series on-chip Ethernet adapter MAC address.
Signature · 1 line
~Randy
Jason Wessel
maintainerRe: [PATCH 15/28] kgdb,docs: Update the kgdb docs to include kdb
Quoted 7 lines · Randy Dunlap
Documentation/kernel-parameters.txt and is between 256 and 4096 characters. It is defined in the file · line 1115
Quoted 3 lines · Jason Wessel
Documentation/kernel-parameters.txt +3
-0+ kgdbwait [KGDB] Stop kernel execution and enter the + kernel debugger at the earliest opportunity if + kgdb was configured on as a boot argument.What does "kgdb was configured on as a boot argument" mean?
Changed to:
Signature · 14 lines
kgdbwait [KGDB] Stop kernel execution and enter the kernel debugger at the earliest opportunity. -- We'll assume someone actually configured the kernel debugger with ekgdboc, kgdboc, or kgdbdbgp. The previous text was attempting to indicate that kgdbwait only does something when you also configure a kgdb I/O driver. Where it stops varies on how early the I/O driver and architecture trap processing is available. Jason.
Re: [Kgdb-bugreport] [PATCH 15/28] kgdb, docs: Update the kgdb docs to include kdb
In reply to Jason WesselQuoted 3 lines · Jason Wessel
Update the kgdb docs to reflect the new directory structure and API.
Merge in the kdb shell information.
See comments/corrections inline below.
Quoted 64 lines
Signed-off-by Jason Wessel <[email protected]>--- Documentation/DocBook/kgdb.tmpl | 640 ++++++++++++++++++++++++++--------- Documentation/kernel-parameters.txt | 7 +- include/linux/kgdb.h | 12 +- lib/Kconfig.kgdb | 2 +- 4 files changed, 495 insertions(+), 166 deletions(-)Documentation/DocBook/kgdb.tmpl +2
-31@@ -4,7 +4,7 @@ <book id="kgdbOnLinux"> <bookinfo> - <title>Using kgdb and the kgdb Internals</title> + <title>Using kgdb, kdb and the kernel debugger internals</title> <authorgroup> <author>@@ -17,33 +17,8 @@ </affiliation> </author> </authorgroup> - - <authorgroup> - <author> - <firstname>Tom</firstname> - <surname>Rini</surname> - <affiliation> - <address> - <email>[email protected]</email> - </address> - </affiliation> - </author> - </authorgroup> - - <authorgroup> - <author> - <firstname>Amit S.</firstname> - <surname>Kale</surname> - <affiliation> - <address> - <email>[email protected]</email> - </address> - </affiliation> - </author> - </authorgroup> - <copyright> - <year>2008</year> + <year>2008,2010</year> <holder>Wind River Systems, Inc.</holder> </copyright> <copyright>@@ -69,41 +44,76 @@ <chapter id="Introduction"> <title>Introduction</title> <para> - kgdb is a source level debugger for linux kernel. It is used along - with gdb to debug a linux kernel. The expectation is that gdb can - be used to "break in" to the kernel to inspect memory, variables - and look through call stack information similar to what an
Documentation/DocBook/kgdb.tmpl line 53
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +7
-3- application developer would use gdb for. It is possible to place - breakpoints in kernel code and perform some limited execution - stepping. + The kernel has two different debugger front ends (kdb and kgdb) + which interface to the debug core. It is possible to use either + of the debugger front ends and dynamically transition between them + if you configure the kernel properly at compile and runtime. + </para> + <para> + Kdb is simplistic shell style interface which you can use on a
shell-style
Quoted 11 lines
Documentation/DocBook/kgdb.tmpl +9
-0+ system console with a keyboard or serial console. You can use it + to inspect memory, registers, process lists, dmesg, and even set + breakpoints to stop in a certain location. Kdb is not a source + level debugger, although you can set breakpoints and execute some + basic kernel run control. Kdb is mainly aimed at doing some + analysis to aid in development or diagnosing kernel problems. You + can access some symbols by name in kernel builtins or in kernel + modules if the code was built + with <symbol>CONFIG_KALLSYMS</symbol>. </para> <para>
Documentation/DocBook/kgdb.tmpl line 65
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +1
-9- Two machines are required for using kgdb. One of these machines is a - development machine and the other is a test machine. The kernel - to be debugged runs on the test machine. The development machine - runs an instance of gdb against the vmlinux file which contains - the symbols (not boot image such as bzImage, zImage, uImage...). - In gdb the developer specifies the connection parameters and - connects to kgdb. The type of connection a developer makes with - gdb depends on the availability of kgdb I/O modules compiled as - builtin's or kernel modules in the test machine's kernel. + Kgdb was intended to be used as a source level debugger for the
is (?)
Documentation/DocBook/kgdb.tmpl line 66
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ linux kernel. It is used along with gdb to debug a linux kernel.
Linux Linux
Quoted 33 lines
Documentation/DocBook/kgdb.tmpl +26
-1+ The expectation is that gdb can be used to "break in" to the + kernel to inspect memory, variables and look through call stack + information similar to the way an application developer would use + gdb to debug an application. It is possible to place breakpoints + in kernel code and perform some limited execution stepping. + </para> + <para> + Two machines are required for using kgdb. One of these machines is + a development machine and the other is the target machine. The + kernel to be debugged runs on the target machine. The development + machine runs an instance of gdb against the vmlinux file which + contains the symbols (not boot image such as bzImage, zImage, + uImage...). In gdb the developer specifies the connection + parameters and connects to kgdb. The type of connection a + developer makes with gdb depends on the availability of kgdb I/O + modules compiled as builtins or kernel modules in the test + machine's kernel. </para> </chapter> <chapter id="CompilingAKernel"> - <title>Compiling a kernel</title> + <title>Compiling a kernel</title> + <para> + <itemizedlist> + <listitem><para>In order to enable compilation of kdb, you must first enable kgdb.</para></listitem> + <listitem><para>The kgdb test compile options are described in the kgdb test suite chapter.</para></listitem> + </itemizedlist> + </para> + <sect1 id="CompileKGDB"> + <title>Kernel config options for kgdb</title> <para> To enable <symbol>CONFIG_KGDB</symbol> you should first turn on "Prompt for development and/or incomplete code/drivers"
Documentation/DocBook/kgdb.tmpl line 107
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +8
-1(CONFIG_EXPERIMENTAL) in "General setup", then under the - "Kernel debugging" select "KGDB: kernel debugging with remote gdb". + "Kernel debugging" select "KGDB: kernel debugger". + </para> + <para> + While it is not a hard requirement that you have symbols in your + vmlinux file, gdb tends not to be very useful without the symbolic + data, so you will want to turn + on <symbol>CONFIG_DEBUG_INFO</symbol> which is called "Compile the + kernel with debug info" in the menu config.
s/menu config/config menu/ throughout.
Documentation/DocBook/kgdb.tmpl line 115
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +5
-5</para> <para> It is advised, but not required that you turn on the - CONFIG_FRAME_POINTER kernel option. This option inserts code to - into the compiled executable which saves the frame information in - registers or on the stack at different points which will allow a - debugger such as gdb to more accurately construct stack back traces - while debugging the kernel. + <symbol>CONFIG_FRAME_POINTER</symbol> kernel option which is called "Compile the + kernel with frame pointers" in the menu config. This option + inserts code to into the compiled executable which saves the frame + information in registers or on the stack at different points which + will allow a debugger such as gdb to more accurately construct
allows a debugger
Quoted 11 lines
Documentation/DocBook/kgdb.tmpl +1
-3+ stack back traces while debugging the kernel. </para> <para> If the architecture that you are using supports the kernel option@@ -116,38 +126,146 @@ this option. </para> <para> - Next you should choose one of more I/O drivers to interconnect debugging - host and debugged target. Early boot debugging requires a KGDB - I/O driver that supports early debugging and the driver must be
Documentation/DocBook/kgdb.tmpl line 135
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +7
-3- built into the kernel directly. Kgdb I/O driver configuration - takes place via kernel or module parameters, see following - chapter. + Next you should choose one of more I/O drivers to interconnect + debugging host and debugged target. Early boot debugging requires + a KGDB I/O driver that supports early debugging and the driver + must be built into the kernel directly. Kgdb I/O driver + configuration takes place via kernel or module parameters which + you can learn more about in the in the section that describes the + kernel parameter kgdboc.
parameter "kgdboc".
Documentation/DocBook/kgdb.tmpl line 137
Quoted 4 lines
Documentation/DocBook/kgdb.tmpl +1
-2</para> - <para> - The kgdb test compile options are described in the kgdb test suite chapter. + <para>Here is an example set of .config to enable kgdb:
of .config symbols to enable or disable for kgdb:
Documentation/DocBook/kgdb.tmpl line 149
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +11
-1+ <itemizedlist> + <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> + <listitem><para>CONFIG_KGDB=y</para></listitem> + <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem> + </itemizedlist> </para> - + </sect1> + <sect1 id="CompileKDB"> + <title>Kernel config options for kdb</title> + <para>Kdb is quite a bit more complex than the simple gdbstub + sitting on top of the kernel's debug core. Kdb must implement an
implement a
Documentation/DocBook/kgdb.tmpl line 162
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +13
-0+ shell, and also adds some helper functions in other parts of the + kernel, responsible for printing out interesting data such as what + you would see if you ran "lsmod", or "ps". In order to build kdb + into the kernel you follow the same steps as you would for kgdb. + </para> + <para>The main config option for kdb + is <symbol>CONFIG_KGDB_KDB</symbol> which is called "KGDB_KDB: + include kdb frontend for kgdb" in the menu config. In theory you + would have already also selected an I/O driver such as the + CONFIG_KGDB_SERIAL_CONSOLE interface if you plan on using kdb on a + serial port, when you were configuring kgdb. + </para> + <para>If you want to use a ps/2 style keyboard with kdb you would
PS/2-style keyboard with kdb, you would
Documentation/DocBook/kgdb.tmpl line 164
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ select CONFIG_KDB_KEYBOARD which is called "KGDB_KDB: keyboard as + input device" in the menu config. This option really does do
does not do (??)
Documentation/DocBook/kgdb.tmpl line 165
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ anything for the gdb interface to kgdb it only works with kdb,
to kgdb; it only
Documentation/DocBook/kgdb.tmpl line 169
Quoted 4 lines
Documentation/DocBook/kgdb.tmpl +4
-0+ because it is not really meaningful to manually type in gdb + remote protocol commands. + </para> + <para>Here is an example set of .config to enable kdb:
set of .config symbols to enable/disable for kdb:
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +10
-2+ <itemizedlist> + <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> + <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem> + <listitem><para>CONFIG_KGDB=y</para></listitem> + <listitem><para>CONFIG_KGDB_SERIAL_CONSOLE=y</para></listitem> + <listitem><para>CONFIG_KGDB_KDB=y</para></listitem> + <listitem><para>CONFIG_KDB_KEYBOARD=y</para></listitem> + </itemizedlist> + </para> + </sect1> </chapter> - <chapter id="EnableKGDB"> - <title>Enable kgdb for debugging</title>
Documentation/DocBook/kgdb.tmpl line 183
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +3
-7- <para> - In order to use kgdb you must activate it by passing configuration - information to one of the kgdb I/O drivers. If you do not pass any - configuration information kgdb will not do anything at all. Kgdb - will only actively hook up to the kernel trap hooks if a kgdb I/O - driver is loaded and configured. If you unconfigure a kgdb I/O - driver, kgdb will unregister all the kernel hook points. + <chapter id="kgdbKernelArgs"> + <title>Kernel Debugger Boot Arguments</title> + <para>This section will describe the various runtime kernel
section describes
Documentation/DocBook/kgdb.tmpl line 185
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ parameters that affect the configuration of the kernel debugger. + The following chapter will cover using kdb and kgdb as well as
chapter covers
Documentation/DocBook/kgdb.tmpl line 186
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ provide some examples of the configuration parameters.</para>
provides
Quoted 8 lines
Documentation/DocBook/kgdb.tmpl +6
-1+ <sect1 id="kgdboc"> + <title>Kernel parameter: kgdboc</title> + <para>The kgdboc driver was originally an abbreviation meant to + stand for "kgdb over console". Today it is the primary mechanism + to configure how to communicate from gdb to kgdb as well as the + devices you want to use to interact with the kdb shell. </para> - <para>
Documentation/DocBook/kgdb.tmpl line 195
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +2
-8- All drivers can be reconfigured at run time, if - <symbol>CONFIG_SYSFS</symbol> and <symbol>CONFIG_MODULES</symbol> - are enabled, by echo'ing a new config string to - <constant>/sys/module/<driver>/parameter/<option></constant>. - The driver can be unconfigured by passing an empty string. You cannot - change the configuration while the debugger is attached. Make sure - to detach the debugger with the <constant>detach</constant> command - prior to trying unconfigure a kgdb I/O driver. + <para>For kgdb/gdb, kgdboc is designed to work with a single serial + port. It was meant to cover the circumstance where you wanted to
is meant you want to
Documentation/DocBook/kgdb.tmpl line 199
Quoted 4 lines
Documentation/DocBook/kgdb.tmpl +4
-0+ use a serial console as your primary console as well as using it to + perform kernel debugging. It is also possible to use kgdb on a + serial port which is not designated as a system console. Kgdboc + may be configured as a kernel built-in or a kernel module. You can
kernel loadable module.
Documentation/DocBook/kgdb.tmpl line 201
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ only make use of <constant>kgdbwait</constant> and early debugging + if you build kgdboc into the kernel as a builtins.
as a builtin.
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +13
-0+ </para> + <sect2 id="kgdbocArgs"> + <title>kgdboc arguments</title> + <para>Usage: <constant>kgdboc=[kbd][[,]serial_device][,baud]</constant></para> + <para>You can configure kgdboc to use the keyboard, and or a serial device + depending on if you are using kdb and or kgdb, in one of the + following scenarios. + <orderedlist> + <listitem><para>kdb and kgdb over only a serial port</para> + <para><constant>kgdboc=<serial_device>[,baud]</constant></para> + <para>Example: <constant>kgdboc=ttyS0,115200</constant></para> + </listitem> + <listitem><para>kdb and kgdb with keyboard and a serial port</para>
Documentation/DocBook/kgdb.tmpl line 224
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ <para><constant>kgdboc=kbd,<serial_device>[,baud]</constant></para> + <para>Example: <constant>kgdboc=kbd,ttyS0,115200</constant></para> + </listitem> + <listitem><para>kdb with a keyboard</para> + <para><constant>kgdboc=kbd</constant></para> + </listitem> + </orderedlist> + </para> + <para>You can configure kgdboc via sysfs or a module or kernel boot line + parameter depending on if you build with CONFIG_KGDBOC as a module
as a loadable module
Documentation/DocBook/kgdb.tmpl line 227
Quoted 3 lines
Documentation/DocBook/kgdb.tmpl +3
-0+ or built-in. + <orderedlist> + <listitem><para>From the module load or build-in</para>
built-in (?)
Documentation/DocBook/kgdb.tmpl line 229
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ <para>As a kernel argument: <constant>kgdboc=<tty-device>,[baud]</constant></para> + <para>As a kernel module: <constant>modprobe kgdboc kgdboc=<tty-device>,[baud]</constant></para>
As a kernel loadable module:
Quoted 11 lines
Documentation/DocBook/kgdb.tmpl +11
-0+ <para>Here are two examples, the first for an x86 target using the + first serial port and the second for the ARM Versatile AB using the + second serial port. + <orderedlist> + <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> + <listitem><para><constant>kgdboc=ttyAMA1,115200</constant></para></listitem> + </orderedlist> + </para> + </listitem> + <listitem><para>From sysfs</para> + <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para>
Documentation/DocBook/kgdb.tmpl line 250
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ <para>NOTE: You do not need to specify the baud if you are + configuring the console on tty which is already configured or + open.</para> + </listitem> + </orderedlist> + </para> + <para>NOTE: Kgdboc does not support interrupting the target via the + gdb remote protocol. You must manually send a sysrq-g unless you + have a proxy that splits console output to a terminal program. + A console proxy has a separate tcp port for the debugger and a separate
TCP
Documentation/DocBook/kgdb.tmpl line 251
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ tcp port for the "human" console. The proxy can take care of sending
TCP
Documentation/DocBook/kgdb.tmpl line 255
Quoted 4 lines
Documentation/DocBook/kgdb.tmpl +3
-0+ the sysrq-g for you. </para> + <para>When using kgdboc with no debugger proxy, you can end up + connecting the debugger for one of two entry points. If an
at (?)
Documentation/DocBook/kgdb.tmpl line 256
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ exception occurs after you have loaded kgdboc a message should
kgdboc,
Documentation/DocBook/kgdb.tmpl line 258
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ print on the console stating it is waiting for the debugger. In + case you disconnect your terminal program and then connect the
this case,
Quoted 30 lines
Documentation/DocBook/kgdb.tmpl +14
-9+ debugger in its place. If you want to interrupt the target system + and forcibly enter a debug session you have to issue a Sysrq + sequence and then type the letter <constant>g</constant>. Then + you disconnect the terminal session and connect gdb. Your options + if you don't like this are to hack gdb to send the sysrq-g for you + as well as on the initial connect, or to use a debugger proxy that + allows an unmodified gdb to do the debugging. + </para> + </sect2> + </sect1> <sect1 id="kgdbwait"> <title>Kernel parameter: kgdbwait</title> <para>@@ -166,99 +284,193 @@ kgdb I/O driver as a kernel module kgdbwait will not do anything. </para> </sect1> - <sect1 id="kgdboc"> - <title>Kernel parameter: kgdboc</title> - <para> - The kgdboc driver was originally an abbreviation meant to stand for - "kgdb over console". Kgdboc is designed to work with a single - serial port. It was meant to cover the circumstance - where you wanted to use a serial console as your primary console as - well as using it to perform kernel debugging. Of course you can - also use kgdboc without assigning a console to the same port. + <sect1 id="kgdbcon"> + <title>Kernel parameter: kgdbcon</title> + <para> The kgdbcon feature allows you to see printk() messages + inside gdb while gdb is connected to the kernel. Kdb does not make
Documentation/DocBook/kgdb.tmpl line 300
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ use of the kgdbcon feature. + </para> + <para>Kgdb supports using the gdb serial protocol to send console + messages to the debugger when the debugger is connected and running. + There are two ways to activate this feature. + <orderedlist> + <listitem><para>Activate with the kernel command line option:</para> + <para><constant>kgdbcon</constant></para> + </listitem> + <listitem><para>Use sysfs before configuring an io driver</para>
I/O
Documentation/DocBook/kgdb.tmpl line 312
Quoted 12 lines
Documentation/DocBook/kgdb.tmpl +12
-0+ <para> + <constant>echo 1 > /sys/module/kgdb/parameters/kgdb_use_con</constant> + </para> + <para> + NOTE: If you do this after you configure the kgdb I/O driver, the + setting will not take effect until the next point the I/O is + reconfigured. + </para> + </listitem> + </orderedlist> + <para>IMPORTANT NOTE: You cannot use kgdboc + kgdbcon on a tty that is an + active system console IE: console=ttyS0,115200 kgdboc=ttyS0 kgdbcon
console;
and then EG: or e.g.: would be better than IE: there.
Quoted 13 lines
Documentation/DocBook/kgdb.tmpl +3
-9+ </para> + <para>It is possible to use this option with kgdboc on a tty that is not a system console. + </para> </para> - <sect2 id="UsingKgdboc"> - <title>Using kgdboc</title> - <para> - You can configure kgdboc via sysfs or a module or kernel boot line - parameter depending on if you build with CONFIG_KGDBOC as a module - or built-in. - <orderedlist> - <listitem><para>From the module load or build-in</para> - <para><constant>kgdboc=<tty-device>,[baud]</constant></para>
Documentation/DocBook/kgdb.tmpl line 325
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +8
-1+ </sect1> + </chapter> + <chapter id="usingKDB"> + <title>Using kdb</title> <para> - The example here would be if your console port was typically ttyS0, you would use something like <constant>kgdboc=ttyS0,115200</constant> or on the ARM Versatile AB you would likely use <constant>kgdboc=ttyAMA0,115200</constant> + </para> + <sect1 id="quickKDBserial"> + <title>Quick start for kdb on a serial port</title> + <para>This is a quick example of how to use kdb</para>
End sentence with .
Documentation/DocBook/kgdb.tmpl line 332
Quoted 7 lines
Documentation/DocBook/kgdb.tmpl +7
-0+ <para><orderedlist> + <listitem><para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>console=ttyS0,115200 kgdboc=ttyS0,115200</constant></para></listitem> + </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted assuming your are using a serial port console:
booted; assuming you are
Documentation/DocBook/kgdb.tmpl line 338
Quoted 8 lines
Documentation/DocBook/kgdb.tmpl +4
-2+ <itemizedlist> + <listitem><para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist> </para> </listitem> - <listitem><para>From sysfs</para> - <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para> + <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para>
s/opps/oops/
s/manually,/manually;/
s/have to enabled/must have enabled/
End last sentence with .
Quoted 41 lines
Documentation/DocBook/kgdb.tmpl +26
-13+ <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using minicom 2.2</para> + <para>Press: <constant>Control-a</constant></para> + <para>Press: <constant>f</constant></para> + <para>Press: <constant>g</constant></para> </listitem> - </orderedlist> - </para> - <para> - NOTE: Kgdboc does not support interrupting the target via the - gdb remote protocol. You must manually send a sysrq-g unless you - have a proxy that splits console output to a terminal problem and - has a separate port for the debugger to connect to that sends the - sysrq-g for you. + <listitem><para>When you have telneted to a terminal server that supports sending a remote break</para> + <para>Press: <constant>Control-]</constant></para> + <para>Type in:<constant>send break</constant></para> + <para>Press: <constant>Enter</constant></para> + <para>Press: <constant>g</constant></para> + </listitem> + </itemizedlist> + </listitem> + <listitem><para>From the kdb prompt you can run the "help" command to see a complete list of the commands that are available.</para> + <para>Some useful commands in kdb include: + <itemizedlist> + <listitem><para>lsmod -- Shows where kernel modules are loaded</para></listitem> + <listitem><para>ps -- Displays only the active processes</para></listitem> + <listitem><para>ps A -- Shows all the processes</para></listitem> + <listitem><para>summary -- Shows kernel version info and memory usage</para></listitem> + <listitem><para>bt -- Get a backtrace of the current process using dump_stack()</para></listitem> + <listitem><para>dmesg -- View the kernel syslog buffer</para></listitem> + <listitem><para>go -- Continue the system</para></listitem> + </itemizedlist> </para> - <para>When using kgdboc with no debugger proxy, you can end up - connecting the debugger for one of two entry points. If an - exception occurs after you have loaded kgdboc a message should print - on the console stating it is waiting for the debugger. In case you - disconnect your terminal program and then connect the debugger in
Documentation/DocBook/kgdb.tmpl line 369
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +3
-7- its place. If you want to interrupt the target system and forcibly - enter a debug session you have to issue a Sysrq sequence and then - type the letter <constant>g</constant>. Then you disconnect the - terminal session and connect gdb. Your options if you don't like - this are to hack gdb to send the sysrq-g for you as well as on the - initial connect, or to use a debugger proxy that allows an - unmodified gdb to do the debugging. + </listitem> + <listitem> + <para>When you are done using kdb you need to consider rebooting the system or using the "go" command to resuming normal kernel execution. If you have paused the kernel for a lengthy period of time, applications that rely on timely networking or anything to do with real wall clock time could get adversely affected, so you should take this into consideration when using the kernel debugger.</para>
s/could get/could be/
Documentation/DocBook/kgdb.tmpl line 375
Quoted 6 lines
Documentation/DocBook/kgdb.tmpl +6
-0+ </listitem> + </orderedlist></para> + </sect1> + <sect1 id="quickKDBkeyboard"> + <title>Quick start for kdb using a keyboard connected console</title> + <para>This is a quick example of how to use kdb with a keyboard</para>
End sentence with .
Quoted 4 lines
Documentation/DocBook/kgdb.tmpl +4
-0+ <para><orderedlist> + <listitem><para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>kgdboc=kbd</constant></para></listitem>
Documentation/DocBook/kgdb.tmpl line 388
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +8
-1+ </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted: + <itemizedlist> + <listitem><para><constant>echo kbd > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist> </para> - </sect2> + </listitem> + <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para>
s/opps/oops/
s/manually,/manually;/
s/have to enabled/must have enabled/
End last sentence with .
Documentation/DocBook/kgdb.tmpl line 400
Quoted 12 lines
Documentation/DocBook/kgdb.tmpl +12
-0+ <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using a laptop keyboard</para> + <para>Press and hold down: <constant>Alt</constant></para> + <para>Press and hold down: <constant>Fn</constant></para> + <para>Press and release the key with the label: <constant>SysRq</constant></para> + <para>Release: <constant>Fn</constant></para> + <para>Press and release: <constant>g</constant></para> + <para>Release: <constant>Alt</constant></para> + </listitem> + <listitem><para>Example using a PS/2 101 keyboard</para>
101-key keyboard
Quoted 26 lines
Documentation/DocBook/kgdb.tmpl +19
-6+ <para>Press and hold down: <constant>Alt</constant></para> + <para>Press and release the key with the label: <constant>SysRq</constant></para> + <para>Press and release: <constant>g</constant></para> + <para>Release: <constant>Alt</constant></para> + </listitem> + </itemizedlist> + </listitem> + <listitem> + <para>Now type in a kdb command such as "help", "dmesg", "bt" or "go" to continue kernel execution.</para> + </listitem> + </orderedlist></para> </sect1> - <sect1 id="kgdbcon"> - <title>Kernel parameter: kgdbcon</title> - <para> - Kgdb supports using the gdb serial protocol to send console messages - to the debugger when the debugger is connected and running. There - are two ways to activate this feature. + </chapter> + <chapter id="EnableKGDB"> + <title>Using kgdb / gdb</title> + <para>In order to use kgdb you must activate it by passing + configuration information to one of the kgdb I/O drivers. If you + do not pass any configuration information kgdb will not do anything + at all. Kgdb will only actively hook up to the kernel trap hooks + if a kgdb I/O driver is loaded and configured. If you unconfigure
Documentation/DocBook/kgdb.tmpl line 430
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ a kgdb I/O driver, kgdb will unregister all the kernel hook points. + </para> + <para> All kgdb I/O drivers can be reconfigured at run time, if + <symbol>CONFIG_SYSFS</symbol> and <symbol>CONFIG_MODULES</symbol> + are enabled, by echo'ing a new config string to + <constant>/sys/module/<driver>/parameter/<option></constant>. + The driver can be unconfigured by passing an empty string. You cannot + change the configuration while the debugger is attached. Make sure + to detach the debugger with the <constant>detach</constant> command + prior to trying unconfigure a kgdb I/O driver.
prior to trying to unconfigure
Quoted 19 lines
Documentation/DocBook/kgdb.tmpl +13
-4+ </para> + <sect1 id="ConnectingGDB"> + <title>Connecting with gdb to a serial port</title> <orderedlist> - <listitem><para>Activate with the kernel command line option:</para> - <para><constant>kgdbcon</constant></para> + <listitem><para>Configure kgdboc</para> + <para>Boot kernel with arguments: + <itemizedlist> + <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> + </itemizedlist></para> + <para>OR</para> + <para>Configure kgdboc after the kernel booted: + <itemizedlist> + <listitem><para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </itemizedlist></para> </listitem> - <listitem><para>Use sysfs before configuring an io driver</para> - <para>
Documentation/DocBook/kgdb.tmpl line 448
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +3
-7- <constant>echo 1 > /sys/module/kgdb/parameters/kgdb_use_con</constant> - </para> - <para> - NOTE: If you do this after you configure the kgdb I/O driver, the - setting will not take effect until the next point the I/O is - reconfigured. - </para> + <listitem> + <para>Stop kernel execution (break into the debugger)</para> + <para>In order to connect to gdb to the via kgdboc the kernel must
In order to connect to gdb via kgdboc, the kernel must
Documentation/DocBook/kgdb.tmpl line 451
Quoted 3 lines
Documentation/DocBook/kgdb.tmpl +3
-0+ first be stopped. There are several ways to stop the kernel which + include using kgdbwait as a boot argument, via a sysrq-g, or running + the kernel until it takes an an exception where it waits for the
takes an exception
Quoted 47 lines
Documentation/DocBook/kgdb.tmpl +19
-21+ debugger to attach. + <itemizedlist> + <listitem><para>When logged in as root or with a super user session you can run:</para> + <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem> + <listitem><para>Example using minicom 2.2</para> + <para>Press: <constant>Control-a</constant></para> + <para>Press: <constant>f</constant></para> + <para>Press: <constant>g</constant></para> </listitem> - </orderedlist> - </para> - <para> - IMPORTANT NOTE: Using this option with kgdb over the console - (kgdboc) is not supported. + <listitem><para>When you have telneted to a terminal server that supports sending a remote break</para> + <para>Press: <constant>Control-]</constant></para> + <para>Type in:<constant>send break</constant></para> + <para>Press: <constant>Enter</constant></para> + <para>Press: <constant>g</constant></para> + </listitem> + </itemizedlist> </para> - </sect1> - </chapter> - <chapter id="ConnectingGDB"> - <title>Connecting gdb</title> - <para> - If you are using kgdboc, you need to have used kgdbwait as a boot - argument, issued a sysrq-g, or the system you are going to debug - has already taken an exception and is waiting for the debugger to - attach before you can connect gdb. - </para> - <para> - If you are not using different kgdb I/O driver other than kgdboc, - you should be able to connect and the target will automatically - respond. - </para> + </listitem> + <listitem> + <para>Connect from from gdb</para> <para> - Example (using a serial port): + Example (using a directly connected port): </para> <programlisting> % gdb ./vmlinux
Documentation/DocBook/kgdb.tmpl line 500
Quoted 6 lines
Documentation/DocBook/kgdb.tmpl +3
-0@@ -283,6 +495,82 @@ communications. You do this prior to issuing the <constant>target remote</constant> command by typing in: <constant>set debug remote 1</constant> </para> + </listitem> + </orderedlist> + <para>Remember if you continue in gdb, and need "break in" again,
need to
Documentation/DocBook/kgdb.tmpl line 501
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ you need to issue an other sysrq. It is easy to create an simple
another sysrq-g. It is easy to create a simple
Quoted 6 lines
Documentation/DocBook/kgdb.tmpl +6
-0+ entry point by putting a breakpoint at <constant>sys_sync</constant> + and then you can run "sync" from a shell or script to break into the + debugger.</para> + </sect1> + </chapter> + <chapter id="switchKdbKgdb">
Documentation/DocBook/kgdb.tmpl line 517
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ <title>kgdb and kdb interoperability</title> + <para>It is possible to transition between kdb and kgdb dynamically. + The debug core will remember which you used the last time and + automatically start in the same mode.</para> + <sect1> + <title>Switching between kdb and kgdb</title> + <sect2> + <title>Switching from kgdb to kdb</title> + <para> + There are two ways to switch from kgdb to kdb, you can use gdb to
to kdb:
Documentation/DocBook/kgdb.tmpl line 519
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ issue a maintenance packet, or you can blindly type the command $3#33. + When ever kernel debugger stops in kgdb mode it will print the
Whenever
Documentation/DocBook/kgdb.tmpl line 521
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +2
-0+ message <constant>KGDB or $3#33 for KDB</constant>. It is important + to note, that you have to type the sequence correctly in one pass.
to note that
Documentation/DocBook/kgdb.tmpl line 529
Quoted 8 lines
Documentation/DocBook/kgdb.tmpl +8
-0+ You cannot type a backspace or delete because kgdb will interpret + that as part of the debug stream. + <orderedlist> + <listitem><para>Change from kgdb to kdb by blindly typing:</para> + <para><constant>$3#33</constant></para></listitem> + <listitem><para>Change from kgdb to kdb with gdb</para> + <para><constant>maintenance packet 3</constant></para> + <para>NOTE: Now you must kill gdb</para></listitem>
tell how to kill?
Quoted 18 lines
Documentation/DocBook/kgdb.tmpl +18
-0+ </orderedlist> + </para> + </sect2> + <sect2> + <title>Change from kdb to kgdb</title> + <para>There are two ways you can change from kdb to kgdb. You can + manually enter kgdb mode by issuing the kgdb command from the kdb + shell prompt, or you can connect gdb while the kdb shell prompt is + active. The kdb shell looks for the typical first commands that gdb + would issue with the gdb remote protocol and if it sees one of those + commands it automatically changes into kgdb mode.</para> + <orderedlist> + <listitem><para>From kdb issue the command:</para> + <para><constant>kgdb</constant></para> + <para>Now disconnect your terminal program and connect gdb in its place</para></listitem> + <listitem><para>At the kdb prompt, disconnect the terminal program and connect gdb in its place.</para></listitem> + </orderedlist> + </sect2>
Documentation/DocBook/kgdb.tmpl line 557
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ </sect1> + <sect1> + <title>Running kdb commands from gdb</title> + <para>It is possible to run a limited set of kdb commands from gdb, + using the gdb monitor command. You don't want to execute any of the + run control or breakpoint operations, because it can disrupt the + state of the kernel debugger. You should be using gdb for + breakpoints and run control operations if you have gdb connected. + The more useful commands to run are things like lsmod, dmesg, ps or + possibly some of the memory information. To see all the kdb
information commands.
Quoted 29 lines
Documentation/DocBook/kgdb.tmpl +17
-2+ commands you can run <constant>monitor help</constant>.</para> + <para>Example: + <informalexample><programlisting> +(gdb) monitor ps +1 idle process (state I) and +27 sleeping system daemon (state M) processes suppressed, +use 'ps A' to see all. +Task Addr Pid Parent [*] cpu State Thread Command + +0xc78291d0 1 0 0 0 S 0xc7829404 init +0xc7954150 942 1 0 0 S 0xc7954384 dropbear +0xc78789c0 944 1 0 0 S 0xc7878bf4 sh +(gdb) + </programlisting></informalexample> + </para> + </sect1> </chapter> <chapter id="KGDBTestSuite"> <title>kgdb Test Suite</title>@@ -309,22 +597,22 @@ </para> </chapter> <chapter id="CommonBackEndReq"> - <title>KGDB Internals</title> + <title>Kernel Debugger Internals</title> <sect1 id="kgdbArchitecture"> <title>Architecture Specifics</title> <para> - Kgdb is organized into three basic components:
Documentation/DocBook/kgdb.tmpl line 610
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +3
-3+ The kernel debugger is organized into a number of components: <orderedlist> - <listitem><para>kgdb core</para> + <listitem><para>The debug core</para> <para> - The kgdb core is found in kernel/kgdb.c. It contains: + The debug core is found in kernel/debugger/debug_core.c. It contains: <itemizedlist> - <listitem><para>All the logic to implement the gdb serial protocol</para></listitem> <listitem><para>A generic OS exception handler which includes sync'ing the processors into a stopped state on an multi cpu system.</para></listitem>
multi-CPU
Documentation/DocBook/kgdb.tmpl line 612
Quoted 2 lines
Documentation/DocBook/kgdb.tmpl +0
-0<listitem><para>The API to talk to the kgdb I/O drivers</para></listitem> <listitem><para>The API to make calls to the arch specific kgdb implementation</para></listitem>
arch-specific
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +1
-0<listitem><para>The logic to perform safe memory reads and writes to memory while using the debugger</para></listitem> <listitem><para>A full implementation for software breakpoints unless overridden by the arch</para></listitem> + <listitem><para>The API to invoke either the kdb or kgdb frontend to the debug core.</para></listitem> </itemizedlist> </para> </listitem>@@ -347,9 +635,31 @@ </itemizedlist> </para> </listitem>
Documentation/DocBook/kgdb.tmpl line 647
Quoted 10 lines
Documentation/DocBook/kgdb.tmpl +10
-0+ <listitem><para>gdbstub frontend (aka kgdb)</para> + <para>The gdbstub is located in kernel/debug/gdbstub.c. It contains:</para> + <itemizedlist> + <listitem><para>All the logic to implement the gdb serial protocol</para></listitem> + </itemizedlist> + </listitem> + <listitem><para>kdb frontend</para> + <para>The kdb debugger shell is broken down into a number of + components. The kdb core is located in kernel/debug/kdb. There + are number of helper functions in some of the other kernel
are a number
Documentation/DocBook/kgdb.tmpl line 648
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ components to make it possible for kdb to examine report
examine and report
Documentation/DocBook/kgdb.tmpl line 655
Quoted 7 lines
Documentation/DocBook/kgdb.tmpl +7
-0+ information about the kernel without taking locks that could + cause a kernel deadlock. The kdb core contains implements the following functionality.</para> + <itemizedlist> + <listitem><para>A simple shell</para></listitem> + <listitem><para>The kdb core command set</para></listitem> + <listitem><para>A registration API to register additional kdb shell commands.</para> + <para>A good example of a self contained kdb module is the "ftdump" command for dumping the ftrace buffer. See: kernel/trace/trace_kdb.c</para></listitem>
self-contained
Documentation/DocBook/kgdb.tmpl line 656
Quoted 1 line
Documentation/DocBook/kgdb.tmpl +1
-0+ <listitem><para>The implementation for kdb_printf() which emit messages directly to I/O drivers, bypassing the kernel log.</para></listitem>
emits
Quoted 21 lines
Documentation/DocBook/kgdb.tmpl +8
-1+ <listitem><para>SW / HW breakpoint management for the kdb shell</para></listitem> + </itemizedlist> + </listitem> <listitem><para>kgdb I/O driver</para> <para> - Each kgdb I/O driver has to provide an implemenation for the following: + Each kgdb I/O driver has to provide an implementation for the following: <itemizedlist> <listitem><para>configuration via builtin or module</para></listitem> <listitem><para>dynamic configuration and kgdb hook registration calls</para></listitem>@@ -453,6 +763,10 @@ <itemizedlist> <listitem><para>Jason Wessel<email>[email protected]</email></para></listitem> </itemizedlist> + In Jan 2010 this document was updated to include kdb. + <itemizedlist> + <listitem><para>Jason Wessel<email>[email protected]</email></para></listitem> + </itemizedlist> </para> </chapter> </book>
Signature · 1 line
~Randy
Jason Wessel
maintainerRe: [Kgdb-bugreport] [PATCH 15/28] kgdb, docs: Update the kgdb docs to include kdb
Quoted 7 lines · Randy Dunlap
Quoted 3 lines · Jason Wessel
Update the kgdb docs to reflect the new directory structure and API.
Merge in the kdb shell information.
See comments/corrections inline below.
Thank very much for the comments. Would you like a credit in the manual?
I merged in all your edits.
Here is the interdiff in case you were curious.
Thanks,
Jason.
DocBook/kgdb.tmpl | 208 ++++++++++++++++++++++++++++---------------------- kernel-parameters.txt | 3 2 files changed, 118 insertions(+), 93 deletions(-)
Documentation/DocBook/kgdb.tmpl +117 -91
@@ -50,20 +50,20 @@ if you configure the kernel properly at compile and runtime. </para> <para> - Kdb is simplistic shell style interface which you can use on a + Kdb is simplistic shell-style interface which you can use on a system console with a keyboard or serial console. You can use it to inspect memory, registers, process lists, dmesg, and even set breakpoints to stop in a certain location. Kdb is not a source level debugger, although you can set breakpoints and execute some basic kernel run control. Kdb is mainly aimed at doing some analysis to aid in development or diagnosing kernel problems. You - can access some symbols by name in kernel builtins or in kernel + can access some symbols by name in kernel built-ins or in kernel modules if the code was built with <symbol>CONFIG_KALLSYMS</symbol>. </para> <para> - Kgdb was intended to be used as a source level debugger for the - linux kernel. It is used along with gdb to debug a linux kernel. + Kgdb is intended to be used as a source level debugger for the + Linux kernel. It is used along with gdb to debug a Linux kernel. The expectation is that gdb can be used to "break in" to the kernel to inspect memory, variables and look through call stack information similar to the way an application developer would use
@@ -79,7 +79,7 @@ uImage...). In gdb the developer specifies the connection parameters and connects to kgdb. The type of connection a developer makes with gdb depends on the availability of kgdb I/O - modules compiled as builtins or kernel modules in the test + modules compiled as built-ins or loadable kernel modules in the test machine's kernel. </para> </chapter>
@@ -104,15 +104,15 @@ vmlinux file, gdb tends not to be very useful without the symbolic data, so you will want to turn on <symbol>CONFIG_DEBUG_INFO</symbol> which is called "Compile the - kernel with debug info" in the menu config. + kernel with debug info" in the config menu. </para> <para> It is advised, but not required that you turn on the <symbol>CONFIG_FRAME_POINTER</symbol> kernel option which is called "Compile the - kernel with frame pointers" in the menu config. This option + kernel with frame pointers" in the config menu. This option inserts code to into the compiled executable which saves the frame information in registers or on the stack at different points which - will allow a debugger such as gdb to more accurately construct + allows a debugger such as gdb to more accurately construct stack back traces while debugging the kernel. </para> <para>
@@ -132,9 +132,10 @@ must be built into the kernel directly. Kgdb I/O driver configuration takes place via kernel or module parameters which you can learn more about in the in the section that describes the - kernel parameter kgdboc. + parameter "kgdboc". </para> - <para>Here is an example set of .config to enable kgdb: + <para>Here is an example set of .config symbols to enable or + disable for kgdb: <itemizedlist> <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem>
@@ -146,7 +147,7 @@ <sect1 id="CompileKDB"> <title>Kernel config options for kdb</title> <para>Kdb is quite a bit more complex than the simple gdbstub - sitting on top of the kernel's debug core. Kdb must implement an + sitting on top of the kernel's debug core. Kdb must implement a shell, and also adds some helper functions in other parts of the kernel, responsible for printing out interesting data such as what you would see if you ran "lsmod", or "ps". In order to build kdb
@@ -154,19 +155,18 @@ </para> <para>The main config option for kdb is <symbol>CONFIG_KGDB_KDB</symbol> which is called "KGDB_KDB: - include kdb frontend for kgdb" in the menu config. In theory you + include kdb frontend for kgdb" in the config menu. In theory you would have already also selected an I/O driver such as the CONFIG_KGDB_SERIAL_CONSOLE interface if you plan on using kdb on a serial port, when you were configuring kgdb. </para> - <para>If you want to use a ps/2 style keyboard with kdb you would + <para>If you want to use a PS/2-style keyboard with kdb, you would select CONFIG_KDB_KEYBOARD which is called "KGDB_KDB: keyboard as - input device" in the menu config. This option really does do - anything for the gdb interface to kgdb it only works with kdb, - because it is not really meaningful to manually type in gdb - remote protocol commands. + input device" in the config menu. The CONFIG_KDB_KEYBOARD option + is not used for anything in the gdb interface to kgdb. The + CONFIG_KDB_KEYBOARD option only works with kdb. </para> - <para>Here is an example set of .config to enable kdb: + <para>Here is an example set of .config symbols to enable/disable kdb: <itemizedlist> <listitem><para># CONFIG_DEBUG_RODATA is not set</para></listitem> <listitem><para>CONFIG_FRAME_POINTER=y</para></listitem>
@@ -180,10 +180,10 @@ </chapter> <chapter id="kgdbKernelArgs"> <title>Kernel Debugger Boot Arguments</title> - <para>This section will describe the various runtime kernel + <para>This section describes the various runtime kernel parameters that affect the configuration of the kernel debugger. - The following chapter will cover using kdb and kgdb as well as - provide some examples of the configuration parameters.</para> + The following chapter covers using kdb and kgdb as well as + provides some examples of the configuration parameters.</para> <sect1 id="kgdboc"> <title>Kernel parameter: kgdboc</title> <para>The kgdboc driver was originally an abbreviation meant to
@@ -192,17 +192,54 @@ devices you want to use to interact with the kdb shell. </para> <para>For kgdb/gdb, kgdboc is designed to work with a single serial - port. It was meant to cover the circumstance where you wanted to + port. It is intended to cover the circumstance where you want to use a serial console as your primary console as well as using it to perform kernel debugging. It is also possible to use kgdb on a serial port which is not designated as a system console. Kgdboc - may be configured as a kernel built-in or a kernel module. You can - only make use of <constant>kgdbwait</constant> and early debugging - if you build kgdboc into the kernel as a builtins. + may be configured as a kernel built-in or a kernel loadable module. + You can only make use of <constant>kgdbwait</constant> and early + debugging if you build kgdboc into the kernel as a built-in. </para> <sect2 id="kgdbocArgs"> <title>kgdboc arguments</title> <para>Usage: <constant>kgdboc=[kbd][[,]serial_device][,baud]</constant></para> + <sect3 id="kgdbocArgs1"> + <title>Using loadable module or built-in</title> + <para> + <orderedlist> + <listitem><para>As a kernel built-in:</para> + <para>Use the kernel boot argument: <constant>kgdboc=<tty-device>,[baud]</constant></para></listitem> + <listitem> + <para>As a kernel loadable module:</para> + <para>Use the command: <constant>modprobe kgdboc kgdboc=<tty-device>,[baud]</constant></para> + <para>Here are two examples of how you might formate the kgdboc + string. The first is for an x86 target using the first serial port. + The second example is for the ARM Versatile AB using the second + serial port. + <orderedlist> + <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> + <listitem><para><constant>kgdboc=ttyAMA1,115200</constant></para></listitem> + </orderedlist> + </para> + </listitem> + </orderedlist></para> + </sect3> + <sect3 id="kgdbocArgs2"> + <title>Configure kgdboc at runtime with sysfs</title> + <para>At run time you can enable or disable kgdboc by echoing a + parameters into the sysfs. Here are two examples:</para> + <orderedlist> + <listitem><para>Enable kgdboc on ttyS0</para> + <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + <listitem><para>Disable kgdboc</para> + <para><constant>echo "" > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> + </orderedlist> + <para>NOTE: You do not need to specify the baud if you are + configuring the console on tty which is already configured or + open.</para> + </sect3> + <sect3 id="kgdbocArgs3"> + <title>More examples</title> <para>You can configure kgdboc to use the keyboard, and or a serial device depending on if you are using kdb and or kgdb, in one of the following scenarios.
@@ -220,42 +257,19 @@ </listitem> </orderedlist> </para> - <para>You can configure kgdboc via sysfs or a module or kernel boot line - parameter depending on if you build with CONFIG_KGDBOC as a module - or built-in. - <orderedlist> - <listitem><para>From the module load or build-in</para> - <para>As a kernel argument: <constant>kgdboc=<tty-device>,[baud]</constant></para> - <para>As a kernel module: <constant>modprobe kgdboc kgdboc=<tty-device>,[baud]</constant></para> - <para>Here are two examples, the first for an x86 target using the - first serial port and the second for the ARM Versatile AB using the - second serial port. - <orderedlist> - <listitem><para><constant>kgdboc=ttyS0,115200</constant></para></listitem> - <listitem><para><constant>kgdboc=ttyAMA1,115200</constant></para></listitem> - </orderedlist> - </para> - </listitem> - <listitem><para>From sysfs</para> - <para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para> - <para>NOTE: You do not need to specify the baud if you are - configuring the console on tty which is already configured or - open.</para> - </listitem> - </orderedlist> - </para> + </sect3> <para>NOTE: Kgdboc does not support interrupting the target via the gdb remote protocol. You must manually send a sysrq-g unless you have a proxy that splits console output to a terminal program. - A console proxy has a separate tcp port for the debugger and a separate - tcp port for the "human" console. The proxy can take care of sending + A console proxy has a separate TCP port for the debugger and a separate + TCP port for the "human" console. The proxy can take care of sending the sysrq-g for you. </para> <para>When using kgdboc with no debugger proxy, you can end up - connecting the debugger for one of two entry points. If an - exception occurs after you have loaded kgdboc a message should + connecting the debugger at one of two entry points. If an + exception occurs after you have loaded kgdboc, a message should print on the console stating it is waiting for the debugger. In - case you disconnect your terminal program and then connect the + this case you disconnect your terminal program and then connect the debugger in its place. If you want to interrupt the target system and forcibly enter a debug session you have to issue a Sysrq sequence and then type the letter <constant>g</constant>. Then
@@ -280,8 +294,9 @@ </para> <para> The kernel will stop and wait as early as the I/O driver and - architecture will allow when you use this option. If you build the - kgdb I/O driver as a kernel module kgdbwait will not do anything. + architecture allows when you use this option. If you build the + kgdb I/O driver as a loadable kernel module kgdbwait will not do + anything. </para> </sect1> <sect1 id="kgdbcon">
@@ -297,7 +312,7 @@ <listitem><para>Activate with the kernel command line option:</para> <para><constant>kgdbcon</constant></para> </listitem> - <listitem><para>Use sysfs before configuring an io driver</para> + <listitem><para>Use sysfs before configuring an I/O driver</para> <para> <constant>echo 1 > /sys/module/kgdb/parameters/kgdb_use_con</constant> </para>
@@ -309,7 +324,7 @@ </listitem> </orderedlist> <para>IMPORTANT NOTE: You cannot use kgdboc + kgdbcon on a tty that is an - active system console IE: console=ttyS0,115200 kgdboc=ttyS0 kgdbcon + active system console. An example incorrect usage is <constant>console=ttyS0,115200 kgdboc=ttyS0 kgdbcon</constant> </para> <para>It is possible to use this option with kgdboc on a tty that is not a system console. </para>
@@ -322,20 +337,20 @@ </para> <sect1 id="quickKDBserial"> <title>Quick start for kdb on a serial port</title> - <para>This is a quick example of how to use kdb</para> + <para>This is a quick example of how to use kdb.</para> <para><orderedlist> <listitem><para>Boot kernel with arguments: <itemizedlist> <listitem><para><constant>console=ttyS0,115200 kgdboc=ttyS0,115200</constant></para></listitem> </itemizedlist></para> <para>OR</para> - <para>Configure kgdboc after the kernel booted assuming your are using a serial port console: + <para>Configure kgdboc after the kernel booted; assuming you are using a serial port console: <itemizedlist> <listitem><para><constant>echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc</constant></para></listitem> </itemizedlist> </para> </listitem> - <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para> + <listitem><para>Enter the kernel debugger manually or by waiting for an oops or fault. There are several ways you can enter the kernel debugger manually; all involve using the sysrq-g, which means you must have enabled CONFIG_MAGIC_SYSRQ=y in your kernel config.</para> <itemizedlist> <listitem><para>When logged in as root or with a super user session you can run:</para> <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem>
@@ -366,13 +381,19 @@ </para> </listitem> <listitem> - <para>When you are done using kdb you need to consider rebooting the system or using the "go" command to resuming normal kernel execution. If you have paused the kernel for a lengthy period of time, applications that rely on timely networking or anything to do with real wall clock time could get adversely affected, so you should take this into consideration when using the kernel debugger.</para> + <para>When you are done using kdb you need to consider rebooting the + system or using the "go" command to resuming normal kernel + execution. If you have paused the kernel for a lengthy period of + time, applications that rely on timely networking or anything to do + with real wall clock time could be adversely affected, so you + should take this into consideration when using the kernel + debugger.</para> </listitem> </orderedlist></para> </sect1> <sect1 id="quickKDBkeyboard"> <title>Quick start for kdb using a keyboard connected console</title> - <para>This is a quick example of how to use kdb with a keyboard</para> + <para>This is a quick example of how to use kdb with a keyboard.</para> <para><orderedlist> <listitem><para>Boot kernel with arguments: <itemizedlist>
@@ -385,7 +406,7 @@ </itemizedlist> </para> </listitem> - <listitem><para>Enter the kernel debugger manually or by waiting for an opps or fault. There are several ways you can enter the kernel debugger manually, all involve using the sysrq-g, which means you have to enabled CONFIG_MAGIC_SYSRQ=y in your kernel config</para> + <listitem><para>Enter the kernel debugger manually or by waiting for an oops or fault. There are several ways you can enter the kernel debugger manually; all involve using the sysrq-g, which means you must have enabled CONFIG_MAGIC_SYSRQ=y in your kernel config.</para> <itemizedlist> <listitem><para>When logged in as root or with a super user session you can run:</para> <para><constant>echo g > /proc/sysrq-trigger</constant></para></listitem>
@@ -397,7 +418,7 @@ <para>Press and release: <constant>g</constant></para> <para>Release: <constant>Alt</constant></para> </listitem> - <listitem><para>Example using a PS/2 101 keyboard</para> + <listitem><para>Example using a PS/2 101-key keyboard</para> <para>Press and hold down: <constant>Alt</constant></para> <para>Press and release the key with the label: <constant>SysRq</constant></para> <para>Press and release: <constant>g</constant></para>
@@ -427,7 +448,7 @@ The driver can be unconfigured by passing an empty string. You cannot change the configuration while the debugger is attached. Make sure to detach the debugger with the <constant>detach</constant> command - prior to trying unconfigure a kgdb I/O driver. + prior to trying to unconfigure a kgdb I/O driver. </para> <sect1 id="ConnectingGDB"> <title>Connecting with gdb to a serial port</title>
@@ -445,10 +466,10 @@ </listitem> <listitem> <para>Stop kernel execution (break into the debugger)</para> - <para>In order to connect to gdb to the via kgdboc the kernel must + <para>In order to connect to gdb via kgdboc, the kernel must first be stopped. There are several ways to stop the kernel which include using kgdbwait as a boot argument, via a sysrq-g, or running - the kernel until it takes an an exception where it waits for the + the kernel until it takes an exception where it waits for the debugger to attach. <itemizedlist> <listitem><para>When logged in as root or with a super user session you can run:</para>
@@ -478,7 +499,7 @@ (gdb) target remote /dev/ttyS0 </programlisting> <para> - Example (kgdb to a terminal server on tcp port 2012): + Example (kgdb to a terminal server on TCP port 2012): </para> <programlisting> % gdb ./vmlinux
@@ -497,8 +518,8 @@ </para> </listitem> </orderedlist> - <para>Remember if you continue in gdb, and need "break in" again, - you need to issue an other sysrq. It is easy to create an simple + <para>Remember if you continue in gdb, and need to "break in" again, + you need to issue an other sysrq-g. It is easy to create a simple entry point by putting a breakpoint at <constant>sys_sync</constant> and then you can run "sync" from a shell or script to break into the debugger.</para>
@@ -514,11 +535,11 @@ <sect2> <title>Switching from kgdb to kdb</title> <para> - There are two ways to switch from kgdb to kdb, you can use gdb to + There are two ways to switch from kgdb to kdb: you can use gdb to issue a maintenance packet, or you can blindly type the command $3#33. - When ever kernel debugger stops in kgdb mode it will print the + Whenever kernel debugger stops in kgdb mode it will print the message <constant>KGDB or $3#33 for KDB</constant>. It is important - to note, that you have to type the sequence correctly in one pass. + to note that you have to type the sequence correctly in one pass. You cannot type a backspace or delete because kgdb will interpret that as part of the debug stream. <orderedlist>
@@ -526,7 +547,8 @@ <para><constant>$3#33</constant></para></listitem> <listitem><para>Change from kgdb to kdb with gdb</para> <para><constant>maintenance packet 3</constant></para> - <para>NOTE: Now you must kill gdb</para></listitem> + <para>NOTE: Now you must kill gdb. Typically you press control-z and + issue the command: kill -9 %</para></listitem> </orderedlist> </para> </sect2>
@@ -554,7 +576,7 @@ state of the kernel debugger. You should be using gdb for breakpoints and run control operations if you have gdb connected. The more useful commands to run are things like lsmod, dmesg, ps or - possibly some of the memory information. To see all the kdb + possibly some of the memory information commands. To see all the kdb commands you can run <constant>monitor help</constant>.</para> <para>Example: <informalexample><programlisting>
@@ -607,24 +629,26 @@ <para> The debug core is found in kernel/debugger/debug_core.c. It contains: <itemizedlist> - <listitem><para>A generic OS exception handler which includes sync'ing the processors into a stopped state on an multi cpu system.</para></listitem> + <listitem><para>A generic OS exception handler which includes + sync'ing the processors into a stopped state on an multi-CPU + system.</para></listitem> <listitem><para>The API to talk to the kgdb I/O drivers</para></listitem> - <listitem><para>The API to make calls to the arch specific kgdb implementation</para></listitem> + <listitem><para>The API to make calls to the arch-specific kgdb implementation</para></listitem> <listitem><para>The logic to perform safe memory reads and writes to memory while using the debugger</para></listitem> <listitem><para>A full implementation for software breakpoints unless overridden by the arch</para></listitem> <listitem><para>The API to invoke either the kdb or kgdb frontend to the debug core.</para></listitem> </itemizedlist> </para> </listitem> - <listitem><para>kgdb arch specific implementation</para> + <listitem><para>kgdb arch-specific implementation</para> <para> This implementation is generally found in arch/*/kernel/kgdb.c. As an example, arch/x86/kernel/kgdb.c contains the specifics to implement HW breakpoint as well as the initialization to dynamically register and unregister for the trap handlers on - this architecture. The arch specific portion implements: + this architecture. The arch-specific portion implements: <itemizedlist> - <listitem><para>contains an arch specific trap catcher which + <listitem><para>contains an arch-specific trap catcher which invokes kgdb_handle_exception() to start kgdb about doing its work</para></listitem> <listitem><para>translation to and from gdb specific packet format to pt_regs</para></listitem>
@@ -644,16 +668,18 @@ <listitem><para>kdb frontend</para> <para>The kdb debugger shell is broken down into a number of components. The kdb core is located in kernel/debug/kdb. There - are number of helper functions in some of the other kernel - components to make it possible for kdb to examine report + are a number of helper functions in some of the other kernel + components to make it possible for kdb to examine and report information about the kernel without taking locks that could cause a kernel deadlock. The kdb core contains implements the following functionality.</para> <itemizedlist> <listitem><para>A simple shell</para></listitem> <listitem><para>The kdb core command set</para></listitem> <listitem><para>A registration API to register additional kdb shell commands.</para> - <para>A good example of a self contained kdb module is the "ftdump" command for dumping the ftrace buffer. See: kernel/trace/trace_kdb.c</para></listitem> - <listitem><para>The implementation for kdb_printf() which emit messages directly to I/O drivers, bypassing the kernel log.</para></listitem> + <para>A good example of a self-contained kdb module is the "ftdump" command for dumping the ftrace buffer. See: kernel/trace/trace_kdb.c</para></listitem> + <listitem><para>The implementation for kdb_printf() which + emits messages directly to I/O drivers, bypassing the kernel + log.</para></listitem> <listitem><para>SW / HW breakpoint management for the kdb shell</para></listitem> </itemizedlist> </listitem>
@@ -661,7 +687,7 @@ <para> Each kgdb I/O driver has to provide an implementation for the following: <itemizedlist> - <listitem><para>configuration via builtin or module</para></listitem> + <listitem><para>configuration via built-in or module</para></listitem> <listitem><para>dynamic configuration and kgdb hook registration calls</para></listitem> <listitem><para>read and write character interface</para></listitem> <listitem><para>A cleanup handler for unconfiguring from the kgdb core</para></listitem>
@@ -726,15 +752,15 @@ underlying low level to the hardware driver having "polling hooks" which the to which the tty driver is attached. In the initial implementation of kgdboc it the serial_core was changed to expose a - low level uart hook for doing polled mode reading and writing of a + low level UART hook for doing polled mode reading and writing of a single character while in an atomic context. When kgdb makes an I/O request to the debugger, kgdboc invokes a call back in the serial - core which in turn uses the call back in the uart driver. It is - certainly possible to extend kgdboc to work with non-uart based + core which in turn uses the call back in the UART driver. It is + certainly possible to extend kgdboc to work with non-UART based consoles in the future. </para> <para> - When using kgdboc with a uart, the uart driver must implement two callbacks in the <constant>struct uart_ops</constant>. Example from drivers/8250.c:<programlisting> + When using kgdboc with a UART, the UART driver must implement two callbacks in the <constant>struct uart_ops</constant>. Example from drivers/8250.c:<programlisting> #ifdef CONFIG_CONSOLE_POLL .poll_get_char = serial8250_get_poll_char, .poll_put_char = serial8250_put_poll_char,
@@ -744,7 +770,7 @@ <constant>#ifdef CONFIG_CONSOLE_POLL</constant>, as shown above. Keep in mind that polling hooks have to be implemented in such a way that they can be called from an atomic context and have to restore - the state of the uart chip on return such that the system can return + the state of the UART chip on return such that the system can return to normal when the debugger detaches. You need to be very careful with any kind of lock you consider, because failing here is most going to mean pressing the reset button.
Documentation/kernel-parameters.txt +1 -2
@@ -1111,8 +1111,7 @@ keyboard and serial format: kbd,<serial_device>[,baud] kgdbwait [KGDB] Stop kernel execution and enter the - kernel debugger at the earliest opportunity if - kgdb was configured on as a boot argument. + kernel debugger at the earliest opportunity. kmac= [MIPS] korina ethernet MAC address. Configure the RouterBoard 532 series on-chip
Re: [Kgdb-bugreport] [PATCH 15/28] kgdb, docs: Update the kgdb docs to include kdb
Quoted 11 lines · Jason Wessel
Quoted 7 lines · Randy Dunlap
Quoted 3 lines · Jason Wessel
Update the kgdb docs to reflect the new directory structure and API.
Merge in the kdb shell information.
See comments/corrections inline below.
Thank very much for the comments. Would you like a credit in the manual?
not needed.
Quoted 10 lines
I merged in all your edits.
Here is the interdiff in case you were curious.
Thanks,
Jason.DocBook/kgdb.tmpl | 208 ++++++++++++++++++++++++++++---------------------- kernel-parameters.txt | 3 2 files changed, 118 insertions(+), 93 deletions(-)
thanks,
Signature · 1 line
~Randy
Jason Wessel
maintainerPATCH 16/28 kgdb: remove post_primary_code references
In reply to Jason WesselRemove all the references to the kgdb_post_primary_code. This function serves no useful purpose because you can obtain the same information from the "struct kgdb_state *ks" from with in the debugger, if for some reason you want the data.
Also remove the unintentional duplicate assignment for ks->ex_vector.
--- arch/x86/kernel/kgdb.c | 29 ----------------------------- include/linux/kgdb.h | 14 -------------- kernel/debug/debug_core.c | 8 -------- 3 files changed, 0 insertions(+), 51 deletions(-)
arch/x86/kernel/kgdb.c +0 -29
@@ -47,20 +47,8 @@#include <asm/debugreg.h> #include <asm/apicdef.h> #include <asm/system.h> -#include <asm/apic.h> -/* -* Put the error code here just in case the user cares: -*/ -static int gdb_x86errcode; - -/* -* Likewise, the vector number here (since GDB only gets the signal -* number through the usual means, and that's not very specific): -*/ -static int gdb_x86vector =-1 ; -/** * pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs * @gdb_regs: A pointer to hold the registers in the order GDB wants.
@@ -399,23 +387,6 @@ void kgdb_disable_hw_debug(struct pt_regs *regs) } } -/** -* kgdb_post_primary_code - Save error vector/code numbers. -* @regs: Original pt_regs. -* @e_vector: Original error vector. -* @err_code: Original error code. -* -* This is needed on architectures which support SMP and KGDB. -* This function is called after all the slave cpus have been put -* to a know spin state and the primary CPU has control over KGDB. -*/ -void kgdb_post_primary_code (struct pt_regs *regs,int e_vector,int err_code) -{ -/* primary processor is completely in the debugger */ - gdb_x86vector = e_vector; - gdb_x86errcode = err_code; -} -#ifdef CONFIG_SMP /** * kgdb_roundup_cpus - Get other CPUs into a holding pattern
include/linux/kgdb.h +0 -14
@@ -36,20 +36,6 @@ struct pt_regs;extern int kgdb_skipexception (int exception,struct pt_regs *regs);/** -* kgdb_post_primary_code - (optional) Save error vector/code numbers. -* @regs: Original pt_regs. -* @e_vector: Original error vector. -* @err_code: Original error code. -* -* This is usually needed on architectures which support SMP and -* KGDB. This function is called after all the secondary cpus have -* been put to a know spin state and the primary CPU has control over -* KGDB. -*/ -extern void kgdb_post_primary_code (struct pt_regs *regs,int e_vector, -int err_code); - -/** * kgdb_disable_hw_debug - (optional) Disable hardware debugging hook * @regs: Current &struct pt_regs. *
kernel/debug/debug_core.c +0 -8
@@ -203,12 +203,6 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs)return 0 ; } -void __weak -kgdb_post_primary_code (struct pt_regs *regs,int e_vector,int err_code) -{ -return ; -} -/** * kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb. * @regs: Current &struct pt_regs.
@@ -586,7 +580,6 @@ return_normal:* At this point the primary processor is completely * in the debugger and all secondary CPUs are quiescent */ -kgdb_post_primary_code (ks->linux_regs, ks->ex_vector, ks->err_code);dbg_deactivate_sw_breakpoints (); kgdb_single_step =0 ; kgdb_contthread = current;
@@ -670,7 +663,6 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) ks->cpu =raw_smp_processor_id (); ks->ex_vector = evector; ks->signo = signo; - ks->ex_vector = evector; ks->err_code = ecode; ks->kgdb_usethreadid =0 ; ks->linux_regs = regs;
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 17/28 x86,kgdb: Add low level debug hook
In reply to Jason WesselThe only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a triple fault is to have a low level "first opportunity handler" in the int3 exception handler.
Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called KGDB_LOW_LEVEL_TRAP.
--- arch/x86/include/asm/kgdb.h | 3 +++ arch/x86/kernel/kgdb.c | 22 +++++++++++++++++++++- arch/x86/kernel/traps.c | 6 ++++++ include/linux/kgdb.h | 1 + kernel/debug/debug_core.c | 2 +- lib/Kconfig.kgdb | 9 +++++++++ 6 files changed, 41 insertions(+), 2 deletions(-)
arch/x86/include/asm/kgdb.h +3 -0
@@ -76,4 +76,7 @@ static inline void arch_kgdb_breakpoint(void)#define BREAK_INSTR_SIZE 1#define CACHE_FLUSH_IS_SAFE 1 +extern int kgdb_ll_trap (int cmd,const char *str, +struct pt_regs *regs,long err,int trap,int sig); +#endif /* _ASM_X86_KGDB_H */
arch/x86/kernel/kgdb.c +21 -1
@@ -538,7 +538,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)return NOTIFY_DONE ; } -if (kgdb_handle_exception (args->trapnr, args->signr, args->err, regs)) +if (kgdb_handle_exception (args->trapnr, args->signr, cmd, regs))return NOTIFY_DONE ;/* Must touch watchdog before return to normal operation */
@@ -546,6 +546,26 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)return NOTIFY_STOP ; } +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +int kgdb_ll_trap (int cmd,const char *str, +struct pt_regs *regs,long err,int trap,int sig) +{ +struct die_args args = { + .regs = regs, + .str = str, + .err = err, + .trapnr = trap, + .signr = sig, + + }; + +if (!kgdb_io_module_registered) +return NOTIFY_DONE ; + +return __kgdb_notify (&args, cmd); +} +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ +static int kgdb_notify (struct notifier_block *self,unsigned long cmd,void *ptr) {
arch/x86/kernel/traps.c +6 -0
@@ -15,6 +15,7 @@#include <linux/kprobes.h> #include <linux/uaccess.h> #include <linux/kdebug.h> +#include <linux/kgdb.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/ptrace.h>
@@ -460,6 +461,11 @@ void restart_nmi(void)/* May run on IST stack. */ dotraplinkage void __kprobes do_int3(struct pt_regs *regs, long error_code) { +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +if (kgdb_ll_trap (DIE_INT3 ,"int3" , regs, error_code,3 ,SIGTRAP ) + ==NOTIFY_STOP ) +return ; +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ #ifdef CONFIG_KPROBES if (notify_die (DIE_INT3 ,"int3" , regs, error_code,3 ,SIGTRAP ) ==NOTIFY_STOP )
include/linux/kgdb.h +1 -0
@@ -60,6 +60,7 @@ struct uart_port;void kgdb_breakpoint (void );extern int kgdb_connected; +extern int kgdb_io_module_registered;extern atomic_t kgdb_setting_breakpoint;extern atomic_t kgdb_cpu_doing_single_step;
kernel/debug/debug_core.c +1 -1
@@ -66,7 +66,7 @@ int kgdb_connected;EXPORT_SYMBOL_GPL (kgdb_connected);/* All the KGDB handlers are installed */ -static int kgdb_io_module_registered; +int kgdb_io_module_registered;/* Guard for recursive entry */ static int exception_level;
lib/Kconfig.kgdb +9 -0
@@ -57,6 +57,15 @@ config KGDB_TESTS_BOOT_STRING information about other strings you could use beyond the default of V1F100. +config KGDB_LOW_LEVEL_TRAP + bool "KGDB: Allow debugging with traps in notifiers" + depends on X86 + default n + help + This will add an extra call back to kgdb for the breakpoint + exception handler on which will will allow kgdb to step + through a notify handler. + config KGDB_KDB bool "KGDB_KDB: include kdb frontend for kgdb" default n
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 18/28 powerpc,kgdb: Introduce low level trap catching
In reply to Jason WesselThe only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to have a low level "first opportunity handler" low level program_check_exception() handler.
The other change here is to make sure that kgdb_handle_exception() is called with correct parameters when catching an oops, because kdb needs to know if the entry was an oops, single step, or breakpoint exception.
--- arch/powerpc/kernel/kgdb.c | 7 +++++-- arch/powerpc/kernel/traps.c | 7 +++++++ lib/Kconfig.kgdb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-)
arch/powerpc/kernel/kgdb.c +5 -2
@@ -20,6 +20,7 @@#include <linux/smp.h> #include <linux/signal.h> #include <linux/ptrace.h> +#include <linux/kdebug.h> #include <asm/current.h> #include <asm/processor.h> #include <asm/machdep.h>
@@ -115,7 +116,9 @@ void kgdb_roundup_cpus(unsigned long flags)/* KGDB functions to use existing PowerPC64 hooks. */ static int kgdb_debugger (struct pt_regs *regs) { -return kgdb_handle_exception (0 ,computeSignal (TRAP (regs)),0 , regs); +if (kgdb_handle_exception (1 ,computeSignal (TRAP (regs)),DIE_OOPS , regs)) +return 0 ; +return 1 ; }static int kgdb_handle_breakpoint (struct pt_regs *regs)
@@ -123,7 +126,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)if (user_mode (regs))return 0 ; -if (kgdb_handle_exception (0 ,SIGTRAP ,0 , regs) !=0 ) +if (kgdb_handle_exception (1 ,SIGTRAP ,0 , regs) !=0 )return 0 ;if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
arch/powerpc/kernel/traps.c +7 -0
@@ -809,12 +809,19 @@ void __kprobes program_check_exception(struct pt_regs *regs)return ; }if (reason &REASON_TRAP ) { + +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +if (debugger_bpt (regs)) +return ; +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ /* trap exception */ if (notify_die (DIE_BPT ,"breakpoint" , regs,5 ,5 ,SIGTRAP ) ==NOTIFY_STOP )return ; +#ifndef CONFIG_KGDB_LOW_LEVEL_TRAP if (debugger_bpt (regs))return ; +#endif /* ! CONFIG_KGDB_LOW_LEVEL_TRAP */ if (!(regs->msr &MSR_PR ) &&/* not user-mode */ report_bug (regs->nip, regs) ==BUG_TRAP_TYPE_WARN ) {
lib/Kconfig.kgdb +1 -1
@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING config KGDB_LOW_LEVEL_TRAP bool "KGDB: Allow debugging with traps in notifiers" - depends on X86 + depends on X86 || PPC default n help This will add an extra call back to kgdb for the breakpoint
Signature · 1 line
1.6.4.rc1
Re: [PATCH 18/28] powerpc,kgdb: Introduce low level trap catching
arch/powerpc/kernel/kgdb.c void kgdb_roundup_cpus(unsigned long flags) · line 122
Quoted 9 lines · Jason Wessel
arch/powerpc/kernel/kgdb.c +3
-1@@ -115,7 +116,9 @@ void kgdb_roundup_cpus(unsigned long flags)/* KGDB functions to use existing PowerPC64 hooks. */ static int kgdb_debugger (struct pt_regs *regs) { -return kgdb_handle_exception (0 ,computeSignal (TRAP (regs)),0 , regs); +if (kgdb_handle_exception (1 ,computeSignal (TRAP (regs)),DIE_OOPS , regs)) +return 0 ; +return 1 ; }
I'm no fan of logic inversions like that but I suppose you are trying to fit into existing hooks. However, I'd rather then do:
return !kgdb...
Quoted 39 lines
arch/powerpc/kernel/kgdb.c +1
-1static int kgdb_handle_breakpoint (struct pt_regs *regs)@@ -123,7 +126,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)if (user_mode (regs))return 0 ; -if (kgdb_handle_exception (0 ,SIGTRAP ,0 , regs) !=0 ) +if (kgdb_handle_exception (1 ,SIGTRAP ,0 , regs) !=0 )return 0 ;if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))arch/powerpc/kernel/traps.c +7
-0@@ -809,12 +809,19 @@ void __kprobes program_check_exception(struct pt_regs *regs)return ; }if (reason &REASON_TRAP ) { + +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +if (debugger_bpt (regs)) +return ; +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ /* trap exception */ if (notify_die (DIE_BPT ,"breakpoint" , regs,5 ,5 ,SIGTRAP ) ==NOTIFY_STOP )return ; +#ifndef CONFIG_KGDB_LOW_LEVEL_TRAP if (debugger_bpt (regs))return ; +#endif /* ! CONFIG_KGDB_LOW_LEVEL_TRAP */ if (!(regs->msr &MSR_PR ) &&/* not user-mode */ report_bug (regs->nip, regs) ==BUG_TRAP_TYPE_WARN ) {lib/Kconfig.kgdb +0
-0
lib/Kconfig.kgdb config KGDB_TESTS_BOOT_STRING · line 65
Quoted 8 lines
lib/Kconfig.kgdb +1
-1@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING config KGDB_LOW_LEVEL_TRAP bool "KGDB: Allow debugging with traps in notifiers" - depends on X86 + depends on X86 || PPC default n help This will add an extra call back to kgdb for the breakpoint
No firm objection, but it -is- a bit ugly... Should we just unconditionally move the debugger_bpt() early on with a comment about why we do so ? Is there any drawback you can think of ?
Cheers,
Ben.
Jason Wessel
maintainerRe: [PATCH 18/28] powerpc,kgdb: Introduce low level trap catching
Quoted 17 lines · Benjamin Herrenschmidt
Review void kgdb_roundup_cpus(unsigned long flags) · line 123
Quoted 10 lines · Jason Wessel
(quoted diff) +3
-1@@ -115,7 +116,9 @@ void kgdb_roundup_cpus(unsigned long flags) /* KGDB functions to use existing PowerPC64 hooks. */ static int kgdb_debugger(struct pt_regs *regs) { - return kgdb_handle_exception(0, computeSignal(TRAP(regs)), 0, regs); + if (kgdb_handle_exception(1, computeSignal(TRAP(regs)), DIE_OOPS, regs)) + return 0; + return 1; }I'm no fan of logic inversions like that but I suppose you are trying to fit into existing hooks. However, I'd rather then do:
Quoted 2 lines
return !kgdb...
I agree and I made the change to return !kgdb...
Quoted 19 lines
Quoted 19 lines
(quoted diff) +8
-0+++ b/arch/powerpc/kernel/traps.c@@ -809,12 +809,19 @@ void __kprobes program_check_exception(struct pt_regs *regs) return; } if (reason & REASON_TRAP) { + +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP + if (debugger_bpt(regs)) + return; +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ /* trap exception */ if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP) == NOTIFY_STOP) return; +#ifndef CONFIG_KGDB_LOW_LEVEL_TRAP if (debugger_bpt(regs)) return; +#endif /* ! CONFIG_KGDB_LOW_LEVEL_TRAP */
Quoted 9 lines
Review void __kprobes program_check_exception(struct pt_regs *regs) · line 827
Quoted 4 lines
(quoted diff) +0
-0if (!(regs->msr & MSR_PR) && /* not user-mode */ report_bug(regs->nip, regs) == BUG_TRAP_TYPE_WARN) {No firm objection, but it -is- a bit ugly... Should we just unconditionally move the
debugger_bpt()early on with a comment about why we do so ? Is there any drawback you can think of ?
I took a peek at xmon, and it suffers from the same problem where you can place a breakpoint in any part of rcu_lock, notify_die, or atomic_notifier_call_chain and meet with recursive faults. I also checked that xmon appears to correctly return so as to continue if the exception was not intended for xmon.
The reason I had not just moved the code block previously is that I was not looking to break anything such as xmon, which is the the only other user of this function.
I'll add your ack, if you agree with the new version of the patch.
Thanks,
Jason.
From: Jason Wessel <[email protected]>
Subject: [PATCH] powerpc,kgdb: Introduce low level trap catching
The only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to allow the kernel debugger to handle the exception first in program_check_exception().
The other change here is to make sure that kgdb_handle_exception() is called with correct parameters when catching an oops, because kdb needs to know if the entry was an oops, single step, or breakpoint exception.
[[email protected]: move debugger_bpt instead of #ifdef]
--- arch/powerpc/kernel/kgdb.c | 6 ++++-- arch/powerpc/kernel/traps.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
arch/powerpc/kernel/kgdb.c +4 -2
@@ -20,6 +20,7 @@#include <linux/smp.h> #include <linux/signal.h> #include <linux/ptrace.h> +#include <linux/kdebug.h> #include <asm/current.h> #include <asm/processor.h> #include <asm/machdep.h>
@@ -115,7 +116,8 @@ void kgdb_roundup_cpus(unsigned long fla/* KGDB functions to use existing PowerPC64 hooks. */ static int kgdb_debugger (struct pt_regs *regs) { -return kgdb_handle_exception (0 ,computeSignal (TRAP (regs)),0 , regs); +return !kgdb_handle_exception (1 ,computeSignal (TRAP (regs)), +DIE_OOPS , regs); }static int kgdb_handle_breakpoint (struct pt_regs *regs)
@@ -123,7 +125,7 @@ static int kgdb_handle_breakpoint(structif (user_mode (regs))return 0 ; -if (kgdb_handle_exception (0 ,SIGTRAP ,0 , regs) !=0 ) +if (kgdb_handle_exception (1 ,SIGTRAP ,0 , regs) !=0 )return 0 ;if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
arch/powerpc/kernel/traps.c +4 -2
@@ -809,12 +809,14 @@ void __kprobes program_check_exception(sreturn ; }if (reason &REASON_TRAP ) { +/* Debugger is first in line to stop recursive faults in +* rcu_lock, notify_die, or atomic_notifier_call_chain */ +if (debugger_bpt (regs)) +return ;/* trap exception */ if (notify_die (DIE_BPT ,"breakpoint" , regs,5 ,5 ,SIGTRAP ) ==NOTIFY_STOP )return ; -if (debugger_bpt (regs)) -return ;if (!(regs->msr &MSR_PR ) &&/* not user-mode */ report_bug (regs->nip, regs) ==BUG_TRAP_TYPE_WARN ) {
Benjamin Herrenschmidt
Acked-byRe: [PATCH 18/28] powerpc,kgdb: Introduce low level trap catching
Quoted 11 lines · Jason Wessel
I took a peek at xmon, and it suffers from the same problem where you can place a breakpoint in any part of
rcu_lock,notify_die, oratomic_notifier_call_chainand meet with recursive faults. I also checked that xmon appears to correctly return so as to continue if the exception was not intended for xmon.The reason I had not just moved the code block previously is that I was not looking to break anything such as xmon, which is the the only other user of this function.
I'll add your ack, if you agree with the new version of the patch.
Almost, just stick a blank line here:
+ /* Debugger is first in line to stop recursive faults in
+ * rcu_lock, notify_die, or atomic_notifier_call_chain */
+ if (debugger_bpt(regs))
+ return;
---->
/* trap exception */
if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
== NOTIFY_STOP)
return;Please :-)
Cheers,
Ben.
Jason Wessel
maintainerRe: [Kgdb-bugreport] [PATCH 18/28] powerpc,kgdb: Introduce low level trap catching
Quoted 12 lines · Benjamin Herrenschmidt
Almost, just stick a blank line here:
arch/powerpc/kernel/traps.c +4
-1+/* Debugger is first in line to stop recursive faults in +* rcu_lock, notify_die, or atomic_notifier_call_chain */ +if (debugger_bpt (regs)) +return ; ---->/* trap exception */ if (notify_die (DIE_BPT ,"breakpoint" , regs,5 ,5 ,SIGTRAP ) ==NOTIFY_STOP )return ;
Quoted 3 lines
Please :-)
Done and pushed to kgdb-next.
Thanks,
Jason.
Jason Wessel
maintainerPATCH 19/28 mips,kgdb: kdb low level trap catch and stack trace
In reply to Jason WesselThe only way the debugger can handle a trap in inside rcu_lock, notify_die, or atomic_notifier_call_chain without a recursive fault is to have a low level "first opportunity handler" do_trap_or_bp() handler.
Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called KGDB_LOW_LEVEL_TRAP.
Also added was a die notification for oops such that kdb can catch an oops for analysis.
There appeared to be no obvious way to pass the struct pt_regs from the original exception back to the stack back tracer, so a special case was added to show_stack() for when kdb is active because you generally desire to generally look at the back trace of the original exception.
--- arch/mips/include/asm/kgdb.h | 2 ++ arch/mips/kernel/kgdb.c | 22 +++++++++++++++++++++- arch/mips/kernel/traps.c | 13 +++++++++++++ include/linux/kdb.h | 3 +++ kernel/debug/kdb/kdb_private.h | 1 - lib/Kconfig.kgdb | 2 +- 6 files changed, 40 insertions(+), 3 deletions(-)
arch/mips/include/asm/kgdb.h +2 -0
@@ -38,6 +38,8 @@ extern int kgdb_early_setup;extern void *saved_vectors[32 ];extern void handle_exception (struct pt_regs *regs);extern void breakinst (void ); +extern int kgdb_ll_trap (int cmd,const char *str, +struct pt_regs *regs,long err,int trap,int sig);#endif /* __KERNEL__ */
arch/mips/kernel/kgdb.c +21 -1
@@ -203,7 +203,7 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,if (atomic_read (&kgdb_active) !=-1 )kgdb_nmicallback (smp_processor_id (), regs); -if (kgdb_handle_exception (trap,compute_signal (trap),0 , regs)) +if (kgdb_handle_exception (trap,compute_signal (trap), cmd, regs))return NOTIFY_DONE ;if (atomic_read (&kgdb_setting_breakpoint))
@@ -217,6 +217,26 @@ static int kgdb_mips_notify(struct notifier_block *self, unsigned long cmd,return NOTIFY_STOP ; } +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +int kgdb_ll_trap (int cmd,const char *str, +struct pt_regs *regs,long err,int trap,int sig) +{ +struct die_args args = { + .regs = regs, + .str = str, + .err = err, + .trapnr = trap, + .signr = sig, + + }; + +if (!kgdb_io_module_registered) +return NOTIFY_DONE ; + +return kgdb_mips_notify (NULL , cmd, &args); +} +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ +static struct notifier_block kgdb_notifier = { .notifier_call = kgdb_mips_notify, };
arch/mips/kernel/traps.c +13 -0
@@ -26,6 +26,7 @@#include <linux/kgdb.h> #include <linux/kdebug.h> #include <linux/notifier.h> +#include <linux/kdb.h> #include <asm/bootinfo.h> #include <asm/branch.h>
@@ -184,6 +185,11 @@ void show_stack(struct task_struct *task, unsigned long *sp) regs.regs[29 ] = task->thread.reg29; regs.regs[31 ] =0 ; regs.cp0_epc = task->thread.reg31; +#ifdef CONFIG_KGDB_KDB + }else if (atomic_read (&kgdb_active) !=-1 && + kdb_current_regs) { +memcpy (®s, kdb_current_regs,sizeof (regs)); +#endif /* CONFIG_KGDB_KDB */ }else {prepare_frametrace (®s); }
@@ -358,6 +364,8 @@ void __noreturn die(const char * str, const struct pt_regs * regs)unsigned long dvpret =dvpe ();#endif /* CONFIG_MIPS_MT_SMTC */ +notify_die (DIE_OOPS , str, (struct pt_regs *)regs,SIGSEGV ,0 ,0 ); +console_verbose ();spin_lock_irq (&die_lock);bust_spinlocks (1 );
@@ -698,6 +706,11 @@ static void do_trap_or_bp(struct pt_regs *regs, unsigned int code,siginfo_t info;char b[40 ]; +#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP +if (kgdb_ll_trap (DIE_TRAP , str, regs, code,0 ,0 ) ==NOTIFY_STOP ) +return ; +#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */ +if (notify_die (DIE_TRAP , str, regs, code,0 ,0 ) ==NOTIFY_STOP )return ;
include/linux/kdb.h +3 -0
@@ -99,6 +99,9 @@ int kdb_process_cpu(const struct task_struct *p) return cpu; } +/* kdb access to register set for stack dumping */ +extern struct pt_regs *kdb_current_regs; +#else /* ! CONFIG_KGDB_KDB */ #define kdb_printf (...)#define kdb_init (x)
kernel/debug/kdb/kdb_private.h +0 -1
@@ -288,7 +288,6 @@ extern void debug_kusage(void);extern void kdb_set_current_task (struct task_struct *);extern struct task_struct *kdb_current_task; -extern struct pt_regs *kdb_current_regs;#ifdef CONFIG_MODULES extern struct list_head *kdb_modules;#endif /* CONFIG_MODULES */
lib/Kconfig.kgdb +1 -1
@@ -59,7 +59,7 @@ config KGDB_TESTS_BOOT_STRING config KGDB_LOW_LEVEL_TRAP bool "KGDB: Allow debugging with traps in notifiers" - depends on X86 || PPC + depends on X86 || PPC || MIPS default n help This will add an extra call back to kgdb for the breakpoint
Signature · 1 line
1.6.4.rc1
Re: [PATCH 19/28] mips,kgdb: kdb low level trap catch and stack trace
Quoted 11 lines · Jason Wessel
The only way the debugger can handle a trap in inside
rcu_lock,notify_die, oratomic_notifier_call_chainwithout a recursive fault is to have a low level "first opportunity handler"do_trap_or_bp()handler.Generally this will be something the vast majority of folks will not need, but for those who need it, it is added as a kernel .config option called
KGDB_LOW_LEVEL_TRAP.Also added was a die notification for oops such that kdb can catch an oops for analysis.
Quoted 8 lines
There appeared to be no obvious way to pass the struct
pt_regsfrom the original exception back to the stack back tracer, so a special case was added toshow_stack()for when kdb is active because you generally desire to generally look at the back trace of the original exception.CC Ralf Baechle <[email protected]>Signed-off-by Jason Wessel <[email protected]>
Ralf
Jason Wessel
maintainerPATCH 20/28 kgdb: Add the ability to schedule a breakpoint via a tasklet
In reply to Jason WesselSome kgdb I/O modules require the ability to create a breakpoint tasklet, such as kgdboc and external modules such as kgdboe. The breakpoint tasklet is used as an asynchronous entry point into the debugger which will have a different function scope than the current execution path where it might not be safe to have an inline breakpoint. This is true of some of the kgdb I/O drivers which share code with kgdb and rest of the kernel users.
--- include/linux/kgdb.h | 1 + kernel/debug/debug_core.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 0 deletions(-)
include/linux/kgdb.h +1 -0
@@ -271,6 +271,7 @@ extern int kgdb_mem2hex(char *mem, char *buf, int count);extern int kgdb_hex2mem (char *buf,char *mem,int count);extern int kgdb_isremovedbreak (unsigned long addr); +extern void kgdb_schedule_breakpoint (void ); extern int kgdb_handle_exception(int ex_vector, int signo, int err_code,
kernel/debug/debug_core.c +26 -0
@@ -114,6 +114,7 @@ EXPORT_SYMBOL_GPL(kgdb_active);*/ static atomic_t passive_cpu_wait[NR_CPUS ];static atomic_t cpu_in_kgdb[NR_CPUS ]; +static atomic_t kgdb_break_tasklet_var;atomic_t kgdb_setting_breakpoint;struct task_struct *kgdb_usethread;
@@ -781,6 +782,31 @@ static void kgdb_unregister_callbacks(void) } } +/* +* There are times a tasklet needs to be used vs a compiled in +* break point so as to cause an exception outside a kgdb I/O module, +* such as is the case with kgdboe, where calling a breakpoint in the +* I/O driver itself would be fatal. +*/ +static void kgdb_tasklet_bpt (unsigned long ing) +{ +kgdb_breakpoint (); +atomic_set (&kgdb_break_tasklet_var,0 ); +} + +static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0); + +void kgdb_schedule_breakpoint (void ) +{ +if (atomic_read (&kgdb_break_tasklet_var) || +atomic_read (&kgdb_active) !=-1 || +atomic_read (&kgdb_setting_breakpoint)) +return ; +atomic_inc (&kgdb_break_tasklet_var); +tasklet_schedule (&kgdb_tasklet_breakpoint); +} +EXPORT_SYMBOL_GPL (kgdb_schedule_breakpoint); +static void kgdb_initial_breakpoint (void ) { kgdb_break_asap =0 ;
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 21/28 kgdboc,kdb: Allow kdb to work on a non open console port
In reply to Jason WesselIf kdb is open on a serial port that is not actually a console make sure to call the poll routines to emit and receive characters.
--- drivers/serial/kgdboc.c | 14 ++++++++++++++ include/linux/kgdb.h | 3 +++ kernel/debug/kdb/kdb_io.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 0 deletions(-)
drivers/serial/kgdboc.c +14 -0
@@ -16,6 +16,7 @@#include <linux/kgdb.h> #include <linux/kdb.h> #include <linux/tty.h> +#include <linux/console.h> #define MAX_CONFIG_LEN 40
@@ -93,12 +94,14 @@ static int configure_kgdboc(void)int tty_line =0 ;int err;char *cptr = config; +struct console *cons; err =kgdboc_option_setup (config);if (err || !strlen (config) ||isspace (config[0 ])) goto noconfig; err = -ENODEV ; + kgdboc_io_ops.is_console =0 ; kgdb_tty_driver =NULL ;if (kgdboc_register_kbd (&cptr))
@@ -108,6 +111,17 @@ static int configure_kgdboc(void)if (!p) goto noconfig; + cons = console_drivers; +while (cons) { +int idx; +if (cons->device && cons->device (cons, &idx) == p && + idx == tty_line) { + kgdboc_io_ops.is_console =1 ; +break ; + } + cons = cons->next; + } + kgdb_tty_driver = p; kgdb_tty_line = tty_line;
include/linux/kgdb.h +3 -0
@@ -247,6 +247,8 @@ struct kgdb_arch {* the I/O driver. * @post_exception: Pointer to a function that will do any cleanup work * for the I/O driver. +* @is_console: 1 if the end device is a console 0 if the I/O device is +* not a console */ struct kgdb_io {const char *name;
@@ -256,6 +258,7 @@ struct kgdb_io {int (*init) (void );void (*pre_exception) (void );void (*post_exception) (void ); +int is_console; };extern struct kgdb_arch arch_kgdb_ops;
kernel/debug/kdb/kdb_io.c +16 -0
@@ -673,6 +673,14 @@ kdb_printit:if (!dbg_kdb_mode && kgdb_connected) {gdbstub_msg_write (kdb_buffer, retlen); }else { +if (!dbg_io_ops->is_console) { + len =strlen (kdb_buffer); + cp = kdb_buffer; +while (len--) { + dbg_io_ops->write_char (*cp); + cp++; + } + }while (c) { c->write (c, kdb_buffer, retlen);touch_nmi_watchdog ();
@@ -719,6 +727,14 @@ kdb_printit:kdb_input_flush (); c = console_drivers; +if (!dbg_io_ops->is_console) { + len =strlen (moreprompt); + cp = moreprompt; +while (len--) { + dbg_io_ops->write_char (*cp); + cp++; + } + }while (c) { c->write (c, moreprompt,strlen (moreprompt));touch_nmi_watchdog ();
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 22/28 printk,kdb: capture printk() when in kdb shell
In reply to Jason WesselCertain calls from the kdb shell will call out to printk(), and any of these calls should get vectored back to the kdb_printf() so that the kdb pager and processing can be used, as well as to properly channel I/O to the polled I/O devices.
--- include/linux/kdb.h | 3 +++ kernel/debug/kdb/kdb_bt.c | 2 ++ kernel/debug/kdb/kdb_io.c | 24 ++++++++++++++++++++---- kernel/debug/kdb/kdb_main.c | 4 ++++ kernel/printk.c | 9 +++++++++ 5 files changed, 38 insertions(+), 4 deletions(-)
include/linux/kdb.h +3 -0
@@ -78,6 +78,9 @@ typedef enum {KDB_REASON_SSTEP ,/* Single Step trap. - regs valid */ } kdb_reason_t; +extern int kdb_trap_printk; +extern int vkdb_printf (const char *fmt,va_list args) + __attribute__ ((format (printf,1 ,0 )));extern int kdb_printf (const char *, ...) __attribute__ ((format (printf,1 ,2 )));typedef int (*kdb_printf_t )(const char *, ...)
kernel/debug/kdb/kdb_bt.c +2 -0
@@ -23,6 +23,7 @@ static void kdb_show_stack(struct task_struct *p, void *addr) {int old_lvl = console_loglevel; console_loglevel =15 ; + kdb_trap_printk++;kdb_set_current_task (p);if (addr) {show_stack ((struct task_struct *)p, addr);
@@ -36,6 +37,7 @@ static void kdb_show_stack(struct task_struct *p, void *addr)show_stack (p,NULL ); } console_loglevel = old_lvl; + kdb_trap_printk--; }/*
kernel/debug/kdb/kdb_io.c +20 -4
@@ -29,6 +29,7 @@#define CMD_BUFLEN 256char kdb_prompt_str[CMD_BUFLEN ]; +int kdb_trap_printk;static void kgdb_transition_check (char *buffer) {
@@ -533,12 +534,12 @@ static int kdb_search_string(char *searched, char *searchfor)return 0 ; } -int kdb_printf (const char *fmt, ...) +int vkdb_printf (const char *fmt,va_list ap) { -va_list ap;int diag;int linecount;int logging, saved_loglevel =0 ; +int saved_trap_printk;int got_printf_lock =0 ;int retlen =0 ;int fnd, len;
@@ -549,6 +550,9 @@ int kdb_printf(const char *fmt, ...)unsigned long uninitialized_var (flags );preempt_disable (); + saved_trap_printk = kdb_trap_printk; + kdb_trap_printk =0 ; +/* Serialize kdb_printf if multiple cpus try to write at once. * But if any cpu goes recursive in kdb, just print the output, * even if it is interleaved with any other text.
@@ -575,9 +579,7 @@ int kdb_printf(const char *fmt, ...) next_avail = kdb_buffer; size_avail =sizeof (kdb_buffer); } -va_start (ap, fmt);vsnprintf (next_avail, size_avail, fmt, ap); -va_end (ap);/* * If kdb_parse() found that the command was cmd xxx | grep yyy
@@ -805,6 +807,20 @@ kdb_print_out: }else {__release (kdb_printf_lock); } + kdb_trap_printk = saved_trap_printk;preempt_enable ();return retlen; } + +int kdb_printf (const char *fmt, ...) +{ +va_list ap; +int r; + +va_start (ap, fmt); + r =vkdb_printf (fmt, ap); +va_end (ap); + +return r; +} +
kernel/debug/kdb/kdb_main.c +4 -0
@@ -1056,7 +1056,9 @@ static void kdb_dumpregs(struct pt_regs *regs) {int old_lvl = console_loglevel; console_loglevel =15 ; + kdb_trap_printk++;show_regs (regs); + kdb_trap_printk--;kdb_printf ("\n" ); console_loglevel = old_lvl; }
@@ -1823,7 +1825,9 @@ static int kdb_sr(int argc, const char **argv) __sysrq_enabled =1 ; } + kdb_trap_printk++;handle_sysrq (*argv[1 ],NULL ); + kdb_trap_printk--;return 0 ; }
kernel/printk.c +9 -0
@@ -33,6 +33,7 @@#include <linux/bootmem.h> #include <linux/syscalls.h> #include <linux/kexec.h> +#include <linux/kdb.h> #include <linux/ratelimit.h> #include <linux/kmsg_dump.h>
@@ -609,6 +610,14 @@ asmlinkage int printk(const char *fmt, ...)va_list args;int r; +#ifdef CONFIG_KGDB_KDB +if (unlikely (kdb_trap_printk)) { +va_start (args, fmt); + r =vkdb_printf (fmt, args); +va_end (args); +return r; + } +#endif va_start (args, fmt); r =vprintk (fmt, args);va_end (args);
Signature · 1 line
1.6.4.rc1
Andrew Morton
maintainerRe: [PATCH 22/28] printk,kdb: capture printk() when in kdb shell
Quoted 5 lines · On Fri, 12 Feb 2010 16:35:37 -0600 Jason Wessel <[email protected]>…
(quoted diff) +1
-0@@ -609,6 +610,14 @@ asmlinkage int printk(const char *fmt, ...) va_list args; int r; +#ifdef CONFIG_KGDB_KDB
Review asmlinkage int printk(const char *fmt, ...) · line 623
Quoted 10 lines
(quoted diff) +7
-0+ if (unlikely(kdb_trap_printk)) { + va_start(args, fmt); + r = vkdb_printf(fmt, args); + va_end(args); + return r; + } +#endif va_start(args, fmt); r = vprintk(fmt, args); va_end(args);
this?
kernel/printk.c renamed from kernel/printk.c~a +4 -0
@@ -594,7 +594,11 @@ asmlinkage int printk(const char *fmt, .int r;va_start (args, fmt); +#ifdef CONFIG_KGDB_KDB + r =vkdb_printf (fmt, args); +#else r =vprintk (fmt, args); +#endif va_end (args);return r;
_
Jason Wessel
maintainerRe: [PATCH 22/28] printk,kdb: capture printk() when in kdb shell
Quoted 36 lines · Andrew Morton
Quoted 6 lines · On Fri, 12 Feb 2010 16:35:37 -0600 Jason Wessel <[email protected]>…
(quoted diff) +1
-0@@ -609,6 +610,14 @@ asmlinkage int printk(const char *fmt, ...) va_list args; int r; +#ifdef CONFIG_KGDB_KDBReview asmlinkage int printk(const char *fmt, ...) · line 623
Quoted 10 lines
(quoted diff) +7
-0+ if (unlikely(kdb_trap_printk)) { + va_start(args, fmt); + r = vkdb_printf(fmt, args); + va_end(args); + return r; + } +#endif va_start(args, fmt); r = vprintk(fmt, args); va_end(args);this?
kernel/printk.c renamed from kernel/printk.c~a +4
-0@@ -594,7 +594,11 @@ asmlinkage int printk(const char *fmt, .int r;va_start (args, fmt); +#ifdef CONFIG_KGDB_KDB + r =vkdb_printf (fmt, args); +#else r =vprintk (fmt, args); +#endif va_end (args);return r;
Quoted 2 lines
_
If you feel that would be cleaner, I can make that change, but I would also have to call vprintk() from vkdb_printf when ever kdb_trap_printk is not set. Do I understand your recommendation correctly?
The only time the kdb_trap_printk is ever set comes when we are inside the kernel debug shell, and do something like "bt". It serves the purpose of letting folks run the stack dumper and a few other functions. We want to trap printk's in this instance because we don't want them in the log them and also for the case when your debug connection is not actually a system log console, or if you run the command via gdb (example is "monitor bt").
Thanks,
Jason.
Andrew Morton
maintainerRe: [PATCH 22/28] printk,kdb: capture printk() when in kdb shell
Quoted 36 lines · On Fri, 12 Feb 2010 17:20:22 -0600 Jason Wessel <[email protected]>…
Quoted 35 lines · Andrew Morton
Quoted 6 lines · On Fri, 12 Feb 2010 16:35:37 -0600 Jason Wessel <[email protected]>…
(quoted diff) +1
-0@@ -609,6 +610,14 @@ asmlinkage int printk(const char *fmt, ...) va_list args; int r; +#ifdef CONFIG_KGDB_KDBReview asmlinkage int printk(const char *fmt, ...) · line 623
Quoted 10 lines
(quoted diff) +7
-0+ if (unlikely(kdb_trap_printk)) { + va_start(args, fmt); + r = vkdb_printf(fmt, args); + va_end(args); + return r; + } +#endif va_start(args, fmt); r = vprintk(fmt, args); va_end(args);this?
kernel/printk.c renamed from kernel/printk.c~a +4
-0@@ -594,7 +594,11 @@ asmlinkage int printk(const char *fmt, .int r;va_start (args, fmt); +#ifdef CONFIG_KGDB_KDB + r =vkdb_printf (fmt, args); +#else r =vprintk (fmt, args); +#endif va_end (args);
Quoted 8 lines
Quoted 3 lines
kernel/printk.c renamed from kernel/printk.c~a +0
-0return r;_
If you feel that would be cleaner, I can make that change, but I would also have to call
vprintk()fromvkdb_printfwhen everkdb_trap_printkis not set. Do I understand your recommendation correctly?
err, no, I must have been in a drunken stupor. Was trying to find a way to avoid the code duplication.
Jason Wessel
maintainerRe: [PATCH 22/28] printk,kdb: capture printk() when in kdb shell
Quoted 14 lines · Andrew Morton
Quoted 5 lines · On Fri, 12 Feb 2010 17:20:22 -0600 Jason Wessel <[email protected]>…
If you feel that would be cleaner, I can make that change, but I would also have to call
vprintk()fromvkdb_printfwhen everkdb_trap_printkis not set. Do I understand your recommendation correctly?Was trying to find
a way to avoid the code duplication.
You did make me think about the interface a bit further. If you were going to ack one of the versions of this patch, which would you prefer? The previous version, this new version or something else?
The difference here is that we use a replaced function call vs using the if statement. There are more lines source in the kdb, but the interface api is clean.
Thanks,
Jason.
From: Jason Wessel <[email protected]>
Subject: [PATCH] printk,kdb: capture printk() when in kdb shell
Certain calls from the kdb shell will call out to printk(), and any of these calls should get vectored back to the kdb_printf() so that the kdb pager and processing can be used, as well as to properly channel I/O to the polled I/O devices.
--- include/linux/kdb.h | 6 ++++ kernel/debug/kdb/kdb_bt.c | 2 + kernel/debug/kdb/kdb_io.c | 56 ++++++++++++++++++++++++++++++++++++++++---- kernel/debug/kdb/kdb_main.c | 4 +++ kernel/printk.c | 8 +++++- 5 files changed, 71 insertions(+), 5 deletions(-)
include/linux/kdb.h +6 -0
@@ -78,6 +78,12 @@ typedef enum {KDB_REASON_SSTEP ,/* Single Step trap. - regs valid */ } kdb_reason_t; +/* kdb printk and lowlevel kernel printk interface */ +extern asmlinkage int (*vprintk_func) (const char *, va_list); +extern void kdb_trap_printk_enable (void ); +extern void kdb_trap_printk_disable (void ); +extern asmlinkage int vkdb_printf(const char *fmt, va_list args) + __attribute__ ((format (printf,1 ,0 )));extern int kdb_printf (const char *, ...) __attribute__ ((format (printf,1 ,2 )));typedef int (*kdb_printf_t )(const char *, ...)
kernel/debug/kdb/kdb_bt.c +2 -0
@@ -23,6 +23,7 @@ static void kdb_show_stack(struct task_s {int old_lvl = console_loglevel; console_loglevel =15 ; +kdb_trap_printk_enable ();kdb_set_current_task (p);if (addr) {show_stack ((struct task_struct *)p, addr);
@@ -36,6 +37,7 @@ static void kdb_show_stack(struct task_sshow_stack (p,NULL ); } console_loglevel = old_lvl; +kdb_trap_printk_disable (); }/*
kernel/printk.c +7 -1
@@ -582,6 +582,12 @@ static int have_callable_console(void)return 0 ; } +#ifdef CONFIG_KGDB_KDB +asmlinkage int (*vprintk_func) (const char *, va_list) = vprintk; +#else +#define vprintk_func (x, y) vprintk(x, y) +#endif +/** * printk - print a kernel message * @fmt: format string
@@ -610,7 +616,7 @@ asmlinkage int printk(const char *fmt, .int r;va_start (args, fmt); - r =vprintk (fmt, args); + r =vprintk_func (fmt, args);va_end (args);return r;
kernel/debug/kdb/kdb_io.c +52 -4
91 lines not on this page · raw message
kernel/debug/kdb/kdb_main.c +4 -0
@@ -1056,7 +1056,9 @@ static void kdb_dumpregs(struct pt_regs {int old_lvl = console_loglevel; console_loglevel =15 ; +kdb_trap_printk_enable ();show_regs (regs); +kdb_trap_printk_disable ();kdb_printf ("\n" ); console_loglevel = old_lvl; }
@@ -1823,7 +1825,9 @@ static int kdb_sr(int argc, const char * __sysrq_enabled =1 ; } +kdb_trap_printk_enable ();handle_sysrq (*argv[1 ],NULL ); +kdb_trap_printk_disable ();return 0 ; }
Jason Wessel
maintainerPATCH 23/28 keyboard, input: Add hook to input to allow low level event clear
In reply to Jason WesselWhen using a keyboard with kdb, on resuming the system there needs to be a hook to allow for the keyboard state to get reset.
This is mainly because there is no way to force the end user to hold down the original keys that were pressed prior to entering kdb.
--- drivers/char/keyboard.c | 29 ++++++++++++++++++++++++----- drivers/input/input.c | 15 +++++++++++++++ drivers/serial/kgdboc.c | 13 +++++++++++++ include/linux/input.h | 10 ++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-)
drivers/char/keyboard.c +24 -5
@@ -1195,6 +1195,11 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)if (keycode <BTN_MISC &&printk_ratelimit ())printk (KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n" , keycode); +if (down) +set_bit (keycode, key_down); +else +clear_bit (keycode, key_down); +#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */ if (keycode ==KEY_SYSRQ && (sysrq_down || (down ==1 && sysrq_alt))) {if (!sysrq_down) {
@@ -1237,11 +1242,6 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) raw_mode =1 ; } -if (down) -set_bit (keycode, key_down); -else -clear_bit (keycode, key_down); -if (rep && (!vc_kbd_mode (kbd,VC_REPEAT ) || (tty && !L_ECHO (tty) &&tty_chars_in_buffer (tty)))) {
@@ -1410,6 +1410,22 @@ static const struct input_device_id kbd_ids[] = {MODULE_DEVICE_TABLE (input, kbd_ids); +#ifdef CONFIG_KDB_KEYBOARD +void kbd_clear_keys (void ) +{ +int i, j, k; + +for (i =0 ; i <ARRAY_SIZE (key_down); i++) { + k = i *BITS_PER_LONG ; +for (j =0 ; j <BITS_PER_LONG ; j++, k++) { +if (test_bit (k, key_down)) { +kbd_keycode (k,0 ,0 ); + } + } + } +} +#endif +static struct input_handler kbd_handler = { .event = kbd_event, .connect = kbd_connect,
@@ -1417,6 +1433,9 @@ static struct input_handler kbd_handler = { .start = kbd_start, .name = "kbd", .id_table = kbd_ids, +#ifdef CONFIG_KDB_KEYBOARD + .dbg_clear_keys = kbd_clear_keys, +#endif };int __init kbd_init (void )
drivers/input/input.c +15 -0
@@ -1692,6 +1692,21 @@ int input_register_handler(struct input_handler *handler) }EXPORT_SYMBOL (input_register_handler); +#ifdef CONFIG_KDB_KEYBOARD +/* input_db_clear_keys - Clear any keyboards if they have a call back, +* after returning from the kernel debugger +*/ +void input_dbg_clear_keys (void ) +{ +struct input_handler *handler; + +list_for_each_entry (handler, &input_handler_list, node) +if (handler->dbg_clear_keys) + handler->dbg_clear_keys (); +} +EXPORT_SYMBOL_GPL (input_dbg_clear_keys); +#endif +/** * input_unregister_handler - unregisters an input handler * @handler: handler to be unregistered
drivers/serial/kgdboc.c +13 -0
@@ -17,6 +17,7 @@#include <linux/kdb.h> #include <linux/tty.h> #include <linux/console.h> +#include <linux/input.h> #define MAX_CONFIG_LEN 40
@@ -35,12 +36,16 @@ static struct tty_driver *kgdb_tty_driver;static int kgdb_tty_line;#ifdef CONFIG_KDB_KEYBOARD +static int kgdboc_use_kbd;/* 1 if we use a keyboard */ +static int kgdboc_register_kbd (char **cptr) { + kgdboc_use_kbd =0 ;if (strncmp (*cptr,"kbd" ,3 ) ==0 ) {if (kdb_poll_idx <KDB_POLL_FUNC_MAX ) { kdb_poll_funcs[kdb_poll_idx] = kdb_get_kbd_char; kdb_poll_idx++; + kgdboc_use_kbd =1 ;if (cptr[0 ][3 ] ==',' ) *cptr +=4 ;else
@@ -63,9 +68,16 @@ static void kgdboc_unregister_kbd(void) } } } + +static inline void kgdboc_clear_kbd (void ) +{ +if (kgdboc_use_kbd) +input_dbg_clear_keys ();/* Release all pressed keys */ +}#else /* ! CONFIG_KDB_KEYBOARD */ #define kgdboc_register_kbd (x) 0#define kgdboc_unregister_kbd () +#define kgdboc_clear_kbd ()#endif /* ! CONFIG_KDB_KEYBOARD */ static int kgdboc_option_setup (char *opt)
@@ -213,6 +225,7 @@ static void kgdboc_post_exp_handler(void)/* decrement the module count when the debugger detaches */ if (!kgdb_connected)module_put (THIS_MODULE ); +kgdboc_clear_kbd (); }static struct kgdb_io kgdboc_io_ops = {
include/linux/input.h +10 -0
@@ -1231,6 +1231,9 @@ struct input_handler {int (*connect)(struct input_handler *handler,struct input_dev *dev,const struct input_device_id *id);void (*disconnect)(struct input_handle *handle);void (*start)(struct input_handle *handle); +#ifdef CONFIG_KDB_KEYBOARD +void (*dbg_clear_keys)(void ); +#endif const struct file_operations *fops;int minor;
@@ -1316,6 +1319,13 @@ int input_flush_device(struct input_handle* handle, struct file* file);void input_event (struct input_dev *dev,unsigned int type,unsigned int code,int value);void input_inject_event (struct input_handle *handle,unsigned int type,unsigned int code,int value); +#ifdef CONFIG_KDB_KEYBOARD +void input_dbg_clear_keys (void ); +#else +static inline void input_dbg_clear_keys (void ) +{} +#endif +static inline void input_report_key (struct input_dev *dev,unsigned int code,int value) {input_event (dev,EV_KEY , code, !!value);
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 24/28 debug_core,kdb: Allow the debug core to process a recursive debug entry
In reply to Jason WesselThis allows kdb to debug a crash with in the kms code with a single level recursive re-entry.
--- kernel/debug/debug_core.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
kernel/debug/debug_core.c +7 -0
@@ -445,6 +445,10 @@ static int kgdb_reenter_check(struct kgdb_state *ks) }printk (KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n" ); +#ifdef CONFIG_KGDB_KDB +/* Allow kdb to debug itself one level */ +return 0 ; +#endif dump_stack ();panic ("Recursive entry to debugger" );
@@ -489,6 +493,9 @@ acquirelock:smp_wmb ();atomic_set (&cpu_in_kgdb[cpu],1 ); +if (exception_level ==1 ) + goto cpu_master_loop; +/* * CPU will loop if it is a slave or request to become a kgdb * master cpu and acquire the kgdb_active lock:
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 25/28 MAINTAINERS: update kgdb, kdb, and debug_core info
In reply to Jason WesselUpdate the maintained files sections.
--- MAINTAINERS | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
MAINTAINERS +4 -2
@@ -3172,15 +3172,17 @@ S: Maintained F: include/linux/kexec.h F: kernel/kexec.c -KGDB +KGDB / KDB / debug_core M: Jason Wessel <[email protected]> L: [email protected] S: Maintained F: Documentation/DocBook/kgdb.tmpl +F: drivers/char/kdb_keyboard.* F: drivers/misc/kgdbts.c F: drivers/serial/kgdboc.c F: include/linux/kgdb.h -F: kernel/kgdb.c +F: include/linux/kdb.h +F: kernel/debug/ KMEMCHECK M: Vegard Nossum <[email protected]>
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 26/28 kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
In reply to Jason WesselIt is highly desirable to trap into kdb on panic, and in order to do so the notifier must be called before smp_send_stop(), else the debug_core will not be able to correctly trap all the CPUs.
--- kernel/debug/debug_core.c | 18 ++++++++++++++++++ kernel/panic.c | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-)
kernel/debug/debug_core.c +18 -0
@@ -754,11 +754,27 @@ static struct sysrq_key_op sysrq_dbg_op = { };#endif +static int kgdb_panic_event (struct notifier_block *self, +unsigned long val, +void *data) +{ +if (dbg_kdb_mode) +kdb_printf ("PANIC: %s\n" , (char *)data); +kgdb_breakpoint (); +return NOTIFY_DONE ; +} + +static struct notifier_block kgdb_panic_event_nb = { + .notifier_call = kgdb_panic_event, +}; +static void kgdb_register_callbacks (void ) {if (!kgdb_io_module_registered) { kgdb_io_module_registered =1 ;kgdb_arch_init (); +atomic_notifier_chain_register (&panic_notifier_list, + &kgdb_panic_event_nb);#ifdef CONFIG_MAGIC_SYSRQ register_sysrq_key ('g' , &sysrq_dbg_op);#endif
@@ -778,6 +794,8 @@ static void kgdb_unregister_callbacks(void)*/ if (kgdb_io_module_registered) { kgdb_io_module_registered =0 ; +atomic_notifier_chain_unregister (&panic_notifier_list, + &kgdb_panic_event_nb);kgdb_arch_exit ();#ifdef CONFIG_MAGIC_SYSRQ unregister_sysrq_key ('g' , &sysrq_dbg_op);
kernel/panic.c +4 -3
@@ -66,10 +66,13 @@ NORET_TYPE void panic(const char * fmt, ...)*/ preempt_disable (); -bust_spinlocks (1 );va_start (args, fmt);vsnprintf (buf,sizeof (buf), fmt, args);va_end (args); + +atomic_notifier_call_chain (&panic_notifier_list,0 , buf); + +bust_spinlocks (1 );printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();
@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)*/ smp_send_stop (); -atomic_notifier_call_chain (&panic_notifier_list,0 , buf); -bust_spinlocks (0 );if (!panic_blink)
Signature · 1 line
1.6.4.rc1
Andrew Morton
maintainerRe: [PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
Quoted 1 line · On Fri, 12 Feb 2010 16:35:41 -0600 Jason Wessel <[email protected]>…
It is highly desirable to trap into kdb on panic,
s/kdb/kgdb/
But is it necessary to do it in-kernel? Why not just put a breakpoint at panic(), add that to your .gdbinit?
Quoted 20 lines
kernel/panic.c +4
-1@@ -66,10 +66,13 @@ NORET_TYPE void panic(const char * fmt, ...)*/ preempt_disable (); -bust_spinlocks (1 );va_start (args, fmt);vsnprintf (buf,sizeof (buf), fmt, args);va_end (args); + +atomic_notifier_call_chain (&panic_notifier_list,0 , buf); + +bust_spinlocks (1 );printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();
kernel/panic.c NORET_TYPE void panic(const char * fmt, ...) · line 99
Quoted 8 lines
kernel/panic.c +0
-2@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)*/ smp_send_stop (); -atomic_notifier_call_chain (&panic_notifier_list,0 , buf); -bust_spinlocks (0 );if (!panic_blink)
So the notifier call now happens before all the printks and the kexec and kmsg_dump handling. What effect does this have upon the code which implements kexec and kmsg_dump?
Jason Wessel
maintainerRe: [PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
Quoted 12 lines · Andrew Morton
Quoted 2 lines · On Fri, 12 Feb 2010 16:35:41 -0600 Jason Wessel <[email protected]>…
It is highly desirable to trap into kdb on panic,
s/kdb/kgdb/
But is it necessary to do it in-kernel? Why not just put a breakpoint at
panic(), add that to your .gdbinit?
If you don't mind consuming a breakpoint that is ok. Certainly there is also the possibility of making this configurable as well.
For now I will omit this patch from any kind of future pull request while we hash out what makes sense.
Quoted 27 lines
Quoted 27 lines
kernel/panic.c +4
-3@@ -66,10 +66,13 @@ NORET_TYPE void panic(const char * fmt, ...)*/ preempt_disable (); -bust_spinlocks (1 );va_start (args, fmt);vsnprintf (buf,sizeof (buf), fmt, args);va_end (args); + +atomic_notifier_call_chain (&panic_notifier_list,0 , buf); + +bust_spinlocks (1 );printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)*/ smp_send_stop (); -atomic_notifier_call_chain (&panic_notifier_list,0 , buf); -bust_spinlocks (0 );
Quoted 8 lines
kernel/panic.c NORET_TYPE void panic(const char * fmt, ...) · line 99
Quoted 2 lines
kernel/panic.c +0
-0if (!panic_blink)So the notifier call now happens before all the printks and the kexec and
kmsg_dumphandling. What effect does this have upon the code which implements kexec andkmsg_dump?
I certainly don't want to break kexec or alter any behavior, does that mean kgdb / kdb should hook the kexec for notification?
I think ideally it is a end user's preference as to if they want in via kexec or the kernel debugger. Calling the smp_send_stop() prior to the notifier was a death sentence for the kernel debugger.
Perhaps I can move the notifier before smp_send_stop()?
Jason.
Andrew Morton
maintainerRe: [PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
Quoted 20 lines · On Fri, 12 Feb 2010 17:43:39 -0600 Jason Wessel <[email protected]>…
Quoted 11 lines
Quoted 11 lines
kernel/panic.c +0
-2printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)*/ smp_send_stop (); -atomic_notifier_call_chain (&panic_notifier_list,0 , buf); -bust_spinlocks (0 );Quoted 8 lines
kernel/panic.c NORET_TYPE void panic(const char * fmt, ...) · line 99
Quoted 2 lines
kernel/panic.c +0
-0if (!panic_blink)So the notifier call now happens before all the printks and the kexec and
kmsg_dumphandling. What effect does this have upon the code which implements kexec andkmsg_dump?
Quoted 8 lines
I certainly don't want to break kexec or alter any behavior, does that mean kgdb / kdb should hook the kexec for notification?
I think ideally it is a end user's preference as to if they want in via kexec or the kernel debugger. Calling the
smp_send_stop()prior to the notifier was a death sentence for the kernel debugger.Perhaps I can move the notifier before
smp_send_stop()?
Well. My question can be simplified to "does this break existing code"?
Re: [PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
Quoted 25 lines · Andrew Morton
Quoted 23 lines · On Fri, 12 Feb 2010 17:43:39 -0600 Jason Wessel <[email protected]>…
Quoted 11 lines
Quoted 11 lines
kernel/panic.c +0
-2printk (KERN_EMERG "Kernel panic - not syncing: %s\n" ,buf);#ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack ();@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...)*/ smp_send_stop (); -atomic_notifier_call_chain (&panic_notifier_list,0 , buf); -bust_spinlocks (0 );Quoted 8 lines
kernel/panic.c NORET_TYPE void panic(const char * fmt, ...) · line 99
Quoted 2 lines
kernel/panic.c +0
-0if (!panic_blink)So the notifier call now happens before all the printks and the kexec and
kmsg_dumphandling. What effect does this have upon the code which implements kexec andkmsg_dump?I certainly don't want to break kexec or alter any behavior, does that mean kgdb / kdb should hook the kexec for notification?
Quoted 7 lines
Quoted 5 lines
I think ideally it is a end user's preference as to if they want in via kexec or the kernel debugger. Calling the
smp_send_stop()prior to the notifier was a death sentence for the kernel debugger.Perhaps I can move the notifier before
smp_send_stop()?Well. My question can be simplified to "does this break existing code"?
Yes. Removing the bust_spinlocks(1) and moving the panic notification up will measurably decrease the reliability of crash dump capture. I expect it will even result in dead_locks where we fail to print the panic message for people who are trying to debug via the console.
Eric
Jason Wessel
maintainerRe: [PATCH 26/28] kdb,panic,debug_core: Allow the debug core to receive a panic before smp_send_stop()
Quoted 25 lines · Eric W. Biederman
Quoted 23 lines · Andrew Morton
Quoted 21 lines · On Fri, 12 Feb 2010 17:43:39 -0600 Jason Wessel <[email protected]>…
Quoted 11 lines
Quoted 11 lines
(quoted diff) +0
-2printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf); #ifdef CONFIG_DEBUG_BUGVERBOSE dump_stack();@@ -91,8 +94,6 @@ NORET_TYPE void panic(const char * fmt, ...) */ smp_send_stop(); - atomic_notifier_call_chain(&panic_notifier_list, 0, buf); - bust_spinlocks(0);Quoted 7 lines
Review NORET_TYPE void panic(const char * fmt, ...) · line 99
Quoted 2 lines
(quoted diff) +0
-0if (!panic_blink)So the notifier call now happens before all the printks and the kexec and
kmsg_dumphandling. What effect does this have upon the code which implements kexec andkmsg_dump?I certainly don't want to break kexec or alter any behavior, does that mean kgdb / kdb should hook the kexec for notification?
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
I think ideally it is a end user's preference as to if they want in via kexec or the kernel debugger. Calling the
smp_send_stop()prior to the notifier was a death sentence for the kernel debugger.Perhaps I can move the notifier before
smp_send_stop()?Well. My question can be simplified to "does this break existing code"?
Yes. Removing the
bust_spinlocks(1)and moving the panic notification up
The bust_spinlocks(1) was not removed but moved around, but the point is moot. Yes, it confirmed beyond the shadow of a doubt to break existing code.
The revised patch does not touch anything in kernel/panic.c. Instead we make a best effort to get the kernel debugger first in line to the notifier. It turns out one of the other notifiers was the culprit in the hanging the system during the panic tests.
If anyone further objects, I will simply drop the kdb panic notification registration entirely.
Thanks,
Jason.
---
From: Jason Wessel <[email protected]>
Subject: [PATCH] kdb,debug_core: Allow the debug core to receive a panic notification
It is highly desirable to trap into kdb on panic. The debug core will attempt to register as the first in line for the panic notifier.
--- kernel/debug/debug_core.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
kernel/debug/debug_core.c +19 -0
@@ -754,11 +754,28 @@ static struct sysrq_key_op sysrq_dbg_op };#endif +static int kgdb_panic_event (struct notifier_block *self, +unsigned long val, +void *data) +{ +if (dbg_kdb_mode) +kdb_printf ("PANIC: %s\n" , (char *)data); +kgdb_breakpoint (); +return NOTIFY_DONE ; +} + +static struct notifier_block kgdb_panic_event_nb = { + .notifier_call = kgdb_panic_event, + .priority =INT_MAX , +}; +static void kgdb_register_callbacks (void ) {if (!kgdb_io_module_registered) { kgdb_io_module_registered =1 ;kgdb_arch_init (); +atomic_notifier_chain_register (&panic_notifier_list, + &kgdb_panic_event_nb);#ifdef CONFIG_MAGIC_SYSRQ register_sysrq_key ('g' , &sysrq_dbg_op);#endif
@@ -778,6 +795,8 @@ static void kgdb_unregister_callbacks(vo*/ if (kgdb_io_module_registered) { kgdb_io_module_registered =0 ; +atomic_notifier_chain_unregister (&panic_notifier_list, + &kgdb_panic_event_nb);kgdb_arch_exit ();#ifdef CONFIG_MAGIC_SYSRQ unregister_sysrq_key ('g' , &sysrq_dbg_op);
Jason Wessel
maintainerPATCH 27/28 kgdbts,sh: Add in breakpoint pc offset for superh
In reply to Jason WesselThe kgdb test suite mimics the behavior of gdb. For the sh architecture the pc must be decremented by 2 for software breakpoint.
--- drivers/misc/kgdbts.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/misc/kgdbts.c +6 -0
@@ -295,6 +295,10 @@ static int check_and_rewind_pc(char *put_str, char *arg)/* On x86 a breakpoint stop requires it to be decremented */ if (addr +1 == kgdbts_regs.ip) offset =-1 ; +#elif defined(CONFIG_SUPERH ) +/* On SUPERH a breakpoint stop requires it to be decremented */ +if (addr +2 == kgdbts_regs.pc) + offset =-2 ;#endif if (strcmp (arg,"silent" ) &&instruction_pointer (&kgdbts_regs) + offset != addr) {
@@ -305,6 +309,8 @@ static int check_and_rewind_pc(char *put_str, char *arg)#ifdef CONFIG_X86 /* On x86 adjust the instruction pointer if needed */ kgdbts_regs.ip += offset; +#elif defined(CONFIG_SUPERH ) + kgdbts_regs.pc += offset;#endif return 0 ; }
Signature · 1 line
1.6.4.rc1
Jason Wessel
maintainerPATCH 28/28 debug_core: Turn off tracing while in the debugger
In reply to Jason WesselThe kernel debugger should turn off kernel tracing any time the debugger is active and restore it on resume.
--- kernel/debug/debug_core.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
kernel/debug/debug_core.c +8 -0
@@ -474,6 +474,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs)int sstep_tries =100 ;int error;int i, cpu; +int trace_on =0 ; acquirelock:/* * Interrupts will be restored by the 'trap return' code, except when
@@ -518,6 +519,8 @@ return_normal:*/ if (arch_kgdb_ops.correct_hw_break) arch_kgdb_ops.correct_hw_break (); +if (trace_on) +tracing_on ();atomic_set (&cpu_in_kgdb[cpu],0 );touch_softlockup_watchdog_sync ();clocksource_touch_watchdog ();
@@ -592,6 +595,9 @@ return_normal: kgdb_single_step =0 ; kgdb_contthread = current; exception_level =0 ; + trace_on =tracing_is_on (); +if (trace_on) +tracing_off ();while (1 ) { cpu_master_loop:
@@ -645,6 +651,8 @@ kgdb_restore:else kgdb_sstep_pid =0 ; } +if (trace_on) +tracing_on ();/* Free kgdb_active */ atomic_set (&kgdb_active,-1 );touch_softlockup_watchdog_sync ();
Signature · 1 line
1.6.4.rc1