/* Remote target communications for serial-line targets in custom GDB protocol
- Copyright 1988, 1991-2000 Free Software Foundation, Inc.
+ Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+ 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdb_string.h"
#include <ctype.h>
#include <fcntl.h>
-#include "frame.h"
#include "inferior.h"
#include "bfd.h"
#include "symfile.h"
#include "target.h"
-#include "gdb_wait.h"
/*#include "terminal.h" */
#include "gdbcmd.h"
#include "objfiles.h"
#include "gdb-stabs.h"
#include "gdbthread.h"
#include "remote.h"
-
-#include "dcache.h"
+#include "regcache.h"
#include <ctype.h>
#include <sys/time.h>
#include <signal.h>
#include "serial.h"
+#include "gdbcore.h" /* for exec_bfd */
+
/* Prototypes for local functions */
static void cleanup_sigint_signal_handler (void *dummy);
static void initialize_sigint_signal_handler (void);
static int remote_xfer_memory (CORE_ADDR memaddr, char *myaddr,
int len, int should_write,
+ struct mem_attrib *attrib,
struct target_ops *target);
static void remote_prepare_to_store (void);
static void remote_fetch_registers (int regno);
-static void remote_resume (int pid, int step, enum target_signal siggnal);
-static void remote_async_resume (int pid, int step,
+static void remote_resume (ptid_t ptid, int step,
+ enum target_signal siggnal);
+static void remote_async_resume (ptid_t ptid, int step,
enum target_signal siggnal);
static int remote_start_remote (PTR);
static int readchar (int timeout);
-static int remote_wait (int pid, struct target_waitstatus *status);
-static int remote_async_wait (int pid, struct target_waitstatus *status);
+static ptid_t remote_wait (ptid_t ptid,
+ struct target_waitstatus *status);
+static ptid_t remote_async_wait (ptid_t ptid,
+ struct target_waitstatus *status);
static void remote_kill (void);
static void remote_async_kill (void);
static void set_thread (int, int);
-static int remote_thread_alive (int);
+static int remote_thread_alive (ptid_t);
static void get_offsets (void);
static int stub_unpack_int (char *buff, int fieldlength);
-static int remote_current_thread (int oldpid);
+static ptid_t remote_current_thread (ptid_t oldptid);
static void remote_find_new_threads (void);
static void record_currthread (int currthread);
-/* exported functions */
+static int fromhex (int a);
+
+static int hex2bin (const char *hex, char *bin, int count);
-extern int fromhex (int a);
+static int bin2hex (const char *bin, char *hex, int count);
static int putpkt_binary (char *buf, int cnt);
config->title = title;
config->detect = CMD_AUTO_BOOLEAN_AUTO;
config->support = PACKET_SUPPORT_UNKNOWN;
- asprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
- name, title);
- asprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
- name, title);
+ xasprintf (&set_doc, "Set use of remote protocol `%s' (%s) packet",
+ name, title);
+ xasprintf (&show_doc, "Show current use of remote protocol `%s' (%s) packet",
+ name, title);
/* set/show TITLE-packet {auto,on,off} */
- asprintf (&cmd_name, "%s-packet", title);
+ xasprintf (&cmd_name, "%s-packet", title);
set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure,
&config->detect, set_doc,
set_remote_list);
if (legacy)
{
char *legacy_name;
- asprintf (&legacy_name, "%s-packet", name);
+ xasprintf (&legacy_name, "%s-packet", name);
add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
set_remote_list);
add_alias_cmd (legacy_name, cmd_name, class_obscure, 0,
config->support = PACKET_ENABLE;
break;
case PACKET_DISABLE:
- internal_error ("packet_ok: attempt to use a disabled packet");
+ internal_error (__FILE__, __LINE__,
+ "packet_ok: attempt to use a disabled packet");
break;
case PACKET_ENABLE:
break;
}
}
+/* Should we try the 'qSymbol' (target symbol lookup service) request? */
+static struct packet_config remote_protocol_qSymbol;
+
+static void
+set_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+ update_packet_config (&remote_protocol_qSymbol);
+}
+
+static void
+show_remote_protocol_qSymbol_packet_cmd (char *args, int from_tty)
+{
+ show_packet_config_cmd (&remote_protocol_qSymbol);
+}
+
+/* Should we try the 'e' (step over range) request? */
+static struct packet_config remote_protocol_e;
+
+static void
+set_remote_protocol_e_packet_cmd (char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+ update_packet_config (&remote_protocol_e);
+}
+
+static void
+show_remote_protocol_e_packet_cmd (char *args, int from_tty)
+{
+ show_packet_config_cmd (&remote_protocol_e);
+}
+
+
+/* Should we try the 'E' (step over range / w signal #) request? */
+static struct packet_config remote_protocol_E;
+
+static void
+set_remote_protocol_E_packet_cmd (char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+ update_packet_config (&remote_protocol_E);
+}
+
+static void
+show_remote_protocol_E_packet_cmd (char *args, int from_tty)
+{
+ show_packet_config_cmd (&remote_protocol_E);
+}
+
+
/* Should we try the 'P' (set register) request? */
static struct packet_config remote_protocol_P;
/* If this is a new thread, add it to GDB's thread list.
If we leave it up to WFI to do this, bad things will happen. */
- if (!in_thread_list (currthread))
+ if (!in_thread_list (pid_to_ptid (currthread)))
{
- add_thread (currthread);
+ add_thread (pid_to_ptid (currthread));
#ifdef UI_OUT
ui_out_text (uiout, "[New ");
- ui_out_text (uiout, target_pid_to_str (currthread));
+ ui_out_text (uiout, target_pid_to_str (pid_to_ptid (currthread)));
ui_out_text (uiout, "]\n");
#else
- printf_filtered ("[New %s]\n", target_pid_to_str (currthread));
+ printf_filtered ("[New %s]\n",
+ target_pid_to_str (pid_to_ptid (currthread)));
#endif
}
}
/* Return nonzero if the thread TH is still alive on the remote system. */
static int
-remote_thread_alive (int tid)
+remote_thread_alive (ptid_t ptid)
{
+ int tid = PIDGET (ptid);
char buf[16];
if (tid < 0)
static int
remote_newthread_step (threadref *ref, void *context)
{
- int pid;
+ ptid_t ptid;
+
+ ptid = pid_to_ptid (threadref_to_int (ref));
- pid = threadref_to_int (ref);
- if (!in_thread_list (pid))
- add_thread (pid);
+ if (!in_thread_list (ptid))
+ add_thread (ptid);
return 1; /* continue iterator */
}
#define CRAZY_MAX_THREADS 1000
-static int
-remote_current_thread (int oldpid)
+static ptid_t
+remote_current_thread (ptid_t oldpid)
{
char *buf = alloca (PBUFSIZ);
putpkt ("qC");
getpkt (buf, PBUFSIZ, 0);
if (buf[0] == 'Q' && buf[1] == 'C')
- return strtol (&buf[2], NULL, 16);
+ return pid_to_ptid (strtol (&buf[2], NULL, 16));
else
return oldpid;
}
{
remote_threadlist_iterator (remote_newthread_step, 0,
CRAZY_MAX_THREADS);
- if (inferior_pid == MAGIC_NULL_PID) /* ack ack ack */
- inferior_pid = remote_current_thread (inferior_pid);
+ if (PIDGET (inferior_ptid) == MAGIC_NULL_PID) /* ack ack ack */
+ inferior_ptid = remote_current_thread (inferior_ptid);
}
/*
do
{
tid = strtol (bufp, &bufp, 16);
- if (tid != 0 && !in_thread_list (tid))
- add_thread (tid);
+ if (tid != 0 && !in_thread_list (pid_to_ptid (tid)))
+ add_thread (pid_to_ptid (tid));
}
while (*bufp++ == ','); /* comma-separated list */
putpkt ("qsThreadInfo");
int n = 0; /* position in display_buf */
if (remote_desc == 0) /* paranoia */
- internal_error ("remote_threads_extra_info");
+ internal_error (__FILE__, __LINE__,
+ "remote_threads_extra_info");
if (use_threadextra_query)
{
- sprintf (bufp, "qThreadExtraInfo,%x", tp->pid);
+ sprintf (bufp, "qThreadExtraInfo,%x", PIDGET (tp->ptid));
putpkt (bufp);
getpkt (bufp, PBUFSIZ, 0);
if (bufp[0] != 0)
{
- char *p;
-
- for (p = display_buf;
- p < display_buf + sizeof(display_buf) - 1 &&
- bufp[0] != 0 &&
- bufp[1] != 0;
- p++, bufp+=2)
- {
- *p = fromhex (bufp[0]) * 16 + fromhex (bufp[1]);
- }
- *p = 0;
+ n = min (strlen (bufp) / 2, sizeof (display_buf));
+ result = hex2bin (bufp, display_buf, n);
+ display_buf [result] = '\0';
return display_buf;
}
}
use_threadextra_query = 0;
set = TAG_THREADID | TAG_EXISTS | TAG_THREADNAME
| TAG_MOREDISPLAY | TAG_DISPLAY;
- int_to_threadref (&id, tp->pid);
+ int_to_threadref (&id, PIDGET (tp->ptid));
if (remote_get_threadinfo (&id, set, &threadinfo))
if (threadinfo.active)
{
asection *sect;
bfd *abfd;
int len;
- char *p;
if (symfile_objfile == NULL)
return -1; /* no can do nothin' */
sect != 0;
sect = sect->next)
{
- p = (unsigned char *) bfd_get_section_name (abfd, sect);
+ const char *p = bfd_get_section_name (abfd, sect);
len = strlen (p);
if (strcmp (p + len - 4, "data") == 0) /* ends in "data" */
if (data_base == 0 ||
/* Let the stub know that we want it to return the thread. */
set_thread (-1, 0);
- inferior_pid = remote_current_thread (inferior_pid);
+ inferior_ptid = remote_current_thread (inferior_ptid);
get_offsets (); /* Get text, data & bss offsets */
/* Generic code for opening a connection to a remote target. */
-static DCACHE *remote_dcache;
-
static void
init_all_packet_configs (void)
{
int i;
+ update_packet_config (&remote_protocol_e);
+ update_packet_config (&remote_protocol_E);
update_packet_config (&remote_protocol_P);
+ update_packet_config (&remote_protocol_qSymbol);
for (i = 0; i < NR_Z_PACKET_TYPES; i++)
update_packet_config (&remote_protocol_Z[i]);
/* Force remote_write_bytes to check whether target supports binary
update_packet_config (&remote_protocol_binary_download);
}
+/* Symbol look-up. */
+
+static void
+remote_check_symbols (struct objfile *objfile)
+{
+ char *msg, *reply, *tmp;
+ struct minimal_symbol *sym;
+ int end;
+
+ if (remote_protocol_qSymbol.support == PACKET_DISABLE)
+ return;
+
+ msg = alloca (PBUFSIZ);
+ reply = alloca (PBUFSIZ);
+
+ /* Invite target to request symbol lookups. */
+
+ putpkt ("qSymbol::");
+ getpkt (reply, PBUFSIZ, 0);
+ packet_ok (reply, &remote_protocol_qSymbol);
+
+ while (strncmp (reply, "qSymbol:", 8) == 0)
+ {
+ tmp = &reply[8];
+ end = hex2bin (tmp, msg, strlen (tmp) / 2);
+ msg[end] = '\0';
+ sym = lookup_minimal_symbol (msg, NULL, NULL);
+ if (sym == NULL)
+ sprintf (msg, "qSymbol::%s", &reply[8]);
+ else
+ sprintf (msg, "qSymbol:%s:%s",
+ paddr_nz (SYMBOL_VALUE_ADDRESS (sym)),
+ &reply[8]);
+ putpkt (msg);
+ getpkt (reply, PBUFSIZ, 0);
+ }
+}
+
static void
remote_open_1 (char *name, int from_tty, struct target_ops *target,
int extended_p)
unpush_target (target);
- if (!remote_dcache)
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
- else
- dcache_invd (remote_dcache);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
be split out into seperate variables, especially since GDB will
someday have a notion of debugging several processes. */
- inferior_pid = MAGIC_NULL_PID;
+ inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);
+#ifdef SOLIB_CREATE_INFERIOR_HOOK
+ /* First delete any symbols previously loaded from shared libraries. */
+ no_shared_libraries (NULL, 0);
+#endif
+
/* Start the remote connection; if error (0), discard this target.
In particular, if the user quits, be sure to discard it
(we'd be in an inconsistent state otherwise). */
if (extended_p)
{
- /* tell the remote that we're using the extended protocol. */
+ /* Tell the remote that we are using the extended protocol. */
char *buf = alloca (PBUFSIZ);
putpkt ("!");
getpkt (buf, PBUFSIZ, 0);
}
+#ifdef SOLIB_CREATE_INFERIOR_HOOK
+ /* FIXME: need a master target_open vector from which all
+ remote_opens can be called, so that stuff like this can
+ go there. Failing that, the following code must be copied
+ to the open function for any remote target that wants to
+ support svr4 shared libraries. */
+
+ /* Set up to detect and load shared libraries. */
+ if (exec_bfd) /* No use without an exec file. */
+ {
+ SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+ remote_check_symbols (symfile_objfile);
+ }
+#endif
}
/* Just like remote_open but with asynchronous support. */
unpush_target (target);
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
flag indicating that a target is active. These functions should
be split out into seperate variables, especially since GDB will
someday have a notion of debugging several processes. */
- inferior_pid = MAGIC_NULL_PID;
+ inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);
/* With this target we start out by owning the terminal. */
remote_async_terminal_ours_p = 1;
/* FIXME: cagney/1999-09-23: During the initial connection it is
assumed that the target is already ready and able to respond to
- requests. Unfortunatly remote_start_remote() eventually calls
+ requests. Unfortunately remote_start_remote() eventually calls
wait_for_inferior() with no timeout. wait_forever_enabled_p gets
around this. Eventually a mechanism that allows
wait_for_inferior() to expect/get timeouts will be
implemented. */
wait_forever_enabled_p = 0;
+#ifdef SOLIB_CREATE_INFERIOR_HOOK
+ /* First delete any symbols previously loaded from shared libraries. */
+ no_shared_libraries (NULL, 0);
+#endif
+
/* Start the remote connection; if error (0), discard this target.
In particular, if the user quits, be sure to discard it
(we'd be in an inconsistent state otherwise). */
if (extended_p)
{
- /* tell the remote that we're using the extended protocol. */
+ /* Tell the remote that we are using the extended protocol. */
char *buf = alloca (PBUFSIZ);
putpkt ("!");
getpkt (buf, PBUFSIZ, 0);
}
+#ifdef SOLIB_CREATE_INFERIOR_HOOK
+ /* FIXME: need a master target_open vector from which all
+ remote_opens can be called, so that stuff like this can
+ go there. Failing that, the following code must be copied
+ to the open function for any remote target that wants to
+ support svr4 shared libraries. */
+
+ /* Set up to detect and load shared libraries. */
+ if (exec_bfd) /* No use without an exec file. */
+ {
+ SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+ remote_check_symbols (symfile_objfile);
+ }
+#endif
}
/* This takes a program previously attached to and detaches it. After
/* Convert hex digit A to a number. */
-int
+static int
fromhex (int a)
{
if (a >= '0' && a <= '9')
error ("Reply contains invalid hex digit %d", a);
}
+static int
+hex2bin (const char *hex, char *bin, int count)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ if (hex[0] == 0 || hex[1] == 0)
+ {
+ /* Hex string is short, or of uneven length.
+ Return the count that has been converted so far. */
+ return i;
+ }
+ *bin++ = fromhex (hex[0]) * 16 + fromhex (hex[1]);
+ hex += 2;
+ }
+ return i;
+}
+
/* Convert number NIB to a hex digit. */
static int
else
return 'a' + nib - 10;
}
+
+static int
+bin2hex (const char *bin, char *hex, int count)
+{
+ int i;
+ /* May use a length, or a nul-terminated string as input. */
+ if (count == 0)
+ count = strlen (bin);
+
+ for (i = 0; i < count; i++)
+ {
+ *hex++ = tohex ((*bin >> 4) & 0xf);
+ *hex++ = tohex (*bin++ & 0xf);
+ }
+ *hex = 0;
+ return i;
+}
\f
/* Tell the remote machine to resume. */
static int last_sent_step;
static void
-remote_resume (int pid, int step, enum target_signal siggnal)
+remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
char *buf = alloca (PBUFSIZ);
+ int pid = PIDGET (ptid);
+ char *p;
if (pid == -1)
set_thread (0, 0); /* run any thread */
else
set_thread (pid, 0); /* run this thread */
- dcache_invd (remote_dcache);
-
last_sent_signal = siggnal;
last_sent_step = step;
if (target_resume_hook)
(*target_resume_hook) ();
+
+ /* The s/S/c/C packets do not return status. So if the target does
+ not support the S or C packets, the debug agent returns an empty
+ string which is detected in remote_wait(). This protocol defect
+ is fixed in the e/E packets. */
+
+ if (step && step_range_end)
+ {
+ /* If the target does not support the 'E' packet, we try the 'S'
+ packet. Ideally we would fall back to the 'e' packet if that
+ too is not supported. But that would require another copy of
+ the code to issue the 'e' packet (and fall back to 's' if not
+ supported) in remote_wait(). */
+
+ if (siggnal != TARGET_SIGNAL_0)
+ {
+ if (remote_protocol_E.support != PACKET_DISABLE)
+ {
+ p = buf;
+ *p++ = 'E';
+ *p++ = tohex (((int) siggnal >> 4) & 0xf);
+ *p++ = tohex (((int) siggnal) & 0xf);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_start);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_end);
+ *p++ = 0;
+
+ putpkt (buf);
+ getpkt (buf, PBUFSIZ, 0);
+
+ if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
+ return;
+ }
+ }
+ else
+ {
+ if (remote_protocol_e.support != PACKET_DISABLE)
+ {
+ p = buf;
+ *p++ = 'e';
+ p += hexnumstr (p, (ULONGEST) step_range_start);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_end);
+ *p++ = 0;
+
+ putpkt (buf);
+ getpkt (buf, PBUFSIZ, 0);
+
+ if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
+ return;
+ }
+ }
+ }
+
if (siggnal != TARGET_SIGNAL_0)
{
buf[0] = step ? 'S' : 'C';
buf[1] = tohex (((int) siggnal >> 4) & 0xf);
- buf[2] = tohex ((int) siggnal & 0xf);
+ buf[2] = tohex (((int) siggnal) & 0xf);
buf[3] = '\0';
}
else
/* Same as remote_resume, but with async support. */
static void
-remote_async_resume (int pid, int step, enum target_signal siggnal)
+remote_async_resume (ptid_t ptid, int step, enum target_signal siggnal)
{
char *buf = alloca (PBUFSIZ);
+ int pid = PIDGET (ptid);
+ char *p;
if (pid == -1)
set_thread (0, 0); /* run any thread */
else
set_thread (pid, 0); /* run this thread */
- dcache_invd (remote_dcache);
-
last_sent_signal = siggnal;
last_sent_step = step;
if (target_resume_hook)
(*target_resume_hook) ();
+ /* The s/S/c/C packets do not return status. So if the target does
+ not support the S or C packets, the debug agent returns an empty
+ string which is detected in remote_wait(). This protocol defect
+ is fixed in the e/E packets. */
+
+ if (step && step_range_end)
+ {
+ /* If the target does not support the 'E' packet, we try the 'S'
+ packet. Ideally we would fall back to the 'e' packet if that
+ too is not supported. But that would require another copy of
+ the code to issue the 'e' packet (and fall back to 's' if not
+ supported) in remote_wait(). */
+
+ if (siggnal != TARGET_SIGNAL_0)
+ {
+ if (remote_protocol_E.support != PACKET_DISABLE)
+ {
+ p = buf;
+ *p++ = 'E';
+ *p++ = tohex (((int) siggnal >> 4) & 0xf);
+ *p++ = tohex (((int) siggnal) & 0xf);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_start);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_end);
+ *p++ = 0;
+
+ putpkt (buf);
+ getpkt (buf, PBUFSIZ, 0);
+
+ if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
+ goto register_event_loop;
+ }
+ }
+ else
+ {
+ if (remote_protocol_e.support != PACKET_DISABLE)
+ {
+ p = buf;
+ *p++ = 'e';
+ p += hexnumstr (p, (ULONGEST) step_range_start);
+ *p++ = ',';
+ p += hexnumstr (p, (ULONGEST) step_range_end);
+ *p++ = 0;
+
+ putpkt (buf);
+ getpkt (buf, PBUFSIZ, 0);
+
+ if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
+ goto register_event_loop;
+ }
+ }
+ }
+
if (siggnal != TARGET_SIGNAL_0)
{
buf[0] = step ? 'S' : 'C';
}
else
strcpy (buf, step ? "s" : "c");
+
+ putpkt (buf);
+register_event_loop:
/* We are about to start executing the inferior, let's register it
with the event loop. NOTE: this is the one place where all the
execution commands end up. We could alternatively do this in each
this information already found in the continuation block? */
if (target_is_async_p ())
target_executing = 1;
- putpkt (buf);
}
\f
Returns "pid", which in the case of a multi-threaded
remote OS, is the thread-id. */
-static int
-remote_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+remote_wait (ptid_t ptid, struct target_waitstatus *status)
{
unsigned char *buf = alloca (PBUFSIZ);
int thread_num = -1;
{
int i;
long regno;
- char regs[MAX_REGISTER_RAW_SIZE];
+ char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
/* Expedited reply, containing Signal, {regno, reg} repeat */
/* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
{
unsigned char *p1;
char *p_temp;
+ int fieldsize;
/* Read the register number */
regno = strtol ((const char *) p, &p_temp, 16);
Packet: '%s'\n",
regno, p, buf);
- for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
- {
- if (p[0] == 0 || p[1] == 0)
- warning ("Remote reply is too short: %s", buf);
- regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
- p += 2;
- }
+ fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (regno));
+ p += 2 * fieldsize;
+ if (fieldsize < REGISTER_RAW_SIZE (regno))
+ warning ("Remote reply is too short: %s", buf);
supply_register (regno, regs);
}
got_status:
if (thread_num != -1)
{
- return thread_num;
+ return pid_to_ptid (thread_num);
}
- return inferior_pid;
+ return inferior_ptid;
}
/* Async version of remote_wait. */
-static int
-remote_async_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
{
unsigned char *buf = alloca (PBUFSIZ);
int thread_num = -1;
{
int i;
long regno;
- char regs[MAX_REGISTER_RAW_SIZE];
+ char* regs = (char*) alloca (MAX_REGISTER_RAW_SIZE);
/* Expedited reply, containing Signal, {regno, reg} repeat */
/* format is: 'Tssn...:r...;n...:r...;n...:r...;#cc', where
{
unsigned char *p1;
char *p_temp;
+ int fieldsize;
/* Read the register number */
regno = strtol ((const char *) p, &p_temp, 16);
Packet: '%s'\n",
regno, p, buf);
- for (i = 0; i < REGISTER_RAW_SIZE (regno); i++)
- {
- if (p[0] == 0 || p[1] == 0)
- warning ("Remote reply is too short: %s", buf);
- regs[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
- p += 2;
- }
+ fieldsize = hex2bin (p, regs, REGISTER_RAW_SIZE (regno));
+ p += 2 * fieldsize;
+ if (fieldsize < REGISTER_RAW_SIZE (regno))
+ warning ("Remote reply is too short: %s", buf);
supply_register (regno, regs);
}
got_status:
if (thread_num != -1)
{
- return thread_num;
+ return pid_to_ptid (thread_num);
}
- return inferior_pid;
+ return inferior_ptid;
}
/* Number of bytes of registers this stub implements. */
char *buf = alloca (PBUFSIZ);
int i;
char *p;
- char regs[REGISTER_BYTES];
+ char *regs = alloca (REGISTER_BYTES);
- set_thread (inferior_pid, 1);
+ set_thread (PIDGET (inferior_ptid), 1);
sprintf (buf, "g");
remote_send (buf, PBUFSIZ);
if (i != register_bytes_found)
{
register_bytes_found = i;
-#ifdef REGISTER_BYTES_OK
- if (!REGISTER_BYTES_OK (i))
+ if (REGISTER_BYTES_OK_P ()
+ && !REGISTER_BYTES_OK (i))
warning ("Remote reply is too short: %s", buf);
-#endif
}
supply_them:
{
supply_register (i, ®s[REGISTER_BYTE (i)]);
if (buf[REGISTER_BYTE (i) * 2] == 'x')
- register_valid[i] = -1; /* register value not available */
+ set_register_cached (i, -1);
}
}
sprintf (buf, "P%x=", regno);
p = buf + strlen (buf);
- regp = ®isters[REGISTER_BYTE (regno)];
- for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
- {
- *p++ = tohex ((regp[i] >> 4) & 0xf);
- *p++ = tohex (regp[i] & 0xf);
- }
- *p = '\0';
+ regp = register_buffer (regno);
+ bin2hex (regp, p, REGISTER_RAW_SIZE (regno));
remote_send (buf, PBUFSIZ);
return buf[0] != '\0';
/* Store register REGNO, or all registers if REGNO == -1, from the contents
- of REGISTERS. FIXME: ignores errors. */
+ of the register cache buffer. FIXME: ignores errors. */
static void
remote_store_registers (int regno)
char *buf = alloca (PBUFSIZ);
int i;
char *p;
+ char *regs;
- set_thread (inferior_pid, 1);
+ set_thread (PIDGET (inferior_ptid), 1);
if (regno >= 0)
{
/* Command describes registers byte by byte,
each byte encoded as two hex characters. */
+ regs = register_buffer (-1);
p = buf + 1;
/* remote_prepare_to_store insures that register_bytes_found gets set. */
- for (i = 0; i < register_bytes_found; i++)
- {
- *p++ = tohex ((registers[i] >> 4) & 0xf);
- *p++ = tohex (registers[i] & 0xf);
- }
- *p = '\0';
-
+ bin2hex (regs, p, register_bytes_found);
remote_send (buf, PBUFSIZ);
}
\f
todo = min (len, max_buf_size / 2);
break;
case PACKET_SUPPORT_UNKNOWN:
- internal_error ("remote_write_bytes: bad switch");
+ internal_error (__FILE__, __LINE__,
+ "remote_write_bytes: bad internal state");
+ default:
+ internal_error (__FILE__, __LINE__, "bad switch");
}
/* Append <memaddr> */
/* Normal mode: Send target system values byte by byte, in
increasing byte addresses. Each byte is encoded as a two hex
value. */
- for (nr_bytes = 0; nr_bytes < todo; nr_bytes++)
- {
- *p++ = tohex ((myaddr[nr_bytes] >> 4) & 0xf);
- *p++ = tohex (myaddr[nr_bytes] & 0xf);
- }
- *p = '\0';
+ nr_bytes = bin2hex (myaddr, p, todo);
+ p += 2 * nr_bytes;
break;
case PACKET_SUPPORT_UNKNOWN:
- internal_error ("remote_write_bytes: bad switch");
+ internal_error (__FILE__, __LINE__,
+ "remote_write_bytes: bad internal state");
+ default:
+ internal_error (__FILE__, __LINE__, "bad switch");
}
putpkt_binary (buf, (int) (p - buf));
each byte encoded as two hex characters. */
p = buf;
- for (i = 0; i < todo; i++)
+ if ((i = hex2bin (p, myaddr, todo)) < todo)
{
- if (p[0] == 0 || p[1] == 0)
- /* Reply is short. This means that we were able to read
- only part of what we wanted to. */
- return i + (origlen - len);
- myaddr[i] = fromhex (p[0]) * 16 + fromhex (p[1]);
- p += 2;
+ /* Reply is short. This means that we were able to read
+ only part of what we wanted to. */
+ return i + (origlen - len);
}
myaddr += todo;
memaddr += todo;
/* ARGSUSED */
static int
remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len,
- int should_write, struct target_ops *target)
+ int should_write,
+ struct mem_attrib *attrib ATTRIBUTE_UNUSED,
+ struct target_ops *target)
{
CORE_ADDR targ_addr;
int targ_len;
+ int res;
+
REMOTE_TRANSLATE_XFER_ADDRESS (mem_addr, mem_len, &targ_addr, &targ_len);
if (targ_len <= 0)
return 0;
- return dcache_xfer_memory (remote_dcache, targ_addr, buffer,
- targ_len, should_write);
+ if (should_write)
+ res = remote_write_bytes (targ_addr, buffer, targ_len);
+ else
+ res = remote_read_bytes (targ_addr, buffer, targ_len);
+
+ return res;
}
executing user code to stop. If FOREVER == 0, this function is
allowed to time out gracefully and return an indication of this to
the caller. */
-int
+static int
getpkt_sane (char *buf,
long sizeof_buf,
int forever)
return 4;
break;
default:
- internal_error ("hw_bp_to_z: bad watchpoint type %d", type);
+ internal_error (__FILE__, __LINE__,
+ "hw_bp_to_z: bad watchpoint type %d", type);
}
}
case PACKET_OK:
return 0;
}
- internal_error ("remote_insert_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_insert_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- *p = '\0';
+ sprintf (p, ",%x", len);
putpkt (buf);
getpkt (buf, PBUFSIZ, 0);
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* FIXME: This function should be static and a member of the remote
addr = remote_address_masked (addr);
p += hexnumstr (p, (ULONGEST) addr);
- *p = '\0';
+ sprintf (p, ",%x", len);
putpkt(buf);
getpkt (buf, PBUFSIZ, 0);
case PACKET_OK:
return 0;
}
- internal_error ("remote_remove_watchpoint: reached end of function");
+ internal_error (__FILE__, __LINE__,
+ "remote_remove_watchpoint: reached end of function");
}
/* Some targets are only capable of doing downloads, and afterwards
struct cleanup *old_chain;
char *tmp;
char *sectdata;
- char *sectname;
+ const char *sectname;
char *buf = alloca (PBUFSIZ);
bfd_size_type size;
bfd_vma lma;
if (size == 0)
continue; /* skip zero-length section */
- sectname = (char *) bfd_get_section_name (exec_bfd, s);
+ sectname = bfd_get_section_name (exec_bfd, s);
if (args && strcmp (args, sectname) != 0)
continue; /* not the section selected by user */
/* be clever; compute the host_crc before waiting for target reply */
sectdata = xmalloc (size);
- old_chain = make_cleanup (free, sectdata);
+ old_chain = make_cleanup (xfree, sectdata);
bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
host_crc = crc32 ((unsigned char *) sectdata, size, 0xffffffff);
error ("\"monitor\" command ``%s'' is too long\n", command);
/* Encode the actual command */
- for (i = 0; command[i]; i++)
- {
- *p++ = tohex ((command[i] >> 4) & 0xf);
- *p++ = tohex (command[i] & 0xf);
- }
- *p = '\0';
+ bin2hex (command, p, 0);
if (putpkt (buf) < 0)
error ("Communication problem with target\n");
{
int sample_thread = SAMPLE_THREAD;
- if (remote_thread_alive (sample_thread))
+ if (remote_thread_alive (pid_to_ptid (sample_thread)))
printf_filtered ("PASS: Thread alive test\n");
else
printf_filtered ("FAIL: Thread alive test\n");
#endif /* 0 */
+/* Convert a thread ID to a string. Returns the string in a static
+ buffer. */
+
+static char *
+remote_pid_to_str (ptid_t ptid)
+{
+ static char buf[30];
+
+ sprintf (buf, "Thread %d", PIDGET (ptid));
+ return buf;
+}
+
static void
init_remote_ops (void)
{
remote_ops.to_thread_alive = remote_thread_alive;
remote_ops.to_find_new_threads = remote_threads_info;
remote_ops.to_extra_thread_info = remote_threads_extra_info;
+ remote_ops.to_pid_to_str = remote_pid_to_str;
remote_ops.to_stop = remote_stop;
remote_ops.to_query = remote_query;
remote_ops.to_rcmd = remote_rcmd;
unpush_target (&remote_cisco_ops);
- if (!remote_dcache)
- remote_dcache = dcache_init (remote_read_bytes, remote_write_bytes);
- else
- dcache_invd (remote_dcache);
-
remote_desc = SERIAL_OPEN (name);
if (!remote_desc)
perror_with_name (name);
flag indicating that a target is active. These functions should
be split out into seperate variables, especially since GDB will
someday have a notion of debugging several processes. */
- inferior_pid = MAGIC_NULL_PID;
+ inferior_ptid = pid_to_ptid (MAGIC_NULL_PID);
/* Start the remote connection; if error (0), discard this target. */
}
}
-static int
-remote_cisco_wait (int pid, struct target_waitstatus *status)
+static ptid_t
+remote_cisco_wait (ptid_t ptid, struct target_waitstatus *status)
{
if (minitelnet () != ENTER_DEBUG)
{
error ("Debugging session terminated by protocol error");
}
putpkt ("?");
- return remote_wait (pid, status);
+ return remote_wait (ptid, status);
}
static void
remote_async (void (*callback) (enum inferior_event_type event_type, void *context), void *context)
{
if (current_target.to_async_mask_value == 0)
- internal_error ("Calling remote_async when async is masked");
+ internal_error (__FILE__, __LINE__,
+ "Calling remote_async when async is masked");
if (callback != NULL)
{
static void
set_remote_cmd (char *args, int from_tty)
{
-
}
static void
show_remote_cmd (char *args, int from_tty)
{
+
show_remote_protocol_Z_packet_cmd (args, from_tty);
+ show_remote_protocol_e_packet_cmd (args, from_tty);
+ show_remote_protocol_E_packet_cmd (args, from_tty);
show_remote_protocol_P_packet_cmd (args, from_tty);
+ show_remote_protocol_qSymbol_packet_cmd (args, from_tty);
show_remote_protocol_binary_download_cmd (args, from_tty);
}
/* Cisco stuff */
tty_input = xmalloc (PBUFSIZ);
- remote_address_size = TARGET_PTR_BIT;
+ remote_address_size = TARGET_ADDR_BIT;
+}
+
+/* Saved pointer to previous owner of the new_objfile event. */
+static void (*remote_new_objfile_chain) (struct objfile *);
+
+/* Function to be called whenever a new objfile (shlib) is detected. */
+static void
+remote_new_objfile (struct objfile *objfile)
+{
+ if (remote_desc != 0) /* Have a remote connection */
+ {
+ remote_check_symbols (objfile);
+ }
+ /* Call predecessor on chain, if any. */
+ if (remote_new_objfile_chain != 0 &&
+ remote_desc == 0)
+ remote_new_objfile_chain (objfile);
}
void
init_remote_cisco_ops ();
add_target (&remote_cisco_ops);
+ /* Hook into new objfile notification. */
+ remote_new_objfile_chain = target_new_objfile_hook;
+ target_new_objfile_hook = remote_new_objfile;
+
#if 0
init_remote_threadtests ();
#endif
add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
"Set the maximum number of bytes per memory write packet (deprecated).\n",
&setlist);
- add_cmd ("remotewritesize", no_class, set_memory_write_packet_size,
+ add_cmd ("remotewritesize", no_class, show_memory_write_packet_size,
"Show the maximum number of bytes per memory write packet (deprecated).\n",
&showlist);
add_cmd ("memory-write-packet-size", no_class,
add_info ("remote-process", remote_info_process,
"Query the remote system for process info.");
+ add_packet_config_cmd (&remote_protocol_qSymbol,
+ "qSymbol", "symbol-lookup",
+ set_remote_protocol_qSymbol_packet_cmd,
+ show_remote_protocol_qSymbol_packet_cmd,
+ &remote_set_cmdlist, &remote_show_cmdlist,
+ 0);
+
+ add_packet_config_cmd (&remote_protocol_e,
+ "e", "step-over-range",
+ set_remote_protocol_e_packet_cmd,
+ show_remote_protocol_e_packet_cmd,
+ &remote_set_cmdlist, &remote_show_cmdlist,
+ 0);
+
+ add_packet_config_cmd (&remote_protocol_E,
+ "E", "step-over-range-w-signal",
+ set_remote_protocol_E_packet_cmd,
+ show_remote_protocol_E_packet_cmd,
+ &remote_set_cmdlist, &remote_show_cmdlist,
+ 0);
+
add_packet_config_cmd (&remote_protocol_P,
"P", "set-register",
set_remote_protocol_P_packet_cmd,