Skip to content

Commit bec4d62

Browse files
committed
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 Reported-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent 8f30d41 commit bec4d62

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎Documentation/DocBook/kgdb.tmpl‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,23 @@
361361
<para>It is possible to use this option with kgdboc on a tty that is not a system console.
362362
</para>
363363
</para>
364+
</sect1>
365+
<sect1 id="kgdbreboot">
366+
<title>Run time parameter: kgdbreboot</title>
367+
<para> The kgdbreboot feature allows you to change how the debugger
368+
deals with the reboot notification. You have 3 choices for the
369+
behavior. The default behavior is always set to 0.</para>
370+
<orderedlist>
371+
<listitem><para>echo -1 > /sys/module/debug_core/parameters/kgdbreboot</para>
372+
<para>Ignore the reboot notification entirely.</para>
373+
</listitem>
374+
<listitem><para>echo 0 > /sys/module/debug_core/parameters/kgdbreboot</para>
375+
<para>Send the detach message to any attached debugger client.</para>
376+
</listitem>
377+
<listitem><para>echo 1 > /sys/module/debug_core/parameters/kgdbreboot</para>
378+
<para>Enter the debugger on reboot notify.</para>
379+
</listitem>
380+
</orderedlist>
364381
</sect1>
365382
</chapter>
366383
<chapter id="usingKDB">

‎kernel/debug/debug_core.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ static int exception_level;
7676
struct kgdb_io *dbg_io_ops;
7777
static DEFINE_SPINLOCK(kgdb_registration_lock);
7878

79+
/* Action for the reboot notifiter, a global allow kdb to change it */
80+
static int kgdbreboot;
7981
/* kgdb console driver is loaded */
8082
static int kgdb_con_registered;
8183
/* determine if kgdb console output should be used */
@@ -97,6 +99,7 @@ static int __init opt_kgdb_con(char *str)
9799
early_param("kgdbcon", opt_kgdb_con);
98100

99101
module_param(kgdb_use_con, int, 0644);
102+
module_param(kgdbreboot, int, 0644);
100103

101104
/*
102105
* Holds information about breakpoints in a kernel. These breakpoints are
@@ -788,8 +791,21 @@ void __init dbg_late_init(void)
788791
static int
789792
dbg_notify_reboot(struct notifier_block *this, unsigned long code, void *x)
790793
{
794+
/*
795+
* Take the following action on reboot notify depending on value:
796+
* 1 == Enter debugger
797+
* 0 == [the default] detatch debug client
798+
* -1 == Do nothing... and use this until the board resets
799+
*/
800+
switch (kgdbreboot) {
801+
case 1:
802+
kgdb_breakpoint();
803+
case -1:
804+
goto done;
805+
}
791806
if (!dbg_kdb_mode)
792807
gdbstub_exit(code);
808+
done:
793809
return NOTIFY_DONE;
794810
}
795811

0 commit comments

Comments
 (0)