2003-08-07 20:26:28 +04:00
|
|
|
/* $NetBSD: kgdb_stub.c,v 1.15 2003/08/07 16:31:52 agc Exp $ */
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1997-02-12 03:51:47 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Stub" to allow remote cpu to debug over a serial line using gdb.
|
|
|
|
*/
|
|
|
|
|
2001-11-12 18:25:01 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-08-07 20:26:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kgdb_stub.c,v 1.15 2003/08/07 16:31:52 agc Exp $");
|
2001-11-20 11:43:19 +03:00
|
|
|
|
|
|
|
#include "opt_kgdb.h"
|
2001-11-12 18:25:01 +03:00
|
|
|
|
1997-02-12 03:51:47 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kgdb.h>
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
#undef DEBUG_KGDB
|
|
|
|
|
|
|
|
#ifdef DEBUG_KGDB
|
|
|
|
#define DPRINTF(x) printf x
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#endif
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
/* XXX: Maybe these should be in the MD files? */
|
2001-11-20 11:43:19 +03:00
|
|
|
#ifndef KGDB_DEV
|
|
|
|
#define KGDB_DEV NODEV
|
1997-02-12 03:51:47 +03:00
|
|
|
#endif
|
2001-11-20 11:43:19 +03:00
|
|
|
#ifndef KGDB_DEVRATE
|
|
|
|
#define KGDB_DEVRATE 19200
|
1997-02-12 03:51:47 +03:00
|
|
|
#endif
|
|
|
|
|
2001-11-20 11:43:19 +03:00
|
|
|
int kgdb_dev = KGDB_DEV; /* remote debugging device (NODEV if none) */
|
|
|
|
int kgdb_rate = KGDB_DEVRATE; /* remote debugging baud rate */
|
1997-02-12 03:51:47 +03:00
|
|
|
int kgdb_active = 0; /* remote debugging active if != 0 */
|
|
|
|
int kgdb_debug_init = 0; /* != 0 waits for remote at system init */
|
|
|
|
int kgdb_debug_panic = 0; /* != 0 waits for remote on panic */
|
|
|
|
label_t *kgdb_recover = 0;
|
|
|
|
|
|
|
|
static void kgdb_copy __P((void *, void *, int));
|
|
|
|
/* static void kgdb_zero __P((void *, int)); */
|
|
|
|
static void kgdb_send __P((u_char *));
|
|
|
|
static int kgdb_recv __P((u_char *, int));
|
|
|
|
static int digit2i __P((u_char));
|
|
|
|
static u_char i2digit __P((int));
|
|
|
|
static void mem2hex __P((void *, void *, int));
|
|
|
|
static u_char *hex2mem __P((void *, u_char *, int));
|
1998-08-13 06:10:37 +04:00
|
|
|
static vaddr_t hex2i __P((u_char **));
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
static int (*kgdb_getc) __P((void *));
|
|
|
|
static void (*kgdb_putc) __P((void *, int));
|
|
|
|
static void *kgdb_ioarg;
|
|
|
|
|
2002-01-06 01:57:38 +03:00
|
|
|
/* KGDB_BUFLEN must be at least (2*KGDB_NUMREGS*sizeof(kgdb_reg_t)+1) */
|
1997-02-12 03:51:47 +03:00
|
|
|
static u_char buffer[KGDB_BUFLEN];
|
|
|
|
static kgdb_reg_t gdb_regs[KGDB_NUMREGS];
|
|
|
|
|
|
|
|
#define GETC() ((*kgdb_getc)(kgdb_ioarg))
|
|
|
|
#define PUTC(c) ((*kgdb_putc)(kgdb_ioarg, c))
|
|
|
|
|
2000-07-19 01:49:08 +04:00
|
|
|
/*
|
|
|
|
* db_trap_callback can be hooked by MD port code to handle special
|
|
|
|
* cases such as disabling hardware watchdogs while in kgdb. Name
|
|
|
|
* is shared with DDB.
|
|
|
|
*/
|
|
|
|
void (*db_trap_callback)(int);
|
|
|
|
|
1997-02-12 03:51:47 +03:00
|
|
|
/*
|
|
|
|
* This little routine exists simply so that bcopy() can be debugged.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
kgdb_copy(vsrc, vdst, len)
|
|
|
|
void *vsrc, *vdst;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
char *src = vsrc;
|
|
|
|
char *dst = vdst;
|
|
|
|
|
|
|
|
while (--len >= 0)
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* ditto for bzero */
|
|
|
|
static void
|
|
|
|
kgdb_zero(vptr, len)
|
|
|
|
void *vptr;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
char *ptr = vptr;
|
|
|
|
|
|
|
|
while (--len >= 0)
|
|
|
|
*ptr++ = (char) 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a hex digit into an integer.
|
|
|
|
* This returns -1 if the argument passed is no
|
|
|
|
* valid hex digit.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
digit2i(c)
|
|
|
|
u_char c;
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9')
|
1998-08-31 00:30:57 +04:00
|
|
|
return (c - '0');
|
1997-02-12 03:51:47 +03:00
|
|
|
else if (c >= 'a' && c <= 'f')
|
1998-08-31 00:30:57 +04:00
|
|
|
return (c - 'a' + 10);
|
1997-02-12 03:51:47 +03:00
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
|
1998-08-31 00:30:57 +04:00
|
|
|
return (c - 'A' + 10);
|
1997-02-12 03:51:47 +03:00
|
|
|
else
|
1998-08-31 00:30:57 +04:00
|
|
|
return (-1);
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the low 4 bits of an integer into
|
|
|
|
* an hex digit.
|
|
|
|
*/
|
|
|
|
static u_char
|
|
|
|
i2digit(n)
|
|
|
|
int n;
|
|
|
|
{
|
1998-08-31 00:30:57 +04:00
|
|
|
return ("0123456789abcdef"[n & 0x0f]);
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a byte array into an hex string.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mem2hex(vdst, vsrc, len)
|
|
|
|
void *vdst, *vsrc;
|
|
|
|
int len;
|
|
|
|
{
|
|
|
|
u_char *dst = vdst;
|
|
|
|
u_char *src = vsrc;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
*dst++ = i2digit(*src >> 4);
|
|
|
|
*dst++ = i2digit(*src++);
|
|
|
|
}
|
|
|
|
*dst = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an hex string into a byte array.
|
|
|
|
* This returns a pointer to the character following
|
|
|
|
* the last valid hex digit. If the string ends in
|
|
|
|
* the middle of a byte, NULL is returned.
|
|
|
|
*/
|
|
|
|
static u_char *
|
|
|
|
hex2mem(vdst, src, maxlen)
|
|
|
|
void *vdst;
|
|
|
|
u_char *src;
|
|
|
|
int maxlen;
|
|
|
|
{
|
|
|
|
u_char *dst = vdst;
|
|
|
|
int msb, lsb;
|
|
|
|
|
|
|
|
while (*src && maxlen--) {
|
|
|
|
msb = digit2i(*src++);
|
|
|
|
if (msb < 0)
|
1998-08-31 00:30:57 +04:00
|
|
|
return (src - 1);
|
1997-02-12 03:51:47 +03:00
|
|
|
lsb = digit2i(*src++);
|
|
|
|
if (lsb < 0)
|
1998-08-31 00:30:57 +04:00
|
|
|
return (NULL);
|
1997-02-12 03:51:47 +03:00
|
|
|
*dst++ = (msb << 4) | lsb;
|
|
|
|
}
|
1998-08-31 00:30:57 +04:00
|
|
|
return (src);
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert an hex string into an integer.
|
|
|
|
* This returns a pointer to the character following
|
|
|
|
* the last valid hex digit.
|
|
|
|
*/
|
1998-08-13 06:10:37 +04:00
|
|
|
static vaddr_t
|
1997-02-12 03:51:47 +03:00
|
|
|
hex2i(srcp)
|
|
|
|
u_char **srcp;
|
|
|
|
{
|
|
|
|
char *src = *srcp;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t r = 0;
|
1997-02-12 03:51:47 +03:00
|
|
|
int nibble;
|
|
|
|
|
|
|
|
while ((nibble = digit2i(*src)) >= 0) {
|
|
|
|
r *= 16;
|
|
|
|
r += nibble;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
*srcp = src;
|
1998-08-31 00:30:57 +04:00
|
|
|
return (r);
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a packet.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
kgdb_send(bp)
|
|
|
|
u_char *bp;
|
|
|
|
{
|
|
|
|
u_char *p;
|
|
|
|
u_char csum, c;
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("kgdb_send: %s\n", bp));
|
1997-02-12 03:51:47 +03:00
|
|
|
do {
|
|
|
|
p = bp;
|
|
|
|
PUTC(KGDB_START);
|
|
|
|
for (csum = 0; (c = *p); p++) {
|
|
|
|
PUTC(c);
|
|
|
|
csum += c;
|
|
|
|
}
|
|
|
|
PUTC(KGDB_END);
|
|
|
|
PUTC(i2digit(csum >> 4));
|
|
|
|
PUTC(i2digit(csum));
|
|
|
|
} while ((c = GETC() & 0x7f) == KGDB_BADP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive a packet.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
kgdb_recv(bp, maxlen)
|
|
|
|
u_char *bp;
|
|
|
|
int maxlen;
|
|
|
|
{
|
|
|
|
u_char *p;
|
2003-01-18 13:06:22 +03:00
|
|
|
int c, csum, tmpcsum;
|
1997-02-12 03:51:47 +03:00
|
|
|
int len;
|
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("kgdb_recv: "));
|
1997-02-12 03:51:47 +03:00
|
|
|
do {
|
|
|
|
p = bp;
|
|
|
|
csum = len = 0;
|
|
|
|
while ((c = GETC()) != KGDB_START)
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("%c",c));
|
|
|
|
DPRINTF(("%c Start ",c));
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
while ((c = GETC()) != KGDB_END && len < maxlen) {
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("%c",c));
|
1997-02-12 03:51:47 +03:00
|
|
|
c &= 0x7f;
|
|
|
|
csum += c;
|
|
|
|
*p++ = c;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
csum &= 0xff;
|
|
|
|
*p = '\0';
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("%c End ", c));
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
if (len >= maxlen) {
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("Long- "));
|
1997-02-12 03:51:47 +03:00
|
|
|
PUTC(KGDB_BADP);
|
|
|
|
continue;
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
tmpcsum = csum;
|
1997-02-12 03:51:47 +03:00
|
|
|
|
2003-01-18 13:06:22 +03:00
|
|
|
c = GETC();
|
|
|
|
DPRINTF(("%c",c));
|
|
|
|
csum -= digit2i(c) * 16;
|
|
|
|
c = GETC();
|
|
|
|
DPRINTF(("%c",c));
|
|
|
|
csum -= digit2i(c);
|
1997-02-12 03:51:47 +03:00
|
|
|
|
|
|
|
if (csum == 0) {
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("Good+ "));
|
1997-02-12 03:51:47 +03:00
|
|
|
PUTC(KGDB_GOODP);
|
|
|
|
/* Sequence present? */
|
|
|
|
if (bp[2] == ':') {
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("Seq %c%c ", bp[0], bp[1]));
|
1997-02-12 03:51:47 +03:00
|
|
|
PUTC(bp[0]);
|
|
|
|
PUTC(bp[1]);
|
|
|
|
len -= 3;
|
|
|
|
kgdb_copy(bp + 3, bp, len);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF((" Bad(wanted %x, off by %d)- ", tmpcsum, csum));
|
1997-02-12 03:51:47 +03:00
|
|
|
PUTC(KGDB_BADP);
|
|
|
|
} while (1);
|
2003-01-18 13:06:22 +03:00
|
|
|
DPRINTF(("kgdb_recv: %s\n", bp));
|
1998-08-31 00:30:57 +04:00
|
|
|
return (len);
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-08-31 00:30:57 +04:00
|
|
|
* This is called by the appropriate tty driver.
|
1997-02-12 03:51:47 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
kgdb_attach(getfn, putfn, ioarg)
|
|
|
|
int (*getfn) __P((void *));
|
|
|
|
void (*putfn) __P((void *, int));
|
|
|
|
void *ioarg;
|
|
|
|
{
|
|
|
|
kgdb_getc = getfn;
|
|
|
|
kgdb_putc = putfn;
|
|
|
|
kgdb_ioarg = ioarg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-08-31 00:30:57 +04:00
|
|
|
* This function does all command processing for interfacing to
|
1997-02-12 03:51:47 +03:00
|
|
|
* a remote gdb. Note that the error codes are ignored by gdb
|
|
|
|
* at present, but might eventually become meaningful. (XXX)
|
|
|
|
* It might makes sense to use POSIX errno values, because
|
|
|
|
* that is what the gdb/remote.c functions want to return.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
kgdb_trap(type, regs)
|
|
|
|
int type;
|
|
|
|
db_regs_t *regs;
|
|
|
|
{
|
|
|
|
label_t jmpbuf;
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t addr;
|
1997-02-12 03:51:47 +03:00
|
|
|
size_t len;
|
|
|
|
u_char *p;
|
|
|
|
|
|
|
|
if (kgdb_dev < 0 || kgdb_getc == NULL) {
|
|
|
|
/* not debugging */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-07-08 02:58:00 +04:00
|
|
|
db_clear_single_step(regs);
|
|
|
|
|
2000-07-19 01:49:08 +04:00
|
|
|
if (db_trap_callback) db_trap_callback(1);
|
|
|
|
|
1997-02-12 03:51:47 +03:00
|
|
|
/* Detect and recover from unexpected traps. */
|
|
|
|
if (kgdb_recover != 0) {
|
|
|
|
printf("kgdb: caught trap 0x%x at %p\n",
|
|
|
|
type, (void*)PC_REGS(regs));
|
|
|
|
kgdb_send("E0E"); /* 14==EFAULT */
|
|
|
|
longjmp(kgdb_recover);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-02-18 19:45:10 +03:00
|
|
|
* The first entry to this function is normally through
|
|
|
|
* a breakpoint trap in kgdb_connect(), in which case we
|
|
|
|
* must advance past the breakpoint because gdb will not.
|
|
|
|
*
|
|
|
|
* Machines vary as to where they leave the PC after a
|
|
|
|
* breakpoint trap. Those that leave the PC set to the
|
|
|
|
* address of the trap instruction (i.e. pc532) will not
|
|
|
|
* define FIXUP_PC_AFTER_BREAK(), and therefore will just
|
|
|
|
* advance the PC. On machines that leave the PC set to
|
|
|
|
* the instruction after the trap, FIXUP_PC_AFTER_BREAK
|
|
|
|
* will be defined to back-up the PC, so that after the
|
|
|
|
* "first-time" part of the if statement below has run,
|
|
|
|
* the PC will be the same as it was on entry.
|
|
|
|
*
|
1997-02-12 03:51:47 +03:00
|
|
|
* On the first entry here, we expect that gdb is not yet
|
|
|
|
* listening to us, so just enter the interaction loop.
|
1997-02-18 19:45:10 +03:00
|
|
|
* After the debugger is "active" (connected) it will be
|
1997-02-12 03:51:47 +03:00
|
|
|
* waiting for a "signaled" message from us.
|
|
|
|
*/
|
|
|
|
if (kgdb_active == 0) {
|
|
|
|
if (!IS_BREAKPOINT_TRAP(type, 0)) {
|
|
|
|
/* No debugger active -- let trap handle this. */
|
2000-07-19 01:49:08 +04:00
|
|
|
if (db_trap_callback) db_trap_callback(0);
|
1997-02-12 03:51:47 +03:00
|
|
|
return (0);
|
|
|
|
}
|
1997-02-18 19:45:10 +03:00
|
|
|
/* Make the PC point at the breakpoint... */
|
|
|
|
#ifdef FIXUP_PC_AFTER_BREAK
|
|
|
|
FIXUP_PC_AFTER_BREAK(regs);
|
|
|
|
#endif
|
|
|
|
/* ... and then advance past it. */
|
1997-09-10 23:37:31 +04:00
|
|
|
#ifdef PC_ADVANCE
|
|
|
|
PC_ADVANCE(regs);
|
|
|
|
#else
|
1997-02-18 19:45:10 +03:00
|
|
|
PC_REGS(regs) += BKPT_SIZE;
|
1997-09-10 23:37:31 +04:00
|
|
|
#endif
|
1997-02-12 03:51:47 +03:00
|
|
|
kgdb_active = 1;
|
|
|
|
} else {
|
2001-09-16 20:34:23 +04:00
|
|
|
/* Tell remote host that an exception has occurred. */
|
1997-02-12 03:51:47 +03:00
|
|
|
sprintf(buffer, "S%02x", kgdb_signal(type));
|
|
|
|
kgdb_send(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stick frame regs into our reg cache. */
|
|
|
|
kgdb_getregs(regs, gdb_regs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interact with gdb until it lets us go.
|
|
|
|
* If we cause a trap, resume here.
|
|
|
|
*/
|
1998-08-31 00:30:57 +04:00
|
|
|
(void)setjmp((kgdb_recover = &jmpbuf));
|
1997-02-12 03:51:47 +03:00
|
|
|
for (;;) {
|
|
|
|
kgdb_recv(buffer, sizeof(buffer));
|
|
|
|
switch (buffer[0]) {
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Unknown command. */
|
|
|
|
kgdb_send("");
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case KGDB_SIGNAL:
|
|
|
|
/*
|
|
|
|
* if this command came from a running gdb,
|
|
|
|
* answer it -- the other guy has no way of
|
|
|
|
* knowing if we're in or out of this loop
|
|
|
|
* when he issues a "remote-signal".
|
|
|
|
*/
|
|
|
|
sprintf(buffer, "S%02x", kgdb_signal(type));
|
|
|
|
kgdb_send(buffer);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case KGDB_REG_R:
|
|
|
|
mem2hex(buffer, gdb_regs, sizeof(gdb_regs));
|
|
|
|
kgdb_send(buffer);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case KGDB_REG_W:
|
|
|
|
p = hex2mem(gdb_regs, buffer + 1, sizeof(gdb_regs));
|
|
|
|
if (p == NULL || *p != '\0')
|
|
|
|
kgdb_send("E01");
|
|
|
|
else {
|
|
|
|
kgdb_setregs(regs, gdb_regs);
|
|
|
|
kgdb_send("OK");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case KGDB_MEM_R:
|
|
|
|
p = buffer + 1;
|
|
|
|
addr = hex2i(&p);
|
|
|
|
if (*p++ != ',') {
|
|
|
|
kgdb_send("E02");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len = hex2i(&p);
|
|
|
|
if (*p != '\0') {
|
|
|
|
kgdb_send("E03");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (len > sizeof(buffer) / 2) {
|
|
|
|
kgdb_send("E04");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (kgdb_acc(addr, len) == 0) {
|
|
|
|
kgdb_send("E05");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
db_read_bytes(addr, (size_t)len,
|
|
|
|
(char *)buffer + sizeof(buffer) / 2);
|
|
|
|
mem2hex(buffer, buffer + sizeof(buffer) / 2, len);
|
|
|
|
kgdb_send(buffer);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case KGDB_MEM_W:
|
|
|
|
p = buffer + 1;
|
|
|
|
addr = hex2i(&p);
|
|
|
|
if (*p++ != ',') {
|
|
|
|
kgdb_send("E06");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len = hex2i(&p);
|
|
|
|
if (*p++ != ':') {
|
|
|
|
kgdb_send("E07");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (len > (sizeof(buffer) - (p - buffer))) {
|
|
|
|
kgdb_send("E08");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p = hex2mem(buffer, p, sizeof(buffer));
|
|
|
|
if (p == NULL) {
|
|
|
|
kgdb_send("E09");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (kgdb_acc(addr, len) == 0) {
|
|
|
|
kgdb_send("E0A");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
db_write_bytes(addr, (size_t)len, (char *)buffer);
|
|
|
|
kgdb_send("OK");
|
|
|
|
continue;
|
|
|
|
|
2002-01-06 01:57:38 +03:00
|
|
|
case KGDB_DETACH:
|
1997-02-12 03:51:47 +03:00
|
|
|
case KGDB_KILL:
|
|
|
|
kgdb_active = 0;
|
|
|
|
printf("kgdb detached\n");
|
|
|
|
db_clear_single_step(regs);
|
2002-01-06 01:57:38 +03:00
|
|
|
kgdb_send("OK");
|
1997-02-12 03:51:47 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
case KGDB_CONT:
|
|
|
|
if (buffer[1]) {
|
|
|
|
p = buffer + 1;
|
|
|
|
addr = hex2i(&p);
|
|
|
|
if (*p) {
|
|
|
|
kgdb_send("E0B");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PC_REGS(regs) = addr;
|
2003-05-13 06:13:14 +04:00
|
|
|
DPRINTF(("kgdb: continuing at %08lx\n", addr));
|
2003-01-18 13:06:22 +03:00
|
|
|
|
|
|
|
} else {
|
|
|
|
DPRINTF((
|
|
|
|
"kgdb: continuing at old address %08lx\n",
|
2003-05-13 06:13:14 +04:00
|
|
|
(vaddr_t)PC_REGS(regs)));
|
1997-02-12 03:51:47 +03:00
|
|
|
}
|
2003-01-18 13:06:22 +03:00
|
|
|
|
1997-02-12 03:51:47 +03:00
|
|
|
db_clear_single_step(regs);
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
case KGDB_STEP:
|
|
|
|
if (buffer[1]) {
|
|
|
|
p = buffer + 1;
|
|
|
|
addr = hex2i(&p);
|
|
|
|
if (*p) {
|
|
|
|
kgdb_send("E0B");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PC_REGS(regs) = addr;
|
|
|
|
}
|
|
|
|
db_set_single_step(regs);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
2000-07-19 01:49:08 +04:00
|
|
|
if (db_trap_callback) db_trap_callback(0);
|
1997-02-12 03:51:47 +03:00
|
|
|
kgdb_recover = 0;
|
|
|
|
return (1);
|
|
|
|
}
|