Skip to content

Commit 3cfb077

Browse files
committed
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
2 parents e23b622 + 36dfea4 commit 3cfb077

8 files changed

Lines changed: 82 additions & 127 deletions

File tree

‎drivers/misc/kgdbts.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
#include <linux/delay.h>
104104
#include <linux/kthread.h>
105105
#include <linux/module.h>
106+
#include <asm/sections.h>
106107

107108
#define v1printk(a...) do { \
108109
if (verbose) \
@@ -222,6 +223,7 @@ static unsigned long lookup_addr(char *arg)
222223
addr = (unsigned long)do_fork;
223224
else if (!strcmp(arg, "hw_break_val"))
224225
addr = (unsigned long)&hw_break_val;
226+
addr = (unsigned long) dereference_function_descriptor((void *)addr);
225227
return addr;
226228
}
227229

‎kernel/debug/debug_core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ extern int dbg_kdb_mode;
7272
#ifdef CONFIG_KGDB_KDB
7373
extern int kdb_stub(struct kgdb_state *ks);
7474
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);
7577
#else /* ! CONFIG_KGDB_KDB */
7678
static inline int kdb_stub(struct kgdb_state *ks)
7779
{

‎kernel/debug/gdbstub.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,10 @@ static void gdb_cmd_query(struct kgdb_state *ks)
783783
len = len / 2;
784784
remcom_out_buffer[len++] = 0;
785785

786+
kdb_common_init_state(ks);
786787
kdb_parse(remcom_out_buffer);
788+
kdb_common_deinit_state();
789+
787790
strcpy(remcom_out_buffer, "OK");
788791
}
789792
break;

‎kernel/debug/kdb/kdb_bp.c‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,47 +486,33 @@ static int kdb_bc(int argc, const char **argv)
486486
/*
487487
* kdb_ss
488488
*
489-
* Process the 'ss' (Single Step) and 'ssb' (Single Step to Branch)
490-
* commands.
489+
* Process the 'ss' (Single Step) command.
491490
*
492491
* ss
493-
* ssb
494492
*
495493
* Parameters:
496494
* argc Argument count
497495
* argv Argument vector
498496
* Outputs:
499497
* None.
500498
* Returns:
501-
* KDB_CMD_SS[B] for success, a kdb error if failure.
499+
* KDB_CMD_SS for success, a kdb error if failure.
502500
* Locking:
503501
* None.
504502
* Remarks:
505503
*
506504
* Set the arch specific option to trigger a debug trap after the next
507505
* instruction.
508-
*
509-
* For 'ssb', set the trace flag in the debug trap handler
510-
* after printing the current insn and return directly without
511-
* invoking the kdb command processor, until a branch instruction
512-
* is encountered.
513506
*/
514507

515508
static int kdb_ss(int argc, const char **argv)
516509
{
517-
int ssb = 0;
518-
519-
ssb = (strcmp(argv[0], "ssb") == 0);
520510
if (argc != 0)
521511
return KDB_ARGCOUNT;
522512
/*
523513
* Set trace flag and go.
524514
*/
525515
KDB_STATE_SET(DOING_SS);
526-
if (ssb) {
527-
KDB_STATE_SET(DOING_SSB);
528-
return KDB_CMD_SSB;
529-
}
530516
return KDB_CMD_SS;
531517
}
532518

@@ -561,8 +547,6 @@ void __init kdb_initbptab(void)
561547

562548
kdb_register_repeat("ss", kdb_ss, "",
563549
"Single Step", 1, KDB_REPEAT_NO_ARGS);
564-
kdb_register_repeat("ssb", kdb_ss, "",
565-
"Single step to branch/call", 0, KDB_REPEAT_NO_ARGS);
566550
/*
567551
* Architecture dependent initialization.
568552
*/

‎kernel/debug/kdb/kdb_debugger.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ EXPORT_SYMBOL_GPL(kdb_poll_idx);
3434

