Replace CONST with const
[deliverable/binutils-gdb.git] / gdb / remote.c
index 8ec75d2558ca9c1ecbc83dcbfd8031b8692dde7f..0555088bdf45e6265c8e79f618a435cc91b8fa46 100644 (file)
@@ -188,7 +188,9 @@ static void record_currthread (int currthread);
 
 static int fromhex (int a);
 
-static int hex2bin (const char *hex, char *bin, int);
+static int hex2bin (const char *hex, char *bin, int count);
+
+static int bin2hex (const char *bin, char *hex, int count);
 
 static int putpkt_binary (char *buf, int cnt);
 
@@ -238,7 +240,7 @@ static int remote_break;
 /* Descriptor for I/O to remote machine.  Initialize it to NULL so that
    remote_open knows that we don't have a file open when the program
    starts.  */
-static serial_t remote_desc = NULL;
+static struct serial *remote_desc = NULL;
 
 /* This is set by the target (thru the 'S' message)
    to denote that the target is in kernel mode.  */
@@ -668,6 +670,22 @@ 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;
 
@@ -1797,7 +1815,7 @@ static void
 remote_close (int quitting)
 {
   if (remote_desc)
-    SERIAL_CLOSE (remote_desc);
+    serial_close (remote_desc);
   remote_desc = NULL;
 }
 
@@ -2012,7 +2030,7 @@ remote_start_remote (PTR dummy)
   immediate_quit++;            /* Allow user to interrupt it */
 
   /* Ack any packet which the remote side has already sent.  */
-  SERIAL_WRITE (remote_desc, "+", 1);
+  serial_write (remote_desc, "+", 1);
 
   /* Let the stub know that we want it to return the thread.  */
   set_thread (-1, 0);
@@ -2068,6 +2086,7 @@ init_all_packet_configs (void)
   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
@@ -2075,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)
@@ -2091,24 +2148,24 @@ serial device is attached to the remote system\n\
 
   unpush_target (target);
 
-  remote_desc = SERIAL_OPEN (name);
+  remote_desc = serial_open (name);
   if (!remote_desc)
     perror_with_name (name);
 
   if (baud_rate != -1)
     {
-      if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
+      if (serial_setbaudrate (remote_desc, baud_rate))
        {
-         SERIAL_CLOSE (remote_desc);
+         serial_close (remote_desc);
          perror_with_name (name);
        }
     }
 
-  SERIAL_RAW (remote_desc);
+  serial_raw (remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
      response to a command, which would be bad.  */
-  SERIAL_FLUSH_INPUT (remote_desc);
+  serial_flush_input (remote_desc);
 
   if (from_tty)
     {
@@ -2167,7 +2224,10 @@ serial device is attached to the remote system\n\
 
   /* Set up to detect and load shared libraries. */
   if (exec_bfd)        /* No use without an exec file. */
-    SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+    {
+      SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+      remote_check_symbols (symfile_objfile);
+    }
 #endif
 }
 
@@ -2185,24 +2245,24 @@ serial device is attached to the remote system\n\
 
   unpush_target (target);
 
-  remote_desc = SERIAL_OPEN (name);
+  remote_desc = serial_open (name);
   if (!remote_desc)
     perror_with_name (name);
 
   if (baud_rate != -1)
     {
-      if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
+      if (serial_setbaudrate (remote_desc, baud_rate))
        {
-         SERIAL_CLOSE (remote_desc);
+         serial_close (remote_desc);
          perror_with_name (name);
        }
     }
 
-  SERIAL_RAW (remote_desc);
+  serial_raw (remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
      response to a command, which would be bad.  */
-  SERIAL_FLUSH_INPUT (remote_desc);
+  serial_flush_input (remote_desc);
 
   if (from_tty)
     {
@@ -2277,7 +2337,10 @@ serial device is attached to the remote system\n\
 
   /* Set up to detect and load shared libraries. */
   if (exec_bfd)        /* No use without an exec file. */
-    SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+    {
+      SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+      remote_check_symbols (symfile_objfile);
+    }
 #endif
 }
 
@@ -2319,7 +2382,7 @@ remote_async_detach (char *args, int from_tty)
 
   /* Unregister the file descriptor from the event loop. */
   if (target_is_async_p ())
-    SERIAL_ASYNC (remote_desc, NULL, 0);
+    serial_async (remote_desc, NULL, 0);
 
   target_mourn_inferior ();
   if (from_tty)
@@ -2346,10 +2409,6 @@ hex2bin (const char *hex, char *bin, int count)
 {
   int i;
 
-  /* May use a length, or a nul-terminated string as input. */
-  if (count == 0)
-    count = strlen (hex) / 2;
-
   for (i = 0; i < count; i++)
     {
       if (hex[0] == 0 || hex[1] == 0)
@@ -2376,7 +2435,7 @@ tohex (int nib)
 }
 
 static int
-bin2hex (char *bin, char *hex, int count)
+bin2hex (const char *bin, char *hex, int count)
 {
   int i;
   /* May use a length, or a nul-terminated string as input. */
@@ -2449,7 +2508,7 @@ remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
              putpkt (buf);
              getpkt (buf, PBUFSIZ, 0);
 
-             if (packet_ok(buf, &remote_protocol_E) == PACKET_OK)
+             if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
                return;
            }
        }
@@ -2467,7 +2526,7 @@ remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
              putpkt (buf);
              getpkt (buf, PBUFSIZ, 0);
 
-             if (packet_ok(buf, &remote_protocol_e) == PACKET_OK)
+             if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
                return;
            }
        }
