*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / remote.c
index 4aa84692b880c5b2f037e94f643a553a2531dbce..a46b92fd7b73b3f07447c95ca83d15da44481d85 100644 (file)
@@ -136,9 +136,9 @@ static void get_offsets (void);
 
 static long read_frame (char *buf, long sizeof_buf);
 
-static int remote_insert_breakpoint (CORE_ADDR, char *);
+static int remote_insert_breakpoint (CORE_ADDR, bfd_byte *);
 
-static int remote_remove_breakpoint (CORE_ADDR, char *);
+static int remote_remove_breakpoint (CORE_ADDR, bfd_byte *);
 
 static int hexnumlen (ULONGEST num);
 
@@ -248,10 +248,7 @@ init_remote_state (struct gdbarch *gdbarch)
   int regnum;
   struct remote_state *rs = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_state);
 
-  if (deprecated_register_bytes () != 0)
-    rs->sizeof_g_packet = deprecated_register_bytes ();
-  else
-    rs->sizeof_g_packet = 0;
+  rs->sizeof_g_packet = 0;
 
   /* Assume a 1:1 regnum<->pnum table.  */
   rs->regs = GDBARCH_OBSTACK_CALLOC (gdbarch, NUM_REGS + NUM_PSEUDO_REGS,
@@ -266,8 +263,8 @@ init_remote_state (struct gdbarch *gdbarch)
       /* ...name = REGISTER_NAME (regnum); */
 
       /* Compute packet size by accumulating the size of all registers.  */
-      if (deprecated_register_bytes () == 0)
-        rs->sizeof_g_packet += register_size (current_gdbarch, regnum);
+      if (regnum < NUM_REGS)
+       rs->sizeof_g_packet += register_size (current_gdbarch, regnum);
     }
 
   /* Default maximum number of characters in a packet body. Many
@@ -640,13 +637,10 @@ add_packet_config_cmd (struct packet_config *config,
                       struct cmd_list_element **show_remote_list,
                       int legacy)
 {
-  struct cmd_list_element *set_cmd;
-  struct cmd_list_element *show_cmd;
   char *set_doc;
   char *show_doc;
-  char *help_doc;
-  char *print;
   char *cmd_name;
+
   config->name = name;
   config->title = title;
   config->detect = AUTO_BOOLEAN_AUTO;
@@ -655,8 +649,6 @@ add_packet_config_cmd (struct packet_config *config,
                        name, title);
   show_doc = xstrprintf ("Show current use of remote protocol `%s' (%s) packet",
                         name, title);
-  print = xstrprintf ("Current use of remote protocol `%s' (%s) is %%s",
-                     name, title);
   /* set/show TITLE-packet {auto,on,off} */
   cmd_name = xstrprintf ("%s-packet", title);
   add_setshow_auto_boolean_cmd (cmd_name, class_obscure,
@@ -972,6 +964,24 @@ show_remote_protocol_qPart_auxv_packet_cmd (struct ui_file *file, int from_tty,
   show_packet_config_cmd (&remote_protocol_qPart_auxv);
 }
 
+/* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */
+static struct packet_config remote_protocol_qGetTLSAddr;
+
+static void
+set_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty,
+                                 struct cmd_list_element *c)
+{
+  update_packet_config (&remote_protocol_qGetTLSAddr);
+}
+
+static void
+show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file *file, int from_tty,
+                                            struct cmd_list_element *c,
+                                            const char *value)
+{
+  show_packet_config_cmd (&remote_protocol_qGetTLSAddr);
+}
+
 static struct packet_config remote_protocol_p;
 
 static void
@@ -2100,6 +2110,7 @@ init_all_packet_configs (void)
      downloading.  */
   update_packet_config (&remote_protocol_binary_download);
   update_packet_config (&remote_protocol_qPart_auxv);
+  update_packet_config (&remote_protocol_qGetTLSAddr);
 }
 
 /* Symbol look-up.  */