3535
static struct kgdb_state *kdb_ks;
3636

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+
3753
int kdb_stub(struct kgdb_state *ks)
3854
{
3955
int error = 0;
@@ -94,13 +110,10 @@ int kdb_stub(struct kgdb_state *ks)
94110
}
95111
/* Set initial kdb state variables */
96112
KDB_STATE_CLEAR(KGDB_TRANS);
97-
kdb_initial_cpu = atomic_read(&kgdb_active);
98-
kdb_current_task = kgdb_info[ks->cpu].task;
99-
kdb_current_regs = kgdb_info[ks->cpu].debuggerinfo;
113+
kdb_common_init_state(ks);
100114
/* Remove any breakpoints as needed by kdb and clear single step */
101115
kdb_bp_remove();
102116
KDB_STATE_CLEAR(DOING_SS);
103-
KDB_STATE_CLEAR(DOING_SSB);
104117
KDB_STATE_SET(PAGER);
105118
/* zero out any offline cpu data */
106119
for_each_present_cpu(i) {
@@ -125,9 +138,7 @@ int kdb_stub(struct kgdb_state *ks)
125138
* Upon exit from the kdb main loop setup break points and restart
126139
* the system based on the requested continue state
127140
*/
128-
kdb_initial_cpu = -1;
129-
kdb_current_task = NULL;
130-
kdb_current_regs = NULL;
141+
kdb_common_deinit_state();
131142
KDB_STATE_CLEAR(PAGER);
132143
kdbnearsym_cleanup();
133144
if (error == KDB_CMD_KGDB) {

‎kernel/debug/kdb/kdb_main.c‎

Lines changed: 37 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static kdbmsg_t kdbmsgs[] = {
124124
};
125125
#undef KDBMSG
126126

127-
static const int __nkdb_err = sizeof(kdbmsgs) / sizeof(kdbmsg_t);
127+
static const int __nkdb_err = ARRAY_SIZE(kdbmsgs);
128128

129129

130130
/*
@@ -175,7 +175,7 @@ static char *__env[] = {
175175
(char *)0,
176176
};
177177

178-
static const int __nenv = (sizeof(__env) / sizeof(char *));
178+
static const int __nenv = ARRAY_SIZE(__env);
179179

180180
struct task_struct *kdb_curr_task(int cpu)
181181
{
@@ -681,34 +681,50 @@ static int kdb_defcmd(int argc, const char **argv)
681681
}
682682
if (argc != 3)
683683
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");
690686
return KDB_NOTIMP;
691687
}
688+
defcmd_set = kmalloc((defcmd_set_count + 1) * sizeof(*defcmd_set),
689+
GFP_KDB);
690+
if (!defcmd_set)
691+
goto fail_defcmd;
692692
memcpy(defcmd_set, save_defcmd_set,
693693
defcmd_set_count * sizeof(*defcmd_set));
694-
kfree(save_defcmd_set);
695694
s = defcmd_set + defcmd_set_count;
696695
memset(s, 0, sizeof(*s));
697696
s->usable = 1;
698697
s->name = kdb_strdup(argv[1], GFP_KDB);
698+
if (!s->name)
699+
goto fail_name;
699700
s->usage = kdb_strdup(argv[2], GFP_KDB);
701+
if (!s->usage)
702+
goto fail_usage;
700703
s->help = kdb_strdup(argv[3], GFP_KDB);
704+
if (!s->help)
705+
goto fail_help;
701706
if (s->usage[0] == '"') {
702-
strcpy(s->usage, s->usage+1);
707+
strcpy(s->usage, argv[2]+1);
703708
s->usage[strlen(s->usage)-1] = '\0';
704709
}
705710
if (s->help[0] == '"') {
706-
strcpy(s->help, s->help+1);
711+
strcpy(s->help, argv[3]+1);
707712
s->help[strlen(s->help)-1] = '\0';
708713
}
709714
++defcmd_set_count;
710715
defcmd_in_progress = 1;
716+
kfree(save_defcmd_set);
711717
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;
712728
}
713729

714730
/*
@@ -1112,7 +1128,6 @@ void kdb_set_current_task(struct task_struct *p)
11121128
* KDB_CMD_GO User typed 'go'.
11131129
* KDB_CMD_CPU User switched to another cpu.
11141130
* KDB_CMD_SS Single step.
1115-
* KDB_CMD_SSB Single step until branch.
11161131
*/
11171132
static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
11181133
kdb_dbtrap_t db_result)
@@ -1151,14 +1166,6 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
11511166
kdb_printf("due to Debug @ " kdb_machreg_fmt "\n",
11521167
instruction_pointer(regs));
11531168
break;
1154-
case KDB_DB_SSB:
1155-
/*
1156-
* In the midst of ssb command. Just return.
1157-
*/
1158-
KDB_DEBUG_STATE("kdb_local 3", reason);
1159-
return KDB_CMD_SSB; /* Continue with SSB command */
1160-
1161-
break;
11621169
case KDB_DB_SS:
11631170
break;
11641171
case KDB_DB_SSBPT:
@@ -1281,7 +1288,6 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs,
12811288
if (diag == KDB_CMD_GO
12821289
|| diag == KDB_CMD_CPU
12831290
|| diag == KDB_CMD_SS
1284-
|| diag == KDB_CMD_SSB
12851291
|| diag == KDB_CMD_KGDB)
12861292
break;
12871293

@@ -1368,12 +1374,6 @@ int kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
13681374
break;
13691375
}
13701376

