Add missing support for -o option.
[deliverable/binutils-gdb.git] / gdb / remote.c
index cba1442607e48f61ddb1b9faf59e2a1306bd5abd..86ba3c1eb14d47e793dcaff50d63f33f2adeef4c 100644 (file)
@@ -1,5 +1,6 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
-   Copyright 1988, 1991-2000, 2001 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.
 
@@ -24,7 +25,6 @@
 #include "gdb_string.h"
 #include <ctype.h>
 #include <fcntl.h>
-#include "frame.h"
 #include "inferior.h"
 #include "bfd.h"
 #include "symfile.h"
@@ -35,6 +35,7 @@
 #include "gdb-stabs.h"
 #include "gdbthread.h"
 #include "remote.h"
+#include "regcache.h"
 
 #include <ctype.h>
 #include <sys/time.h>
@@ -49,6 +50,8 @@
 #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);
@@ -76,8 +79,9 @@ 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);
 
@@ -111,8 +115,10 @@ static void remote_send (char *buf, long sizeof_buf);
 
 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);
@@ -130,7 +136,7 @@ static void interrupt_query (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);
 
@@ -174,15 +180,17 @@ static void packet_command (char *, int);
 
 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);
 
@@ -662,6 +670,56 @@ packet_ok (const char *buf, struct packet_config *config)
     }
 }
 
+/* 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;
@@ -857,15 +915,16 @@ record_currthread (int currthread)
 
   /* 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
     }
 }
@@ -903,8 +962,9 @@ set_thread (int th, int gen)
 /*  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)
@@ -1578,25 +1638,26 @@ remote_threadlist_iterator (rmt_thread_action stepfunction, void *context,
 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;
 }
@@ -1610,8 +1671,8 @@ remote_find_new_threads (void)
 {
   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);
 }
 
 /*
@@ -1643,8 +1704,8 @@ remote_threads_info (void)
              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");
@@ -1687,22 +1748,14 @@ remote_threads_extra_info (struct thread_info *tp)
 
   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;
        }
     }
@@ -1711,7 +1764,7 @@ remote_threads_extra_info (struct thread_info *tp)
   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)
       {
@@ -1875,7 +1928,6 @@ remote_cisco_section_offsets (bfd_vma text_addr,
   asection *sect;
   bfd *abfd;
   int len;
-  char *p;
 
   if (symfile_objfile == NULL)
     return -1;                 /* no can do nothin' */
@@ -1892,7 +1944,7 @@ remote_cisco_section_offsets (bfd_vma text_addr,
        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 ||
@@ -1983,7 +2035,7 @@ remote_start_remote (PTR dummy)
   /* 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 */
 
@@ -2031,7 +2083,10 @@ 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
@@ -2039,6 +2094,44 @@ init_all_packet_configs (void)
   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)
@@ -2098,7 +2191,12 @@ serial device is attached to the remote system\n\
      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).  */
@@ -2112,11 +2210,25 @@ serial device is attached to the remote system\n\
 
   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. */
@@ -2176,7 +2288,7 @@ serial device is attached to the remote system\n\
      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;
@@ -2190,6 +2302,11 @@ serial device is attached to the remote system\n\
      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).  */
@@ -2206,11 +2323,25 @@ serial device is attached to the remote system\n\
 
   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
@@ -2260,7 +2391,7 @@ remote_async_detach (char *args, int from_tty)
 
 /* Convert hex digit A to a number.  */
 
-int
+static int
 fromhex (int a)
 {
   if (a >= '0' && a <= '9')
@@ -2273,6 +2404,25 @@ fromhex (int a)
     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
@@ -2283,6 +2433,23 @@ tohex (int nib)
   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.  */
 
@@ -2291,9 +2458,11 @@ static enum target_signal last_sent_signal = TARGET_SIGNAL_0;
 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 */
@@ -2308,11 +2477,66 @@ remote_resume (int pid, int step, enum target_signal siggnal)
   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
@@ -2323,9 +2547,11 @@ remote_resume (int pid, int step, enum target_signal siggnal)
 
 /* 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 */
@@ -2340,6 +2566,60 @@ remote_async_resume (int pid, int step, enum target_signal siggnal)
   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';
@@ -2349,7 +2629,10 @@ remote_async_resume (int pid, int step, enum target_signal siggnal)
     }
   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
@@ -2366,7 +2649,6 @@ remote_async_resume (int pid, int step, enum target_signal siggnal)
      this information already found in the continuation block?  */
   if (target_is_async_p ())
     target_executing = 1;
