summaryrefslogtreecommitdiffstats
path: root/contrib/gdb/gdb/gdbserver/remote-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gdb/gdb/gdbserver/remote-utils.c')
-rw-r--r--contrib/gdb/gdb/gdbserver/remote-utils.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/contrib/gdb/gdb/gdbserver/remote-utils.c b/contrib/gdb/gdb/gdbserver/remote-utils.c
index 0a7e0fb..adf5299 100644
--- a/contrib/gdb/gdb/gdbserver/remote-utils.c
+++ b/contrib/gdb/gdb/gdbserver/remote-utils.c
@@ -1,21 +1,24 @@
/* Remote utility routines for the remote server for GDB.
- Copyright (C) 1986, 1989, 1993 Free Software Foundation, Inc.
+ Copyright 1986, 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
+ 2002
+ Free Software Foundation, Inc.
-This file is part of GDB.
+ This file is part of GDB.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include "server.h"
#include "terminal.h"
@@ -30,8 +33,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include <sys/ioctl.h>
#include <signal.h>
#include <fcntl.h>
+#include <sys/time.h>
+#include <unistd.h>
int remote_debug = 0;
+struct ui_file *gdb_stdlog;
static int remote_desc;
@@ -39,11 +45,10 @@ static int remote_desc;
NAME is the filename used for communication. */
void
-remote_open (name)
- char *name;
+remote_open (char *name)
{
int save_fcntl_flags;
-
+
if (!strchr (name, ':'))
{
remote_desc = open (name, O_RDWR);
@@ -53,17 +58,17 @@ remote_open (name)
#ifdef HAVE_TERMIOS
{
struct termios termios;
- tcgetattr(remote_desc, &termios);
+ tcgetattr (remote_desc, &termios);
termios.c_iflag = 0;
termios.c_oflag = 0;
termios.c_lflag = 0;
- termios.c_cflag &= ~(CSIZE|PARENB);
+ termios.c_cflag &= ~(CSIZE | PARENB);
termios.c_cflag |= CLOCAL | CS8;
- termios.c_cc[VMIN] = 0;
+ termios.c_cc[VMIN] = 1;
termios.c_cc[VTIME] = 0;
- tcsetattr(remote_desc, TCSANOW, &termios);
+ tcsetattr (remote_desc, TCSANOW, &termios);
}
#endif
@@ -75,9 +80,9 @@ remote_open (name)
termio.c_iflag = 0;
termio.c_oflag = 0;
termio.c_lflag = 0;
- termio.c_cflag &= ~(CSIZE|PARENB);
+ termio.c_cflag &= ~(CSIZE | PARENB);
termio.c_cflag |= CLOCAL | CS8;
- termio.c_cc[VMIN] = 0;
+ termio.c_cc[VMIN] = 1;
termio.c_cc[VTIME] = 0;
ioctl (remote_desc, TCSETA, &termio);
@@ -94,7 +99,7 @@ remote_open (name)
}
#endif
-
+ fprintf (stderr, "Remote debugging using %s\n", name);
}
else
{
@@ -102,7 +107,6 @@ remote_open (name)
int port;
struct sockaddr_in sockaddr;
int tmp;
- struct protoent *protoent;
int tmp_desc;
port_str = strchr (name, ':');
@@ -115,52 +119,54 @@ remote_open (name)
/* Allow rapid reuse of this port. */
tmp = 1;
- setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *)&tmp,
- sizeof(tmp));
+ setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp,
+ sizeof (tmp));
sockaddr.sin_family = PF_INET;
- sockaddr.sin_port = htons(port);
+ sockaddr.sin_port = htons (port);
sockaddr.sin_addr.s_addr = INADDR_ANY;
- if (bind (tmp_desc, (struct sockaddr *)&sockaddr, sizeof (sockaddr))
+ if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr))
|| listen (tmp_desc, 1))
perror_with_name ("Can't bind address");
tmp = sizeof (sockaddr);
- remote_desc = accept (tmp_desc, (struct sockaddr *)&sockaddr, &tmp);
+ remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp);
if (remote_desc == -1)
perror_with_name ("Accept failed");
- protoent = getprotobyname ("tcp");
- if (!protoent)
- perror_with_name ("getprotobyname");
-
/* Enable TCP keep alive process. */
tmp = 1;
- setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp));
+ setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp));
/* Tell TCP not to delay small packets. This greatly speeds up
- interactive response. */
+ interactive response. */
tmp = 1;
- setsockopt (remote_desc, protoent->p_proto, TCP_NODELAY,
- (char *)&tmp, sizeof(tmp));
+ setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &tmp, sizeof (tmp));
close (tmp_desc); /* No longer need this */
- signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbserver simply
- exits when the remote side dies. */
+ signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbserver simply
+ exits when the remote side dies. */
+
+ /* Convert IP address to string. */
+ fprintf (stderr, "Remote debugging from host %s\n",
+ inet_ntoa (sockaddr.sin_addr));
}
#if defined(F_SETFL) && defined (FASYNC)
save_fcntl_flags = fcntl (remote_desc, F_GETFL, 0);
fcntl (remote_desc, F_SETFL, save_fcntl_flags | FASYNC);
+#if defined (F_SETOWN)
+ fcntl (remote_desc, F_SETOWN, getpid ());
+#endif
+#endif
disable_async_io ();
-#endif /* FASYNC */
- fprintf (stderr, "Remote debugging using %s\n", name);
}
void
-remote_close()
+remote_close (void)
{
close (remote_desc);
}
@@ -168,8 +174,7 @@ remote_close()
/* Convert hex digit A to a number. */
static int
-fromhex (a)
- int a;
+fromhex (int a)
{
if (a >= '0' && a <= '9')
return a - '0';
@@ -177,13 +182,13 @@ fromhex (a)
return a - 'a' + 10;
else
error ("Reply contains invalid hex digit");
+ return 0;
}
/* Convert number NIB to a hex digit. */
static int
-tohex (nib)
- int nib;
+tohex (int nib)
{
if (nib < 10)
return '0' + nib;
@@ -195,16 +200,17 @@ tohex (nib)
The data of the packet is in BUF. Returns >= 0 on success, -1 otherwise. */
int
-putpkt (buf)
- char *buf;
+putpkt (char *buf)
{
int i;
unsigned char csum = 0;
- char buf2[2000];
+ char *buf2;
char buf3[1];
int cnt = strlen (buf);
char *p;
+ buf2 = malloc (PBUFSIZ);
+
/* Copy the packet into buffer BUF2, encapsulating it
and giving it a checksum. */
@@ -246,11 +252,13 @@ putpkt (buf)
else
perror ("putpkt(read)");
+ free (buf2);
return -1;
}
}
while (buf3[0] != '+');
+ free (buf2);
return 1; /* Success! */
}
@@ -260,30 +268,41 @@ putpkt (buf)
will cause us to send a SIGINT to the child. */
static void
-input_interrupt()
+input_interrupt (int unused)
{
- int cc;
- char c;
+ fd_set readset;
+ struct timeval immediate = { 0, 0 };
- cc = read (remote_desc, &c, 1);
+ /* Protect against spurious interrupts. This has been observed to
+ be a problem under NetBSD 1.4 and 1.5. */
- if (cc != 1 || c != '\003')
+ FD_ZERO (&readset);
+ FD_SET (remote_desc, &readset);
+ if (select (remote_desc + 1, &readset, 0, 0, &immediate) > 0)
{
- fprintf(stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
- return;
- }
+ int cc;
+ char c;
+
+ cc = read (remote_desc, &c, 1);
- kill (inferior_pid, SIGINT);
+ if (cc != 1 || c != '\003')
+ {
+ fprintf (stderr, "input_interrupt, cc = %d c = %d\n", cc, c);
+ return;
+ }
+
+ kill (inferior_pid, SIGINT);
+ }
}
void
-enable_async_io()
+enable_async_io (void)
{
signal (SIGIO, input_interrupt);
}
void
-disable_async_io()
+disable_async_io (void)
{
signal (SIGIO, SIG_IGN);
}
@@ -291,7 +310,7 @@ disable_async_io()
/* Returns next char from remote GDB. -1 if error. */
static int
-readchar ()
+readchar (void)
{
static char buf[BUFSIZ];
static int bufcnt = 0;
@@ -321,8 +340,7 @@ readchar ()
and store it in BUF. Returns length of packet, or negative if error. */
int
-getpkt (buf)
- char *buf;
+getpkt (char *buf)
{
char *bp;
unsigned char csum, c1, c2;
@@ -358,7 +376,7 @@ getpkt (buf)
c1 = fromhex (readchar ());
c2 = fromhex (readchar ());
-
+
if (csum == (c1 << 4) + c2)
break;
@@ -378,8 +396,7 @@ getpkt (buf)
}
void
-write_ok (buf)
- char *buf;
+write_ok (char *buf)
{
buf[0] = 'O';
buf[1] = 'K';
@@ -387,8 +404,7 @@ write_ok (buf)
}
void
-write_enn (buf)
- char *buf;
+write_enn (char *buf)
{
buf[0] = 'E';
buf[1] = 'N';
@@ -397,9 +413,7 @@ write_enn (buf)
}
void
-convert_int_to_ascii (from, to, n)
- char *from, *to;
- int n;
+convert_int_to_ascii (char *from, char *to, int n)
{
int nib;
char ch;
@@ -416,9 +430,7 @@ convert_int_to_ascii (from, to, n)
void
-convert_ascii_to_int (from, to, n)
- char *from, *to;
- int n;
+convert_ascii_to_int (char *from, char *to, int n)
{
int nib1, nib2;
while (n--)
@@ -430,17 +442,18 @@ convert_ascii_to_int (from, to, n)
}
static char *
-outreg(regno, buf)
- int regno;
- char *buf;
+outreg (int regno, char *buf)
{
- extern char registers[];
- int regsize = REGISTER_RAW_SIZE (regno);
+ int regsize = register_size (regno);
- *buf++ = tohex (regno >> 4);
+ if ((regno >> 12) != 0)
+ *buf++ = tohex ((regno >> 12) & 0xf);
+ if ((regno >> 8) != 0)
+ *buf++ = tohex ((regno >> 8) & 0xf);
+ *buf++ = tohex ((regno >> 4) & 0xf);
*buf++ = tohex (regno & 0xf);
*buf++ = ':';
- convert_int_to_ascii (&registers[REGISTER_BYTE (regno)], buf, regsize);
+ convert_int_to_ascii (register_data (regno), buf, regsize);
buf += 2 * regsize;
*buf++ = ';';
@@ -448,35 +461,27 @@ outreg(regno, buf)
}
void
-prepare_resume_reply (buf, status, signo)
- char *buf;
- char status;
- unsigned char signo;
+prepare_resume_reply (char *buf, char status, unsigned char signo)
{
- int nib;
+ int nib, sig;
*buf++ = status;
- /* FIXME! Should be converting this signal number (numbered
- according to the signal numbering of the system we are running on)
- to the signal numbers used by the gdb protocol (see enum target_signal
- in gdb/target.h). */
- nib = ((signo & 0xf0) >> 4);
+ sig = (int)target_signal_from_host (signo);
+
+ nib = ((sig & 0xf0) >> 4);
*buf++ = tohex (nib);
- nib = signo & 0x0f;
+ nib = sig & 0x0f;
*buf++ = tohex (nib);
if (status == 'T')
{
- buf = outreg (PC_REGNUM, buf);
- buf = outreg (FP_REGNUM, buf);
- buf = outreg (SP_REGNUM, buf);
-#ifdef NPC_REGNUM
- buf = outreg (NPC_REGNUM, buf);
-#endif
-#ifdef O7_REGNUM
- buf = outreg (O7_REGNUM, buf);
-#endif
+ const char **regp = gdbserver_expedite_regs;
+ while (*regp)
+ {
+ buf = outreg (find_regno (*regp), buf);
+ regp ++;
+ }
/* If the debugger hasn't used any thread features, don't burden it with
threads. If we didn't check this, GDB 4.13 and older would choke. */
@@ -495,10 +500,7 @@ prepare_resume_reply (buf, status, signo)
}
void
-decode_m_packet (from, mem_addr_ptr, len_ptr)
- char *from;
- CORE_ADDR *mem_addr_ptr;
- unsigned int *len_ptr;
+decode_m_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr)
{
int i = 0, j = 0;
char ch;
@@ -520,10 +522,8 @@ decode_m_packet (from, mem_addr_ptr, len_ptr)
}
void
-decode_M_packet (from, mem_addr_ptr, len_ptr, to)
- char *from, *to;
- CORE_ADDR *mem_addr_ptr;
- unsigned int *len_ptr;
+decode_M_packet (char *from, CORE_ADDR *mem_addr_ptr, unsigned int *len_ptr,
+ char *to)
{
int i = 0;
char ch;
OpenPOWER on IntegriCloud