@@ -2537,7 +2596,7 @@ remote_async_resume (ptid_t ptid, int step, enum target_signal siggnal)
              putpkt (buf);
              getpkt (buf, PBUFSIZ, 0);
 
-             if (packet_ok(buf, &remote_protocol_E) == PACKET_OK)
+             if (packet_ok (buf, &remote_protocol_E) == PACKET_OK)
                goto register_event_loop;
            }
        }
@@ -2555,7 +2614,7 @@ remote_async_resume (ptid_t ptid, int step, enum target_signal siggnal)
              putpkt (buf);
              getpkt (buf, PBUFSIZ, 0);
 
-             if (packet_ok(buf, &remote_protocol_e) == PACKET_OK)
+             if (packet_ok (buf, &remote_protocol_e) == PACKET_OK)
                goto register_event_loop;
            }
        }
@@ -2706,9 +2765,9 @@ remote_stop (void)
     fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
 
   if (remote_break)
-    SERIAL_SEND_BREAK (remote_desc);
+    serial_send_break (remote_desc);
   else
-    SERIAL_WRITE (remote_desc, "\003", 1);
+    serial_write (remote_desc, "\003", 1);
 }
 
 /* Ask the user what to do when an interrupt is received.  */
@@ -2843,6 +2902,7 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
              {
                unsigned char *p1;
                char *p_temp;
+               int fieldsize;
 
                /* Read the register number */
                regno = strtol ((const char *) p, &p_temp, 16);
@@ -2876,8 +2936,9 @@ Packet: '%s'\n",
 Packet: '%s'\n",
                               regno, p, buf);
 
-                   if (hex2bin (p, regs, REGISTER_RAW_SIZE (regno))
-                       < REGISTER_RAW_SIZE (regno))
+                   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);
                  }
@@ -3060,6 +3121,7 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
              {
                unsigned char *p1;
                char *p_temp;
+               int fieldsize;
 
                /* Read the register number */
                regno = strtol ((const char *) p, &p_temp, 16);
@@ -3093,8 +3155,9 @@ Packet: '%s'\n",
 Packet: '%s'\n",
                               regno, p, buf);
 
-                   if (hex2bin (p, regs, REGISTER_RAW_SIZE (regno)) 
-                       < REGISTER_RAW_SIZE (regno))
+                   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);
                  }
@@ -3630,6 +3693,7 @@ remote_write_bytes (CORE_ADDR memaddr, char *myaddr, int len)
         increasing byte addresses.  Each byte is encoded as a two hex
         value.  */
       nr_bytes = bin2hex (myaddr, p, todo);