-  putpkt (buf);
 }
 \f
 
@@ -2575,8 +2857,8 @@ remote_console_output (char *msg)
    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;
@@ -2620,6 +2902,7 @@ remote_wait (int pid, struct target_waitstatus *status)
              {
                unsigned char *p1;
                char *p_temp;
+               int fieldsize;
 
                /* Read the register number */
                regno = strtol ((const char *) p, &p_temp, 16);
@@ -2653,13 +2936,10 @@ Packet: '%s'\n",
 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);
                  }
 
@@ -2784,14 +3064,14 @@ Packet Dropped");
 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;
@@ -2841,6 +3121,7 @@ remote_async_wait (int pid, struct target_waitstatus *status)
              {
                unsigned char *p1;
                char *p_temp;
+               int fieldsize;
 
                /* Read the register number */
                regno = strtol ((const char *) p, &p_temp, 16);
@@ -2874,13 +3155,10 @@ Packet: '%s'\n",
 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);
                  }
 
@@ -3008,9 +3286,9 @@ Packet Dropped");
 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.  */
@@ -3029,7 +3307,7 @@ remote_fetch_registers (int regno)
   char *p;
   char *regs = alloca (REGISTER_BYTES);
 
-  set_thread (inferior_pid, 1);
+  set_thread (PIDGET (inferior_ptid), 1);
 
   sprintf (buf, "g");
   remote_send (buf, PBUFSIZ);
@@ -3130,12 +3408,7 @@ store_register_using_P (int regno)
   sprintf (buf, "P%x=", regno);
   p = buf + strlen (buf);
   regp = register_buffer (regno);
-  for (i = 0; i < REGISTER_RAW_SIZE (regno); ++i)
-    {
-      *p++ = tohex ((regp[i] >> 4) & 0xf);
-      *p++ = tohex (regp[i] & 0xf);
-    }
-  *p = '\0';
+  bin2hex (regp, p, REGISTER_RAW_SIZE (regno));
   remote_send (buf, PBUFSIZ);
 
   return buf[0] != '\0';
@@ -3153,7 +3426,7 @@ remote_store_registers (int regno)
   char *p;
   char *regs;
 
-  set_thread (inferior_pid, 1);
+  set_thread (PIDGET (inferior_ptid), 1);
 
   if (regno >= 0)
     {
@@ -3192,13 +3465,7 @@ remote_store_registers (int regno)
   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 ((regs[i] >> 4) & 0xf);
-      *p++ = tohex (regs[i] & 0xf);
-    }
-  *p = '\0';
-
+  bin2hex (regs, p, register_bytes_found);
   remote_send (buf, PBUFSIZ);
 }
 \f
@@ -3425,12 +3692,8 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
       /* 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 (__FILE__, __LINE__,
@@ -3521,14 +3784,11 @@ remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
          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;
@@ -3985,7 +4245,7 @@ getpkt (char *buf,
    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)
@@ -4572,7 +4832,7 @@ compare_sections_command (char *args, int from_tty)
   struct cleanup *old_chain;
   char *tmp;
   char *sectdata;
-  char *sectname;
+  const char *sectname;
   char *buf = alloca (PBUFSIZ);
   bfd_size_type size;
   bfd_vma lma;
@@ -4594,7 +4854,7 @@ compare_sections_command (char *args, int from_tty)
       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 */
 
@@ -4728,12 +4988,7 @@ remote_rcmd (char *command,
     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");
@@ -4827,7 +5082,7 @@ threadalive_test (char *cmd, int tty)
 {
   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");
@@ -4934,6 +5189,18 @@ init_remote_threadtests (void)
 
 #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)
 {
@@ -4961,6 +5228,7 @@ Specify the serial device it is connected to\n\
   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;
@@ -5100,7 +5368,7 @@ device is attached to the remote system (e.g. host:port).");
      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. */
 
@@ -5332,15 +5600,15 @@ minitelnet (void)
     }
 }
 
-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
@@ -5498,14 +5766,17 @@ Specify the serial device it is connected to (e.g. /dev/ttya).",
 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);
 }
 
@@ -5516,7 +5787,24 @@ build_remote_gdbarch_data (void)
 
   /* 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
@@ -5549,6 +5837,10 @@ _initialize_remote (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
@@ -5649,6 +5941,27 @@ in a memory packet.\n",
   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,
This page took 0.040993 seconds and 4 git commands to generate.