/* Remote target communications for serial-line targets in custom GDB protocol
- Copyright 1988, 1991, 1992 Free Software Foundation, Inc.
+ Copyright 1988, 1991, 1992, 1993 Free Software Foundation, Inc.
This file is part of GDB.
static void
remote_resume PARAMS ((int, int));
+static int
+remote_start_remote PARAMS ((char *));
+
static void
remote_open PARAMS ((char *, int));
remote_store_registers PARAMS ((int));
static void
-getpkt PARAMS ((char *));
+getpkt PARAMS ((char *, int));
static void
putpkt PARAMS ((char *));
return B38400; /* Random */
}
+/* Stub for catch_errors. */
+
+static int
+remote_start_remote (dummy)
+ char *dummy;
+{
+ /* Ack any packet which the remote side has already sent. */
+ write (remote_desc, "+\r", 2);
+ putpkt ("?"); /* initiate a query from remote machine */
+
+ start_remote (); /* Initialize gdb process mechanisms */
+ return 1;
+}
+
/* Open a connection to a remote debugger.
NAME is the filename used for communication. */
if (baud_rate)
{
- if (1 != sscanf (baud_rate, "%d ", &a_rate))
+ if (sscanf (baud_rate, "%d", &a_rate) == 1)
{
b_rate = damn_b (a_rate);
baudrate_set = 1;
ioctl (remote_desc, TIOCSETP, &sg);
if (from_tty)
- printf ("Remote debugging using %s\n", name);
+ {
+ puts_filtered ("Remote debugging using ");
+ puts_filtered (name);
+ puts_filtered ("\n");
+ }
push_target (&remote_ops); /* Switch to using remote target now */
#ifndef HAVE_TERMIO
perror ("remote_open: error in signal");
#endif
- /* Ack any packet which the remote side has already sent. */
- write (remote_desc, "+\r", 2);
- putpkt ("?"); /* initiate a query from remote machine */
-
- start_remote (); /* Initialize gdb process mechanisms */
+ /* Start the remote connection; if error (0), discard this target. */
+ immediate_quit++; /* Allow user to interrupt it */
+ if (!catch_errors (remote_start_remote, (char *)0,
+ "Couldn't establish connection to remote target\n"))
+ pop_target();
}
/* remote_detach()
pop_target ();
if (from_tty)
- printf ("Ending remote debugging.\n");
+ puts_filtered ("Ending remote debugging.\n");
}
/* Convert hex digit A to a number. */
void (*ofunc)();
unsigned char *p;
int i;
- char regs[REGISTER_RAW_SIZE (PC_REGNUM) + REGISTER_RAW_SIZE (FP_REGNUM)];
+ long regno;
+ char regs[MAX_REGISTER_RAW_SIZE];
WSETEXIT ((*status), 0);
ofunc = (void (*)()) signal (SIGINT, remote_interrupt);
- getpkt ((char *) buf);
+ getpkt ((char *) buf, 1);
signal (SIGINT, ofunc);
if (buf[0] == 'E')
error ("Remote failure reply: %s", buf);
if (buf[0] == 'T')
{
- /* Expedited reply, containing Signal, PC, and FP. */
+ /* Expedited reply, containing Signal, {regno, reg} repeat */
+ /* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
+ ss = signal number
+ n... = register number
+ r... = register contents
+ */
+
p = &buf[3]; /* after Txx */
- for (i = 0; i < sizeof (regs); i++)
+
+ while (*p)
{
- if (p[0] == 0 || p[1] == 0)
- error ("Remote reply is too short: %s", buf);
- regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
- p += 2;
+ regno = strtol (p, &p, 16); /* Read the register number */
+
+ if (*p++ != ':'
+ || regno >= NUM_REGS)
+ error ("Remote sent bad register number %s", buf);
+
+ for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
+ {
+ if (p[0] == 0 || p[1] == 0)
+ error ("Remote reply is too short: %s", buf);
+ regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
+ p += 2;
+ }
+
+ if (*p++ != ';')
+ error("Remote register badly formatted: %s", buf);
+
+ supply_register (regno, regs);
}
- supply_register (PC_REGNUM, ®s[0]);
- supply_register (FP_REGNUM, ®s[REGISTER_RAW_SIZE (PC_REGNUM)]);
}
else if (buf[0] != 'S')
error ("Invalid remote reply: %s", buf);
static void
remote_prepare_to_store ()
{
- remote_fetch_registers (-1);
+ /* Make sure the entire registers array is valid. */
+ read_register_bytes (0, (char *)NULL, REGISTER_BYTES);
}
/* Store the remote registers from the contents of the block REGISTERS.
remote_files_info (ignore)
struct target_ops *ignore;
{
- printf ("Debugging a target over a serial line.\n");
+ puts_filtered ("Debugging a target over a serial line.\n");
}
\f
/*
*/
/* Read a single character from the remote end.
- (If supported, we actually read many characters and buffer them up.) */
+ (If supported, we actually read many characters and buffer them up.)
+ Timeouts cause a zero (nul) to be returned. */
static int
readchar ()
static int inbuf_index, inbuf_count;
#define INBUFSIZE PBUFSIZ
static char inbuf[INBUFSIZE];
+ struct cleanup *old_chain;
if (inbuf_index >= inbuf_count)
{
+#ifndef HAVE_TERMIO
+ extern int alarm ();
+#endif
+
/* Time to do another read... */
inbuf_index = 0;
inbuf_count = 0;
/* termio does the timeout for us. */
inbuf_count = read (remote_desc, inbuf, INBUFSIZE);
#else
+ /* Cancel alarm on error. */
+ old_chain = make_cleanup (alarm, (char *)0);
alarm (timeout);
inbuf_count = read (remote_desc, inbuf, INBUFSIZE);
- alarm (0);
+ do_cleanups (old_chain); /* Cancel the alarm now. */
#endif
}
- /* Just return the next character from the buffer. */
+ /* Just return the next character from the buffer (or a zero if we
+ got an error and no chars were stored in inbuf). */
return inbuf[inbuf_index++] & 0x7f;
}
{
putpkt (buf);
- getpkt (buf);
+ getpkt (buf, 0);
if (buf[0] == 'E')
error ("Remote failure reply: %s", buf);
}
/* Read a packet from the remote machine, with error checking,
- and store it in BUF. BUF is expected to be of size PBUFSIZ. */
+ and store it in BUF. BUF is expected to be of size PBUFSIZ.
+ If FOREVER, wait forever rather than timing out; this is used
+ while the target is executing user code. */
static void
-getpkt (buf)
+getpkt (buf, forever)
char *buf;
{
char *bp;
unsigned char csum;
- int c;
+ int c = 0;
unsigned char c1, c2;
int retries = 0;
#define MAX_RETRIES 10
while (1)
{
+ /* This can loop forever if the remote side sends us characters
+ continuously, but if it pauses, we'll get a zero from readchar
+ because of timeout. Then we'll count that as a retry. */
+ while (c != '$')
+ if (0 == (c = readchar()))
+ if (!forever)
+ {
+ if (++retries >= MAX_RETRIES)
+ if (kiodebug) puts_filtered ("Timed out.\n");
+ goto out;
+ }
+
/* Force csum to be zero here because of possible error retry. */
csum = 0;
-
- while ((c = readchar()) != '$');
-
bp = buf;
+
while (1)
{
c = readchar ();
+ if (c == '\0')
+ {
+ if (kiodebug)
+ puts_filtered ("Timeout in mid-packet, retrying\n");
+ goto whole; /* Start a new packet, count retries */
+ }
+ if (c == '$')
+ {
+ if (kiodebug)
+ puts_filtered ("Saw new packet start in middle of old one\n");
+ goto whole; /* Start a new packet, count retries */
+ }
if (c == '#')
break;
if (bp >= buf+PBUFSIZ-1)
{
*bp = '\0';
- printf_filtered ("Remote packet too long: %s\n", buf);
+ puts_filtered ("Remote packet too long: ");
+ puts_filtered (buf);
+ puts_filtered ("\n");
goto whole;
}
*bp++ = c;
c2 = fromhex (readchar ());
if ((csum & 0xff) == (c1 << 4) + c2)
break;
- printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
- (c1 << 4) + c2, csum & 0xff, buf);
+ printf_filtered ("Bad checksum, sentsum=0x%x, csum=0x%x, buf=",
+ (c1 << 4) + c2, csum & 0xff);
+ puts_filtered (buf);
+ puts_filtered ("\n");
/* Try the whole thing again. */
whole:
}
}
+out:
+
#if 0
immediate_quit--;
#endif
remote_fetch_registers, /* to_fetch_registers */
remote_store_registers, /* to_store_registers */
remote_prepare_to_store, /* to_prepare_to_store */
- NULL, /* to_convert_to_virtual */
- NULL, /* to_convert_from_virtual */
remote_xfer_memory, /* to_xfer_memory */
remote_files_info, /* to_files_info */
NULL, /* to_insert_breakpoint */
NULL, /* to_lookup_symbol */
NULL, /* to_create_inferior */
NULL, /* to_mourn_inferior */
+ 0, /* to_can_run */
+ 0, /* to_notice_signals */
process_stratum, /* to_stratum */
NULL, /* to_next */
1, /* to_has_all_memory */