Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for_linux-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb

Pull KGDB/KDB fixes and cleanups from Jason Wessel:
"For a change we removed more code than we added. If people aren't
using it we shouldn't be carrying it. :-)

Cleanups:
- Remove kdb ssb command - there is no in kernel disassembler to
support it

- Remove kdb ll command - Always caused a kernel oops and there were
no bug reports so no one was using this command

- Use kernel ARRAY_SIZE macro instead of array computations

Fixes:
- Stop oops in kdb if user executes kdb_defcmd with args

- kdb help command truncated text

- ppc64 support for kgdbts

- Add missing kconfig option from original kdb port for dealing with
catastrophic kernel crashes such that you can reboot automatically
on continue from kdb"

* tag 'for_linux-3.9' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/kgdb:
kdb: Remove unhandled ssb command
kdb: Prevent kernel oops with kdb_defcmd
kdb: Remove the ll command
kdb_main: fix help print
kdb: Fix overlap in buffers with strcpy
Fixed dead ifdef block by adding missing Kconfig option.
kdb: Setup basic kdb state before invoking commands via kgdb
kdb: use ARRAY_SIZE where possible
kgdb/kgdbts: support ppc64
kdb: A fix for kdb command table expansion

+82 -127
+2
drivers/misc/kgdbts.c
··· 103 103 #include <linux/delay.h> 104 104 #include <linux/kthread.h> 105 105 #include <linux/module.h> 106 + #include <asm/sections.h> 106 107 107 108 #define v1printk(a...) do { \ 108 109 if (verbose) \ ··· 223 222 addr = (unsigned long)do_fork; 224 223 else if (!strcmp(arg, "hw_break_val")) 225 224 addr = (unsigned long)&hw_break_val; 225 + addr = (unsigned long) dereference_function_descriptor((void *)addr); 226 226 return addr; 227 227 } 228 228
+2
kernel/debug/debug_core.h
··· 72 72 #ifdef CONFIG_KGDB_KDB 73 73 extern int kdb_stub(struct kgdb_state *ks); 74 74 extern int kdb_parse(const char *cmdstr); 75 + extern int kdb_common_init_state(struct kgdb_state *ks); 76 + extern int kdb_common_deinit_state(void); 75 77 #else /* ! CONFIG_KGDB_KDB */ 76 78 static inline int kdb_stub(struct kgdb_state *ks) 77 79 {
+3
kernel/debug/gdbstub.c
··· 783 783 len = len / 2; 784 784 remcom_out_buffer[len++] = 0; 785 785 786 + kdb_common_init_state(ks); 786 787 kdb_parse(remcom_out_buffer); 788 + kdb_common_deinit_state(); 789 + 787 790 strcpy(remcom_out_buffer, "OK"); 788 791 } 789 792 break;
+2 -18
kernel/debug/kdb/kdb_bp.c
··· 486 486 /* 487 487 * kdb_ss 488 488 * 489 - * Process the 'ss' (Single Step) and 'ssb' (Single Step to Branch) 490 - * commands. 489 + * Process the 'ss' (Single Step) command. 491 490 * 492 491 * ss 493 - * ssb 494 492 * 495 493 * Parameters: 496 494 * argc Argument count ··· 496 498 * Outputs: 497 499 * None. 498 500 * Returns: 499 - * KDB_CMD_SS[B] for success, a kdb error if failure. 501 + * KDB_CMD_SS for success, a kdb error if failure. 500 502 * Locking: 501 503 * None. 502 504 * Remarks: 503 505 * 504 506 * Set the arch specific option to trigger a debug trap after the next 505 507 * instruction. 506 - * 507 - * For 'ssb', set the trace flag in the debug trap handler 508 - * after printing the current insn and return directly without 509 - * invoking the kdb command processor, until a branch instruction 510 - * is encountered. 511 508 */ 512 509 513 510 static int kdb_ss(int argc, const char **argv) 514 511 { 515 - int ssb = 0; 516 - 517 - ssb = (strcmp(argv[0], "ssb") == 0); 518 512 if (argc != 0) 519 513 return KDB_ARGCOUNT; 520 514 /* 521 515 * Set trace flag and go. 522 516 */ 523 517 KDB_STATE_SET(DOING_SS); 524 - if (ssb) { 525 - KDB_STATE_SET(DOING_SSB); 526 - return KDB_CMD_SSB; 527 - } 528 518 return KDB_CMD_SS; 529 519 } 530 520 ··· 547 561 548 562 kdb_register_repeat("ss", kdb_ss, "", 549 563 "Single Step", 1, KDB_REPEAT_NO_ARGS); 550 - kdb_register_repeat("ssb", kdb_ss, "", 551 - "Single step to branch/call", 0, KDB_REPEAT_NO_ARGS); 552 564 /* 553 565 * Architecture dependent initialization. 554 566 */
+18 -7
kernel/debug/kdb/kdb_debugger.c
··· 34 34 35 35 static struct kgdb_state *kdb_ks; 36 36 37 + int kdb_common_init_state(struct kgdb_state *ks) 38 + { 39 + kdb_initial_cpu = atomic_read(&kgdb_active); 40 + kdb_current_task = kgdb_info[ks->cpu].task; 41 + kdb_current_regs = kgdb_info[ks->cpu].debuggerinfo; 42 + return 0; 43 + } 44 + 45 + int kdb_common_deinit_state(void) 46 + { 47 + kdb_initial_cpu = -1; 48 + kdb_current_task = NULL; 49 + kdb_current_regs = NULL; 50 + return 0; 51 + } 52 + 37 53 int kdb_stub(struct kgdb_state *ks) 38 54 { 39 55 int error = 0; ··· 110 94 } 111 95 /* Set initial kdb state variables */ 112 96 KDB_STATE_CLEAR(KGDB_TRANS); 113 - kdb_initial_cpu = atomic_read(&kgdb_active); 114 - kdb_current_task = kgdb_info[ks->cpu].task; 115 - kdb_current_regs = kgdb_info[ks->cpu].debuggerinfo; 97 + kdb_common_init_state(ks); 116 98 /* Remove any breakpoints as needed by kdb and clear single step */ 117 99 kdb_bp_remove(); 118 100 KDB_STATE_CLEAR(DOING_SS); 119 - KDB_STATE_CLEAR(DOING_SSB); 120 101 KDB_STATE_SET(PAGER); 121 102 /* zero out any offline cpu data */ 122 103 for_each_present_cpu(i) { ··· 138 125 * Upon exit from the kdb main loop setup break points and restart 139 126 * the system based on the requested continue state 140 127 */ 141 - kdb_initial_cpu = -1; 142 - kdb_current_task = NULL; 143 - kdb_current_regs = NULL; 128 + kdb_common_deinit_state(); 144 129 KDB_STATE_CLEAR(PAGER); 145 130 kdbnearsym_cleanup(); 146 131 if (error == KDB_CMD_KGDB) {
+37 -98
kernel/debug/kdb/kdb_main.c
··· 124 124 }; 125 125 #undef KDBMSG 126 126 127 - static const int __nkdb_err = sizeof(kdbmsgs) / sizeof(kdbmsg_t); 127 + static const int __nkdb_err = ARRAY_SIZE(kdbmsgs); 128 128 129 129 130 130 /* ··· 175 175 (char *)0, 176 176 }; 177 177 178 - static const int __nenv = (sizeof(__env) / sizeof(char *)); 178 + static const int __nenv = ARRAY_SIZE(__env); 179 179 180 180 struct task_struct *kdb_curr_task(int cpu) 181 181 { ··· 681 681 } 682 682 if (argc != 3) 683 683 return KDB_ARGCOUNT; 684 - defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set), 685 - GFP_KDB); 686 - if (!defcmd_set) { 687 - kdb_printf("Could not allocate new defcmd_set entry for %s\n", 688 - argv[1]); 689 - defcmd_set = save_defcmd_set; 684 + if (in_dbg_master()) { 685 + kdb_printf("Command only available during kdb_init()\n"); 690 686 return KDB_NOTIMP; 691 687 } 688 + defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set), 689 + GFP_KDB); 690 + if (!defcmd_set) 691 + goto fail_defcmd; 692 692 memcpy(defcmd_set, save_defcmd_set, 693 693 defcmd_set_count * sizeof(*defcmd_set)); 694 - kfree(save_defcmd_set); 695 694 s = defcmd_set + defcmd_set_count; 696 695 memset(s, 0, sizeof(*s)); 697 696 s->usable = 1; 698 697 s->name = kdb_strdup(argv[1], GFP_KDB); 698 + if (!s->name) 699 + goto fail_name; 699 700 s->usage = kdb_strdup(argv[2], GFP_KDB); 701 + if (!s->usage) 702 + goto fail_usage; 700 703 s->help = kdb_strdup(argv[3], GFP_KDB); 704 + if (!s->help) 705 + goto fail_help; 701 706 if (s->usage[0] == '"') { 702 - strcpy(s->usage, s->usage+1); 707 + strcpy(s->usage, argv[2]+1); 703 708 s->usage[strlen(s->usage)-1] = '\0'; 704 709 } 705 710 if (s->help[0] == '"') { 706 - strcpy(s->help, s->help+1); 711 + strcpy(s->help, argv[3]+1); 707 712 s->help[strlen(s->help)-1] = '\0'; 708 713 } 709 714 ++defcmd_set_count; 710 715 defcmd_in_progress = 1; 716 + kfree(save_defcmd_set); 711 717 return 0; 718 + fail_help: 719 + kfree(s->usage); 720 + fail_usage: 721 + kfree(s->name); 722 + fail_name: 723 + kfree(defcmd_set); 724 + fail_defcmd: 725 + kdb_printf("Could not allocate new defcmd_set entry for %s\n", argv[1]); 726 + defcmd_set = save_defcmd_set; 727 + return KDB_NOTIMP; 712 728 } 713 729 714 730 /* ··· 1128 1112 * KDB_CMD_GO User typed 'go'. 1129 1113 * KDB_CMD_CPU User switched to another cpu. 1130 1114 * KDB_CMD_SS Single step. 1131 - * KDB_CMD_SSB Single step until branch. 1132 1115 */ 1133 1116 static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, 1134 1117 kdb_dbtrap_t db_result) ··· 1165 1150 #endif 1166 1151 kdb_printf("due to Debug @ " kdb_machreg_fmt "\n", 1167 1152 instruction_pointer(regs)); 1168 - break; 1169 - case KDB_DB_SSB: 1170 - /* 1171 - * In the midst of ssb command. Just return. 1172 - */ 1173 - KDB_DEBUG_STATE("kdb_local 3", reason); 1174 - return KDB_CMD_SSB; /* Continue with SSB command */ 1175 - 1176 1153 break; 1177 1154 case KDB_DB_SS: 1178 1155 break; ··· 1288 1281 if (diag == KDB_CMD_GO 1289 1282 || diag == KDB_CMD_CPU 1290 1283 || diag == KDB_CMD_SS 1291 - || diag == KDB_CMD_SSB 1292 1284 || diag == KDB_CMD_KGDB) 1293 1285 break; 1294 1286 ··· 1371 1365 1372 1366 if (result == KDB_CMD_SS) { 1373 1367 KDB_STATE_SET(DOING_SS); 1374 - break; 1375 - } 1376 - 1377 - if (result == KDB_CMD_SSB) { 1378 - KDB_STATE_SET(DOING_SS); 1379 - KDB_STATE_SET(DOING_SSB); 1380 1368 break; 1381 1369 } 1382 1370 ··· 2350 2350 return 0; 2351 2351 } 2352 2352 2353 - /* 2354 - * kdb_ll - This function implements the 'll' command which follows a 2355 - * linked list and executes an arbitrary command for each 2356 - * element. 2357 - */ 2358 - static int kdb_ll(int argc, const char **argv) 2359 - { 2360 - int diag = 0; 2361 - unsigned long addr; 2362 - long offset = 0; 2363 - unsigned long va; 2364 - unsigned long linkoffset; 2365 - int nextarg; 2366 - const char *command; 2367 - 2368 - if (argc != 3) 2369 - return KDB_ARGCOUNT; 2370 - 2371 - nextarg = 1; 2372 - diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL); 2373 - if (diag) 2374 - return diag; 2375 - 2376 - diag = kdbgetularg(argv[2], &linkoffset); 2377 - if (diag) 2378 - return diag; 2379 - 2380 - /* 2381 - * Using the starting address as 2382 - * the first element in the list, and assuming that 2383 - * the list ends with a null pointer. 2384 - */ 2385 - 2386 - va = addr; 2387 - command = kdb_strdup(argv[3], GFP_KDB); 2388 - if (!command) { 2389 - kdb_printf("%s: cannot duplicate command\n", __func__); 2390 - return 0; 2391 - } 2392 - /* Recursive use of kdb_parse, do not use argv after this point */ 2393 - argv = NULL; 2394 - 2395 - while (va) { 2396 - char buf[80]; 2397 - 2398 - if (KDB_FLAG(CMD_INTERRUPT)) 2399 - goto out; 2400 - 2401 - sprintf(buf, "%s " kdb_machreg_fmt "\n", command, va); 2402 - diag = kdb_parse(buf); 2403 - if (diag) 2404 - goto out; 2405 - 2406 - addr = va + linkoffset; 2407 - if (kdb_getword(&va, addr, sizeof(va))) 2408 - goto out; 2409 - } 2410 - 2411 - out: 2412 - kfree(command); 2413 - return diag; 2414 - } 2415 - 2416 2353 static int kdb_kgdb(int argc, const char **argv) 2417 2354 { 2418 2355 return KDB_CMD_KGDB; ··· 2367 2430 kdb_printf("-----------------------------" 2368 2431 "-----------------------------\n"); 2369 2432 for_each_kdbcmd(kt, i) { 2370 - if (kt->cmd_name) 2371 - kdb_printf("%-15.15s %-20.20s %s\n", kt->cmd_name, 2372 - kt->cmd_usage, kt->cmd_help); 2433 + char *space = ""; 2373 2434 if (KDB_FLAG(CMD_INTERRUPT)) 2374 2435 return 0; 2436 + if (!kt->cmd_name) 2437 + continue; 2438 + if (strlen(kt->cmd_usage) > 20) 2439 + space = "\n "; 2440 + kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name, 2441 + kt->cmd_usage, space, kt->cmd_help); 2375 2442 } 2376 2443 return 0; 2377 2444 } ··· 2680 2739 (kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new)); 2681 2740 kfree(kdb_commands); 2682 2741 } 2683 - memset(new + kdb_max_commands, 0, 2742 + memset(new + kdb_max_commands - KDB_BASE_CMD_MAX, 0, 2684 2743 kdb_command_extend * sizeof(*new)); 2685 2744 kdb_commands = new; 2686 2745 kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX; ··· 2784 2843 "Stack traceback", 1, KDB_REPEAT_NONE); 2785 2844 kdb_register_repeat("btp", kdb_bt, "<pid>", 2786 2845 "Display stack for process <pid>", 0, KDB_REPEAT_NONE); 2787 - kdb_register_repeat("bta", kdb_bt, "[DRSTCZEUIMA]", 2788 - "Display stack all processes", 0, KDB_REPEAT_NONE); 2846 + kdb_register_repeat("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]", 2847 + "Backtrace all processes matching state flag", 0, KDB_REPEAT_NONE); 2789 2848 kdb_register_repeat("btc", kdb_bt, "", 2790 2849 "Backtrace current process on each cpu", 0, KDB_REPEAT_NONE); 2791 2850 kdb_register_repeat("btt", kdb_bt, "<vaddr>", 2792 2851 "Backtrace process given its struct task address", 0, 2793 2852 KDB_REPEAT_NONE); 2794 - kdb_register_repeat("ll", kdb_ll, "<first-element> <linkoffset> <cmd>", 2795 - "Execute cmd for each element in linked list", 0, KDB_REPEAT_NONE); 2796 2853 kdb_register_repeat("env", kdb_env, "", 2797 2854 "Show environment variables", 0, KDB_REPEAT_NONE); 2798 2855 kdb_register_repeat("set", kdb_set, "",
-4
kernel/debug/kdb/kdb_private.h
··· 19 19 #define KDB_CMD_GO (-1001) 20 20 #define KDB_CMD_CPU (-1002) 21 21 #define KDB_CMD_SS (-1003) 22 - #define KDB_CMD_SSB (-1004) 23 22 #define KDB_CMD_KGDB (-1005) 24 23 25 24 /* Internal debug flags */ ··· 124 125 * kdb control */ 125 126 #define KDB_STATE_HOLD_CPU 0x00000010 /* Hold this cpu inside kdb */ 126 127 #define KDB_STATE_DOING_SS 0x00000020 /* Doing ss command */ 127 - #define KDB_STATE_DOING_SSB 0x00000040 /* Doing ssb command, 128 - * DOING_SS is also set */ 129 128 #define KDB_STATE_SSBPT 0x00000080 /* Install breakpoint 130 129 * after one ss, independent of 131 130 * DOING_SS */ ··· 188 191 typedef enum { 189 192 KDB_DB_BPT, /* Breakpoint */ 190 193 KDB_DB_SS, /* Single-step trap */ 191 - KDB_DB_SSB, /* Single step to branch */ 192 194 KDB_DB_SSBPT, /* Single step over breakpoint */ 193 195 KDB_DB_NOBPT /* Spurious breakpoint */ 194 196 } kdb_dbtrap_t;
+18
lib/Kconfig.kgdb
··· 80 80 help 81 81 KDB can use a PS/2 type keyboard for an input device 82 82 83 + config KDB_CONTINUE_CATASTROPHIC 84 + int "KDB: continue after catastrophic errors" 85 + depends on KGDB_KDB 86 + default "0" 87 + help 88 + This integer controls the behaviour of kdb when the kernel gets a 89 + catastrophic error, i.e. for a panic or oops. 90 + When KDB is active and a catastrophic error occurs, nothing extra 91 + will happen until you type 'go'. 92 + CONFIG_KDB_CONTINUE_CATASTROPHIC == 0 (default). The first time 93 + you type 'go', you will be warned by kdb. The secend time you type 94 + 'go', KDB tries to continue. No guarantees that the 95 + kernel is still usable in this situation. 96 + CONFIG_KDB_CONTINUE_CATASTROPHIC == 1. KDB tries to continue. 97 + No guarantees that the kernel is still usable in this situation. 98 + CONFIG_KDB_CONTINUE_CATASTROPHIC == 2. KDB forces a reboot. 99 + If you are not sure, say 0. 100 + 83 101 endif # KGDB