2002-10-03 09:29:15 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
2004-11-01 20:14:02 +03:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
#include <winsock2.h>
|
|
|
|
#define SIGTRAP 5
|
|
|
|
#else
|
2002-10-03 09:29:15 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2002-10-07 00:43:02 +04:00
|
|
|
#include <netinet/tcp.h>
|
2002-10-03 09:29:15 +04:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <signal.h>
|
2002-10-07 00:43:02 +04:00
|
|
|
#include <netdb.h>
|
2004-11-01 20:14:02 +03:00
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
#define NEED_CPU_REG_SHORTCUTS 1
|
|
|
|
|
|
|
|
#include "bochs.h"
|
2006-04-25 19:59:20 +04:00
|
|
|
#include "cpu/cpu.h"
|
2004-06-19 19:20:15 +04:00
|
|
|
#include "iodev/iodev.h"
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
#define LOG_THIS genlog->
|
|
|
|
#define IFDBG(x) x
|
|
|
|
|
|
|
|
static int last_stop_reason = GDBSTUB_STOP_NO_REASON;
|
|
|
|
|
|
|
|
#define GDBSTUB_EXECUTION_BREAKPOINT (0xac1)
|
|
|
|
#define GDBSTUB_TRACE (0xac2)
|
|
|
|
#define GDBSTUB_USER_BREAK (0xac3)
|
|
|
|
|
2006-03-04 15:43:47 +03:00
|
|
|
static bx_list_c *gdbstub_list;
|
2002-10-03 09:29:15 +04:00
|
|
|
static int listen_socket_fd;
|
|
|
|
static int socket_fd;
|
|
|
|
|
|
|
|
static int hex(char ch)
|
|
|
|
{
|
|
|
|
if ((ch >= 'a') && (ch <= 'f')) return(ch - 'a' + 10);
|
|
|
|
if ((ch >= '0') && (ch <= '9')) return(ch - '0');
|
|
|
|
if ((ch >= 'A') && (ch <= 'F')) return(ch - 'A' + 10);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put_debug_char(char ch)
|
|
|
|
{
|
|
|
|
send(socket_fd, &ch, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char get_debug_char(void)
|
|
|
|
{
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
recv(socket_fd, &ch, 1, 0);
|
|
|
|
|
|
|
|
return(ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char hexchars[]="0123456789abcdef";
|
|
|
|
|
|
|
|
static void put_reply(char* buffer)
|
|
|
|
{
|
|
|
|
unsigned char csum;
|
|
|
|
int i;
|
|
|
|
|
2002-10-04 17:20:09 +04:00
|
|
|
BX_DEBUG (("put_buffer %s", buffer));
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
do {
|
2002-10-03 09:29:15 +04:00
|
|
|
put_debug_char('$');
|
|
|
|
|
|
|
|
csum = 0;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (buffer[i] != 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_debug_char(buffer[i]);
|
|
|
|
csum = csum + buffer[i];
|
|
|
|
i++;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
put_debug_char('#');
|
|
|
|
put_debug_char(hexchars[csum >> 4]);
|
|
|
|
put_debug_char(hexchars[csum % 16]);
|
2006-06-17 16:09:55 +04:00
|
|
|
} while (get_debug_char() != '+');
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void get_command(char* buffer)
|
|
|
|
{
|
|
|
|
unsigned char checksum;
|
|
|
|
unsigned char xmitcsum;
|
|
|
|
char ch;
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
do{
|
2002-10-03 09:29:15 +04:00
|
|
|
while ((ch = get_debug_char()) != '$');
|
|
|
|
|
|
|
|
checksum = 0;
|
|
|
|
xmitcsum = 0;
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
while (1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
ch = get_debug_char();
|
|
|
|
if (ch == '#') break;
|
|
|
|
checksum = checksum + ch;
|
|
|
|
buffer[count] = ch;
|
|
|
|
count++;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
buffer[count] = 0;
|
|
|
|
|
|
|
|
if (ch == '#')
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
xmitcsum = hex(get_debug_char()) << 4;
|
|
|
|
xmitcsum += hex(get_debug_char());
|
|
|
|
if (checksum != xmitcsum)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("Bad checksum"));
|
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
if (checksum != xmitcsum)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_debug_char('-');
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_debug_char('+');
|
|
|
|
if (buffer[2] == ':')
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_debug_char(buffer[0]);
|
|
|
|
put_debug_char(buffer[1]);
|
|
|
|
count = strlen(buffer);
|
|
|
|
for (i = 3; i <= count; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
buffer[i - 3] = buffer[i];
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (checksum != xmitcsum);
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void hex2mem(char* buf, unsigned char* mem, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char ch;
|
|
|
|
|
|
|
|
for (i = 0; i<count; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
ch = hex(*buf++) << 4;
|
|
|
|
ch = ch + hex(*buf++);
|
|
|
|
*mem = ch;
|
|
|
|
mem++;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char* mem2hex(char* mem, char* buf, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char ch;
|
|
|
|
|
|
|
|
for (i = 0; i<count; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
ch = *mem;
|
|
|
|
mem++;
|
|
|
|
*buf = hexchars[ch >> 4];
|
|
|
|
buf++;
|
|
|
|
*buf = hexchars[ch % 16];
|
|
|
|
buf++;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
*buf = 0;
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
|
2005-02-16 21:58:48 +03:00
|
|
|
int hexdigit(char c)
|
|
|
|
{
|
|
|
|
if (isdigit(c))
|
|
|
|
return c - '0';
|
|
|
|
else if (isupper(c))
|
|
|
|
return c - 'A' + 10;
|
|
|
|
else
|
|
|
|
return c - 'a' + 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bit64u read_little_endian_hex(char *&buf)
|
|
|
|
{
|
|
|
|
int byte;
|
|
|
|
Bit64u ret = 0;
|
|
|
|
int n = 0;
|
|
|
|
while (isxdigit(*buf)) {
|
|
|
|
byte = hexdigit(*buf++);
|
|
|
|
if (isxdigit(*buf))
|
|
|
|
byte = (byte << 4) | hexdigit(*buf++);
|
|
|
|
ret |= (unsigned long long)byte << (n*8);
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
static int continue_thread = -1;
|
|
|
|
static int other_thread = 0;
|
|
|
|
|
2005-03-16 19:36:31 +03:00
|
|
|
#if !BX_SUPPORT_X86_64
|
2002-10-03 09:29:15 +04:00
|
|
|
#define NUMREGS (16)
|
|
|
|
#define NUMREGSBYTES (NUMREGS * 4)
|
|
|
|
static int registers[NUMREGS];
|
2005-02-16 21:58:48 +03:00
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
#define MAX_BREAKPOINTS (255)
|
2004-11-01 20:14:02 +03:00
|
|
|
static unsigned int breakpoints[MAX_BREAKPOINTS] = {0,};
|
|
|
|
static unsigned int nr_breakpoints = 0;
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
static int stub_trace_flag = 0;
|
|
|
|
static int instr_count = 0;
|
|
|
|
static int saved_eip = 0;
|
|
|
|
|
|
|
|
int bx_gdbstub_check(unsigned int eip)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned char ch;
|
|
|
|
long arg;
|
|
|
|
int r;
|
2004-11-01 20:14:02 +03:00
|
|
|
#if defined(__CYGWIN__) || defined(__MINGW32__)
|
2002-10-03 09:29:15 +04:00
|
|
|
fd_set fds;
|
|
|
|
struct timeval tv = {0, 0};
|
2004-11-01 20:14:02 +03:00
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
instr_count++;
|
|
|
|
|
|
|
|
if ((instr_count % 500) == 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2004-11-01 20:14:02 +03:00
|
|
|
#if !defined(__CYGWIN__) && !defined(__MINGW32__)
|
2002-10-03 09:29:15 +04:00
|
|
|
arg = fcntl(socket_fd, F_GETFL);
|
|
|
|
fcntl(socket_fd, F_SETFL, arg | O_NONBLOCK);
|
|
|
|
r = recv(socket_fd, &ch, 1, 0);
|
|
|
|
fcntl(socket_fd, F_SETFL, arg);
|
|
|
|
#else
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(socket_fd, &fds);
|
2006-06-17 16:09:55 +04:00
|
|
|
r = select(socket_fd + 1, &fds, NULL, NULL, &tv);
|
2002-10-03 09:29:15 +04:00
|
|
|
if (r == 1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2004-11-01 20:14:02 +03:00
|
|
|
r = recv(socket_fd, (char *)&ch, 1, 0);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
#endif
|
|
|
|
if (r == 1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("Got byte %x", (unsigned int)ch));
|
2002-10-03 09:29:15 +04:00
|
|
|
last_stop_reason = GDBSTUB_USER_BREAK;
|
|
|
|
return(GDBSTUB_USER_BREAK);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2002-10-04 17:20:09 +04:00
|
|
|
// why is trace before breakpoints? does that mean it would never
|
|
|
|
// hit a breakpoint during tracing?
|
2002-10-03 09:29:15 +04:00
|
|
|
if (stub_trace_flag == 1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
last_stop_reason = GDBSTUB_TRACE;
|
|
|
|
return(GDBSTUB_TRACE);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
for (i = 0; i < nr_breakpoints; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
if (eip == breakpoints[i])
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("found breakpoint at %x", eip));
|
2002-10-03 09:29:15 +04:00
|
|
|
last_stop_reason = GDBSTUB_EXECUTION_BREAKPOINT;
|
|
|
|
return(GDBSTUB_EXECUTION_BREAKPOINT);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
last_stop_reason = GDBSTUB_STOP_NO_REASON;
|
|
|
|
return(GDBSTUB_STOP_NO_REASON);
|
|
|
|
}
|
|
|
|
|
2004-11-01 20:14:02 +03:00
|
|
|
static int remove_breakpoint(unsigned int addr, int len)
|
2002-10-03 09:29:15 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (len != 1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
return(0);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_BREAKPOINTS; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
if (breakpoints[i] == addr)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("Removing breakpoint at %x", addr));
|
2002-10-03 09:29:15 +04:00
|
|
|
breakpoints[i] = 0;
|
|
|
|
return(1);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2004-11-01 20:14:02 +03:00
|
|
|
static void insert_breakpoint(unsigned int addr)
|
2002-10-03 09:29:15 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("setting breakpoint at %x", addr));
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2004-11-01 20:14:02 +03:00
|
|
|
for (i = 0; i < (unsigned)MAX_BREAKPOINTS; i++)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
if (breakpoints[i] == 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
breakpoints[i] = addr;
|
|
|
|
if (i >= nr_breakpoints)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
nr_breakpoints = i + 1;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
return;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
BX_INFO(("No slot for breakpoint"));
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
2005-02-16 21:58:48 +03:00
|
|
|
static void do_pc_breakpoint(int insert, unsigned long long addr, int len)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
if (insert)
|
2005-02-24 22:50:36 +03:00
|
|
|
insert_breakpoint(addr+i);
|
2005-02-16 21:58:48 +03:00
|
|
|
else
|
2005-02-24 22:50:36 +03:00
|
|
|
remove_breakpoint(addr+i, 1);
|
2005-02-16 21:58:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_breakpoint(int insert, char* buffer)
|
|
|
|
{
|
|
|
|
char* ebuf;
|
2005-02-24 22:50:36 +03:00
|
|
|
unsigned long type = strtoul(buffer, &ebuf, 16);
|
2005-02-16 21:58:48 +03:00
|
|
|
unsigned long long addr = strtoull(ebuf+1, &ebuf, 16);
|
|
|
|
unsigned long len = strtoul(ebuf+1, &ebuf, 16);
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
do_pc_breakpoint(insert, addr, len);
|
|
|
|
put_reply("OK");
|
2005-02-24 22:50:36 +03:00
|
|
|
break;
|
2005-02-16 21:58:48 +03:00
|
|
|
default:
|
|
|
|
put_reply("");
|
2005-02-24 22:50:36 +03:00
|
|
|
break;
|
2005-02-16 21:58:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
static void write_signal(char* buf, int signal)
|
|
|
|
{
|
|
|
|
buf[0] = hexchars[signal >> 4];
|
|
|
|
buf[1] = hexchars[signal % 16];
|
|
|
|
buf[2] = 0;
|
|
|
|
}
|
|
|
|
|
2005-02-16 21:58:48 +03:00
|
|
|
static int access_linear(Bit64u laddress,
|
2002-10-03 09:29:15 +04:00
|
|
|
unsigned len,
|
|
|
|
unsigned int rw,
|
|
|
|
Bit8u* data)
|
|
|
|
{
|
2006-06-17 16:09:55 +04:00
|
|
|
bx_phy_address phys;
|
2006-06-21 20:30:14 +04:00
|
|
|
bx_bool valid;
|
2006-06-17 16:09:55 +04:00
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
if (((laddress & 0xfff) + len) > 4096)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
valid = access_linear(laddress,
|
|
|
|
4096 - (laddress & 0xfff),
|
|
|
|
rw,
|
|
|
|
data);
|
2006-06-21 20:30:14 +04:00
|
|
|
if (!valid) return(0);
|
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
valid = access_linear(laddress,
|
|
|
|
len + (laddress & 0xfff) - 4096,
|
|
|
|
rw,
|
2006-01-17 20:15:29 +03:00
|
|
|
(Bit8u *)((unsigned long)data +
|
2003-12-08 01:29:14 +03:00
|
|
|
4096 - (laddress & 0xfff)));
|
2002-10-03 09:29:15 +04:00
|
|
|
return(valid);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2006-06-21 20:28:06 +04:00
|
|
|
valid = BX_CPU(0)->dbg_xlate_linear2phy(laddress, (bx_phy_address*)&phys);
|
2006-06-21 20:30:14 +04:00
|
|
|
if (!valid) return(0);
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2006-06-21 20:30:14 +04:00
|
|
|
if (rw == BX_READ) {
|
2006-10-03 01:27:14 +04:00
|
|
|
valid = BX_MEM(0)->dbg_fetch_mem(BX_CPU(0), phys, len, data);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2006-06-21 20:30:14 +04:00
|
|
|
else {
|
2002-10-22 16:50:56 +04:00
|
|
|
valid = BX_MEM(0)->dbg_set_mem(phys, len, data);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2006-06-21 20:30:14 +04:00
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
return(valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_loop(void)
|
|
|
|
{
|
|
|
|
char buffer[255];
|
|
|
|
char obuf[255];
|
|
|
|
int ne;
|
|
|
|
unsigned char mem[255];
|
|
|
|
|
|
|
|
ne = 0;
|
|
|
|
|
|
|
|
while (ne == 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
get_command(buffer);
|
2002-10-04 17:20:09 +04:00
|
|
|
BX_DEBUG (("get_buffer %s", buffer));
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
switch (buffer[0])
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
case 'c':
|
|
|
|
{
|
|
|
|
char buf[255];
|
|
|
|
int new_eip;
|
|
|
|
|
|
|
|
if (buffer[1] != 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
new_eip = atoi(buffer + 1);
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("continuing at %x", new_eip));
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2002-10-22 16:50:56 +04:00
|
|
|
for (int i=0; i<BX_SMP_PROCESSORS; i++) {
|
|
|
|
BX_CPU(i)->invalidate_prefetch_q();
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
saved_eip = EIP;
|
|
|
|
|
2002-10-22 16:50:56 +04:00
|
|
|
BX_CPU(0)->dword.eip = new_eip;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
stub_trace_flag = 0;
|
2004-01-17 11:36:29 +03:00
|
|
|
bx_cpu.ispanic = 0;
|
2006-04-29 11:12:13 +04:00
|
|
|
bx_cpu.cpu_loop(0);
|
2004-01-17 11:36:29 +03:00
|
|
|
if (bx_cpu.ispanic)
|
|
|
|
{
|
|
|
|
last_stop_reason = GDBSTUB_EXECUTION_BREAKPOINT;
|
|
|
|
}
|
|
|
|
|
2002-11-09 00:29:16 +03:00
|
|
|
DEV_vga_refresh();
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
if (buffer[1] != 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
bx_cpu.invalidate_prefetch_q();
|
|
|
|
BX_CPU_THIS_PTR dword.eip = saved_eip;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("stopped with %x", last_stop_reason));
|
2002-10-03 09:29:15 +04:00
|
|
|
buf[0] = 'S';
|
|
|
|
if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT ||
|
|
|
|
last_stop_reason == GDBSTUB_TRACE)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
write_signal(&buf[1], SIGTRAP);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
write_signal(&buf[1], 0);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply(buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
char buf[255];
|
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("stepping"));
|
2002-10-03 09:29:15 +04:00
|
|
|
stub_trace_flag = 1;
|
2006-04-29 11:12:13 +04:00
|
|
|
bx_cpu.cpu_loop(0);
|
2002-11-09 00:29:16 +03:00
|
|
|
DEV_vga_refresh();
|
2002-10-03 09:29:15 +04:00
|
|
|
stub_trace_flag = 0;
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("stopped with %x", last_stop_reason));
|
2002-10-03 09:29:15 +04:00
|
|
|
buf[0] = 'S';
|
|
|
|
if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT ||
|
|
|
|
last_stop_reason == GDBSTUB_TRACE)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
write_signal(&buf[1], SIGTRAP);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
write_signal(&buf[1], SIGTRAP);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply(buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
{
|
2005-02-16 21:58:48 +03:00
|
|
|
Bit64u addr;
|
2002-10-03 09:29:15 +04:00
|
|
|
int len;
|
|
|
|
unsigned char mem[255];
|
|
|
|
char* ebuf;
|
|
|
|
|
2005-02-16 21:58:48 +03:00
|
|
|
addr = strtoull(&buffer[1], &ebuf, 16);
|
2002-10-03 09:29:15 +04:00
|
|
|
len = strtoul(ebuf + 1, &ebuf, 16);
|
|
|
|
hex2mem(ebuf + 1, mem, len);
|
|
|
|
|
|
|
|
if (len == 1 && mem[0] == 0xcc)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
insert_breakpoint(addr);
|
|
|
|
put_reply("OK");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else if (remove_breakpoint(addr, len))
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("OK");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
if (access_linear(addr,
|
|
|
|
len,
|
|
|
|
BX_WRITE,
|
|
|
|
mem))
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("OK");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("ENN");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
{
|
2005-02-16 21:58:48 +03:00
|
|
|
Bit64u addr;
|
2002-10-03 09:29:15 +04:00
|
|
|
int len;
|
|
|
|
char* ebuf;
|
|
|
|
|
2005-02-16 21:58:48 +03:00
|
|
|
addr = strtoull(&buffer[1], &ebuf, 16);
|
2002-10-03 09:29:15 +04:00
|
|
|
len = strtoul(ebuf + 1, NULL, 16);
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("addr %x len %x", addr, len));
|
2002-10-03 09:29:15 +04:00
|
|
|
|
|
|
|
access_linear(addr,
|
|
|
|
len,
|
|
|
|
BX_READ,
|
|
|
|
mem);
|
|
|
|
mem2hex((char *)mem, obuf, len);
|
|
|
|
put_reply(obuf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
int reg;
|
2005-02-16 21:58:48 +03:00
|
|
|
unsigned long long value;
|
2002-10-03 09:29:15 +04:00
|
|
|
char* ebuf;
|
|
|
|
|
|
|
|
reg = strtoul(&buffer[1], &ebuf, 16);
|
2005-02-16 21:58:48 +03:00
|
|
|
++ebuf;
|
|
|
|
value = read_little_endian_hex(ebuf);
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_INFO(("reg %d set to %llx", reg, value));
|
2005-03-16 19:36:31 +03:00
|
|
|
#if !BX_SUPPORT_X86_64
|
2002-10-03 09:29:15 +04:00
|
|
|
switch (reg)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
case 1:
|
|
|
|
EAX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
ECX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
EBX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
ESP = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
EBP = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
ESI = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
EDI = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
EIP = value;
|
|
|
|
BX_CPU_THIS_PTR invalidate_prefetch_q();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2005-02-16 21:58:48 +03:00
|
|
|
#else
|
|
|
|
switch (reg)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2005-02-16 21:58:48 +03:00
|
|
|
case 0:
|
|
|
|
RAX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
RBX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
RCX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
RDX = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
RSI = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
RDI = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
ESP = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
RBP = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
R8 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
R9 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
R10 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
R11 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
R12 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
R13 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
R15 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
R15 = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
RIP = value;
|
|
|
|
BX_CPU_THIS_PTR invalidate_prefetch_q();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2005-02-16 21:58:48 +03:00
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("OK");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'g':
|
2005-03-16 19:36:31 +03:00
|
|
|
#if !BX_SUPPORT_X86_64
|
2002-10-03 09:29:15 +04:00
|
|
|
registers[0] = EAX;
|
|
|
|
registers[1] = ECX;
|
|
|
|
registers[2] = EDX;
|
|
|
|
registers[3] = EBX;
|
|
|
|
registers[4] = ESP;
|
|
|
|
registers[5] = EBP;
|
|
|
|
registers[6] = ESI;
|
|
|
|
registers[7] = EDI;
|
|
|
|
if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
registers[8] = EIP + 1;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
registers[8] = EIP;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
registers[9] = BX_CPU_THIS_PTR read_eflags();
|
|
|
|
registers[10] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value;
|
|
|
|
registers[11] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value;
|
|
|
|
registers[12] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value;
|
|
|
|
registers[13] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value;
|
|
|
|
registers[14] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value;
|
|
|
|
registers[15] =
|
|
|
|
BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value;
|
|
|
|
mem2hex((char *)registers, obuf, NUMREGSBYTES);
|
2005-02-16 21:58:48 +03:00
|
|
|
#else
|
|
|
|
#define PUTREG(buf, val, len) do { \
|
|
|
|
Bit64u u = (val); \
|
|
|
|
(buf) = mem2hex((char*)&u, (buf), (len)); \
|
|
|
|
} while (0)
|
|
|
|
char* buf;
|
|
|
|
buf = obuf;
|
|
|
|
PUTREG(buf, RAX, 8);
|
|
|
|
PUTREG(buf, RBX, 8);
|
|
|
|
PUTREG(buf, RCX, 8);
|
|
|
|
PUTREG(buf, RDX, 8);
|
|
|
|
PUTREG(buf, RSI, 8);
|
|
|
|
PUTREG(buf, RDI, 8);
|
|
|
|
PUTREG(buf, RBP, 8);
|
2005-02-22 21:24:19 +03:00
|
|
|
PUTREG(buf, RSP, 8);
|
2005-02-16 21:58:48 +03:00
|
|
|
PUTREG(buf, R8, 8);
|
|
|
|
PUTREG(buf, R9, 8);
|
|
|
|
PUTREG(buf, R10, 8);
|
|
|
|
PUTREG(buf, R11, 8);
|
|
|
|
PUTREG(buf, R12, 8);
|
|
|
|
PUTREG(buf, R13, 8);
|
|
|
|
PUTREG(buf, R14, 8);
|
|
|
|
PUTREG(buf, R15, 8);
|
|
|
|
Bit64u rip;
|
|
|
|
rip = RIP;
|
|
|
|
if (last_stop_reason == GDBSTUB_EXECUTION_BREAKPOINT)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2005-02-16 21:58:48 +03:00
|
|
|
++rip;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2005-02-16 21:58:48 +03:00
|
|
|
PUTREG(buf, rip, 8);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR read_eflags(), 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.value, 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_SS].selector.value, 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_DS].selector.value, 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_ES].selector.value, 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_FS].selector.value, 4);
|
|
|
|
PUTREG(buf, BX_CPU_THIS_PTR sregs[BX_SEG_REG_GS].selector.value, 4);
|
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply(obuf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
sprintf(obuf, "S%02x", SIGTRAP);
|
|
|
|
put_reply(obuf);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
if (buffer[1] == 'c')
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
continue_thread = strtol(&buffer[2], NULL, 16);
|
|
|
|
put_reply("OK");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else if (buffer[1] == 'g')
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
other_thread = strtol(&buffer[2], NULL, 16);
|
|
|
|
put_reply("OK");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
else
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("ENN");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
if (buffer[1] == 'C')
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
sprintf(obuf,"%Lx", 1);
|
|
|
|
put_reply(obuf);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-07 00:43:02 +04:00
|
|
|
else if (strncmp(&buffer[1], "Offsets", strlen("Offsets")) == 0)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
2002-10-03 09:29:15 +04:00
|
|
|
sprintf(obuf,
|
|
|
|
"Text=%x;Data=%x;Bss=%x",
|
2006-03-04 15:43:47 +03:00
|
|
|
SIM->get_param_num("text_base", gdbstub_list)->get(),
|
|
|
|
SIM->get_param_num("data_base", gdbstub_list)->get(),
|
|
|
|
SIM->get_param_num("bss_base", gdbstub_list)->get());
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply(obuf);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
else {
|
2002-10-03 09:29:15 +04:00
|
|
|
put_reply("ENN");
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
break;
|
2005-02-16 21:58:48 +03:00
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
do_breakpoint(1, buffer+1);
|
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
do_breakpoint(0, buffer+1);
|
|
|
|
break;
|
2002-10-03 09:29:15 +04:00
|
|
|
case 'k':
|
2006-06-17 16:09:55 +04:00
|
|
|
BX_PANIC(("Debugger asked us to quit\n"));
|
2002-10-03 09:29:15 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
put_reply("");
|
|
|
|
break;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wait_for_connect(int portn)
|
|
|
|
{
|
|
|
|
struct sockaddr_in sockaddr;
|
2002-10-07 00:43:02 +04:00
|
|
|
socklen_t sockaddr_len;
|
|
|
|
struct protoent *protoent;
|
2002-10-03 09:29:15 +04:00
|
|
|
int r;
|
|
|
|
int opt;
|
|
|
|
|
|
|
|
listen_socket_fd = socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
if (listen_socket_fd == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_PANIC(("Failed to create socket\n"));
|
2002-10-03 09:29:15 +04:00
|
|
|
exit(1);
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2002-10-07 00:43:02 +04:00
|
|
|
/* Allow rapid reuse of this port */
|
|
|
|
opt = 1;
|
2004-11-01 20:14:02 +03:00
|
|
|
#if __MINGW32__
|
|
|
|
r = setsockopt(listen_socket_fd, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt));
|
|
|
|
#else
|
2002-10-07 00:43:02 +04:00
|
|
|
r = setsockopt(listen_socket_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
2004-11-01 20:14:02 +03:00
|
|
|
#endif
|
2002-10-07 00:43:02 +04:00
|
|
|
if (r == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("setsockopt(SO_REUSEADDR) failed\n"));
|
|
|
|
}
|
2002-10-07 00:43:02 +04:00
|
|
|
|
|
|
|
memset (&sockaddr, '\000', sizeof sockaddr);
|
2002-11-09 00:29:16 +03:00
|
|
|
#if BX_HAVE_SOCKADDR_IN_SIN_LEN
|
2002-10-22 16:50:56 +04:00
|
|
|
// if you don't have sin_len change that to #if 0. This is the subject of
|
|
|
|
// bug [ 626840 ] no 'sin_len' in 'struct sockaddr_in'.
|
2002-10-07 00:43:02 +04:00
|
|
|
sockaddr.sin_len = sizeof sockaddr;
|
2002-10-22 16:50:56 +04:00
|
|
|
#endif
|
2002-10-03 09:29:15 +04:00
|
|
|
sockaddr.sin_family = AF_INET;
|
|
|
|
sockaddr.sin_port = htons(portn);
|
2002-10-07 00:43:02 +04:00
|
|
|
sockaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
|
|
|
|
|
|
|
r = bind(listen_socket_fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
|
2002-10-03 09:29:15 +04:00
|
|
|
if (r == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_PANIC(("Failed to bind socket\n"));
|
|
|
|
}
|
2002-10-07 00:43:02 +04:00
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
r = listen(listen_socket_fd, 0);
|
|
|
|
if (r == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_PANIC(("Failed to listen on socket\n"));
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2002-10-07 00:43:02 +04:00
|
|
|
sockaddr_len = sizeof sockaddr;
|
|
|
|
socket_fd = accept(listen_socket_fd, (struct sockaddr *)&sockaddr, &sockaddr_len);
|
2002-10-03 09:29:15 +04:00
|
|
|
if (socket_fd == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_PANIC(("Failed to accept on socket\n"));
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
close(listen_socket_fd);
|
|
|
|
|
2002-10-07 00:43:02 +04:00
|
|
|
protoent = getprotobyname ("tcp");
|
|
|
|
if (!protoent)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("getprotobyname (\"tcp\") failed\n"));
|
2002-10-07 00:43:02 +04:00
|
|
|
return;
|
2006-06-17 16:09:55 +04:00
|
|
|
}
|
2002-10-07 00:43:02 +04:00
|
|
|
|
|
|
|
/* Disable Nagle - allow small packets to be sent without delay. */
|
2002-10-03 09:29:15 +04:00
|
|
|
opt = 1;
|
2004-11-01 20:14:02 +03:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
r = setsockopt (socket_fd, protoent->p_proto, TCP_NODELAY, (const char *)&opt, sizeof(opt));
|
|
|
|
#else
|
2002-10-07 00:43:02 +04:00
|
|
|
r = setsockopt (socket_fd, protoent->p_proto, TCP_NODELAY, &opt, sizeof(opt));
|
2004-11-01 20:14:02 +03:00
|
|
|
#endif
|
2002-10-07 00:43:02 +04:00
|
|
|
if (r == -1)
|
2006-06-17 16:09:55 +04:00
|
|
|
{
|
|
|
|
BX_INFO(("setsockopt(TCP_NODELAY) failed\n"));
|
|
|
|
}
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void bx_gdbstub_init(int argc, char* argv[])
|
|
|
|
{
|
2006-03-04 15:43:47 +03:00
|
|
|
gdbstub_list = (bx_list_c*) SIM->get_param(BXPN_GDBSTUB);
|
|
|
|
int portn = SIM->get_param_num("port", gdbstub_list)->get();
|
2002-10-03 09:29:15 +04:00
|
|
|
|
2004-11-01 20:14:02 +03:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
WSADATA wsaData;
|
|
|
|
WSAStartup(2, &wsaData);
|
|
|
|
#endif
|
|
|
|
|
2002-10-03 09:29:15 +04:00
|
|
|
/* Wait for connect */
|
2002-10-07 00:43:02 +04:00
|
|
|
printf("Waiting for gdb connection on localhost:%d\n", portn);
|
2002-10-03 09:29:15 +04:00
|
|
|
wait_for_connect(portn);
|
|
|
|
|
|
|
|
/* Do debugger command loop */
|
|
|
|
debug_loop();
|
|
|
|
|
|
|
|
/* CPU loop */
|
2006-04-29 11:12:13 +04:00
|
|
|
bx_cpu.cpu_loop(0);
|
2002-10-03 09:29:15 +04:00
|
|
|
}
|