+      p += 2 * nr_bytes;
       break;
     case PACKET_SUPPORT_UNKNOWN:
       internal_error (__FILE__, __LINE__,
@@ -3844,7 +3908,7 @@ readchar (int timeout)
 {
   int ch;
 
-  ch = SERIAL_READCHAR (remote_desc, timeout);
+  ch = serial_readchar (remote_desc, timeout);
 
   if (ch >= 0)
     return (ch & 0x7f);
@@ -3942,7 +4006,7 @@ putpkt_binary (char *buf, int cnt)
          fprintf_unfiltered (gdb_stdlog, "...");
          gdb_flush (gdb_stdlog);
        }
-      if (SERIAL_WRITE (remote_desc, buf2, p - buf2))
+      if (serial_write (remote_desc, buf2, p - buf2))
        perror_with_name ("putpkt: write failed");
 
       /* read until either a timeout occurs (-2) or '+' is read */
@@ -4125,7 +4189,7 @@ read_frame (char *buf,
 
            if (repeat > 0 && repeat <= 255 
                && bc > 0
-                && bc + repeat < sizeof_buf - 1)
+                && bc + repeat - 1 < sizeof_buf - 1)
              {
                memset (&buf[bc], buf[bc - 1], repeat);
                bc += repeat;
@@ -4244,19 +4308,19 @@ getpkt_sane (char *buf,
              fputstr_unfiltered (buf, 0, gdb_stdlog);
              fprintf_unfiltered (gdb_stdlog, "\n");
            }
-         SERIAL_WRITE (remote_desc, "+", 1);
+         serial_write (remote_desc, "+", 1);
          return 0;
        }
 
       /* Try the whole thing again.  */
     retry:
-      SERIAL_WRITE (remote_desc, "-", 1);
+      serial_write (remote_desc, "-", 1);
     }
 
   /* We have tried hard enough, and just can't receive the packet.  Give up. */
 
   printf_unfiltered ("Ignoring packet error, continuing...\n");
-  SERIAL_WRITE (remote_desc, "+", 1);
+  serial_write (remote_desc, "+", 1);
   return 1;
 }
 \f
