37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/ptrace.h>
40 #include <linux/string.h>
42 #include <linux/sched.h>
44 #include <linux/reboot.h>
53 #include <asm/cacheflush.h>
54 #include <asm/byteorder.h>
59 static int kgdb_break_asap;
73 static int exception_level;
79 static int kgdbreboot;
81 static int kgdb_con_registered;
83 static int kgdb_use_con;
107 static struct kgdb_bkpt kgdb_break[KGDB_MAX_BREAKPOINTS] = {
108 [0 ... KGDB_MAX_BREAKPOINTS-1] = { .state = BP_UNDEFINED }
125 static atomic_t kgdb_break_tasklet_var;
132 static pid_t kgdb_sstep_pid;
144 static int kgdb_do_roundup = 1;
146 static int __init opt_nokgdbroundup(
char *
str)
184 struct kgdb_bkpt tmp;
198 "memory destroyed at: %lx", addr);
221 static void kgdb_flush_swbreak_addr(
unsigned long addr)
243 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
244 if (kgdb_break[i].
state != BP_SET)
251 kgdb_break[i].bpt_addr);
255 kgdb_flush_swbreak_addr(kgdb_break[i].bpt_addr);
256 kgdb_break[
i].state = BP_ACTIVE;
270 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
271 if ((kgdb_break[i].
state == BP_SET) &&
272 (kgdb_break[i].bpt_addr == addr))
275 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
276 if (kgdb_break[i].
state == BP_REMOVED &&
277 kgdb_break[i].bpt_addr == addr) {
284 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
285 if (kgdb_break[i].
state == BP_UNDEFINED) {
295 kgdb_break[breakno].state = BP_SET;
296 kgdb_break[breakno].type = BP_BREAKPOINT;
297 kgdb_break[breakno].bpt_addr =
addr;
308 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
309 if (kgdb_break[i].
state != BP_ACTIVE)
314 kgdb_break[i].bpt_addr);
318 kgdb_flush_swbreak_addr(kgdb_break[i].bpt_addr);
319 kgdb_break[
i].state = BP_SET;
328 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
329 if ((kgdb_break[i].
state == BP_SET) &&
330 (kgdb_break[i].bpt_addr == addr)) {
331 kgdb_break[
i].state = BP_REMOVED;
342 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
343 if ((kgdb_break[i].
state == BP_REMOVED) &&
344 (kgdb_break[i].bpt_addr == addr))
356 for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
357 if (kgdb_break[i].
state != BP_ACTIVE)
362 kgdb_break[i].bpt_addr);
364 kgdb_break[
i].state = BP_UNDEFINED;
383 static int kgdb_io_ready(
int print_wait)
392 #ifdef CONFIG_KGDB_KDB
433 if (exception_level > 1) {
435 panic(
"Recursive entry to debugger");
438 printk(
KERN_CRIT "KGDB: re-enter exception: ALL breakpoints killed\n");
439 #ifdef CONFIG_KGDB_KDB
444 panic(
"Recursive entry to debugger");
449 static void dbg_touch_watchdogs(
void)
460 int sstep_tries = 100;
493 if (exception_level == 1) {
496 goto cpu_master_loop;
507 goto cpu_master_loop;
530 dbg_touch_watchdogs();
543 if (
atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
545 kgdb_info[cpu].
task->pid != kgdb_sstep_pid) && --sstep_tries) {
548 dbg_touch_watchdogs();
554 if (!kgdb_io_ready(1)) {
585 while (kgdb_do_roundup && (
atomic_read(&masters_in_kgdb) +
632 while (kgdb_do_roundup &&
atomic_read(&slaves_in_kgdb))
637 if (
atomic_read(&kgdb_cpu_doing_single_step) != -1) {
638 int sstep_cpu =
atomic_read(&kgdb_cpu_doing_single_step);
640 kgdb_sstep_pid =
kgdb_info[sstep_cpu].task->pid;
657 dbg_touch_watchdogs();
687 if (kgdb_reenter_check(ks))
692 ret = kgdb_cpu_enter(ks, regs, DCPU_WANT_MASTER);
712 .notifier_call = module_event,
727 kgdb_cpu_enter(ks, regs, DCPU_IS_SLAVE);
734 static void kgdb_console_write(
struct console *co,
const char *
s,
749 static struct console kgdbcons = {
751 .write = kgdb_console_write,
756 #ifdef CONFIG_MAGIC_SYSRQ
757 static void sysrq_handle_dbg(
int key)
764 #ifdef CONFIG_KGDB_KDB
777 .help_msg =
"debug(G)",
778 .action_msg =
"DEBUG",
793 .notifier_call = kgdb_panic_event,
818 switch (kgdbreboot) {
831 .notifier_call = dbg_notify_reboot,
836 static void kgdb_register_callbacks(
void)
846 &kgdb_panic_event_nb);
847 #ifdef CONFIG_MAGIC_SYSRQ
850 if (kgdb_use_con && !kgdb_con_registered) {
852 kgdb_con_registered = 1;
857 static void kgdb_unregister_callbacks(
void)
869 &kgdb_panic_event_nb);
871 #ifdef CONFIG_MAGIC_SYSRQ
874 if (kgdb_con_registered) {
876 kgdb_con_registered = 0;
887 static void kgdb_tasklet_bpt(
unsigned long ing)
902 tasklet_schedule(&kgdb_tasklet_breakpoint);
906 static void kgdb_initial_breakpoint(
void)
924 spin_lock(&kgdb_registration_lock);
927 spin_unlock(&kgdb_registration_lock);
930 "registered with KGDB.\n");
934 if (new_dbg_io_ops->init) {
935 err = new_dbg_io_ops->init();
937 spin_unlock(&kgdb_registration_lock);
944 spin_unlock(&kgdb_registration_lock);
947 new_dbg_io_ops->name);
950 kgdb_register_callbacks();
953 kgdb_initial_breakpoint();
973 kgdb_unregister_callbacks();
975 spin_lock(&kgdb_registration_lock);
980 spin_unlock(&kgdb_registration_lock);
983 "kgdb: Unregistered I/O driver %s, debugger disabled.\n",
984 old_dbg_io_ops->name);
1018 static int __init opt_kgdb_wait(
char *
str)
1020 kgdb_break_asap = 1;
1024 kgdb_initial_breakpoint();