@@ -2165,7 +2176,6 @@ static void
 remote_open_1 (char *name, int from_tty, struct target_ops *target,
               int extended_p, int async_p)
 {
-  struct exception ex;
   struct remote_state *rs = get_remote_state ();
   if (name == 0)
     error (_("To open a remote debug connection, you need to specify what\n"
@@ -2268,14 +2278,17 @@ remote_open_1 (char *name, int from_tty, struct target_ops *target,
      been fixed - the function set_cmd_context() makes it possible for
      all the ``target ....'' commands to share a common callback
      function.  See cli-dump.c.  */
-  ex = catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
-  if (ex.reason < 0)
-    {
-      pop_target ();
-      if (async_p)
-       wait_forever_enabled_p = 1;
-      throw_exception (ex);
-    }
+  {
+    struct gdb_exception ex
+      = catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
+    if (ex.reason < 0)
+      {
+       pop_target ();
+       if (async_p)
+         wait_forever_enabled_p = 1;
+       throw_exception (ex);
+      }
+  }
 
   if (async_p)
     wait_forever_enabled_p = 1;
@@ -2337,9 +2350,6 @@ remote_detach (char *args, int from_tty)
 static void
 remote_disconnect (char *args, int from_tty)
 {
-  struct remote_state *rs = get_remote_state ();
-  char *buf = alloca (rs->remote_packet_size);
-
   if (args)
     error (_("Argument given to \"detach\" when remotely debugging."));
 
@@ -2555,7 +2565,6 @@ remote_resume (ptid_t ptid, int step, enum target_signal siggnal)
   struct remote_state *rs = get_remote_state ();
   char *buf = alloca (rs->remote_packet_size);
   int pid = PIDGET (ptid);
-  char *p;
 
   last_sent_signal = siggnal;
   last_sent_step = step;
@@ -2856,7 +2865,6 @@ remote_wait (ptid_t ptid, struct target_waitstatus *status)
          continue;
        case 'T':               /* Status with PC, SP, FP, ...  */
          {
-           int i;
            char regs[MAX_REGISTER_SIZE];
 
            /* Expedited reply, containing Signal, {regno, reg} repeat.  */
@@ -3052,7 +3060,6 @@ remote_async_wait (ptid_t ptid, struct target_waitstatus *status)
          continue;
        case 'T':               /* Status with PC, SP, FP, ...  */
          {
-           int i;
            char regs[MAX_REGISTER_SIZE];
 
            /* Expedited reply, containing Signal, {regno, reg} repeat.  */
@@ -3430,7 +3437,6 @@ store_register_using_P (int regnum)
   char *buf = alloca (rs->remote_packet_size);
   char regp[MAX_REGISTER_SIZE];
   char *p;
-  int i;
 
   sprintf (buf, "P%s=", phex_nz (reg->pnum, 0));
   p = buf + strlen (buf);
@@ -3451,7 +3457,6 @@ remote_store_registers (int regnum)
   struct remote_state *rs = get_remote_state ();
   char *buf;
   char *regs;
-  int i;
   char *p;
 
   set_thread (PIDGET (inferior_ptid), 1);
@@ -4492,7 +4497,7 @@ static unsigned char little_break_insn[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT;
    of bytes returned by BREAKPOINT_FROM_PC.  */
 
 static int
-remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
+remote_insert_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
 {
   struct remote_state *rs = get_remote_state ();
 #ifdef DEPRECATED_REMOTE_BREAKPOINT
@@ -4552,7 +4557,7 @@ remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
 }
 
 static int
-remote_remove_breakpoint (CORE_ADDR addr, char *contents_cache)
+remote_remove_breakpoint (CORE_ADDR addr, bfd_byte *contents_cache)
 {
   struct remote_state *rs = get_remote_state ();
   int bp_size;
@@ -5084,7 +5089,6 @@ remote_rcmd (char *command,
             struct ui_file *outbuf)
 {
   struct remote_state *rs = get_remote_state ();
-  int i;
   char *buf = alloca (rs->remote_packet_size);
   char *p = buf;
 
@@ -5319,6 +5323,52 @@ remote_pid_to_str (ptid_t ptid)
   return buf;
 }
 
+/* Get the address of the thread local variable in OBJFILE which is
+   stored at OFFSET within the thread local storage for thread PTID.  */
+
+static CORE_ADDR
+remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset)
+{
+  if (remote_protocol_qGetTLSAddr.support != PACKET_DISABLE)
+    {
+      struct remote_state *rs = get_remote_state ();
+      char *buf = alloca (rs->remote_packet_size);
+      char *p = buf;
+      enum packet_result result;
+
+      strcpy (p, "qGetTLSAddr:");
+      p += strlen (p);
+      p += hexnumstr (p, PIDGET (ptid));
+      *p++ = ',';
+      p += hexnumstr (p, offset);
+      *p++ = ',';
+      p += hexnumstr (p, lm);
+      *p++ = '\0';
+
+      putpkt (buf);
+      getpkt (buf, rs->remote_packet_size, 0);
+      result = packet_ok (buf, &remote_protocol_qGetTLSAddr);
+      if (result == PACKET_OK)
+       {
+         ULONGEST result;
+
+         unpack_varlen_hex (buf, &result);
+         return result;
+       }
+      else if (result == PACKET_UNKNOWN)
+       throw_error (TLS_GENERIC_ERROR,
+                    _("Remote target doesn't support qGetTLSAddr packet"));
+      else
+       throw_error (TLS_GENERIC_ERROR,
+                    _("Remote target failed to process qGetTLSAddr request"));
+    }
+  else
+    throw_error (TLS_GENERIC_ERROR,
+                _("TLS not supported or disabled on this target"));
+  /* Not reached.  */
+  return 0;
+}
+
 static void
 init_remote_ops (void)
 {
@@ -5358,6 +5408,7 @@ Specify the serial device it is connected to\n\
   remote_ops.to_stop = remote_stop;
   remote_ops.to_xfer_partial = remote_xfer_partial;
   remote_ops.to_rcmd = remote_rcmd;
+  remote_ops.to_get_thread_local_address = remote_get_thread_local_address;
   remote_ops.to_stratum = process_stratum;
   remote_ops.to_has_all_memory = 1;
   remote_ops.to_has_memory = 1;
@@ -5533,6 +5584,7 @@ show_remote_cmd (char *args, int from_tty)
   show_remote_protocol_vcont_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
   show_remote_protocol_binary_download_cmd (gdb_stdout, from_tty, NULL, NULL);
   show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
+  show_remote_protocol_qGetTLSAddr_packet_cmd (gdb_stdout, from_tty, NULL, NULL);
 }
 
 static void
@@ -5563,7 +5615,6 @@ _initialize_remote (void)
 {
   static struct cmd_list_element *remote_set_cmdlist;
   static struct cmd_list_element *remote_show_cmdlist;
-  struct cmd_list_element *tmpcmd;
 
   /* architecture specific data */
   remote_gdbarch_data_handle = 
@@ -5763,6 +5814,13 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
                         &remote_set_cmdlist, &remote_show_cmdlist,
                         0);
 
+  add_packet_config_cmd (&remote_protocol_qGetTLSAddr,
+                        "qGetTLSAddr", "get-thread-local-storage-address",
+                        set_remote_protocol_qGetTLSAddr_packet_cmd,
+                        show_remote_protocol_qGetTLSAddr_packet_cmd,
+                        &remote_set_cmdlist, &remote_show_cmdlist,
+                        0);
+
   /* Keep the old ``set remote Z-packet ...'' working.  */
   add_setshow_auto_boolean_cmd ("Z-packet", class_obscure,
                                &remote_Z_packet_detect, _("\
This page took 0.02691 seconds and 4 git commands to generate.