Skip to content

Commit 4402c15

Browse files
committed
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. CC: Ingo Molnar <mingo@elte.hu> CC: Andrew Morton <akpm@linux-foundation.org> CC: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
1 parent 5b778da commit 4402c15

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

kernel/debug/debug_core.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,28 @@ static struct sysrq_key_op sysrq_dbg_op = {
762762
};
763763
#endif
764764

765+
static int kgdb_panic_event(struct notifier_block *self,
766+
unsigned long val,
767+
void *data)
768+
{
769+
if (dbg_kdb_mode)
770+
kdb_printf("PANIC: %s\n", (char *)data);
771+
kgdb_breakpoint();
772+
return NOTIFY_DONE;
773+
}
774+
775+
static struct notifier_block kgdb_panic_event_nb = {
776+
.notifier_call = kgdb_panic_event,
777+
.priority = INT_MAX,
778+
};
779+
765780
static void kgdb_register_callbacks(void)
766781
{
767782
if (!kgdb_io_module_registered) {
768783
kgdb_io_module_registered = 1;
769784
kgdb_arch_init();
785+
atomic_notifier_chain_register(&panic_notifier_list,
786+
&kgdb_panic_event_nb);
770787
#ifdef CONFIG_MAGIC_SYSRQ
771788
register_sysrq_key('g', &sysrq_dbg_op);
772789
#endif
@@ -786,6 +803,8 @@ static void kgdb_unregister_callbacks(void)
786803
*/
787804
if (kgdb_io_module_registered) {
788805
kgdb_io_module_registered = 0;
806+
atomic_notifier_chain_unregister(&panic_notifier_list,
807+
&kgdb_panic_event_nb);
789808
kgdb_arch_exit();
790809
#ifdef CONFIG_MAGIC_SYSRQ
791810
unregister_sysrq_key('g', &sysrq_dbg_op);

0 commit comments

Comments
 (0)