4 * Maintainer: Jason Wessel <jason.wessel@windriver.com>
6 * Copyright (C) 2000-2001 VERITAS Software Corporation.
7 * Copyright (C) 2002-2004 Timesys Corporation
8 * Copyright (C) 2003-2004 Amit S. Kale <amitkale@linsyssoft.com>
9 * Copyright (C) 2004 Pavel Machek <pavel@ucw.cz>
10 * Copyright (C) 2004-2006 Tom Rini <trini@kernel.crashing.org>
11 * Copyright (C) 2004-2006 LinSysSoft Technologies Pvt. Ltd.
12 * Copyright (C) 2005-2009 Wind River Systems, Inc.
13 * Copyright (C) 2007 MontaVista Software, Inc.
14 * Copyright (C) 2008 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
16 * Contributors at various stages not listed above:
17 * Jason Wessel ( jason.wessel@windriver.com )
18 * George Anzinger <george@mvista.com>
19 * Anurekh Saxena (anurekh.saxena@timesys.com)
20 * Lake Stevens Instrument Division (Glenn Engel)
21 * Jim Kingdon, Cygnus Support.
23 * Original KGDB stub: David Grothe <dave@gcom.com>,
24 * Tigran Aivazian <tigran@sco.com>
26 * This file is licensed under the terms of the GNU General Public License
27 * version 2. This program is licensed "as is" without any warranty of any
28 * kind, whether express or implied.
31 #include <linux/kernel.h>
32 #include <linux/kgdb.h>
33 #include <linux/kdb.h>
34 #include <linux/serial_core.h>
35 #include <linux/reboot.h>
36 #include <linux/uaccess.h>
37 #include <asm/cacheflush.h>
38 #include <asm/unaligned.h>
39 #include "debug_core.h"
41 #define KGDB_MAX_THREAD_QUERY 17
43 /* Our I/O buffers. */
44 static char remcom_in_buffer[BUFMAX];
45 static char remcom_out_buffer[BUFMAX];
46 static int gdbstub_use_prev_in_buf;
47 static int gdbstub_prev_in_buf_pos;
49 /* Storage for the registers, in GDB format. */
50 static unsigned long gdb_regs[(NUMREGBYTES +
51 sizeof(unsigned long) - 1) /
52 sizeof(unsigned long)];
55 * GDB remote protocol parser:
58 #ifdef CONFIG_KGDB_KDB
59 static int gdbstub_read_wait(void)
64 if (unlikely(gdbstub_use_prev_in_buf)) {
65 if (gdbstub_prev_in_buf_pos < gdbstub_use_prev_in_buf)
66 return remcom_in_buffer[gdbstub_prev_in_buf_pos++];
68 gdbstub_use_prev_in_buf = 0;
71 /* poll any additional I/O interfaces that are defined */
73 for (i = 0; kdb_poll_funcs[i] != NULL; i++) {
74 ret = kdb_poll_funcs[i]();
81 static int gdbstub_read_wait(void)
83 int ret = dbg_io_ops->read_char();
84 while (ret == NO_POLL_CHAR)
85 ret = dbg_io_ops->read_char();
89 /* scan for the sequence $<data>#<checksum> */
90 static void get_packet(char *buffer)
92 unsigned char checksum;
93 unsigned char xmitcsum;
99 * Spin and wait around for the start character, ignore all
102 while ((ch = (gdbstub_read_wait())) != '$')
112 * now, read until a # or end of buffer is found:
114 while (count < (BUFMAX - 1)) {
115 ch = gdbstub_read_wait();
118 checksum = checksum + ch;
124 xmitcsum = hex_to_bin(gdbstub_read_wait()) << 4;
125 xmitcsum += hex_to_bin(gdbstub_read_wait());
127 if (checksum != xmitcsum)
128 /* failed checksum */
129 dbg_io_ops->write_char('-');
131 /* successful transfer */
132 dbg_io_ops->write_char('+');
133 if (dbg_io_ops->flush)
137 } while (checksum != xmitcsum);
141 * Send the packet in buffer.
142 * Check for gdb connection if asked for.
144 static void put_packet(char *buffer)
146 unsigned char checksum;
151 * $<packet info>#<checksum>.
154 dbg_io_ops->write_char('$');
158 while ((ch = buffer[count])) {
159 dbg_io_ops->write_char(ch);
164 dbg_io_ops->write_char('#');
165 dbg_io_ops->write_char(hex_asc_hi(checksum));
166 dbg_io_ops->write_char(hex_asc_lo(checksum));
167 if (dbg_io_ops->flush)
170 /* Now see what we get in reply. */
171 ch = gdbstub_read_wait();
174 ch = gdbstub_read_wait();
176 /* If we get an ACK, we are done. */
181 * If we get the start of another packet, this means
182 * that GDB is attempting to reconnect. We will NAK
183 * the packet being sent, and stop trying to send this
187 dbg_io_ops->write_char('-');
188 if (dbg_io_ops->flush)
195 static char gdbmsgbuf[BUFMAX + 1];
197 void gdbstub_msg_write(const char *s, int len)
209 /* Fill and send buffers... */
211 bufptr = gdbmsgbuf + 1;
213 /* Calculate how many this time */
214 if ((len << 1) > (BUFMAX - 2))
215 wcount = (BUFMAX - 2) >> 1;
219 /* Pack in hex chars */
220 for (i = 0; i < wcount; i++)
221 bufptr = hex_byte_pack(bufptr, s[i]);
229 put_packet(gdbmsgbuf);
234 * Convert the memory pointed to by mem into hex, placing result in
235 * buf. Return a pointer to the last char put in buf (null). May
238 char *kgdb_mem2hex(char *mem, char *buf, int count)
244 * We use the upper half of buf as an intermediate buffer for the
245 * raw memory copy. Hex conversion will work against this one.
249 err = probe_kernel_read(tmp, mem, count);
253 buf = hex_byte_pack(buf, *tmp);
263 * Convert the hex array pointed to by buf into binary to be placed in
264 * mem. Return a pointer to the character AFTER the last byte
265 * written. May return an error.
267 int kgdb_hex2mem(char *buf, char *mem, int count)
273 * We use the upper half of buf as an intermediate buffer for the
274 * raw memory that is converted from hex.
276 tmp_raw = buf + count * 2;
278 tmp_hex = tmp_raw - 1;
279 while (tmp_hex >= buf) {
281 *tmp_raw = hex_to_bin(*tmp_hex--);
282 *tmp_raw |= hex_to_bin(*tmp_hex--) << 4;
285 return probe_kernel_write(mem, tmp_raw, count);
289 * While we find nice hex chars, build a long_val.
290 * Return number of chars processed.
292 int kgdb_hex2long(char **ptr, unsigned long *long_val)
305 hex_val = hex_to_bin(**ptr);
309 *long_val = (*long_val << 4) | hex_val;
315 *long_val = -*long_val;
321 * Copy the binary array pointed to by buf into mem. Fix $, #, and
322 * 0x7d escaped with 0x7d. Return -EFAULT on failure or 0 on success.
323 * The input buf is overwitten with the result to write to mem.
325 static int kgdb_ebin2mem(char *buf, char *mem, int count)
330 while (count-- > 0) {
333 c[size] = *buf++ ^ 0x20;
337 return probe_kernel_write(mem, c, size);
340 #if DBG_MAX_REG_NUM > 0
341 void pt_regs_to_gdb_regs(unsigned long *gdb_regs, struct pt_regs *regs)
345 char *ptr = (char *)gdb_regs;
347 for (i = 0; i < DBG_MAX_REG_NUM; i++) {
348 dbg_get_reg(i, ptr + idx, regs);
349 idx += dbg_reg_def[i].size;
353 void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs)
357 char *ptr = (char *)gdb_regs;
359 for (i = 0; i < DBG_MAX_REG_NUM; i++) {
360 dbg_set_reg(i, ptr + idx, regs);
361 idx += dbg_reg_def[i].size;
364 #endif /* DBG_MAX_REG_NUM > 0 */
366 /* Write memory due to an 'M' or 'X' packet. */
367 static int write_mem_msg(int binary)
369 char *ptr = &remcom_in_buffer[1];
371 unsigned long length;
374 if (kgdb_hex2long(&ptr, &addr) > 0 && *(ptr++) == ',' &&
375 kgdb_hex2long(&ptr, &length) > 0 && *(ptr++) == ':') {
377 err = kgdb_ebin2mem(ptr, (char *)addr, length);
379 err = kgdb_hex2mem(ptr, (char *)addr, length);
382 if (CACHE_FLUSH_IS_SAFE)
383 flush_icache_range(addr, addr + length);
390 static void error_packet(char *pkt, int error)
394 pkt[1] = hex_asc[(error / 10)];
395 pkt[2] = hex_asc[(error % 10)];
400 * Thread ID accessors. We represent a flat TID space to GDB, where
401 * the per CPU idle threads (which under Linux all have PID 0) are
402 * remapped to negative TIDs.
405 #define BUF_THREAD_ID_SIZE 8
407 static char *pack_threadid(char *pkt, unsigned char *id)
409 unsigned char *limit;
412 limit = id + (BUF_THREAD_ID_SIZE / 2);
414 if (!lzero || *id != 0) {
415 pkt = hex_byte_pack(pkt, *id);
422 pkt = hex_byte_pack(pkt, 0);
427 static void int_to_threadref(unsigned char *id, int value)
429 put_unaligned_be32(value, id);
432 static struct task_struct *getthread(struct pt_regs *regs, int tid)
435 * Non-positive TIDs are remapped to the cpu shadow information
437 if (tid == 0 || tid == -1)
438 tid = -atomic_read(&kgdb_active) - 2;
439 if (tid < -1 && tid > -NR_CPUS - 2) {
440 if (kgdb_info[-tid - 2].task)
441 return kgdb_info[-tid - 2].task;
443 return idle_task(-tid - 2);
446 printk(KERN_ERR "KGDB: Internal thread select error\n");
452 * find_task_by_pid_ns() does not take the tasklist lock anymore
453 * but is nicely RCU locked - hence is a pretty resilient
456 return find_task_by_pid_ns(tid, &init_pid_ns);
461 * Remap normal tasks to their real PID,
462 * CPU shadow threads are mapped to -CPU - 2
464 static inline int shadow_pid(int realpid)
469 return -raw_smp_processor_id() - 2;
473 * All the functions that start with gdb_cmd are the various
474 * operations to implement the handlers for the gdbserial protocol
475 * where KGDB is communicating with an external debugger
478 /* Handle the '?' status packets */
479 static void gdb_cmd_status(struct kgdb_state *ks)
482 * We know that this packet is only sent
483 * during initial connect. So to be safe,
484 * we clear out our breakpoints now in case
485 * GDB is reconnecting.
487 dbg_remove_all_break();
489 remcom_out_buffer[0] = 'S';
490 hex_byte_pack(&remcom_out_buffer[1], ks->signo);
493 static void gdb_get_regs_helper(struct kgdb_state *ks)
495 struct task_struct *thread;
496 void *local_debuggerinfo;
499 thread = kgdb_usethread;
501 thread = kgdb_info[ks->cpu].task;
502 local_debuggerinfo = kgdb_info[ks->cpu].debuggerinfo;
504 local_debuggerinfo = NULL;
505 for_each_online_cpu(i) {
507 * Try to find the task on some other
508 * or possibly this node if we do not
509 * find the matching task then we try
510 * to approximate the results.
512 if (thread == kgdb_info[i].task)
513 local_debuggerinfo = kgdb_info[i].debuggerinfo;
518 * All threads that don't have debuggerinfo should be
519 * in schedule() sleeping, since all other CPUs
520 * are in kgdb_wait, and thus have debuggerinfo.
522 if (local_debuggerinfo) {
523 pt_regs_to_gdb_regs(gdb_regs, local_debuggerinfo);
526 * Pull stuff saved during switch_to; nothing
527 * else is accessible (or even particularly
530 * This should be enough for a stack trace.
532 sleeping_thread_to_gdb_regs(gdb_regs, thread);
536 /* Handle the 'g' get registers request */
537 static void gdb_cmd_getregs(struct kgdb_state *ks)
539 gdb_get_regs_helper(ks);
540 kgdb_mem2hex((char *)gdb_regs, remcom_out_buffer, NUMREGBYTES);
543 /* Handle the 'G' set registers request */
544 static void gdb_cmd_setregs(struct kgdb_state *ks)
546 kgdb_hex2mem(&remcom_in_buffer[1], (char *)gdb_regs, NUMREGBYTES);
548 if (kgdb_usethread && kgdb_usethread != current) {
549 error_packet(remcom_out_buffer, -EINVAL);
551 gdb_regs_to_pt_regs(gdb_regs, ks->linux_regs);
552 strcpy(remcom_out_buffer, "OK");
556 /* Handle the 'm' memory read bytes */
557 static void gdb_cmd_memread(struct kgdb_state *ks)
559 char *ptr = &remcom_in_buffer[1];
560 unsigned long length;
564 if (kgdb_hex2long(&ptr, &addr) > 0 && *ptr++ == ',' &&
565 kgdb_hex2long(&ptr, &length) > 0) {
566 err = kgdb_mem2hex((char *)addr, remcom_out_buffer, length);
568 error_packet(remcom_out_buffer, -EINVAL);
570 error_packet(remcom_out_buffer, -EINVAL);
574 /* Handle the 'M' memory write bytes */
575 static void gdb_cmd_memwrite(struct kgdb_state *ks)
577 int err = write_mem_msg(0);
580 error_packet(remcom_out_buffer, err);
582 strcpy(remcom_out_buffer, "OK");
585 #if DBG_MAX_REG_NUM > 0
586 static char *gdb_hex_reg_helper(int regnum, char *out)
591 for (i = 0; i < regnum; i++)
592 offset += dbg_reg_def[i].size;
593 return kgdb_mem2hex((char *)gdb_regs + offset, out,
594 dbg_reg_def[i].size);
597 /* Handle the 'p' individual regster get */
598 static void gdb_cmd_reg_get(struct kgdb_state *ks)
600 unsigned long regnum;
601 char *ptr = &remcom_in_buffer[1];
603 kgdb_hex2long(&ptr, ®num);
604 if (regnum >= DBG_MAX_REG_NUM) {
605 error_packet(remcom_out_buffer, -EINVAL);
608 gdb_get_regs_helper(ks);
609 gdb_hex_reg_helper(regnum, remcom_out_buffer);
612 /* Handle the 'P' individual regster set */
613 static void gdb_cmd_reg_set(struct kgdb_state *ks)
615 unsigned long regnum;
616 char *ptr = &remcom_in_buffer[1];
619 kgdb_hex2long(&ptr, ®num);
621 !(!kgdb_usethread || kgdb_usethread == current) ||
622 !dbg_get_reg(regnum, gdb_regs, ks->linux_regs)) {
623 error_packet(remcom_out_buffer, -EINVAL);
626 memset(gdb_regs, 0, sizeof(gdb_regs));
627 while (i < sizeof(gdb_regs) * 2)
628 if (hex_to_bin(ptr[i]) >= 0)
633 kgdb_hex2mem(ptr, (char *)gdb_regs, i);
634 dbg_set_reg(regnum, gdb_regs, ks->linux_regs);
635 strcpy(remcom_out_buffer, "OK");
637 #endif /* DBG_MAX_REG_NUM > 0 */
639 /* Handle the 'X' memory binary write bytes */
640 static void gdb_cmd_binwrite(struct kgdb_state *ks)
642 int err = write_mem_msg(1);
645 error_packet(remcom_out_buffer, err);
647 strcpy(remcom_out_buffer, "OK");
650 /* Handle the 'D' or 'k', detach or kill packets */
651 static void gdb_cmd_detachkill(struct kgdb_state *ks)
655 /* The detach case */
656 if (remcom_in_buffer[0] == 'D') {
657 error = dbg_remove_all_break();
659 error_packet(remcom_out_buffer, error);
661 strcpy(remcom_out_buffer, "OK");
664 put_packet(remcom_out_buffer);
667 * Assume the kill case, with no exit code checking,
668 * trying to force detach the debugger:
670 dbg_remove_all_break();
675 /* Handle the 'R' reboot packets */
676 static int gdb_cmd_reboot(struct kgdb_state *ks)
678 /* For now, only honor R0 */
679 if (strcmp(remcom_in_buffer, "R0") == 0) {
680 printk(KERN_CRIT "Executing emergency reboot\n");
681 strcpy(remcom_out_buffer, "OK");
682 put_packet(remcom_out_buffer);
685 * Execution should not return from
686 * machine_emergency_restart()
688 machine_emergency_restart();
696 /* Handle the 'q' query packets */
697 static void gdb_cmd_query(struct kgdb_state *ks)
699 struct task_struct *g;
700 struct task_struct *p;
701 unsigned char thref[BUF_THREAD_ID_SIZE];
707 switch (remcom_in_buffer[1]) {
710 if (memcmp(remcom_in_buffer + 2, "ThreadInfo", 10))
714 remcom_out_buffer[0] = 'm';
715 ptr = remcom_out_buffer + 1;
716 if (remcom_in_buffer[1] == 'f') {
717 /* Each cpu is a shadow thread */
718 for_each_online_cpu(cpu) {
720 int_to_threadref(thref, -cpu - 2);
721 ptr = pack_threadid(ptr, thref);
727 do_each_thread(g, p) {
728 if (i >= ks->thr_query && !finished) {
729 int_to_threadref(thref, p->pid);
730 ptr = pack_threadid(ptr, thref);
733 if (ks->thr_query % KGDB_MAX_THREAD_QUERY == 0)
737 } while_each_thread(g, p);
743 /* Current thread id */
744 strcpy(remcom_out_buffer, "QC");
745 ks->threadid = shadow_pid(current->pid);
746 int_to_threadref(thref, ks->threadid);
747 pack_threadid(remcom_out_buffer + 2, thref);
750 if (memcmp(remcom_in_buffer + 1, "ThreadExtraInfo,", 16))
754 ptr = remcom_in_buffer + 17;
755 kgdb_hex2long(&ptr, &ks->threadid);
756 if (!getthread(ks->linux_regs, ks->threadid)) {
757 error_packet(remcom_out_buffer, -EINVAL);
760 if ((int)ks->threadid > 0) {
761 kgdb_mem2hex(getthread(ks->linux_regs,
763 remcom_out_buffer, 16);
765 static char tmpstr[23 + BUF_THREAD_ID_SIZE];
767 sprintf(tmpstr, "shadowCPU%d",
768 (int)(-ks->threadid - 2));
769 kgdb_mem2hex(tmpstr, remcom_out_buffer, strlen(tmpstr));
772 #ifdef CONFIG_KGDB_KDB
774 if (strncmp(remcom_in_buffer, "qRcmd,", 6) == 0) {
775 int len = strlen(remcom_in_buffer + 6);
777 if ((len % 2) != 0) {
778 strcpy(remcom_out_buffer, "E01");
781 kgdb_hex2mem(remcom_in_buffer + 6,
782 remcom_out_buffer, len);
784 remcom_out_buffer[len++] = 0;
786 kdb_parse(remcom_out_buffer);
787 strcpy(remcom_out_buffer, "OK");
794 /* Handle the 'H' task query packets */
795 static void gdb_cmd_task(struct kgdb_state *ks)
797 struct task_struct *thread;
800 switch (remcom_in_buffer[1]) {
802 ptr = &remcom_in_buffer[2];
803 kgdb_hex2long(&ptr, &ks->threadid);
804 thread = getthread(ks->linux_regs, ks->threadid);
805 if (!thread && ks->threadid > 0) {
806 error_packet(remcom_out_buffer, -EINVAL);
809 kgdb_usethread = thread;
810 ks->kgdb_usethreadid = ks->threadid;
811 strcpy(remcom_out_buffer, "OK");
814 ptr = &remcom_in_buffer[2];
815 kgdb_hex2long(&ptr, &ks->threadid);
817 kgdb_contthread = NULL;
819 thread = getthread(ks->linux_regs, ks->threadid);
820 if (!thread && ks->threadid > 0) {
821 error_packet(remcom_out_buffer, -EINVAL);
824 kgdb_contthread = thread;
826 strcpy(remcom_out_buffer, "OK");
831 /* Handle the 'T' thread query packets */
832 static void gdb_cmd_thread(struct kgdb_state *ks)
834 char *ptr = &remcom_in_buffer[1];
835 struct task_struct *thread;
837 kgdb_hex2long(&ptr, &ks->threadid);
838 thread = getthread(ks->linux_regs, ks->threadid);
840 strcpy(remcom_out_buffer, "OK");
842 error_packet(remcom_out_buffer, -EINVAL);
845 /* Handle the 'z' or 'Z' breakpoint remove or set packets */
846 static void gdb_cmd_break(struct kgdb_state *ks)
849 * Since GDB-5.3, it's been drafted that '0' is a software
850 * breakpoint, '1' is a hardware breakpoint, so let's do that.
852 char *bpt_type = &remcom_in_buffer[1];
853 char *ptr = &remcom_in_buffer[2];
855 unsigned long length;
858 if (arch_kgdb_ops.set_hw_breakpoint && *bpt_type >= '1') {
863 if (*bpt_type != '0' && *bpt_type != '1')
869 * Test if this is a hardware breakpoint, and
872 if (*bpt_type == '1' && !(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT))
876 if (*(ptr++) != ',') {
877 error_packet(remcom_out_buffer, -EINVAL);
880 if (!kgdb_hex2long(&ptr, &addr)) {
881 error_packet(remcom_out_buffer, -EINVAL);
884 if (*(ptr++) != ',' ||
885 !kgdb_hex2long(&ptr, &length)) {
886 error_packet(remcom_out_buffer, -EINVAL);
890 if (remcom_in_buffer[0] == 'Z' && *bpt_type == '0')
891 error = dbg_set_sw_break(addr);
892 else if (remcom_in_buffer[0] == 'z' && *bpt_type == '0')
893 error = dbg_remove_sw_break(addr);
894 else if (remcom_in_buffer[0] == 'Z')
895 error = arch_kgdb_ops.set_hw_breakpoint(addr,
896 (int)length, *bpt_type - '0');
897 else if (remcom_in_buffer[0] == 'z')
898 error = arch_kgdb_ops.remove_hw_breakpoint(addr,
899 (int) length, *bpt_type - '0');
902 strcpy(remcom_out_buffer, "OK");
904 error_packet(remcom_out_buffer, error);
907 /* Handle the 'C' signal / exception passing packets */
908 static int gdb_cmd_exception_pass(struct kgdb_state *ks)
910 /* C09 == pass exception
911 * C15 == detach kgdb, pass exception
913 if (remcom_in_buffer[1] == '0' && remcom_in_buffer[2] == '9') {
915 ks->pass_exception = 1;
916 remcom_in_buffer[0] = 'c';
918 } else if (remcom_in_buffer[1] == '1' && remcom_in_buffer[2] == '5') {
920 ks->pass_exception = 1;
921 remcom_in_buffer[0] = 'D';
922 dbg_remove_all_break();
927 gdbstub_msg_write("KGDB only knows signal 9 (pass)"
928 " and 15 (pass and disconnect)\n"
929 "Executing a continue without signal passing\n", 0);
930 remcom_in_buffer[0] = 'c';
933 /* Indicate fall through */
938 * This function performs all gdbserial command procesing
940 int gdb_serial_stub(struct kgdb_state *ks)
945 /* Initialize comm buffer and globals. */
946 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
947 kgdb_usethread = kgdb_info[ks->cpu].task;
948 ks->kgdb_usethreadid = shadow_pid(kgdb_info[ks->cpu].task->pid);
949 ks->pass_exception = 0;
951 if (kgdb_connected) {
952 unsigned char thref[BUF_THREAD_ID_SIZE];
955 /* Reply to host that an exception has occurred */
956 ptr = remcom_out_buffer;
958 ptr = hex_byte_pack(ptr, ks->signo);
959 ptr += strlen(strcpy(ptr, "thread:"));
960 int_to_threadref(thref, shadow_pid(current->pid));
961 ptr = pack_threadid(ptr, thref);
963 put_packet(remcom_out_buffer);
969 /* Clear the out buffer. */
970 memset(remcom_out_buffer, 0, sizeof(remcom_out_buffer));
972 get_packet(remcom_in_buffer);
974 switch (remcom_in_buffer[0]) {
975 case '?': /* gdbserial status */
978 case 'g': /* return the value of the CPU registers */
981 case 'G': /* set the value of the CPU registers - return OK */
984 case 'm': /* mAA..AA,LLLL Read LLLL bytes at address AA..AA */
987 case 'M': /* MAA..AA,LLLL: Write LLLL bytes at address AA..AA */
988 gdb_cmd_memwrite(ks);
990 #if DBG_MAX_REG_NUM > 0
991 case 'p': /* pXX Return gdb register XX (in hex) */
994 case 'P': /* PXX=aaaa Set gdb register XX to aaaa (in hex) */
997 #endif /* DBG_MAX_REG_NUM > 0 */
998 case 'X': /* XAA..AA,LLLL: Write LLLL bytes at address AA..AA */
999 gdb_cmd_binwrite(ks);
1001 /* kill or detach. KGDB should treat this like a
1004 case 'D': /* Debugger detach */
1005 case 'k': /* Debugger detach via kill */
1006 gdb_cmd_detachkill(ks);
1007 goto default_handle;
1008 case 'R': /* Reboot */
1009 if (gdb_cmd_reboot(ks))
1010 goto default_handle;
1012 case 'q': /* query command */
1015 case 'H': /* task related */
1018 case 'T': /* Query thread status */
1021 case 'z': /* Break point remove */
1022 case 'Z': /* Break point set */
1025 #ifdef CONFIG_KGDB_KDB
1026 case '3': /* Escape into back into kdb */
1027 if (remcom_in_buffer[1] == '\0') {
1028 gdb_cmd_detachkill(ks);
1029 return DBG_PASS_EVENT;
1032 case 'C': /* Exception passing */
1033 tmp = gdb_cmd_exception_pass(ks);
1035 goto default_handle;
1038 /* Fall through on tmp < 0 */
1039 case 'c': /* Continue packet */
1040 case 's': /* Single step packet */
1041 if (kgdb_contthread && kgdb_contthread != current) {
1042 /* Can't switch threads in kgdb */
1043 error_packet(remcom_out_buffer, -EINVAL);
1046 dbg_activate_sw_breakpoints();
1047 /* Fall through to default processing */
1050 error = kgdb_arch_handle_exception(ks->ex_vector,
1057 * Leave cmd processing on error, detach,
1058 * kill, continue, or single step.
1060 if (error >= 0 || remcom_in_buffer[0] == 'D' ||
1061 remcom_in_buffer[0] == 'k') {
1068 /* reply to the request */
1069 put_packet(remcom_out_buffer);
1073 if (ks->pass_exception)
1078 int gdbstub_state(struct kgdb_state *ks, char *cmd)
1084 error = kgdb_arch_handle_exception(ks->ex_vector,
1093 strcpy(remcom_in_buffer, cmd);
1096 strcpy(remcom_in_buffer, cmd);
1097 gdbstub_use_prev_in_buf = strlen(remcom_in_buffer);
1098 gdbstub_prev_in_buf_pos = 0;
1101 dbg_io_ops->write_char('+');
1102 put_packet(remcom_out_buffer);
1107 * gdbstub_exit - Send an exit message to GDB
1108 * @status: The exit code to report.
1110 void gdbstub_exit(int status)
1112 unsigned char checksum, ch, buffer[3];
1115 if (!kgdb_connected)
1119 if (!dbg_io_ops || dbg_kdb_mode)
1123 buffer[1] = hex_asc_hi(status);
1124 buffer[2] = hex_asc_lo(status);
1126 dbg_io_ops->write_char('$');
1129 for (loop = 0; loop < 3; loop++) {
1132 dbg_io_ops->write_char(ch);
1135 dbg_io_ops->write_char('#');
1136 dbg_io_ops->write_char(hex_asc_hi(checksum));
1137 dbg_io_ops->write_char(hex_asc_lo(checksum));
1139 /* make sure the output is flushed, lest the bootloader clobber it */
1140 if (dbg_io_ops->flush)
1141 dbg_io_ops->flush();