Skip to content

Commit

Permalink
kdb,debug_core: Allow the debug core to receive a panic notification
Browse files Browse the repository at this point in the history
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 <[email protected]>
CC: Andrew Morton <[email protected]>
CC: Eric W. Biederman <[email protected]>
Signed-off-by: Jason Wessel <[email protected]>
  • Loading branch information
jwessel committed May 21, 2010
1 parent 5b778da commit 4402c15
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kernel/debug/debug_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,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
Expand All @@ -786,6 +803,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);
Expand Down

0 comments on commit 4402c15

Please sign in to comment.