1371-
if (result == KDB_CMD_SSB) {
1372-
KDB_STATE_SET(DOING_SS);
1373-
KDB_STATE_SET(DOING_SSB);
1374-
break;
1375-
}
1376-
13771377
if (result == KDB_CMD_KGDB) {
13781378
if (!KDB_STATE(DOING_KGDB))
13791379
kdb_printf("Entering please attach debugger "
@@ -2350,69 +2350,6 @@ static int kdb_pid(int argc, const char **argv)
23502350
return 0;
23512351
}
23522352

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-
24162353
static int kdb_kgdb(int argc, const char **argv)
24172354
{
24182355
return KDB_CMD_KGDB;
@@ -2430,11 +2367,15 @@ static int kdb_help(int argc, const char **argv)
24302367
kdb_printf("-----------------------------"
24312368
"-----------------------------\n");
24322369
for_each_kdbcmd(kt, i) {
2433-
if (kt->cmd_name)
2434-
kdb_printf("%-15.15s %-20.20s %s\n", kt->cmd_name,
2435-
kt->cmd_usage, kt->cmd_help);
2370+
char *space = "";
24362371
if (KDB_FLAG(CMD_INTERRUPT))
24372372
return 0;
2373+
if (!kt->cmd_name)
2374+
continue;
2375+
if (strlen(kt->cmd_usage) > 20)
2376+
space = "\n ";
2377+
kdb_printf("%-15.15s %-20s%s%s\n", kt->cmd_name,
2378+
kt->cmd_usage, space, kt->cmd_help);
24382379
}
24392380
return 0;
24402381
}
@@ -2739,7 +2680,7 @@ int kdb_register_repeat(char *cmd,
27392680
(kdb_max_commands - KDB_BASE_CMD_MAX) * sizeof(*new));
27402681
kfree(kdb_commands);
27412682
}
2742-
memset(new + kdb_max_commands, 0,
2683+
memset(new + kdb_max_commands - KDB_BASE_CMD_MAX, 0,
27432684
kdb_command_extend * sizeof(*new));
27442685
kdb_commands = new;
27452686
kp = kdb_commands + kdb_max_commands - KDB_BASE_CMD_MAX;
@@ -2843,15 +2784,13 @@ static void __init kdb_inittab(void)
28432784
"Stack traceback", 1, KDB_REPEAT_NONE);
28442785
kdb_register_repeat("btp", kdb_bt, "<pid>",
28452786
"Display stack for process <pid>", 0, KDB_REPEAT_NONE);
2846-
kdb_register_repeat("bta", kdb_bt, "[DRSTCZEUIMA]",
2847-
"Display stack all processes", 0, KDB_REPEAT_NONE);
2787+
kdb_register_repeat("bta", kdb_bt, "[D|R|S|T|C|Z|E|U|I|M|A]",
2788+
"Backtrace all processes matching state flag", 0, KDB_REPEAT_NONE);
28482789
kdb_register_repeat("btc", kdb_bt, "",
28492790
"Backtrace current process on each cpu", 0, KDB_REPEAT_NONE);
28502791
kdb_register_repeat("btt", kdb_bt, "<vaddr>",
28512792
"Backtrace process given its struct task address", 0,
28522793
KDB_REPEAT_NONE);
2853-
kdb_register_repeat("ll", kdb_ll, "<first-element> <linkoffset> <cmd>",
2854-
"Execute cmd for each element in linked list", 0, KDB_REPEAT_NONE);
28552794
kdb_register_repeat("env", kdb_env, "",
28562795
"Show environment variables", 0, KDB_REPEAT_NONE);
28572796
kdb_register_repeat("set", kdb_set, "",

0 commit comments

Comments
 (0)