Skip to content

Commit 72f9adf

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb: kdb,kgdb: Allow arbitrary kgdb magic knock sequences kdb: Remove all references to DOING_KGDB2 kdb,kgdb: Implement switch and pass buffer from kdb -> gdb kdb: cleanup unused variables missed in the original kdb merge
2 parents 5f66d2b + 37f86b4 commit 72f9adf

File tree

7 files changed

+53
-42
lines changed

7 files changed

+53
-42
lines changed

kernel/debug/gdbstub.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
/* Our I/O buffers. */
4343
static char remcom_in_buffer[BUFMAX];
4444
static char remcom_out_buffer[BUFMAX];
45+
static int gdbstub_use_prev_in_buf;
46+
static int gdbstub_prev_in_buf_pos;
4547

4648
/* Storage for the registers, in GDB format. */
4749
static unsigned long gdb_regs[(NUMREGBYTES +
@@ -58,6 +60,13 @@ static int gdbstub_read_wait(void)
5860
int ret = -1;
5961
int i;
6062

63+
if (unlikely(gdbstub_use_prev_in_buf)) {
64+
if (gdbstub_prev_in_buf_pos < gdbstub_use_prev_in_buf)
65+
return remcom_in_buffer[gdbstub_prev_in_buf_pos++];
66+
else
67+
gdbstub_use_prev_in_buf = 0;
68+
}
69+
6170
/* poll any additional I/O interfaces that are defined */
6271
while (ret < 0)
6372
for (i = 0; kdb_poll_funcs[i] != NULL; i++) {
@@ -109,7 +118,6 @@ static void get_packet(char *buffer)
109118
buffer[count] = ch;
110119
count = count + 1;
111120
}
112-
buffer[count] = 0;
113121

114122
if (ch == '#') {
115123
xmitcsum = hex_to_bin(gdbstub_read_wait()) << 4;
@@ -124,6 +132,7 @@ static void get_packet(char *buffer)
124132
if (dbg_io_ops->flush)
125133
dbg_io_ops->flush();
126134
}
135+
buffer[count] = 0;
127136
} while (checksum != xmitcsum);
128137
}
129138

@@ -1082,12 +1091,11 @@ int gdbstub_state(struct kgdb_state *ks, char *cmd)
10821091
case 'c':
10831092
strcpy(remcom_in_buffer, cmd);
10841093
return 0;
1085-
case '?':
1086-
gdb_cmd_status(ks);
1087-
break;
1088-
case '\0':
1089-
strcpy(remcom_out_buffer, "");
1090-
break;
1094+
case '$':
1095+
strcpy(remcom_in_buffer, cmd);
1096+
gdbstub_use_prev_in_buf = strlen(remcom_in_buffer);
1097+
gdbstub_prev_in_buf_pos = 0;
1098+
return 0;
10911099
}
10921100
dbg_io_ops->write_char('+');
10931101
put_packet(remcom_out_buffer);

kernel/debug/kdb/kdb_bt.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ kdb_bt(int argc, const char **argv)
112112
unsigned long addr;
113113
long offset;
114114

115-
kdbgetintenv("BTARGS", &argcount); /* Arguments to print */
116-
kdbgetintenv("BTAPROMPT", &btaprompt); /* Prompt after each
117-
* proc in bta */
115+
/* Prompt after each proc in bta */
116+
kdbgetintenv("BTAPROMPT", &btaprompt);
118117

