diff options
Diffstat (limited to 'kernel/debug')
| -rw-r--r-- | kernel/debug/debug_core.c | 34 | ||||
| -rw-r--r-- | kernel/debug/gdbstub.c | 10 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_bp.c | 7 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_bt.c | 1 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_io.c | 2 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_keyboard.c | 95 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_main.c | 3 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_private.h | 7 | ||||
| -rw-r--r-- | kernel/debug/kdb/kdb_support.c | 4 |
9 files changed, 135 insertions, 28 deletions
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 0d7c08784efb..1dc53bae56e1 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
| 42 | #include <linux/sched.h> | 42 | #include <linux/sched.h> |
| 43 | #include <linux/sysrq.h> | 43 | #include <linux/sysrq.h> |
| 44 | #include <linux/reboot.h> | ||
| 44 | #include <linux/init.h> | 45 | #include <linux/init.h> |
| 45 | #include <linux/kgdb.h> | 46 | #include <linux/kgdb.h> |
| 46 | #include <linux/kdb.h> | 47 | #include <linux/kdb.h> |
| @@ -52,7 +53,6 @@ | |||
| 52 | #include <asm/cacheflush.h> | 53 | #include <asm/cacheflush.h> |
| 53 | #include <asm/byteorder.h> | 54 | #include <asm/byteorder.h> |
| 54 | #include <linux/atomic.h> | 55 | #include <linux/atomic.h> |
| 55 | #include <asm/system.h> | ||
| 56 | 56 | ||
| 57 | #include "debug_core.h" | 57 | #include "debug_core.h" |
| 58 | 58 | ||
| @@ -75,6 +75,8 @@ static int exception_level; | |||
| 75 | struct kgdb_io *dbg_io_ops; | 75 | struct kgdb_io *dbg_io_ops; |
| 76 | static DEFINE_SPINLOCK(kgdb_registration_lock); | 76 | static DEFINE_SPINLOCK(kgdb_registration_lock); |
| 77 | 77 | ||
| 78 | /* Action for the reboot notifiter, a global allow kdb to change it */ | ||
| 79 | static int kgdbreboot; | ||
| 78 | /* kgdb console driver is loaded */ | 80 | /* kgdb console driver is loaded */ |
| 79 | static int kgdb_con_registered; | 81 | static int kgdb_con_registered; |
| 80 | /* determine if kgdb console output should be used */ | 82 | /* determine if kgdb console output should be used */ |
| @@ -96,6 +98,7 @@ static int __init opt_kgdb_con(char *str) | |||
| 96 | early_param("kgdbcon", opt_kgdb_con); | 98 | early_param("kgdbcon", opt_kgdb_con); |
| 97 | 99 | ||
| 98 | module_param(kgdb_use_con, int, 0644); | 100 | module_param(kgdb_use_con, int, 0644); |
| 101 | module_param(kgdbreboot, int, 0644); | ||
| 99 | 102 | ||
| 100 | /* | 103 | /* |
| 101 | * Holds information about breakpoints in a kernel. These breakpoints are | 104 | * Holds information about breakpoints in a kernel. These breakpoints are |
| @@ -784,6 +787,33 @@ void __init dbg_late_init(void) | |||
| 784 | kdb_init(KDB_INIT_FULL); | 787 | kdb_init(KDB_INIT_FULL); |
| 785 | } | 788 | } |
| 786 | 789 | ||
| 790 | static int | ||
| 791 | dbg_notify_reboot(struct notifier_block *this, unsigned long code, void *x) | ||
| 792 | { | ||
| 793 | /* | ||
| 794 | * Take the following action on reboot notify depending on value: | ||
| 795 | * 1 == Enter debugger | ||
| 796 | * 0 == [the default] detatch debug client | ||
| 797 | * -1 == Do nothing... and use this until the board resets | ||
| 798 | */ | ||
| 799 | switch (kgdbreboot) { | ||
| 800 | case 1: | ||
| 801 | kgdb_breakpoint(); | ||
| 802 | case -1: | ||
| 803 | goto done; | ||
| 804 | } | ||
| 805 | if (!dbg_kdb_mode) | ||
| 806 | gdbstub_exit(code); | ||
| 807 | done: | ||
| 808 | return NOTIFY_DONE; | ||
| 809 | } | ||
| 810 | |||
| 811 | static struct notifier_block dbg_reboot_notifier = { | ||
| 812 | .notifier_call = dbg_notify_reboot, | ||
| 813 | .next = NULL, | ||
| 814 | .priority = INT_MAX, | ||
| 815 | }; | ||
| 816 | |||
| 787 | static void kgdb_register_callbacks(void) | 817 | static void kgdb_register_callbacks(void) |
| 788 | { | 818 | { |
| 789 | if (!kgdb_io_module_registered) { | 819 | if (!kgdb_io_module_registered) { |
| @@ -791,6 +821,7 @@ static void kgdb_register_callbacks(void) | |||
| 791 | kgdb_arch_init(); | 821 | kgdb_arch_init(); |
| 792 | if (!dbg_is_early) | 822 | if (!dbg_is_early) |
| 793 | kgdb_arch_late(); | 823 | kgdb_arch_late(); |
| 824 | register_reboot_notifier(&dbg_reboot_notifier); | ||
| 794 | atomic_notifier_chain_register(&panic_notifier_list, | 825 | atomic_notifier_chain_register(&panic_notifier_list, |
| 795 | &kgdb_panic_event_nb); | 826 | &kgdb_panic_event_nb); |
| 796 | #ifdef CONFIG_MAGIC_SYSRQ | 827 | #ifdef CONFIG_MAGIC_SYSRQ |
| @@ -812,6 +843,7 @@ static void kgdb_unregister_callbacks(void) | |||
| 812 | */ | 843 | */ |
| 813 | if (kgdb_io_module_registered) { | 844 | if (kgdb_io_module_registered) { |
| 814 | kgdb_io_module_registered = 0; | 845 | kgdb_io_module_registered = 0; |
| 846 | unregister_reboot_notifier(&dbg_reboot_notifier); | ||
| 815 | atomic_notifier_chain_unregister(&panic_notifier_list, | 847 | atomic_notifier_chain_unregister(&panic_notifier_list, |
| 816 | &kgdb_panic_event_nb); | 848 | &kgdb_panic_event_nb); |
| 817 | kgdb_arch_exit(); | 849 | kgdb_arch_exit(); |
diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index c22d8c28ad84..ce615e064482 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c | |||
| @@ -1111,6 +1111,13 @@ void gdbstub_exit(int status) | |||
| 1111 | unsigned char checksum, ch, buffer[3]; | 1111 | unsigned char checksum, ch, buffer[3]; |
| 1112 | int loop; | 1112 | int loop; |
| 1113 | 1113 | ||
| 1114 | if (!kgdb_connected) | ||
| 1115 | return; | ||
| 1116 | kgdb_connected = 0; | ||
| 1117 | |||
| 1118 | if (!dbg_io_ops || dbg_kdb_mode) | ||
| 1119 | return; | ||
| 1120 | |||
| 1114 | buffer[0] = 'W'; | 1121 | buffer[0] = 'W'; |
| 1115 | buffer[1] = hex_asc_hi(status); | 1122 | buffer[1] = hex_asc_hi(status); |
| 1116 | buffer[2] = hex_asc_lo(status); | 1123 | buffer[2] = hex_asc_lo(status); |
| @@ -1129,5 +1136,6 @@ void gdbstub_exit(int status) | |||
| 1129 | dbg_io_ops->write_char(hex_asc_lo(checksum)); | 1136 | dbg_io_ops->write_char(hex_asc_lo(checksum)); |
| 1130 | 1137 | ||
| 1131 | /* make sure the output is flushed, lest the bootloader clobber it */ | 1138 | /* make sure the output is flushed, lest the bootloader clobber it */ |
| 1132 | dbg_io_ops->flush(); | 1139 | if (dbg_io_ops->flush) |
| 1140 | dbg_io_ops->flush(); | ||
| 1133 | } | 1141 | } |
diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c index 20059ef4459a..8418c2f8ec5d 100644 --- a/kernel/debug/kdb/kdb_bp.c +++ b/kernel/debug/kdb/kdb_bp.c | |||
| @@ -153,6 +153,13 @@ static int _kdb_bp_install(struct pt_regs *regs, kdb_bp_t *bp) | |||
| 153 | } else { | 153 | } else { |
| 154 | kdb_printf("%s: failed to set breakpoint at 0x%lx\n", | 154 | kdb_printf("%s: failed to set breakpoint at 0x%lx\n", |
| 155 | __func__, bp->bp_addr); | 155 | __func__, bp->bp_addr); |
| 156 | #ifdef CONFIG_DEBUG_RODATA | ||
| 157 | if (!bp->bp_type) { | ||
| 158 | kdb_printf("Software breakpoints are unavailable.\n" | ||
| 159 | " Change the kernel CONFIG_DEBUG_RODATA=n\n" | ||
| 160 | " OR use hw breaks: help bph\n"); | ||
| 161 | } | ||
| 162 | #endif | ||
| 156 | return 1; | 163 | return 1; |
| 157 | } | 164 | } |
| 158 | return 0; | 165 | return 0; |
diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c index 7179eac7b41c..07c9bbb94a0b 100644 --- a/kernel/debug/kdb/kdb_bt.c +++ b/kernel/debug/kdb/kdb_bt.c | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | #include <linux/sched.h> | 15 | #include <linux/sched.h> |
| 16 | #include <linux/kdb.h> | 16 | #include <linux/kdb.h> |
| 17 | #include <linux/nmi.h> | 17 | #include <linux/nmi.h> |
| 18 | #include <asm/system.h> | ||
| 19 | #include "kdb_private.h" | 18 | #include "kdb_private.h" |
| 20 | 19 | ||
| 21 | 20 | ||
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 4802eb5840e1..9b5f17da1c56 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c | |||
| @@ -689,7 +689,7 @@ kdb_printit: | |||
| 689 | if (!dbg_kdb_mode && kgdb_connected) { | 689 | if (!dbg_kdb_mode && kgdb_connected) { |
| 690 | gdbstub_msg_write(kdb_buffer, retlen); | 690 | gdbstub_msg_write(kdb_buffer, retlen); |
| 691 | } else { | 691 | } else { |
| 692 | if (!dbg_io_ops->is_console) { | 692 | if (dbg_io_ops && !dbg_io_ops->is_console) { |
| 693 | len = strlen(kdb_buffer); | 693 | len = strlen(kdb_buffer); |
| 694 | cp = kdb_buffer; | 694 | cp = kdb_buffer; |
| 695 | while (len--) { | 695 | while (len--) { |
diff --git a/kernel/debug/kdb/kdb_keyboard.c b/kernel/debug/kdb/kdb_keyboard.c index 4bca634975c0..118527aa60ea 100644 --- a/kernel/debug/kdb/kdb_keyboard.c +++ b/kernel/debug/kdb/kdb_keyboard.c | |||
| @@ -25,6 +25,7 @@ | |||
| 25 | #define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */ | 25 | #define KBD_STAT_MOUSE_OBF 0x20 /* Mouse output buffer full */ |
| 26 | 26 | ||
| 27 | static int kbd_exists; | 27 | static int kbd_exists; |
| 28 | static int kbd_last_ret; | ||
| 28 | 29 | ||
| 29 | /* | 30 | /* |
| 30 | * Check if the keyboard controller has a keypress for us. | 31 | * Check if the keyboard controller has a keypress for us. |
| @@ -90,8 +91,11 @@ int kdb_get_kbd_char(void) | |||
| 90 | return -1; | 91 | return -1; |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 93 | if ((scancode & 0x80) != 0) | 94 | if ((scancode & 0x80) != 0) { |
| 95 | if (scancode == 0x9c) | ||
| 96 | kbd_last_ret = 0; | ||
| 94 | return -1; | 97 | return -1; |
| 98 | } | ||
| 95 | 99 | ||
| 96 | scancode &= 0x7f; | 100 | scancode &= 0x7f; |
| 97 | 101 | ||
| @@ -178,35 +182,82 @@ int kdb_get_kbd_char(void) | |||
| 178 | return -1; /* ignore unprintables */ | 182 | return -1; /* ignore unprintables */ |
| 179 | } | 183 | } |
| 180 | 184 | ||
| 181 | if ((scancode & 0x7f) == 0x1c) { | 185 | if (scancode == 0x1c) { |
| 182 | /* | 186 | kbd_last_ret = 1; |
| 183 | * enter key. All done. Absorb the release scancode. | 187 | return 13; |
| 184 | */ | 188 | } |
| 189 | |||
| 190 | return keychar & 0xff; | ||
| 191 | } | ||
| 192 | EXPORT_SYMBOL_GPL(kdb_get_kbd_char); | ||
| 193 | |||
| 194 | /* | ||
| 195 | * Best effort cleanup of ENTER break codes on leaving KDB. Called on | ||
| 196 | * exiting KDB, when we know we processed an ENTER or KP ENTER scan | ||
| 197 | * code. | ||
| 198 | */ | ||
| 199 | void kdb_kbd_cleanup_state(void) | ||
| 200 | { | ||
| 201 | int scancode, scanstatus; | ||
| 202 | |||
| 203 | /* | ||
| 204 | * Nothing to clean up, since either | ||
| 205 | * ENTER was never pressed, or has already | ||
| 206 | * gotten cleaned up. | ||
| 207 | */ | ||
| 208 | if (!kbd_last_ret) | ||
| 209 | return; | ||
| 210 | |||
| 211 | kbd_last_ret = 0; | ||
| 212 | /* | ||
| 213 | * Enter key. Need to absorb the break code here, lest it gets | ||
| 214 | * leaked out if we exit KDB as the result of processing 'g'. | ||
| 215 | * | ||
| 216 | * This has several interesting implications: | ||
| 217 | * + Need to handle KP ENTER, which has break code 0xe0 0x9c. | ||
| 218 | * + Need to handle repeat ENTER and repeat KP ENTER. Repeats | ||
| 219 | * only get a break code at the end of the repeated | ||
| 220 | * sequence. This means we can't propagate the repeated key | ||
| 221 | * press, and must swallow it away. | ||
| 222 | * + Need to handle possible PS/2 mouse input. | ||
| 223 | * + Need to handle mashed keys. | ||
| 224 | */ | ||
| 225 | |||
| 226 | while (1) { | ||
| 185 | while ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) | 227 | while ((inb(KBD_STATUS_REG) & KBD_STAT_OBF) == 0) |
| 186 | ; | 228 | cpu_relax(); |
| 187 | 229 | ||
| 188 | /* | 230 | /* |
| 189 | * Fetch the scancode | 231 | * Fetch the scancode. |
| 190 | */ | 232 | */ |
| 191 | scancode = inb(KBD_DATA_REG); | 233 | scancode = inb(KBD_DATA_REG); |
| 192 | scanstatus = inb(KBD_STATUS_REG); | 234 | scanstatus = inb(KBD_STATUS_REG); |
| 193 | 235 | ||
| 194 | while (scanstatus & KBD_STAT_MOUSE_OBF) { | 236 | /* |
| 195 | scancode = inb(KBD_DATA_REG); | 237 | * Skip mouse input. |
| 196 | scanstatus = inb(KBD_STATUS_REG); | 238 | */ |
| 197 | } | 239 | if (scanstatus & KBD_STAT_MOUSE_OBF) |
| 240 | continue; | ||
| 198 | 241 | ||
| 199 | if (scancode != 0x9c) { | 242 | /* |
| 200 | /* | 243 | * If we see 0xe0, this is either a break code for KP |
| 201 | * Wasn't an enter-release, why not? | 244 | * ENTER, or a repeat make for KP ENTER. Either way, |
| 202 | */ | 245 | * since the second byte is equivalent to an ENTER, |
| 203 | kdb_printf("kdb: expected enter got 0x%x status 0x%x\n", | 246 | * skip the 0xe0 and try again. |
| 204 | scancode, scanstatus); | 247 | * |
| 205 | } | 248 | * If we see 0x1c, this must be a repeat ENTER or KP |
| 249 | * ENTER (and we swallowed 0xe0 before). Try again. | ||
| 250 | * | ||
| 251 | * We can also see make and break codes for other keys | ||
| 252 | * mashed before or after pressing ENTER. Thus, if we | ||
| 253 | * see anything other than 0x9c, we have to try again. | ||
| 254 | * | ||
| 255 | * Note, if you held some key as ENTER was depressed, | ||
| 256 | * that break code would get leaked out. | ||
| 257 | */ | ||
| 258 | if (scancode != 0x9c) | ||
| 259 | continue; | ||
| 206 | 260 | ||
| 207 | return 13; | 261 | return; |
| 208 | } | 262 | } |
| 209 | |||
| 210 | return keychar & 0xff; | ||
| 211 | } | 263 | } |
| 212 | EXPORT_SYMBOL_GPL(kdb_get_kbd_char); | ||
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index e2ae7349437f..67b847dfa2bb 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c | |||
| @@ -1400,6 +1400,9 @@ int kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error, | |||
| 1400 | if (KDB_STATE(DOING_SS)) | 1400 | if (KDB_STATE(DOING_SS)) |
| 1401 | KDB_STATE_CLEAR(SSBPT); | 1401 | KDB_STATE_CLEAR(SSBPT); |
| 1402 | 1402 | ||
| 1403 | /* Clean up any keyboard devices before leaving */ | ||
| 1404 | kdb_kbd_cleanup_state(); | ||
| 1405 | |||
| 1403 | return result; | 1406 | return result; |
| 1404 | } | 1407 | } |
| 1405 | 1408 | ||
diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h index e381d105b40b..47c4e56e513b 100644 --- a/kernel/debug/kdb/kdb_private.h +++ b/kernel/debug/kdb/kdb_private.h | |||
| @@ -246,6 +246,13 @@ extern void debug_kusage(void); | |||
| 246 | 246 | ||
| 247 | extern void kdb_set_current_task(struct task_struct *); | 247 | extern void kdb_set_current_task(struct task_struct *); |
| 248 | extern struct task_struct *kdb_current_task; | 248 | extern struct task_struct *kdb_current_task; |
| 249 | |||
| 250 | #ifdef CONFIG_KDB_KEYBOARD | ||
| 251 | extern void kdb_kbd_cleanup_state(void); | ||
| 252 | #else /* ! CONFIG_KDB_KEYBOARD */ | ||
| 253 | #define kdb_kbd_cleanup_state() | ||
| 254 | #endif /* ! CONFIG_KDB_KEYBOARD */ | ||
| 255 | |||
| 249 | #ifdef CONFIG_MODULES | 256 | #ifdef CONFIG_MODULES |
| 250 | extern struct list_head *kdb_modules; | 257 | extern struct list_head *kdb_modules; |
| 251 | #endif /* CONFIG_MODULES */ | 258 | #endif /* CONFIG_MODULES */ |
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c index 7d6fb40d2188..d35cc2d3a4cc 100644 --- a/kernel/debug/kdb/kdb_support.c +++ b/kernel/debug/kdb/kdb_support.c | |||
| @@ -384,9 +384,9 @@ static int kdb_getphys(void *res, unsigned long addr, size_t size) | |||
| 384 | if (!pfn_valid(pfn)) | 384 | if (!pfn_valid(pfn)) |
| 385 | return 1; | 385 | return 1; |
| 386 | page = pfn_to_page(pfn); | 386 | page = pfn_to_page(pfn); |
| 387 | vaddr = kmap_atomic(page, KM_KDB); | 387 | vaddr = kmap_atomic(page); |
| 388 | memcpy(res, vaddr + (addr & (PAGE_SIZE - 1)), size); | 388 | memcpy(res, vaddr + (addr & (PAGE_SIZE - 1)), size); |
| 389 | kunmap_atomic(vaddr, KM_KDB); | 389 | kunmap_atomic(vaddr); |
| 390 | 390 | ||
| 391 | return 0; | 391 | return 0; |
| 392 | } | 392 | } |
