kgdb: Small usability improvements for x86
Subsystems (3)
cover kgdb: Small usability improvements for x86
[resent due to wrong list CC in first round]
This cleans up the "info register" result on x86 and adds gdb detach on reboot/shutdown for this target arch. See patches for details.
Jan Kiszka (4):
kgdb: x86: Return all segment registers also in 64-bit mode
kgdb: Make gdbstub_exit a nop unless gdb is attached
kgdb: Respect that flush op is optional
kgdb: x86: Detach gdb if machine shuts down or reboots
arch/x86/include/asm/kgdb.h | 6 +++++- arch/x86/kernel/kgdb.c | 6 ++++-- arch/x86/kernel/reboot.c | 6 ++++++ include/linux/kgdb.h | 1 + kernel/debug/gdbstub.c | 6 +++++- 5 files changed, 21 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.3.4
PATCH 1/4 kgdb: x86: Return all segment registers also in 64-bit mode
Even if the content is always 0, gdb expects us to return also ds, es, fs, and gs while in x86-64 mode. Do this to avoid ugly errors on "info registers".
--- arch/x86/include/asm/kgdb.h | 6 +++++- arch/x86/kernel/kgdb.c | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
arch/x86/include/asm/kgdb.h +5 -1
@@ -64,9 +64,13 @@ enum regnames {GDB_PS ,/* 17 */ GDB_CS ,/* 18 */ GDB_SS ,/* 19 */ +GDB_DS ,/* 20 */ +GDB_ES ,/* 21 */ +GDB_FS ,/* 22 */ + GDB_GS, /* 23 */ };#define GDB_ORIG_AX 57 -#define DBG_MAX_REG_NUM 20 +#define DBG_MAX_REG_NUM 24/* 17 64 bit regs and 3 32 bit regs */ #define NUMREGBYTES ((17 * 8) + (3 * 4))#endif /* ! CONFIG_X86_32 */
arch/x86/kernel/kgdb.c +4 -2
@@ -67,8 +67,6 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { "ss", 4, offsetof(struct pt_regs, ss) }, { "ds", 4, offsetof(struct pt_regs, ds) }, { "es", 4, offsetof(struct pt_regs, es) }, - { "fs", 4, -1 }, - { "gs", 4, -1 }, #else { "ax", 8, offsetof(struct pt_regs, ax) }, { "bx", 8, offsetof(struct pt_regs, bx) },
@@ -90,7 +88,11 @@ struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = { "flags", 4, offsetof(struct pt_regs, flags) }, { "cs", 4, offsetof(struct pt_regs, cs) }, { "ss", 4, offsetof(struct pt_regs, ss) }, + { "ds", 4, -1 }, + { "es", 4, -1 }, #endif + { "fs", 4, -1 }, + { "gs", 4, -1 }, }; int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
Signature · 1 line
1.7.3.4
Jason Wessel
maintainerRe: [PATCH 1/4] kgdb: x86: Return all segment registers also in 64-bit mode
Quoted 18 lines · Jan Kiszka
Even if the content is always 0, gdb expects us to return also ds, es, fs, and gs while in x86-64 mode. Do this to avoid ugly errors on "info registers".
Signed-off-by Jan Kiszka <[email protected]>--- arch/x86/include/asm/kgdb.h | 6 +++++- arch/x86/kernel/kgdb.c | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-)arch/x86/include/asm/kgdb.h +0
-0@@ -64,9 +64,13 @@ enum regnames {GDB_PS ,/* 17 */ GDB_CS ,/* 18 */ GDB_SS, /* 19 */
arch/x86/include/asm/kgdb.h enum regnames { · line 75
Quoted 10 lines
arch/x86/include/asm/kgdb.h +5
-1+GDB_DS ,/* 20 */ +GDB_ES ,/* 21 */ +GDB_FS ,/* 22 */ + GDB_GS, /* 23 */ };#define GDB_ORIG_AX 57 -#define DBG_MAX_REG_NUM 20 +#define DBG_MAX_REG_NUM 24/* 17 64 bit regs and 3 32 bit regs */ #define NUMREGBYTES ((17 * 8) + (3 * 4))
You bumped the register numbers correctly, but you also need to add the correct padding to the NUMREGBYTES or you might not get a large enough memory block for the register struct.
You added 2 32 bit regs, so it should change to:
/* 17 64 bit regs and 5 32 bit regs */
#define NUMREGBYTES ((17 * 8) + (5 * 4))
The rest should be fine. I can test this and add it to the merge queue with the NUMREGBYTES change, unless you disagree.
Cheers,
Jason.
Re: [PATCH 1/4] kgdb: x86: Return all segment registers also in 64-bit mode
Quoted 32 lines · Jason Wessel
Quoted 18 lines · Jan Kiszka
Even if the content is always 0, gdb expects us to return also ds, es, fs, and gs while in x86-64 mode. Do this to avoid ugly errors on "info registers".
Signed-off-by Jan Kiszka <[email protected]>--- arch/x86/include/asm/kgdb.h | 6 +++++- arch/x86/kernel/kgdb.c | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-)arch/x86/include/asm/kgdb.h +0
-0@@ -64,9 +64,13 @@ enum regnames {GDB_PS ,/* 17 */ GDB_CS ,/* 18 */ GDB_SS, /* 19 */arch/x86/include/asm/kgdb.h enum regnames { · line 75
Quoted 10 lines
arch/x86/include/asm/kgdb.h +5
-1+GDB_DS ,/* 20 */ +GDB_ES ,/* 21 */ +GDB_FS ,/* 22 */ + GDB_GS, /* 23 */ };#define GDB_ORIG_AX 57 -#define DBG_MAX_REG_NUM 20 +#define DBG_MAX_REG_NUM 24/* 17 64 bit regs and 3 32 bit regs */ #define NUMREGBYTES ((17 * 8) + (3 * 4))You bumped the register numbers correctly, but you also need to add the correct padding to the NUMREGBYTES or you might not get a large enough memory block for the register struct.
Quoted 5 lines
You added 2 32 bit regs, so it should change to:
/* 17 64 bit regs and 5 32 bit regs */
#define NUMREGBYTES ((17 * 8) + (5 * 4))
Oops. Most probably explains the random gs content I saw these days in a 64-bit debugging session.
Quoted 2 lines
The rest should be fine. I can test this and add it to the merge queue with the NUMREGBYTES change, unless you disagree.
I don't disagree. :)
Thanks,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Jason Wessel
maintainerRe: [PATCH 1/4] kgdb: x86: Return all segment registers also in 64-bit mode
Quoted 3 lines · Jan Kiszka
On 2012-03-16 16:57, Jason Wessel wrote:
The rest should be fine. I can test this and add it to the merge queue with the NUMREGBYTES change, unless you disagree.
I don't disagree. :)
Sounds fine. I added this to the merge queue for the 3.4 kernel.
Cheers,
Jason.
PATCH 2/4 kgdb: Make gdbstub_exit a nop unless gdb is attached
In reply to Jan KiszkaThis allows to call gdbstub_exit without worrying if
- CONFIG_KGDB is enabled
- if an kgdb I/O driver is loaded
- if a gdb frontend is currently attached
--- include/linux/kgdb.h | 1 + kernel/debug/gdbstub.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)
include/linux/kgdb.h +1 -0
@@ -306,6 +306,7 @@ extern atomic_t kgdb_active;extern bool dbg_is_early;extern void __init dbg_late_init (void );#else /* ! CONFIG_KGDB */ +static inline void gdbstub_exit (int status) { }#define in_dbg_master () (0)#define dbg_late_init ()#endif /* ! CONFIG_KGDB */
kernel/debug/gdbstub.c +3 -0
@@ -1111,6 +1111,9 @@ void gdbstub_exit(int status)unsigned char checksum, ch, buffer[3 ];int loop; +if (!dbg_io_ops || !kgdb_connected) +return ; + buffer[0 ] ='W' ; buffer[1 ] =hex_asc_hi (status); buffer[2 ] =hex_asc_lo (status);
Signature · 1 line
1.7.3.4
Jason Wessel
maintainerRe: [PATCH 2/4] kgdb: Make gdbstub_exit a nop unless gdb is attached
Quoted 4 lines · Jan Kiszka
This allows to call
gdbstub_exitwithout worrying if
-CONFIG_KGDBis enabled
- if an kgdb I/O driver is loaded
- if a gdb frontend is currently attached
If you took a look at the alternate patch I sent in the 4 of 4 response, I made a modification for kdb to continue to work properly, namely disconnect and do not emit characters if we are in kdb mode.
Quoted 6 lines
kernel/debug/gdbstub.c +0
-0
kernel/debug/gdbstub.c void gdbstub_exit(int status) · line 1119
Quoted 9 lines
kernel/debug/gdbstub.c +3
-0@@ -1111,6 +1111,9 @@ void gdbstub_exit(int status)unsigned char checksum, ch, buffer[3 ];int loop; +if (!dbg_io_ops || !kgdb_connected) +return ; + buffer[0 ] ='W' ; buffer[1 ] =hex_asc_hi (status); buffer[2 ] =hex_asc_lo (status);
I patched against what you originally had there.
kernel/debug/gdbstub.c +4 -1
@@ -1110,8 +1110,11 @@ void gdbstub_exit(int status) {unsigned char checksum, ch, buffer[3 ];int loop; +if (!kgdb_connected) +return ; + kgdb_connected =0 ; -if (!dbg_io_ops || !kgdb_connected) +if (!dbg_io_ops || dbg_kdb_mode)return ; buffer[0 ] ='W' ;
---
Depending on what we come to agreement on with patches 2-4 in your series I'll fold the changes into the reboot notifier.
It is possible to have both the reboot notifier and the low level modifications to the arch specific reboot hooks as a final catch, but I am interested to see what you think about just using the reboot notifier.
Cheers,
Jason.
PATCH 3/4 kgdb: Respect that flush op is optional
In reply to Jan KiszkaNot all kgdb I/O drivers implement a flush operation. Adjust gdbstub_exit accordingly.
--- kernel/debug/gdbstub.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/debug/gdbstub.c +2 -1
@@ -1132,5 +1132,6 @@ void gdbstub_exit(int status) dbg_io_ops->write_char (hex_asc_lo (checksum));/* make sure the output is flushed, lest the bootloader clobber it */ - dbg_io_ops->flush (); +if (dbg_io_ops->flush) + dbg_io_ops->flush (); }
Signature · 1 line
1.7.3.4
Jason Wessel
maintainerRe: [PATCH 3/4] kgdb: Respect that flush op is optional
Quoted 2 lines · Jan Kiszka
Not all kgdb I/O drivers implement a flush operation. Adjust
gdbstub_exitaccordingly.
The flush is certainly optional. The reason we never saw this bug is because it was only used by some code not in the mainline, where it is in fact patched. The out of tree patch hooked into the reboot notifier.
It makes me wonder if using the reboot notifier is enough vs the call backs you placed in the critical power off points in your patch [4/4]. I'll respond separately to that thread because there are other folks in the CC line.
If we decide to roll with this series, I will definitely merge this patch, else I will remove the code since it is not used except for out of tree patches.
Thanks,
Jason.
Re: [PATCH 3/4] kgdb: Respect that flush op is optional
Quoted 7 lines · Jason Wessel
Quoted 2 lines · Jan Kiszka
Not all kgdb I/O drivers implement a flush operation. Adjust
gdbstub_exitaccordingly.The flush is certainly optional. The reason we never saw this bug is because it was only used by some code not in the mainline, where it is in fact patched. The out of tree patch hooked into the reboot notifier.
It makes me wonder if using the reboot notifier is enough vs the call backs you placed in the critical power off points in your patch [4/4]. I'll respond separately to that thread because there are other folks in the CC line.
I looked at other (granted: not kgdb-) archs and found them hooking their machine_xxx handlers. Also, do we trigger the notifier on all reboot/shutdown types?
Quoted 2 lines
If we decide to roll with this series, I will definitely merge this patch, else I will remove the code since it is not used except for out of tree patches.
Even with a reboot notifier, you still need the logic of gdbstub_exit. So I doubt it makes sense to be removed, rather start to be used - finally.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Jason Wessel
maintainerRe: [PATCH 3/4] kgdb: Respect that flush op is optional
Quoted 4 lines · Jan Kiszka
Quoted 3 lines · Jason Wessel
Quoted 2 lines · Jan Kiszka
Not all kgdb I/O drivers implement a flush operation. Adjust
gdbstub_exitaccordingly.
Quoted 8 lines
Quoted 3 lines
The flush is certainly optional. The reason we never saw this bug is because it was only used by some code not in the mainline, where it is in fact patched. The out of tree patch hooked into the reboot notifier.
It makes me wonder if using the reboot notifier is enough vs the call backs you placed in the critical power off points in your patch [4/4]. I'll respond separately to that thread because there are other folks in the CC line.
I looked at other (granted: not kgdb-) archs and found them hooking their
machine_xxxhandlers. Also, do we trigger the notifier on all reboot/shutdown types?From what I can tell, all the safe shutdown types go through notifier, however if you do something like:
echo o > /proc/sysrq-trigger
This will avoid the reboot notifier hook. It is a question of how aggressively you want to catch all these cases or patch the kernel such that these holes provide notifications.
Quoted 3 lines
Quoted 1 line
If we decide to roll with this series, I will definitely merge this patch, else I will remove the code since it is not used except for out of tree patches.
Even with a reboot notifier, you still need the logic of
gdbstub_exit. So I doubt it makes sense to be removed, rather start to be used - finally.
You are correct about that, and it is actually used in the reboot notifier version.
Jason.
PATCH 4/4 kgdb: x86: Detach gdb if machine shuts down or reboots
In reply to Jan KiszkaHook into machine restart/power-off/halt handlers and call gdbstub_exit so that a attached gdb frontend is properly informed. If kgdb is disabled or no frontend attached, gdbstub_exit will do nothing.
--- arch/x86/kernel/reboot.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/kernel/reboot.c +6 -0
@@ -7,6 +7,7 @@#include <linux/sched.h> #include <linux/tboot.h> #include <linux/delay.h> +#include <linux/kgdb.h> #include <acpi/reboot.h> #include <asm/io.h> #include <asm/apic.h>
@@ -683,6 +684,7 @@ void native_machine_shutdown(void)static void __machine_emergency_restart (int emergency) { reboot_emergency = emergency; +gdbstub_exit (1 ); machine_ops.emergency_restart (); }
@@ -730,6 +732,7 @@ struct machine_ops machine_ops = {void machine_power_off (void ) { +gdbstub_exit (0 ); machine_ops.power_off (); }
@@ -745,17 +748,20 @@ void machine_emergency_restart(void)void machine_restart (char *cmd) { +gdbstub_exit (0 ); machine_ops.restart (cmd); }void machine_halt (void ) { +gdbstub_exit (0 ); machine_ops.halt (); }#ifdef CONFIG_KEXEC void machine_crash_shutdown (struct pt_regs *regs) { +gdbstub_exit (1 ); machine_ops.crash_shutdown (regs); }#endif
Signature · 1 line
1.7.3.4
Jason Wessel
maintainerRe: [PATCH 4/4] kgdb: x86: Detach gdb if machine shuts down or reboots
Quoted 4 lines · Jan Kiszka
Hook into machine restart/power-off/halt handlers and call
gdbstub_exitso that a attached gdb frontend is properly informed. If kgdb is disabled or no frontend attached,gdbstub_exitwill do nothing.
We have long had an out of tree patch which hooked the reboot notifier, vs adding call backs to the actual reboot functions. It seems at first glance that all of cases that Jan probably cares about are actually caught by the reboot notifier.
I attached the patch I am referencing, and perhaps Jan can try it out. It applies on top of Jan's series at the moment.
A few more comments first.
Review
Quoted 4 lines
static void
__machine_emergency_restart(int emergency){(quoted diff) +1
-0reboot_emergency = emergency; + gdbstub_exit(1);
If we do have to add callbacks at the arch level, my preference is to pass the stop code like you would have received in the reboot notifier. Specifically something like: gdbstub_exit(SYS_RESTART).
Review struct machine_ops machine_ops = { · line 735
Quoted 8 lines
(quoted diff) +1
-0machine_ops.emergency_restart(); }@@ -730,6 +732,7 @@ struct machine_ops machine_ops = { void machine_power_off(void) { + gdbstub_exit(0);
Similarly gdbstub_exit(SYS_HALT) and so on.
Jan, what do you think about trying the reboot notifier version?
Thanks,
Jason.
From: Jason Wessel <[email protected]>
Subject: [PATCH] kgdb,debug-core,gdbstub: Hook the reboot notifier for debugger detach
The gdbstub and kdb should get detached if the system is rebooting. Calling gdbstub_exit() will set the proper debug core state and send a message to any debugger that is connected to correctly detach.
An attached debugger will receive the exit code from include/linux/reboot.h based on SYS_HALT, SYS_REBOOT, etc...
--- kernel/debug/debug_core.c | 17 +++++++++++++++++ kernel/debug/gdbstub.c | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-)
kernel/debug/debug_core.c +17 -0
@@ -41,6 +41,7 @@#include <linux/delay.h> #include <linux/sched.h> #include <linux/sysrq.h> +#include <linux/reboot.h> #include <linux/init.h> #include <linux/kgdb.h> #include <linux/kdb.h>
@@ -784,6 +785,20 @@ void __init dbg_late_init(void)kdb_init (KDB_INIT_FULL ); } +static int +dbg_notify_reboot (struct notifier_block *this,unsigned long code,void *x) +{ +if (!dbg_kdb_mode) +gdbstub_exit (code); +return NOTIFY_DONE ; +} + +static struct notifier_block dbg_reboot_notifier = { + .notifier_call = dbg_notify_reboot, + .next =NULL , + .priority =INT_MAX , +}; +static void kgdb_register_callbacks (void ) {if (!kgdb_io_module_registered) {
@@ -791,6 +806,7 @@ static void kgdb_register_callbacks(voidkgdb_arch_init ();if (!dbg_is_early)kgdb_arch_late (); +register_reboot_notifier (&dbg_reboot_notifier);atomic_notifier_chain_register (&panic_notifier_list, &kgdb_panic_event_nb);#ifdef CONFIG_MAGIC_SYSRQ
@@ -812,6 +828,7 @@ static void kgdb_unregister_callbacks(vo*/ if (kgdb_io_module_registered) { kgdb_io_module_registered =0 ; +unregister_reboot_notifier (&dbg_reboot_notifier);atomic_notifier_chain_unregister (&panic_notifier_list, &kgdb_panic_event_nb);kgdb_arch_exit ();
kernel/debug/gdbstub.c +4 -1
@@ -1110,8 +1110,11 @@ void gdbstub_exit(int status) {unsigned char checksum, ch, buffer[3 ];int loop; +if (!kgdb_connected) +return ; + kgdb_connected =0 ; -if (!dbg_io_ops || !kgdb_connected) +if (!dbg_io_ops || dbg_kdb_mode)return ; buffer[0 ] ='W' ;
Re: [PATCH 4/4] kgdb: x86: Detach gdb if machine shuts down or reboots
Quoted 13 lines · Jason Wessel
Quoted 4 lines · Jan Kiszka
Hook into machine restart/power-off/halt handlers and call
gdbstub_exitso that a attached gdb frontend is properly informed. If kgdb is disabled or no frontend attached,gdbstub_exitwill do nothing.We have long had an out of tree patch which hooked the reboot notifier, vs adding call backs to the actual reboot functions. It seems at first glance that all of cases that Jan probably cares about are actually caught by the reboot notifier.
I attached the patch I am referencing, and perhaps Jan can try it out. It applies on top of Jan's series at the moment.
A few more comments first.
Quoted 7 lines
Review
Quoted 4 lines
static void
__machine_emergency_restart(int emergency){(quoted diff) +1
-0reboot_emergency = emergency; + gdbstub_exit(1);If we do have to add callbacks at the arch level, my preference is to pass the stop code like you would have received in the reboot notifier. Specifically something like:
gdbstub_exit(SYS_RESTART).
Yes, that sounds reasonable.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +0
-0machine_ops.emergency_restart(); }@@ -730,6 +732,7 @@ struct machine_ops machine_ops = {
Quoted 8 lines
Review struct machine_ops machine_ops = { · line 735
Quoted 3 lines
(quoted diff) +1
-0void machine_power_off(void) { + gdbstub_exit(0);Similarly
gdbstub_exit(SYS_HALT)and so on.Jan, what do you think about trying the reboot notifier version?
An arch-independent hook has its advantages, no question. Maybe we should just start this way and then evolved on top as needed.
I was wondering why those other archs do not use the notifier. Maybe one motivation is to avoid that too much code is excluded from the debugger by detaching too early. Could possibly be addressed by making detach-on-reboot runtime configurable.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Jason Wessel
maintainerRe: [PATCH 4/4] kgdb: x86: Detach gdb if machine shuts down or reboots
Quoted 4 lines · Jan Kiszka
An arch-independent hook has its advantages, no question. Maybe we should just start this way and then evolved on top as needed.
Sounds good to me. I added the reboot notifier patch into the merge queue for kgdb/kdb.
Quoted 4 lines
I was wondering why those other archs do not use the notifier. Maybe one motivation is to avoid that too much code is excluded from the debugger by detaching too early. Could possibly be addressed by making detach-on-reboot runtime configurable.
There really isn't a whole lot of code between reboot hook invoked from kernel_restart_prepare(), and the place where the reset is invoked. Specifically it looked like:
usermodehelper_disable();
device_shutdown();
syscore_shutdown();
machine_restart(cmd);Attached is the patch you asked for the conditional behavior with respect to the reboot hook. This also implements the ability to stop on a reboot that is not a panic().
Cheers,
Jason.
Quoted 1 line
From
7bd0d272730f276b996110d8777d8deacbcb3d15Mon Sep 17 00:00:00 2001
From: Jason Wessel <[email protected]>
Date: Mon, 19 Mar 2012 19:35:55 -0500
Subject: [PATCH] kgdb,debug_core: add the ability to control the reboot
notifier
Sometimes it is desirable to stop the kernel debugger before allowing a system to reboot either with kdb or kgdb. This patch adds the ability to turn the reboot notifier on and off or enter the debugger and stop kernel execution before rebooting.
It is possible to change the setting after booting the kernel with the following:
echo 1 > /sys/module/debug_core/parameters/kgdbreboot
It is also possible to change this setting using kdb / kgdb to manipulate the variable directly.
Using KDB:
mm kgdbreboot 1
Using gdb:
set kgdbreboot=1
--- Documentation/DocBook/kgdb.tmpl | 17 +++++++++++++++++ kernel/debug/debug_core.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
Documentation/DocBook/kgdb.tmpl +17 -0
@@ -362,6 +362,23 @@ </para> </para> </sect1> + <sect1 id="kgdbreboot"> + <title>Run time parameter: kgdbreboot</title> + <para> The kgdbreboot feature allows you to change how the debugger + deals with the reboot notification. You have 3 choices for the + behavior. The default behavior is always set to 0.</para> + <orderedlist> + <listitem><para>echo -1 > /sys/module/debug_core/parameters/kgdbreboot</para> + <para>Ignore the reboot notification entirely.</para> + </listitem> + <listitem><para>echo 0 > /sys/module/debug_core/parameters/kgdbreboot</para> + <para>Send the detach message to any attached debugger client.</para> + </listitem> + <listitem><para>echo 1 > /sys/module/debug_core/parameters/kgdbreboot</para> + <para>Enter the debugger on reboot notify.</para> + </listitem> + </orderedlist> + </sect1> </chapter> <chapter id="usingKDB"> <title>Using kdb</title>
kernel/debug/debug_core.c +16 -0
@@ -76,6 +76,8 @@ static int exception_level;struct kgdb_io *dbg_io_ops;static DEFINE_SPINLOCK (kgdb_registration_lock); +/* Action for the reboot notifiter, a global allow kdb to change it */ +static int kgdbreboot;/* kgdb console driver is loaded */ static int kgdb_con_registered;/* determine if kgdb console output should be used */
@@ -97,6 +99,7 @@ static int __init opt_kgdb_con(char *str)early_param ("kgdbcon" , opt_kgdb_con);module_param (kgdb_use_con, int,0644 ); +module_param (kgdbreboot, int,0644 );/* * Holds information about breakpoints in a kernel. These breakpoints are
@@ -788,8 +791,21 @@ void __init dbg_late_init(void)static int dbg_notify_reboot (struct notifier_block *this,unsigned long code,void *x) { +/* +* Take the following action on reboot notify depending on value: +* 1 == Enter debugger +* 0 == [the default] detatch debug client +* -1 == Do nothing... and use this until the board resets +*/ +switch (kgdbreboot) { +case 1 : +kgdb_breakpoint (); +case -1 : + goto done; + }if (!dbg_kdb_mode)gdbstub_exit (code); +done:return NOTIFY_DONE ; }
Signature · 1 line
1.7.5.4
Re: [Kgdb-bugreport] [PATCH 4/4] kgdb: x86: Detach gdb if machine shuts down or reboots
Hello.
Quoted 13 lines · Jason Wessel
Quoted 2 lines
An arch-independent hook has its advantages, no question. Maybe we should just start this way and then evolved on top as needed.
Sounds good to me. I added the reboot notifier patch into the merge queue for kgdb/kdb.
Quoted 4 lines
I was wondering why those other archs do not use the notifier. Maybe one motivation is to avoid that too much code is excluded from the debugger by detaching too early. Could possibly be addressed by making detach-on-reboot runtime configurable.
There really isn't a whole lot of code between reboot hook invoked from
kernel_restart_prepare(), and the place where the reset is invoked. Specifically it looked like:
Quoted 6 lines
usermodehelper_disable(); device_shutdown(); syscore_shutdown(); machine_restart(cmd);Attached is the patch you asked for the conditional behavior with respect to the reboot hook.
You forgot to attach it?
Quoted 1 line
This also implements the ability to stop on a reboot that is not a
panic().
WBR, Sergei
Jason Wessel
maintainerRe: [Kgdb-bugreport] [PATCH 4/4] kgdb: x86: Detach gdb if machine shuts down or reboots
Quoted 11 lines · Sergei Shtylyov
Hello.
Quoted 7 lines · Jason Wessel
Quoted 2 lines
An arch-independent hook has its advantages, no question. Maybe we should just start this way and then evolved on top as needed.
Sounds good to me. I added the reboot notifier patch into the merge queue for kgdb/kdb.
Quoted 4 lines
I was wondering why those other archs do not use the notifier. Maybe one motivation is to avoid that too much code is excluded from the debugger by detaching too early. Could possibly be addressed by making detach-on-reboot runtime configurable.
Quoted 8 lines
Quoted 7 lines
There really isn't a whole lot of code between reboot hook invoked from
kernel_restart_prepare(), and the place where the reset is invoked. Specifically it looked like:usermodehelper_disable(); device_shutdown(); syscore_shutdown(); machine_restart(cmd);Attached is the patch you asked for the conditional behavior with respect to the reboot hook.
You forgot to attach it?
Source Forge [kgdb mailling list] is eating attachments. I had definitely attached it. See:
https://lkml.org/lkml/2012/3/19/735
I also included this patch in the potential merge queue as patch 5 of 5, sent to the kgdb mailing list.
http://sourceforge.net/mailarchive/message.php?msg_id=29008292
Jason.
Jason.