119118
if (strcmp(argv[0], "bta") == 0) {
120119
struct task_struct *g, *p;

kernel/debug/kdb/kdb_cmds

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ defcmd dumpcommon "" "Common kdb debugging"
1818
endefcmd
1919

2020
defcmd dumpall "" "First line debugging"
21-
set BTSYMARG 1
22-
set BTARGS 9
2321
pid R
2422
-dumpcommon
2523
-bta
2624
endefcmd
2725

2826
defcmd dumpcpu "" "Same as dumpall but only tasks on cpus"
29-
set BTSYMARG 1
30-
set BTARGS 9
3127
pid R
3228
-dumpcommon
3329
-btc

kernel/debug/kdb/kdb_debugger.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ EXPORT_SYMBOL_GPL(kdb_poll_funcs);
3030
int kdb_poll_idx = 1;
3131
EXPORT_SYMBOL_GPL(kdb_poll_idx);
3232

33+
static struct kgdb_state *kdb_ks;
34+
3335
int kdb_stub(struct kgdb_state *ks)
3436
{
3537
int error = 0;
@@ -39,6 +41,7 @@ int kdb_stub(struct kgdb_state *ks)
3941
kdb_dbtrap_t db_result = KDB_DB_NOBPT;
4042
int i;
4143

44+
kdb_ks = ks;
4245
if (KDB_STATE(REENTRY)) {
4346
reason = KDB_REASON_SWITCH;
4447
KDB_STATE_CLEAR(REENTRY);
@@ -123,20 +126,8 @@ int kdb_stub(struct kgdb_state *ks)
123126
KDB_STATE_CLEAR(PAGER);
124127
kdbnearsym_cleanup();
125128
if (error == KDB_CMD_KGDB) {
126-
if (KDB_STATE(DOING_KGDB) || KDB_STATE(DOING_KGDB2)) {
127-
/*
128-
* This inteface glue which allows kdb to transition in into
129-
* the gdb stub. In order to do this the '?' or '' gdb serial
130-
* packet response is processed here. And then control is
131-
* passed to the gdbstub.
132-
*/
133-
if (KDB_STATE(DOING_KGDB))
134-
gdbstub_state(ks, "?");
135-
else
136-
gdbstub_state(ks, "");
129+
if (KDB_STATE(DOING_KGDB))
137130
KDB_STATE_CLEAR(DOING_KGDB);
138-
KDB_STATE_CLEAR(DOING_KGDB2);
139-
}
140131
return DBG_PASS_EVENT;
141132
}
142133
kdb_bp_install(ks->linux_regs);
@@ -166,3 +157,7 @@ int kdb_stub(struct kgdb_state *ks)
166157
return kgdb_info[ks->cpu].ret_state;
167158
}
168159

160+
void kdb_gdb_state_pass(char *buf)
161+
{
162+
gdbstub_state(kdb_ks, buf);
163+
}

kernel/debug/kdb/kdb_io.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@ char kdb_prompt_str[CMD_BUFLEN];
3131

3232
int kdb_trap_printk;
3333

34-
static void kgdb_transition_check(char *buffer)
34+
static int kgdb_transition_check(char *buffer)
3535
{
36-
int slen = strlen(buffer);
37-
if (strncmp(buffer, "$?#3f", slen) != 0 &&
38-
strncmp(buffer, "$qSupported#37", slen) != 0 &&
39-
strncmp(buffer, "+$qSupported#37", slen) != 0) {
36+
if (buffer[0] != '+' && buffer[0] != '$') {
4037
KDB_STATE_SET(KGDB_TRANS);
4138
kdb_printf("%s", buffer);
39+
} else {
40+
int slen = strlen(buffer);
41+
if (slen > 3 && buffer[slen - 3] == '#') {
42+
kdb_gdb_state_pass(buffer);
43+
strcpy(buffer, "kgdb");
44+
KDB_STATE_SET(DOING_KGDB);
45+
return 1;
46+
}
4247
}
48+
return 0;
4349
}
4450

4551
static int kdb_read_get_key(char *buffer, size_t bufsize)
@@ -251,6 +257,10 @@ static char *kdb_read(char *buffer, size_t bufsize)
251257
case 13: /* enter */
252258
*lastchar++ = '\n';
253259
*lastchar++ = '\0';
260+
if (!KDB_STATE(KGDB_TRANS)) {
261+
KDB_STATE_SET(KGDB_TRANS);
262+
kdb_printf("%s", buffer);
263+
}
254264
kdb_printf("\n");
255265
return buffer;
256266
case 4: /* Del */
@@ -382,22 +392,26 @@ static char *kdb_read(char *buffer, size_t bufsize)
382392
* printed characters if we think that
383393
* kgdb is connecting, until the check
384394
* fails */
385-
if (!KDB_STATE(KGDB_TRANS))
386-
kgdb_transition_check(buffer);
387-
else
395+
if (!KDB_STATE(KGDB_TRANS)) {
396+
if (kgdb_transition_check(buffer))
397+
return buffer;
398+
} else {
388399
kdb_printf("%c", key);
400+
}
389401
}
390402
/* Special escape to kgdb */
391403
if (lastchar - buffer >= 5 &&
392404
strcmp(lastchar - 5, "$?#3f") == 0) {
405+
kdb_gdb_state_pass(lastchar - 5);
393406
strcpy(buffer, "kgdb");
394407
KDB_STATE_SET(DOING_KGDB);
395408
return buffer;
396409
}
397-
if (lastchar - buffer >= 14 &&
398-
strcmp(lastchar - 14, "$qSupported#37") == 0) {
410+
if (lastchar - buffer >= 11 &&
411+
strcmp(lastchar - 11, "$qSupported") == 0) {
412+
kdb_gdb_state_pass(lastchar - 11);
399413
strcpy(buffer, "kgdb");
400-
KDB_STATE_SET(DOING_KGDB2);
414+
KDB_STATE_SET(DOING_KGDB);
401415
return buffer;
402416
}
403417
}

kernel/debug/kdb/kdb_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ static char *__env[] = {
145145
#endif
146146
"RADIX=16",
147147
"MDCOUNT=8", /* lines of md output */
148-
"BTARGS=9", /* 9 possible args in bt */
149148
KDB_PLATFORM_ENV,
150149
"DTABCOUNT=30",
151150
"NOSECT=1",
@@ -172,6 +171,7 @@ static char *__env[] = {
172171
(char *)0,
173172
(char *)0,
174173
(char *)0,
174+
(char *)0,
175175
};
176176

177177
static const int __nenv = (sizeof(__env) / sizeof(char *));
@@ -1386,7 +1386,7 @@ int kdb_main_loop(kdb_reason_t reason, kdb_reason_t reason2, int error,
13861386
}
13871387

13881388
if (result == KDB_CMD_KGDB) {
1389-
if (!(KDB_STATE(DOING_KGDB) || KDB_STATE(DOING_KGDB2)))
1389+
if (!KDB_STATE(DOING_KGDB))
13901390
kdb_printf("Entering please attach debugger "
13911391
"or use $D#44+ or $3#33\n");
13921392
break;

kernel/debug/kdb/kdb_private.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define KDB_CMD_SS (-1003)
2222
#define KDB_CMD_SSB (-1004)
2323
#define KDB_CMD_KGDB (-1005)
24-
#define KDB_CMD_KGDB2 (-1006)
2524

2625
/* Internal debug flags */
2726
#define KDB_DEBUG_FLAG_BP 0x0002 /* Breakpoint subsystem debug */
@@ -146,7 +145,6 @@ extern int kdb_state;
146145
* keyboard on this cpu */
147146
#define KDB_STATE_KEXEC 0x00040000 /* kexec issued */
148147
#define KDB_STATE_DOING_KGDB 0x00080000 /* kgdb enter now issued */
149-
#define KDB_STATE_DOING_KGDB2 0x00100000 /* kgdb enter now issued */
150148
#define KDB_STATE_KGDB_TRANS 0x00200000 /* Transition to kgdb */
151149
#define KDB_STATE_ARCH 0xff000000 /* Reserved for arch
152150
* specific use */
@@ -218,6 +216,7 @@ extern void kdb_print_nameval(const char *name, unsigned long val);
218216
extern void kdb_send_sig_info(struct task_struct *p, struct siginfo *info);
219217
extern void kdb_meminfo_proc_show(void);
220218
extern char *kdb_getstr(char *, size_t, char *);
219+
extern void kdb_gdb_state_pass(char *buf);
221220

222221
/* Defines for kdb_symbol_print */
223222
#define KDB_SP_SPACEB 0x0001 /* Space before string */

0 commit comments

Comments
 (0)