History

kgdb: gdb "monitor" -> kdb passthrough

One of the driving forces behind integrating another front end (kdb) to the debug core is to allow front end commands to be accessible via gdb's monitor command. It is true that you could write gdb macros to get certain data, but you may want to just use gdb to access the commands that are available in the kdb front end. This patch implements the Rcmd gdb stub packet. In gdb you access this with the "monitor" command. For instance you could type "monitor help", "monitor lsmod" or "monitor ps A" etc... There is no error checking or command restrictions on what you can and cannot access at this point. Doing something like trying to set breakpoints with the monitor command is going to cause nothing but problems. Perhaps in the future only the commands that are actually known to work with the gdb monitor command will be available.

Jason Wessel committed 16 years ago

Commit a0de0551 parent 6d45a1a5 files · +34 −6Browse files

Showing the changes to kernel/debug (5 of 5 files). Show all

Unified · Split

5 files
  1. kernel/debug/debug_core.c +1 −1
  2. kernel/debug/debug_core.h +2 −0
  3. kernel/debug/gdbstub.c +22 −0
  4. kernel/debug/kdb/kdb_io.c +9 −4
  5. kernel/debug/kdb/kdb_private.h +0 −1
kernel/debug/debug_core.c+1−1
@@ -82,7 +82,7 @@ static int kgdb_use_con; · 81 unmodified lines
8282 int dbg_switch_cpu;
8383
8484 /* Use kdb or gdbserver mode */
85−static int dbg_kdb_mode = 1;
85+int dbg_kdb_mode = 1;
8686
8787 static int __init opt_kgdb_con(char *str)
8888 {
kernel/debug/debug_core.h+2−0
@@ -66,9 +66,11 @@ extern void gdbstub_msg_write(const char *s, int len); · 65 unmodified lines
6666
6767 /* gdbstub functions used for kdb <-> gdbstub transition */
6868 extern int gdbstub_state(struct kgdb_state *ks, char *cmd);
69+extern int dbg_kdb_mode;
6970
7071 #ifdef CONFIG_KGDB_KDB
7172 extern int kdb_stub(struct kgdb_state *ks);
73+extern int kdb_parse(const char *cmdstr);
7274 #else /* ! CONFIG_KGDB_KDB */
7375 static inline int kdb_stub(struct kgdb_state *ks)
7476 {
kernel/debug/gdbstub.c+22−0
@@ -201,6 +201,9 @@ void gdbstub_msg_write(const char *s, int len) · 200 unmodified lines
201201 int wcount;
202202 int i;
203203
204+ if (len == 0)
205+ len = strlen(s);
206+
204207 /* 'O'utput */
205208 gdbmsgbuf[0] = 'O';
206209
@@ -685,6 +688,25 @@ static void gdb_cmd_query(struct kgdb_state *ks) · 478 unmodified lines
685688 kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr));
686689 }
687690 break;
691+#ifdef CONFIG_KGDB_KDB
692+ case 'R':
693+ if (strncmp(remcom_in_buffer, "qRcmd,", 6) == 0) {
694+ int len = strlen(remcom_in_buffer + 6);
695+
696+ if ((len % 2) != 0) {
697+ strcpy(remcom_out_buffer, "E01");
698+ break;
699+ }
700+ kgdb_hex2mem(remcom_in_buffer + 6,
701+ remcom_out_buffer, len);
702+ len = len / 2;
703+ remcom_out_buffer[len++] = 0;
704+
705+ kdb_parse(remcom_out_buffer);
706+ strcpy(remcom_out_buffer, "OK");
707+ }
708+ break;
709+#endif
688710 }
689711 }
690712
kernel/debug/kdb/kdb_io.c+9−4
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/smp.h>
2222 #include <linux/nmi.h>
2323 #include <linux/delay.h>
24+#include <linux/kgdb.h>
2425 #include <linux/kdb.h>
2526 #include <linux/kallsyms.h>
2627 #include "kdb_private.h"
@@ -669,10 +670,14 @@ kdb_printit: · 642 unmodified lines
669670 * Write to all consoles.
670671 */
671672 retlen = strlen(kdb_buffer);
672− while (c) {
673− c->write(c, kdb_buffer, retlen);
674− touch_nmi_watchdog();
675− c = c->next;
673+ if (!dbg_kdb_mode && kgdb_connected) {
674+ gdbstub_msg_write(kdb_buffer, retlen);
675+ } else {
676+ while (c) {
677+ c->write(c, kdb_buffer, retlen);
678+ touch_nmi_watchdog();
679+ c = c->next;
680+ }
676681 }
677682 if (logging) {
678683 saved_loglevel = console_loglevel;
kernel/debug/kdb/kdb_private.h+0−1
@@ -254,7 +254,6 @@ extern unsigned long kdb_task_state(const struct task_struct *p, · 253 unmodified lines
254254 unsigned long mask);
255255 extern void kdb_ps_suppressed(void);
256256 extern void kdb_ps1(const struct task_struct *p);
257−extern int kdb_parse(const char *cmdstr);
258257 extern void kdb_print_nameval(const char *name, unsigned long val);
259258 extern void kdb_send_sig_info(struct task_struct *p, struct siginfo *info);
260259 extern void kdb_meminfo_proc_show(void);