@@ -4287,7 +4351,7 @@ remote_async_kill (void)
 {
   /* Unregister the file descriptor from the event loop. */
   if (target_is_async_p ())
-    SERIAL_ASYNC (remote_desc, NULL, 0);
+    serial_async (remote_desc, NULL, 0);
 
   /* For some mysterious reason, wait_for_inferior calls kill instead of
      mourn after it gets TARGET_WAITKIND_SIGNALLED.  Work around it.  */
@@ -5163,8 +5227,8 @@ Specify the serial device it is connected to\n\
   remote_ops.to_mourn_inferior = remote_mourn;
   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_extra_thread_info = remote_threads_extra_info;
   remote_ops.to_stop = remote_stop;
   remote_ops.to_query = remote_query;
   remote_ops.to_rcmd = remote_rcmd;
@@ -5255,7 +5319,7 @@ device is attached to the remote system (e.g. host:port).");
 
   unpush_target (&remote_cisco_ops);
 
-  remote_desc = SERIAL_OPEN (name);
+  remote_desc = serial_open (name);
   if (!remote_desc)
     perror_with_name (name);
 
@@ -5266,17 +5330,17 @@ device is attached to the remote system (e.g. host:port).");
    */
 
   baud_rate = (baud_rate > 0) ? baud_rate : 9600;
-  if (SERIAL_SETBAUDRATE (remote_desc, baud_rate))
+  if (serial_setbaudrate (remote_desc, baud_rate))
     {
-      SERIAL_CLOSE (remote_desc);
+      serial_close (remote_desc);
       perror_with_name (name);
     }
 
-  SERIAL_RAW (remote_desc);
+  serial_raw (remote_desc);
 
   /* If there is something sitting in the buffer we might take it as a
      response to a command, which would be bad.  */
-  SERIAL_FLUSH_INPUT (remote_desc);
+  serial_flush_input (remote_desc);
 
   if (from_tty)
     {
@@ -5444,7 +5508,7 @@ readtty (void)
 
   /* Make this a zero terminated string and write it out */
   tty_input[tty_bytecount] = 0;
-  if (SERIAL_WRITE (remote_desc, tty_input, tty_bytecount))
+  if (serial_write (remote_desc, tty_input, tty_bytecount))
     {
       perror_with_name ("readtty: write failed");
       return FATAL_ERROR;
@@ -5490,7 +5554,7 @@ minitelnet (void)
 
       FD_ZERO (&input);
       FD_SET (fileno (stdin), &input);
-      FD_SET (DEPRECATED_SERIAL_FD (remote_desc), &input);
+      FD_SET (deprecated_serial_fd (remote_desc), &input);
 
       status = select (tablesize, &input, 0, 0, 0);
       if ((status == -1) && (errno != EINTR))
@@ -5514,9 +5578,9 @@ minitelnet (void)
          quit_flag = 0;
 
          if (remote_break)
-           SERIAL_SEND_BREAK (remote_desc);
+           serial_send_break (remote_desc);
          else
-           SERIAL_WRITE (remote_desc, "\003", 1);
+           serial_write (remote_desc, "\003", 1);
 
          continue;
        }
@@ -5572,7 +5636,8 @@ Specify the serial device it is connected to (e.g. host:2020).";
   remote_cisco_ops.to_mourn_inferior = remote_cisco_mourn;
   remote_cisco_ops.to_thread_alive = remote_thread_alive;
   remote_cisco_ops.to_find_new_threads = remote_threads_info;
-  remote_ops.to_extra_thread_info = remote_threads_extra_info;
+  remote_cisco_ops.to_pid_to_str = remote_pid_to_str;
+  remote_cisco_ops.to_extra_thread_info = remote_threads_extra_info;
   remote_cisco_ops.to_stratum = process_stratum;
   remote_cisco_ops.to_has_all_memory = 1;
   remote_cisco_ops.to_has_memory = 1;
@@ -5586,14 +5651,14 @@ static int
 remote_can_async_p (void)
 {
   /* We're async whenever the serial device is. */
-  return (current_target.to_async_mask_value) && SERIAL_CAN_ASYNC_P (remote_desc);
+  return (current_target.to_async_mask_value) && serial_can_async_p (remote_desc);
 }
 
 static int
 remote_is_async_p (void)
 {
   /* We're async whenever the serial device is. */
-  return (current_target.to_async_mask_value) && SERIAL_IS_ASYNC_P (remote_desc);
+  return (current_target.to_async_mask_value) && serial_is_async_p (remote_desc);
 }
 
 /* Pass the SERIAL event on and up to the client.  One day this code
@@ -5605,7 +5670,7 @@ static void *async_client_context;
 static serial_event_ftype remote_async_serial_handler;
 
 static void
-remote_async_serial_handler (serial_t scb, void *context)
+remote_async_serial_handler (struct serial *scb, void *context)
 {
   /* Don't propogate error information up to the client.  Instead let
      the client find out about the error by querying the target.  */
@@ -5621,12 +5686,12 @@ remote_async (void (*callback) (enum inferior_event_type event_type, void *conte
 
   if (callback != NULL)
     {
-      SERIAL_ASYNC (remote_desc, remote_async_serial_handler, NULL);
+      serial_async (remote_desc, remote_async_serial_handler, NULL);
       async_client_callback = callback;
       async_client_context = context;
     }
   else
-    SERIAL_ASYNC (remote_desc, NULL, NULL);
+    serial_async (remote_desc, NULL, NULL);
 }
 
 /* Target async and target extended-async.
@@ -5662,7 +5727,8 @@ Specify the serial device it is connected to (e.g. /dev/ttya).";
   remote_async_ops.to_mourn_inferior = remote_async_mourn;
   remote_async_ops.to_thread_alive = remote_thread_alive;
   remote_async_ops.to_find_new_threads = remote_threads_info;
-  remote_ops.to_extra_thread_info = remote_threads_extra_info;
+  remote_async_ops.to_pid_to_str = remote_pid_to_str;
+  remote_async_ops.to_extra_thread_info = remote_threads_extra_info;
   remote_async_ops.to_stop = remote_stop;
   remote_async_ops.to_query = remote_query;
   remote_async_ops.to_rcmd = remote_rcmd;
@@ -5702,7 +5768,6 @@ Specify the serial device it is connected to (e.g. /dev/ttya).",
 static void
 set_remote_cmd (char *args, int from_tty)
 {
-  
 }
 
 static void
@@ -5713,6 +5778,7 @@ show_remote_cmd (char *args, int 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);
 }
 
@@ -5726,6 +5792,23 @@ build_remote_gdbarch_data (void)
   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
 _initialize_remote (void)
 {
@@ -5756,6 +5839,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
@@ -5790,10 +5877,9 @@ terminating `#' character and checksum.",
           &maintenancelist);
 
   add_show_from_set
-    (add_set_cmd ("remotebreak", no_class,
-                 var_boolean, (char *) &remote_break,
-                 "Set whether to send break if interrupted.\n",
-                 &setlist),
+    (add_set_boolean_cmd ("remotebreak", no_class, &remote_break,
+                         "Set whether to send break if interrupted.\n",
+                         &setlist),
      &showlist);
 
   /* Install commands for configuring memory read/write packets. */
@@ -5856,6 +5942,13 @@ 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,
This page took 0.031329 seconds and 4 git commands to generate.