/* Generic support for remote debugging interfaces.
|
/* Generic support for remote debugging interfaces.
|
|
|
Copyright 1993, 1994, 1998 Free Software Foundation, Inc.
|
Copyright 1993, 1994, 1998 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
|
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
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
Boston, MA 02111-1307, USA. */
|
Boston, MA 02111-1307, USA. */
|
|
|
/* This file actually contains two distinct logical "packages". They
|
/* This file actually contains two distinct logical "packages". They
|
are packaged together in this one file because they are typically
|
are packaged together in this one file because they are typically
|
used together.
|
used together.
|
|
|
The first package is an addition to the serial package. The
|
The first package is an addition to the serial package. The
|
addition provides reading and writing with debugging output and
|
addition provides reading and writing with debugging output and
|
timeouts based on user settable variables. These routines are
|
timeouts based on user settable variables. These routines are
|
intended to support serial port based remote backends. These
|
intended to support serial port based remote backends. These
|
functions are prefixed with sr_.
|
functions are prefixed with sr_.
|
|
|
The second package is a collection of more or less generic
|
The second package is a collection of more or less generic
|
functions for use by remote backends. They support user settable
|
functions for use by remote backends. They support user settable
|
variables for debugging, retries, and the like.
|
variables for debugging, retries, and the like.
|
|
|
Todo:
|
Todo:
|
|
|
* a pass through mode a la kermit or telnet.
|
* a pass through mode a la kermit or telnet.
|
* autobaud.
|
* autobaud.
|
* ask remote to change his baud rate.
|
* ask remote to change his baud rate.
|
*/
|
*/
|
|
|
#include <ctype.h>
|
#include <ctype.h>
|
|
|
#include "defs.h"
|
#include "defs.h"
|
#include "gdb_string.h"
|
#include "gdb_string.h"
|
#include "gdbcmd.h"
|
#include "gdbcmd.h"
|
#include "target.h"
|
#include "target.h"
|
#include "serial.h"
|
#include "serial.h"
|
#include "gdbcore.h" /* for exec_bfd */
|
#include "gdbcore.h" /* for exec_bfd */
|
#include "inferior.h" /* for generic_mourn_inferior */
|
#include "inferior.h" /* for generic_mourn_inferior */
|
#include "remote-utils.h"
|
#include "remote-utils.h"
|
|
|
|
|
void _initialize_sr_support PARAMS ((void));
|
void _initialize_sr_support PARAMS ((void));
|
|
|
struct _sr_settings sr_settings =
|
struct _sr_settings sr_settings =
|
{
|
{
|
4, /* timeout:
|
4, /* timeout:
|
remote-hms.c had 2
|
remote-hms.c had 2
|
remote-bug.c had "with a timeout of 2, we time out waiting for
|
remote-bug.c had "with a timeout of 2, we time out waiting for
|
the prompt after an s-record dump."
|
the prompt after an s-record dump."
|
|
|
remote.c had (2): This was 5 seconds, which is a long time to
|
remote.c had (2): This was 5 seconds, which is a long time to
|
sit and wait. Unless this is going though some terminal server
|
sit and wait. Unless this is going though some terminal server
|
or multiplexer or other form of hairy serial connection, I
|
or multiplexer or other form of hairy serial connection, I
|
would think 2 seconds would be plenty.
|
would think 2 seconds would be plenty.
|
*/
|
*/
|
|
|
10, /* retries */
|
10, /* retries */
|
NULL, /* device */
|
NULL, /* device */
|
NULL, /* descriptor */
|
NULL, /* descriptor */
|
};
|
};
|
|
|
struct gr_settings *gr_settings = NULL;
|
struct gr_settings *gr_settings = NULL;
|
|
|
static void usage PARAMS ((char *, char *));
|
static void usage PARAMS ((char *, char *));
|
static void sr_com PARAMS ((char *, int));
|
static void sr_com PARAMS ((char *, int));
|
|
|
static void
|
static void
|
usage (proto, junk)
|
usage (proto, junk)
|
char *proto;
|
char *proto;
|
char *junk;
|
char *junk;
|
{
|
{
|
if (junk != NULL)
|
if (junk != NULL)
|
fprintf_unfiltered (gdb_stderr, "Unrecognized arguments: `%s'.\n", junk);
|
fprintf_unfiltered (gdb_stderr, "Unrecognized arguments: `%s'.\n", junk);
|
|
|
error ("Usage: target %s [DEVICE [SPEED [DEBUG]]]\n\
|
error ("Usage: target %s [DEVICE [SPEED [DEBUG]]]\n\
|
where DEVICE is the name of a device or HOST:PORT", proto, proto);
|
where DEVICE is the name of a device or HOST:PORT", proto, proto);
|
|
|
return;
|
return;
|
}
|
}
|
|
|
#define CHECKDONE(p, q) \
|
#define CHECKDONE(p, q) \
|
{ \
|
{ \
|
if (q == p) \
|
if (q == p) \
|
{ \
|
{ \
|
if (*p == '\0') \
|
if (*p == '\0') \
|
return; \
|
return; \
|
else \
|
else \
|
usage(proto, p); \
|
usage(proto, p); \
|
} \
|
} \
|
}
|
}
|
|
|
void
|
void
|
sr_scan_args (proto, args)
|
sr_scan_args (proto, args)
|
char *proto;
|
char *proto;
|
char *args;
|
char *args;
|
{
|
{
|
int n;
|
int n;
|
char *p, *q;
|
char *p, *q;
|
|
|
/* if no args, then nothing to do. */
|
/* if no args, then nothing to do. */
|
if (args == NULL || *args == '\0')
|
if (args == NULL || *args == '\0')
|
return;
|
return;
|
|
|
/* scan off white space. */
|
/* scan off white space. */
|
for (p = args; isspace (*p); ++p);;
|
for (p = args; isspace (*p); ++p);;
|
|
|
/* find end of device name. */
|
/* find end of device name. */
|
for (q = p; *q != '\0' && !isspace (*q); ++q);;
|
for (q = p; *q != '\0' && !isspace (*q); ++q);;
|
|
|
/* check for missing or empty device name. */
|
/* check for missing or empty device name. */
|
CHECKDONE (p, q);
|
CHECKDONE (p, q);
|
sr_set_device (savestring (p, q - p));
|
sr_set_device (savestring (p, q - p));
|
|
|
/* look for baud rate. */
|
/* look for baud rate. */
|
n = strtol (q, &p, 10);
|
n = strtol (q, &p, 10);
|
|
|
/* check for missing or empty baud rate. */
|
/* check for missing or empty baud rate. */
|
CHECKDONE (p, q);
|
CHECKDONE (p, q);
|
baud_rate = n;
|
baud_rate = n;
|
|
|
/* look for debug value. */
|
/* look for debug value. */
|
n = strtol (p, &q, 10);
|
n = strtol (p, &q, 10);
|
|
|
/* check for missing or empty debug value. */
|
/* check for missing or empty debug value. */
|
CHECKDONE (p, q);
|
CHECKDONE (p, q);
|
sr_set_debug (n);
|
sr_set_debug (n);
|
|
|
/* scan off remaining white space. */
|
/* scan off remaining white space. */
|
for (p = q; isspace (*p); ++p);;
|
for (p = q; isspace (*p); ++p);;
|
|
|
/* if not end of string, then there's unrecognized junk. */
|
/* if not end of string, then there's unrecognized junk. */
|
if (*p != '\0')
|
if (*p != '\0')
|
usage (proto, p);
|
usage (proto, p);
|
|
|
return;
|
return;
|
}
|
}
|
|
|
void
|
void
|
gr_generic_checkin ()
|
gr_generic_checkin ()
|
{
|
{
|
sr_write_cr ("");
|
sr_write_cr ("");
|
gr_expect_prompt ();
|
gr_expect_prompt ();
|
}
|
}
|
|
|
void
|
void
|
gr_open (args, from_tty, gr)
|
gr_open (args, from_tty, gr)
|
char *args;
|
char *args;
|
int from_tty;
|
int from_tty;
|
struct gr_settings *gr;
|
struct gr_settings *gr;
|
{
|
{
|
target_preopen (from_tty);
|
target_preopen (from_tty);
|
sr_scan_args (gr->ops->to_shortname, args);
|
sr_scan_args (gr->ops->to_shortname, args);
|
unpush_target (gr->ops);
|
unpush_target (gr->ops);
|
|
|
gr_settings = gr;
|
gr_settings = gr;
|
|
|
gr_set_dcache (dcache_init (gr->readfunc, gr->writefunc));
|
gr_set_dcache (dcache_init (gr->readfunc, gr->writefunc));
|
|
|
if (sr_get_desc () != NULL)
|
if (sr_get_desc () != NULL)
|
gr_close (0);
|
gr_close (0);
|
|
|
/* If no args are specified, then we use the device specified by a
|
/* If no args are specified, then we use the device specified by a
|
previous command or "set remotedevice". But if there is no
|
previous command or "set remotedevice". But if there is no
|
device, better stop now, not dump core. */
|
device, better stop now, not dump core. */
|
|
|
if (sr_get_device () == NULL)
|
if (sr_get_device () == NULL)
|
usage (gr->ops->to_shortname, NULL);
|
usage (gr->ops->to_shortname, NULL);
|
|
|
sr_set_desc (SERIAL_OPEN (sr_get_device ()));
|
sr_set_desc (SERIAL_OPEN (sr_get_device ()));
|
if (!sr_get_desc ())
|
if (!sr_get_desc ())
|
perror_with_name ((char *) sr_get_device ());
|
perror_with_name ((char *) sr_get_device ());
|
|
|
if (baud_rate != -1)
|
if (baud_rate != -1)
|
{
|
{
|
if (SERIAL_SETBAUDRATE (sr_get_desc (), baud_rate) != 0)
|
if (SERIAL_SETBAUDRATE (sr_get_desc (), baud_rate) != 0)
|
{
|
{
|
SERIAL_CLOSE (sr_get_desc ());
|
SERIAL_CLOSE (sr_get_desc ());
|
perror_with_name (sr_get_device ());
|
perror_with_name (sr_get_device ());
|
}
|
}
|
}
|
}
|
|
|
SERIAL_RAW (sr_get_desc ());
|
SERIAL_RAW (sr_get_desc ());
|
|
|
/* If there is something sitting in the buffer we might take it as a
|
/* If there is something sitting in the buffer we might take it as a
|
response to a command, which would be bad. */
|
response to a command, which would be bad. */
|
SERIAL_FLUSH_INPUT (sr_get_desc ());
|
SERIAL_FLUSH_INPUT (sr_get_desc ());
|
|
|
/* default retries */
|
/* default retries */
|
if (sr_get_retries () == 0)
|
if (sr_get_retries () == 0)
|
sr_set_retries (1);
|
sr_set_retries (1);
|
|
|
/* default clear breakpoint function */
|
/* default clear breakpoint function */
|
if (gr_settings->clear_all_breakpoints == NULL)
|
if (gr_settings->clear_all_breakpoints == NULL)
|
gr_settings->clear_all_breakpoints = remove_breakpoints;
|
gr_settings->clear_all_breakpoints = remove_breakpoints;
|
|
|
if (from_tty)
|
if (from_tty)
|
{
|
{
|
printf_filtered ("Remote debugging using `%s'", sr_get_device ());
|
printf_filtered ("Remote debugging using `%s'", sr_get_device ());
|
if (baud_rate != -1)
|
if (baud_rate != -1)
|
printf_filtered (" at baud rate of %d",
|
printf_filtered (" at baud rate of %d",
|
baud_rate);
|
baud_rate);
|
printf_filtered ("\n");
|
printf_filtered ("\n");
|
}
|
}
|
|
|
push_target (gr->ops);
|
push_target (gr->ops);
|
gr_checkin ();
|
gr_checkin ();
|
gr_clear_all_breakpoints ();
|
gr_clear_all_breakpoints ();
|
return;
|
return;
|
}
|
}
|
|
|
/* Read a character from the remote system masking it down to 7 bits
|
/* Read a character from the remote system masking it down to 7 bits
|
and doing all the fancy timeout stuff. */
|
and doing all the fancy timeout stuff. */
|
|
|
int
|
int
|
sr_readchar ()
|
sr_readchar ()
|
{
|
{
|
int buf;
|
int buf;
|
|
|
buf = SERIAL_READCHAR (sr_get_desc (), sr_get_timeout ());
|
buf = SERIAL_READCHAR (sr_get_desc (), sr_get_timeout ());
|
|
|
if (buf == SERIAL_TIMEOUT)
|
if (buf == SERIAL_TIMEOUT)
|
error ("Timeout reading from remote system.");
|
error ("Timeout reading from remote system.");
|
|
|
if (sr_get_debug () > 0)
|
if (sr_get_debug () > 0)
|
printf_unfiltered ("%c", buf);
|
printf_unfiltered ("%c", buf);
|
|
|
return buf & 0x7f;
|
return buf & 0x7f;
|
}
|
}
|
|
|
int
|
int
|
sr_pollchar ()
|
sr_pollchar ()
|
{
|
{
|
int buf;
|
int buf;
|
|
|
buf = SERIAL_READCHAR (sr_get_desc (), 0);
|
buf = SERIAL_READCHAR (sr_get_desc (), 0);
|
if (buf == SERIAL_TIMEOUT)
|
if (buf == SERIAL_TIMEOUT)
|
buf = 0;
|
buf = 0;
|
if (sr_get_debug () > 0)
|
if (sr_get_debug () > 0)
|
{
|
{
|
if (buf)
|
if (buf)
|
printf_unfiltered ("%c", buf);
|
printf_unfiltered ("%c", buf);
|
else
|
else
|
printf_unfiltered ("<empty character poll>");
|
printf_unfiltered ("<empty character poll>");
|
}
|
}
|
|
|
return buf & 0x7f;
|
return buf & 0x7f;
|
}
|
}
|
|
|
/* Keep discarding input from the remote system, until STRING is found.
|
/* Keep discarding input from the remote system, until STRING is found.
|
Let the user break out immediately. */
|
Let the user break out immediately. */
|
void
|
void
|
sr_expect (string)
|
sr_expect (string)
|
char *string;
|
char *string;
|
{
|
{
|
char *p = string;
|
char *p = string;
|
|
|
immediate_quit = 1;
|
immediate_quit = 1;
|
while (1)
|
while (1)
|
{
|
{
|
if (sr_readchar () == *p)
|
if (sr_readchar () == *p)
|
{
|
{
|
p++;
|
p++;
|
if (*p == '\0')
|
if (*p == '\0')
|
{
|
{
|
immediate_quit = 0;
|
immediate_quit = 0;
|
return;
|
return;
|
}
|
}
|
}
|
}
|
else
|
else
|
p = string;
|
p = string;
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
sr_write (a, l)
|
sr_write (a, l)
|
char *a;
|
char *a;
|
int l;
|
int l;
|
{
|
{
|
int i;
|
int i;
|
|
|
if (SERIAL_WRITE (sr_get_desc (), a, l) != 0)
|
if (SERIAL_WRITE (sr_get_desc (), a, l) != 0)
|
perror_with_name ("sr_write: Error writing to remote");
|
perror_with_name ("sr_write: Error writing to remote");
|
|
|
if (sr_get_debug () > 0)
|
if (sr_get_debug () > 0)
|
for (i = 0; i < l; i++)
|
for (i = 0; i < l; i++)
|
printf_unfiltered ("%c", a[i]);
|
printf_unfiltered ("%c", a[i]);
|
|
|
return;
|
return;
|
}
|
}
|
|
|
void
|
void
|
sr_write_cr (s)
|
sr_write_cr (s)
|
char *s;
|
char *s;
|
{
|
{
|
sr_write (s, strlen (s));
|
sr_write (s, strlen (s));
|
sr_write ("\r", 1);
|
sr_write ("\r", 1);
|
return;
|
return;
|
}
|
}
|
|
|
int
|
int
|
sr_timed_read (buf, n)
|
sr_timed_read (buf, n)
|
char *buf;
|
char *buf;
|
int n;
|
int n;
|
{
|
{
|
int i;
|
int i;
|
char c;
|
char c;
|
|
|
i = 0;
|
i = 0;
|
while (i < n)
|
while (i < n)
|
{
|
{
|
c = sr_readchar ();
|
c = sr_readchar ();
|
|
|
if (c == 0)
|
if (c == 0)
|
return i;
|
return i;
|
buf[i] = c;
|
buf[i] = c;
|
i++;
|
i++;
|
|
|
}
|
}
|
return i;
|
return i;
|
}
|
}
|
|
|
/* Get a hex digit from the remote system & return its value. If
|
/* Get a hex digit from the remote system & return its value. If
|
ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
|
ignore_space is nonzero, ignore spaces (not newline, tab, etc). */
|
|
|
int
|
int
|
sr_get_hex_digit (ignore_space)
|
sr_get_hex_digit (ignore_space)
|
int ignore_space;
|
int ignore_space;
|
{
|
{
|
int ch;
|
int ch;
|
|
|
while (1)
|
while (1)
|
{
|
{
|
ch = sr_readchar ();
|
ch = sr_readchar ();
|
if (ch >= '0' && ch <= '9')
|
if (ch >= '0' && ch <= '9')
|
return ch - '0';
|
return ch - '0';
|
else if (ch >= 'A' && ch <= 'F')
|
else if (ch >= 'A' && ch <= 'F')
|
return ch - 'A' + 10;
|
return ch - 'A' + 10;
|
else if (ch >= 'a' && ch <= 'f')
|
else if (ch >= 'a' && ch <= 'f')
|
return ch - 'a' + 10;
|
return ch - 'a' + 10;
|
else if (ch != ' ' || !ignore_space)
|
else if (ch != ' ' || !ignore_space)
|
{
|
{
|
gr_expect_prompt ();
|
gr_expect_prompt ();
|
error ("Invalid hex digit from remote system.");
|
error ("Invalid hex digit from remote system.");
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
/* Get a byte from the remote and put it in *BYT. Accept any number
|
/* Get a byte from the remote and put it in *BYT. Accept any number
|
leading spaces. */
|
leading spaces. */
|
void
|
void
|
sr_get_hex_byte (byt)
|
sr_get_hex_byte (byt)
|
char *byt;
|
char *byt;
|
{
|
{
|
int val;
|
int val;
|
|
|
val = sr_get_hex_digit (1) << 4;
|
val = sr_get_hex_digit (1) << 4;
|
val |= sr_get_hex_digit (0);
|
val |= sr_get_hex_digit (0);
|
*byt = val;
|
*byt = val;
|
}
|
}
|
|
|
/* Read a 32-bit hex word from the remote, preceded by a space */
|
/* Read a 32-bit hex word from the remote, preceded by a space */
|
long
|
long
|
sr_get_hex_word ()
|
sr_get_hex_word ()
|
{
|
{
|
long val;
|
long val;
|
int j;
|
int j;
|
|
|
val = 0;
|
val = 0;
|
for (j = 0; j < 8; j++)
|
for (j = 0; j < 8; j++)
|
val = (val << 4) + sr_get_hex_digit (j == 0);
|
val = (val << 4) + sr_get_hex_digit (j == 0);
|
return val;
|
return val;
|
}
|
}
|
|
|
/* Put a command string, in args, out to the remote. The remote is assumed to
|
/* Put a command string, in args, out to the remote. The remote is assumed to
|
be in raw mode, all writing/reading done through desc.
|
be in raw mode, all writing/reading done through desc.
|
Ouput from the remote is placed on the users terminal until the
|
Ouput from the remote is placed on the users terminal until the
|
prompt from the remote is seen.
|
prompt from the remote is seen.
|
FIXME: Can't handle commands that take input. */
|
FIXME: Can't handle commands that take input. */
|
|
|
static void
|
static void
|
sr_com (args, fromtty)
|
sr_com (args, fromtty)
|
char *args;
|
char *args;
|
int fromtty;
|
int fromtty;
|
{
|
{
|
sr_check_open ();
|
sr_check_open ();
|
|
|
if (!args)
|
if (!args)
|
return;
|
return;
|
|
|
/* Clear all input so only command relative output is displayed */
|
/* Clear all input so only command relative output is displayed */
|
|
|
sr_write_cr (args);
|
sr_write_cr (args);
|
sr_write ("\030", 1);
|
sr_write ("\030", 1);
|
registers_changed ();
|
registers_changed ();
|
gr_expect_prompt ();
|
gr_expect_prompt ();
|
}
|
}
|
|
|
void
|
void
|
gr_close (quitting)
|
gr_close (quitting)
|
int quitting;
|
int quitting;
|
{
|
{
|
gr_clear_all_breakpoints ();
|
gr_clear_all_breakpoints ();
|
|
|
if (sr_is_open ())
|
if (sr_is_open ())
|
{
|
{
|
SERIAL_CLOSE (sr_get_desc ());
|
SERIAL_CLOSE (sr_get_desc ());
|
sr_set_desc (NULL);
|
sr_set_desc (NULL);
|
}
|
}
|
|
|
return;
|
return;
|
}
|
}
|
|
|
/* gr_detach()
|
/* gr_detach()
|
takes a program previously attached to and detaches it.
|
takes a program previously attached to and detaches it.
|
We better not have left any breakpoints
|
We better not have left any breakpoints
|
in the program or it'll die when it hits one.
|
in the program or it'll die when it hits one.
|
Close the open connection to the remote debugger.
|
Close the open connection to the remote debugger.
|
Use this when you want to detach and do something else
|
Use this when you want to detach and do something else
|
with your gdb. */
|
with your gdb. */
|
|
|
void
|
void
|
gr_detach (args, from_tty)
|
gr_detach (args, from_tty)
|
char *args;
|
char *args;
|
int from_tty;
|
int from_tty;
|
{
|
{
|
if (args)
|
if (args)
|
error ("Argument given to \"detach\" when remotely debugging.");
|
error ("Argument given to \"detach\" when remotely debugging.");
|
|
|
if (sr_is_open ())
|
if (sr_is_open ())
|
gr_clear_all_breakpoints ();
|
gr_clear_all_breakpoints ();
|
|
|
pop_target ();
|
pop_target ();
|
if (from_tty)
|
if (from_tty)
|
puts_filtered ("Ending remote debugging.\n");
|
puts_filtered ("Ending remote debugging.\n");
|
|
|
return;
|
return;
|
}
|
}
|
|
|
void
|
void
|
gr_files_info (ops)
|
gr_files_info (ops)
|
struct target_ops *ops;
|
struct target_ops *ops;
|
{
|
{
|
#ifdef __GO32__
|
#ifdef __GO32__
|
printf_filtered ("\tAttached to DOS asynctsr\n");
|
printf_filtered ("\tAttached to DOS asynctsr\n");
|
#else
|
#else
|
printf_filtered ("\tAttached to %s", sr_get_device ());
|
printf_filtered ("\tAttached to %s", sr_get_device ());
|
if (baud_rate != -1)
|
if (baud_rate != -1)
|
printf_filtered ("at %d baud", baud_rate);
|
printf_filtered ("at %d baud", baud_rate);
|
printf_filtered ("\n");
|
printf_filtered ("\n");
|
#endif
|
#endif
|
|
|
if (exec_bfd)
|
if (exec_bfd)
|
{
|
{
|
printf_filtered ("\tand running program %s\n",
|
printf_filtered ("\tand running program %s\n",
|
bfd_get_filename (exec_bfd));
|
bfd_get_filename (exec_bfd));
|
}
|
}
|
printf_filtered ("\tusing the %s protocol.\n", ops->to_shortname);
|
printf_filtered ("\tusing the %s protocol.\n", ops->to_shortname);
|
}
|
}
|
|
|
void
|
void
|
gr_mourn ()
|
gr_mourn ()
|
{
|
{
|
gr_clear_all_breakpoints ();
|
gr_clear_all_breakpoints ();
|
unpush_target (gr_get_ops ());
|
unpush_target (gr_get_ops ());
|
generic_mourn_inferior ();
|
generic_mourn_inferior ();
|
}
|
}
|
|
|
void
|
void
|
gr_kill ()
|
gr_kill ()
|
{
|
{
|
return;
|
return;
|
}
|
}
|
|
|
/* This is called not only when we first attach, but also when the
|
/* This is called not only when we first attach, but also when the
|
user types "run" after having attached. */
|
user types "run" after having attached. */
|
void
|
void
|
gr_create_inferior (execfile, args, env)
|
gr_create_inferior (execfile, args, env)
|
char *execfile;
|
char *execfile;
|
char *args;
|
char *args;
|
char **env;
|
char **env;
|
{
|
{
|
int entry_pt;
|
int entry_pt;
|
|
|
if (args && *args)
|
if (args && *args)
|
error ("Can't pass arguments to remote process.");
|
error ("Can't pass arguments to remote process.");
|
|
|
if (execfile == 0 || exec_bfd == 0)
|
if (execfile == 0 || exec_bfd == 0)
|
error ("No executable file specified");
|
error ("No executable file specified");
|
|
|
entry_pt = (int) bfd_get_start_address (exec_bfd);
|
entry_pt = (int) bfd_get_start_address (exec_bfd);
|
sr_check_open ();
|
sr_check_open ();
|
|
|
gr_kill ();
|
gr_kill ();
|
gr_clear_all_breakpoints ();
|
gr_clear_all_breakpoints ();
|
|
|
init_wait_for_inferior ();
|
init_wait_for_inferior ();
|
gr_checkin ();
|
gr_checkin ();
|
|
|
insert_breakpoints (); /* Needed to get correct instruction in cache */
|
insert_breakpoints (); /* Needed to get correct instruction in cache */
|
proceed (entry_pt, -1, 0);
|
proceed (entry_pt, -1, 0);
|
}
|
}
|
|
|
/* Given a null terminated list of strings LIST, read the input until we find one of
|
/* Given a null terminated list of strings LIST, read the input until we find one of
|
them. Return the index of the string found or -1 on error. '?' means match
|
them. Return the index of the string found or -1 on error. '?' means match
|
any single character. Note that with the algorithm we use, the initial
|
any single character. Note that with the algorithm we use, the initial
|
character of the string cannot recur in the string, or we will not find some
|
character of the string cannot recur in the string, or we will not find some
|
cases of the string in the input. If PASSTHROUGH is non-zero, then
|
cases of the string in the input. If PASSTHROUGH is non-zero, then
|
pass non-matching data on. */
|
pass non-matching data on. */
|
|
|
int
|
int
|
gr_multi_scan (list, passthrough)
|
gr_multi_scan (list, passthrough)
|
char *list[];
|
char *list[];
|
int passthrough;
|
int passthrough;
|
{
|
{
|
char *swallowed = NULL; /* holding area */
|
char *swallowed = NULL; /* holding area */
|
char *swallowed_p = swallowed; /* Current position in swallowed. */
|
char *swallowed_p = swallowed; /* Current position in swallowed. */
|
int ch;
|
int ch;
|
int ch_handled;
|
int ch_handled;
|
int i;
|
int i;
|
int string_count;
|
int string_count;
|
int max_length;
|
int max_length;
|
char **plist;
|
char **plist;
|
|
|
/* Look through the strings. Count them. Find the largest one so we can
|
/* Look through the strings. Count them. Find the largest one so we can
|
allocate a holding area. */
|
allocate a holding area. */
|
|
|
for (max_length = string_count = i = 0;
|
for (max_length = string_count = i = 0;
|
list[i] != NULL;
|
list[i] != NULL;
|
++i, ++string_count)
|
++i, ++string_count)
|
{
|
{
|
int length = strlen (list[i]);
|
int length = strlen (list[i]);
|
|
|
if (length > max_length)
|
if (length > max_length)
|
max_length = length;
|
max_length = length;
|
}
|
}
|
|
|
/* if we have no strings, then something is wrong. */
|
/* if we have no strings, then something is wrong. */
|
if (string_count == 0)
|
if (string_count == 0)
|
return (-1);
|
return (-1);
|
|
|
/* otherwise, we will need a holding area big enough to hold almost two
|
/* otherwise, we will need a holding area big enough to hold almost two
|
copies of our largest string. */
|
copies of our largest string. */
|
swallowed_p = swallowed = alloca (max_length << 1);
|
swallowed_p = swallowed = alloca (max_length << 1);
|
|
|
/* and a list of pointers to current scan points. */
|
/* and a list of pointers to current scan points. */
|
plist = (char **) alloca (string_count * sizeof (*plist));
|
plist = (char **) alloca (string_count * sizeof (*plist));
|
|
|
/* and initialize */
|
/* and initialize */
|
for (i = 0; i < string_count; ++i)
|
for (i = 0; i < string_count; ++i)
|
plist[i] = list[i];
|
plist[i] = list[i];
|
|
|
for (ch = sr_readchar (); /* loop forever */ ; ch = sr_readchar ())
|
for (ch = sr_readchar (); /* loop forever */ ; ch = sr_readchar ())
|
{
|
{
|
QUIT; /* Let user quit and leave process running */
|
QUIT; /* Let user quit and leave process running */
|
ch_handled = 0;
|
ch_handled = 0;
|
|
|
for (i = 0; i < string_count; ++i)
|
for (i = 0; i < string_count; ++i)
|
{
|
{
|
if (ch == *plist[i] || *plist[i] == '?')
|
if (ch == *plist[i] || *plist[i] == '?')
|
{
|
{
|
++plist[i];
|
++plist[i];
|
if (*plist[i] == '\0')
|
if (*plist[i] == '\0')
|
return (i);
|
return (i);
|
|
|
if (!ch_handled)
|
if (!ch_handled)
|
*swallowed_p++ = ch;
|
*swallowed_p++ = ch;
|
|
|
ch_handled = 1;
|
ch_handled = 1;
|
}
|
}
|
else
|
else
|
plist[i] = list[i];
|
plist[i] = list[i];
|
}
|
}
|
|
|
if (!ch_handled)
|
if (!ch_handled)
|
{
|
{
|
char *p;
|
char *p;
|
|
|
/* Print out any characters which have been swallowed. */
|
/* Print out any characters which have been swallowed. */
|
if (passthrough)
|
if (passthrough)
|
{
|
{
|
for (p = swallowed; p < swallowed_p; ++p)
|
for (p = swallowed; p < swallowed_p; ++p)
|
fputc_unfiltered (*p, gdb_stdout);
|
fputc_unfiltered (*p, gdb_stdout);
|
|
|
fputc_unfiltered (ch, gdb_stdout);
|
fputc_unfiltered (ch, gdb_stdout);
|
}
|
}
|
|
|
swallowed_p = swallowed;
|
swallowed_p = swallowed;
|
}
|
}
|
}
|
}
|
#if 0
|
#if 0
|
/* Never reached. */
|
/* Never reached. */
|
return (-1);
|
return (-1);
|
#endif
|
#endif
|
}
|
}
|
|
|
/* Get ready to modify the registers array. On machines which store
|
/* Get ready to modify the registers array. On machines which store
|
individual registers, this doesn't need to do anything. On machines
|
individual registers, this doesn't need to do anything. On machines
|
which store all the registers in one fell swoop, this makes sure
|
which store all the registers in one fell swoop, this makes sure
|
that registers contains all the registers from the program being
|
that registers contains all the registers from the program being
|
debugged. */
|
debugged. */
|
|
|
void
|
void
|
gr_prepare_to_store ()
|
gr_prepare_to_store ()
|
{
|
{
|
/* Do nothing, since we assume we can store individual regs */
|
/* Do nothing, since we assume we can store individual regs */
|
}
|
}
|
|
|
/* Read a word from remote address ADDR and return it.
|
/* Read a word from remote address ADDR and return it.
|
* This goes through the data cache.
|
* This goes through the data cache.
|
*/
|
*/
|
int
|
int
|
gr_fetch_word (addr)
|
gr_fetch_word (addr)
|
CORE_ADDR addr;
|
CORE_ADDR addr;
|
{
|
{
|
return dcache_fetch (gr_get_dcache (), addr);
|
return dcache_fetch (gr_get_dcache (), addr);
|
}
|
}
|
|
|
/* Write a word WORD into remote address ADDR.
|
/* Write a word WORD into remote address ADDR.
|
This goes through the data cache. */
|
This goes through the data cache. */
|
|
|
void
|
void
|
gr_store_word (addr, word)
|
gr_store_word (addr, word)
|
CORE_ADDR addr;
|
CORE_ADDR addr;
|
int word;
|
int word;
|
{
|
{
|
dcache_poke (gr_get_dcache (), addr, word);
|
dcache_poke (gr_get_dcache (), addr, word);
|
}
|
}
|
|
|
void
|
void
|
_initialize_sr_support ()
|
_initialize_sr_support ()
|
{
|
{
|
/* FIXME-now: if target is open... */
|
/* FIXME-now: if target is open... */
|
add_show_from_set (add_set_cmd ("remotedevice", no_class,
|
add_show_from_set (add_set_cmd ("remotedevice", no_class,
|
var_filename, (char *) &sr_settings.device,
|
var_filename, (char *) &sr_settings.device,
|
"Set device for remote serial I/O.\n\
|
"Set device for remote serial I/O.\n\
|
This device is used as the serial port when debugging using remote\n\
|
This device is used as the serial port when debugging using remote\n\
|
targets.", &setlist),
|
targets.", &setlist),
|
&showlist);
|
&showlist);
|
|
|
add_com ("remote <command>", class_obscure, sr_com,
|
add_com ("remote <command>", class_obscure, sr_com,
|
"Send a command to the remote monitor.");
|
"Send a command to the remote monitor.");
|
|
|
}
|
}
|
|
|