doc/ChangeLog:
[deliverable/binutils-gdb.git] / gdb / remote.c
index c229bffab22d0125e4bdfc106757224eead3f2fe..152ab66ab9dcaacd31862dc074a73e82189d2342 100644 (file)
@@ -89,9 +89,9 @@ static void build_remote_gdbarch_data (void);
 
 static void remote_files_info (struct target_ops *ignore);
 
-static void remote_prepare_to_store (void);
+static void remote_prepare_to_store (struct regcache *regcache);
 
-static void remote_fetch_registers (int regno);
+static void remote_fetch_registers (struct regcache *regcache, int regno);
 
 static void remote_resume (ptid_t ptid, int step,
                            enum target_signal siggnal);
@@ -108,7 +108,7 @@ static void remote_open_1 (char *, int, struct target_ops *, int extended_p,
 
 static void remote_close (int quitting);
 
-static void remote_store_registers (int regno);
+static void remote_store_registers (struct regcache *regcache, int regno);
 
 static void remote_mourn (void);
 static void remote_async_mourn (void);
@@ -334,12 +334,19 @@ init_remote_state (struct gdbarch *gdbarch)
 
   rsa = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct remote_arch_state);
 
-  /* Assume a 1:1 regnum<->pnum table.  */
+  /* Use the architecture to build a regnum<->pnum table, which will be
+     1:1 unless a feature set specifies otherwise.  */
   rsa->regs = GDBARCH_OBSTACK_CALLOC (gdbarch, NUM_REGS, struct packet_reg);
   for (regnum = 0; regnum < NUM_REGS; regnum++)
     {
       struct packet_reg *r = &rsa->regs[regnum];
-      r->pnum = regnum;
+
+      if (register_size (current_gdbarch, regnum) == 0)
+       /* Do not try to fetch zero-sized (placeholder) registers.  */
+       r->pnum = -1;
+      else
+       r->pnum = gdbarch_remote_register_number (gdbarch, regnum);
+
       r->regnum = regnum;
     }
 
@@ -893,6 +900,7 @@ enum {
   PACKET_Z3,
   PACKET_Z4,
   PACKET_qXfer_auxv,
+  PACKET_qXfer_features,
   PACKET_qXfer_memory_map,
   PACKET_qGetTLSAddr,
   PACKET_qSupported,
@@ -2294,6 +2302,8 @@ static struct protocol_feature remote_protocol_features[] = {
   { "PacketSize", PACKET_DISABLE, remote_packet_size, -1 },
   { "qXfer:auxv:read", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_auxv },
+  { "qXfer:features:read", PACKET_DISABLE, remote_supported_packet,
+    PACKET_qXfer_features },
   { "qXfer:memory-map:read", PACKET_DISABLE, remote_supported_packet,
     PACKET_qXfer_memory_map },
   { "QPassSignals", PACKET_DISABLE, remote_supported_packet,
@@ -2590,7 +2600,11 @@ remote_detach (char *args, int from_tty)
 
   /* Tell the remote target to detach.  */
   strcpy (rs->buf, "D");
-  remote_send (&rs->buf, &rs->buf_size);
+  putpkt (rs->buf);
+  getpkt (&rs->buf, &rs->buf_size, 0);
+
+  if (rs->buf[0] == 'E')
+    error (_("Can't detach process."));
 
   /* Unregister the file descriptor from the event loop.  */
   if (target_is_async_p ())
@@ -3476,7 +3490,7 @@ got_status:
 /* Fetch a single register using a 'p' packet.  */
 
 static int
-fetch_register_using_p (struct packet_reg *reg)
+fetch_register_using_p (struct regcache *regcache, struct packet_reg *reg)
 {
   struct remote_state *rs = get_remote_state ();
   char *buf, *p;
@@ -3511,8 +3525,7 @@ fetch_register_using_p (struct packet_reg *reg)
   /* If this register is unfetchable, tell the regcache.  */
   if (buf[0] == 'x')
     {
-      regcache_raw_supply (current_regcache, reg->regnum, NULL);
-      set_register_cached (reg->regnum, -1);
+      regcache_raw_supply (regcache, reg->regnum, NULL);
       return 1;
     }
 
@@ -3527,7 +3540,7 @@ fetch_register_using_p (struct packet_reg *reg)
       regp[i++] = fromhex (p[0]) * 16 + fromhex (p[1]);
       p += 2;
     }
-  regcache_raw_supply (current_regcache, reg->regnum, regp);
+  regcache_raw_supply (regcache, reg->regnum, regp);
   return 1;
 }
 
@@ -3568,7 +3581,7 @@ send_g_packet (void)
 }
 
 static void
-process_g_packet (void)
+process_g_packet (struct regcache *regcache)
 {
   struct remote_state *rs = get_remote_state ();
   struct remote_arch_state *rsa = get_remote_arch_state ();
@@ -3650,11 +3663,10 @@ process_g_packet (void)
                gdb_assert (r->offset * 2 < strlen (rs->buf));
                /* The register isn't available, mark it as such (at
                    the same time setting the value to zero).  */
-               regcache_raw_supply (current_regcache, r->regnum, NULL);
-               set_register_cached (i, -1);
+               regcache_raw_supply (regcache, r->regnum, NULL);
              }
            else
-             regcache_raw_supply (current_regcache, r->regnum,
+             regcache_raw_supply (regcache, r->regnum,
                                   regs + r->offset);
          }
       }
@@ -3662,14 +3674,14 @@ process_g_packet (void)
 }
 
 static void
-fetch_registers_using_g (void)
+fetch_registers_using_g (struct regcache *regcache)
 {
   send_g_packet ();
-  process_g_packet ();
+  process_g_packet (regcache);
 }
 
 static void
-remote_fetch_registers (int regnum)
+remote_fetch_registers (struct regcache *regcache, int regnum)
 {
   struct remote_state *rs = get_remote_state ();
   struct remote_arch_state *rsa = get_remote_arch_state ();
@@ -3688,30 +3700,28 @@ remote_fetch_registers (int regnum)
         contents, so fall back to 'p'.  */
       if (reg->in_g_packet)
        {
-         fetch_registers_using_g ();
+         fetch_registers_using_g (regcache);
          if (reg->in_g_packet)
            return;
        }
 
-      if (fetch_register_using_p (reg))
+      if (fetch_register_using_p (regcache, reg))
        return;
 
       /* This register is not available.  */
-      regcache_raw_supply (current_regcache, reg->regnum, NULL);
-      set_register_cached (reg->regnum, -1);
+      regcache_raw_supply (regcache, reg->regnum, NULL);
 
       return;
     }
 
-  fetch_registers_using_g ();
+  fetch_registers_using_g (regcache);
 
   for (i = 0; i < NUM_REGS; i++)
     if (!rsa->regs[i].in_g_packet)
-      if (!fetch_register_using_p (&rsa->regs[i]))
+      if (!fetch_register_using_p (regcache, &rsa->regs[i]))
        {
          /* This register is not available.  */
-         regcache_raw_supply (current_regcache, i, NULL);
-         set_register_cached (i, -1);
+         regcache_raw_supply (regcache, i, NULL);
        }
 }
 
@@ -3720,7 +3730,7 @@ remote_fetch_registers (int regnum)
    first.  */
 
 static void
-remote_prepare_to_store (void)
+remote_prepare_to_store (struct regcache *regcache)
 {
   struct remote_arch_state *rsa = get_remote_arch_state ();
   int i;
@@ -3734,7 +3744,7 @@ remote_prepare_to_store (void)
       /* Make sure all the necessary registers are cached.  */
       for (i = 0; i < NUM_REGS; i++)
        if (rsa->regs[i].in_g_packet)
-         regcache_raw_read (current_regcache, rsa->regs[i].regnum, buf);
+         regcache_raw_read (regcache, rsa->regs[i].regnum, buf);
       break;
     case PACKET_ENABLE:
       break;
@@ -3745,7 +3755,7 @@ remote_prepare_to_store (void)
    packet was not recognized.  */
 
 static int
-store_register_using_P (struct packet_reg *reg)
+store_register_using_P (const struct regcache *regcache, struct packet_reg *reg)
 {
   struct remote_state *rs = get_remote_state ();
   struct remote_arch_state *rsa = get_remote_arch_state ();
@@ -3762,7 +3772,7 @@ store_register_using_P (struct packet_reg *reg)
 
   xsnprintf (buf, get_remote_packet_size (), "P%s=", phex_nz (reg->pnum, 0));
   p = buf + strlen (buf);
-  regcache_raw_collect (current_regcache, reg->regnum, regp);
+  regcache_raw_collect (regcache, reg->regnum, regp);
   bin2hex (regp, p, register_size (current_gdbarch, reg->regnum));
   remote_send (&rs->buf, &rs->buf_size);
 
@@ -3784,7 +3794,7 @@ store_register_using_P (struct packet_reg *reg)
    contents of the register cache buffer.  FIXME: ignores errors.  */
 
 static void
-store_registers_using_G (void)
+store_registers_using_G (const struct regcache *regcache)
 {
   struct remote_state *rs = get_remote_state ();
   struct remote_arch_state *rsa = get_remote_arch_state ();
@@ -3801,7 +3811,7 @@ store_registers_using_G (void)
       {
        struct packet_reg *r = &rsa->regs[i];
        if (r->in_g_packet)
-         regcache_raw_collect (current_regcache, r->regnum, regs + r->offset);
+         regcache_raw_collect (regcache, r->regnum, regs + r->offset);
       }
   }
 
@@ -3819,7 +3829,7 @@ store_registers_using_G (void)
    of the register cache buffer.  FIXME: ignores errors.  */
 
 static void
-remote_store_registers (int regnum)
+remote_store_registers (struct regcache *regcache, int regnum)
 {
   struct remote_state *rs = get_remote_state ();
   struct remote_arch_state *rsa = get_remote_arch_state ();
@@ -3836,7 +3846,7 @@ remote_store_registers (int regnum)
         possible; we often change only a small number of registers.
         Sometimes we change a larger number; we'd need help from a
         higher layer to know to use 'G'.  */
-      if (store_register_using_P (reg))
+      if (store_register_using_P (regcache, reg))
        return;
 
       /* For now, don't complain if we have no way to write the
@@ -3846,15 +3856,15 @@ remote_store_registers (int regnum)
       if (!reg->in_g_packet)
        return;
 
-      store_registers_using_G ();
+      store_registers_using_G (regcache);
       return;
     }
 
-  store_registers_using_G ();
+  store_registers_using_G (regcache);
 
   for (i = 0; i < NUM_REGS; i++)
     if (!rsa->regs[i].in_g_packet)
-      if (!store_register_using_P (&rsa->regs[i]))
+      if (!store_register_using_P (regcache, &rsa->regs[i]))
        /* See above for why we do not issue an error here.  */
        continue;
 }
@@ -4098,12 +4108,6 @@ remote_write_bytes_aux (const char *header, CORE_ADDR memaddr,
     internal_error (__FILE__, __LINE__,
                    "remote_write_bytes_aux: bad packet format");
 
-  /* Should this be the selected frame?  */
-  gdbarch_remote_translate_xfer_address (current_gdbarch,
-                                        current_regcache,
-                                        memaddr, len,
-                                        &memaddr, &len);
-
   if (len <= 0)
     return 0;
 
@@ -4296,12 +4300,6 @@ remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
   int max_buf_size;            /* Max size of packet output buffer.  */
   int origlen;
 
-  /* Should this be the selected frame?  */
-  gdbarch_remote_translate_xfer_address (current_gdbarch,
-                                        current_regcache,
-                                        memaddr, len,
-                                        &memaddr, &len);
-
   if (len <= 0)
     return 0;
 
@@ -5098,35 +5096,6 @@ extended_remote_async_create_inferior (char *exec_file, char *args,
 }
 \f
 
-/* On some machines, e.g. 68k, we may use a different breakpoint
-   instruction than other targets; in those use
-   DEPRECATED_REMOTE_BREAKPOINT instead of just BREAKPOINT_FROM_PC.
-   Also, bi-endian targets may define
-   DEPRECATED_LITTLE_REMOTE_BREAKPOINT and
-   DEPRECATED_BIG_REMOTE_BREAKPOINT.  If none of these are defined, we
-   just call the standard routines that are in mem-break.c.  */
-
-/* NOTE: cagney/2003-06-08: This is silly.  A remote and simulator
-   target should use an identical BREAKPOINT_FROM_PC.  As for native,
-   the ARCH-OS-tdep.c code can override the default.  */
-
-#if defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && defined (DEPRECATED_BIG_REMOTE_BREAKPOINT) && !defined(DEPRECATED_REMOTE_BREAKPOINT)
-#define DEPRECATED_REMOTE_BREAKPOINT
-#endif
-
-#ifdef DEPRECATED_REMOTE_BREAKPOINT
-
-/* If the target isn't bi-endian, just pretend it is.  */
-#if !defined (DEPRECATED_LITTLE_REMOTE_BREAKPOINT) && !defined (DEPRECATED_BIG_REMOTE_BREAKPOINT)
-#define DEPRECATED_LITTLE_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
-#define DEPRECATED_BIG_REMOTE_BREAKPOINT DEPRECATED_REMOTE_BREAKPOINT
-#endif
-
-static unsigned char big_break_insn[] = DEPRECATED_BIG_REMOTE_BREAKPOINT;
-static unsigned char little_break_insn[] = DEPRECATED_LITTLE_REMOTE_BREAKPOINT;
-
-#endif /* DEPRECATED_REMOTE_BREAKPOINT */
-
 /* Insert a breakpoint.  On targets that have software breakpoint
    support, we ask the remote target to do the work; on targets
    which don't, we insert a traditional memory breakpoint.  */
@@ -5136,9 +5105,6 @@ remote_insert_breakpoint (struct bp_target_info *bp_tgt)
 {
   CORE_ADDR addr = bp_tgt->placed_address;
   struct remote_state *rs = get_remote_state ();
-#ifdef DEPRECATED_REMOTE_BREAKPOINT
-  int val;
-#endif
 
   /* Try the "Z" s/w breakpoint packet if it is not already disabled.
      If it succeeds, then set the support to PACKET_ENABLE.  If it
@@ -5171,24 +5137,7 @@ remote_insert_breakpoint (struct bp_target_info *bp_tgt)
        }
     }
 
-#ifdef DEPRECATED_REMOTE_BREAKPOINT
-  bp_tgt->placed_size = bp_tgt->shadow_len = sizeof big_break_insn;
-  val = target_read_memory (addr, bp_tgt->shadow_contents, bp_tgt->shadow_len);
-
-  if (val == 0)
-    {
-      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-       val = target_write_memory (addr, (char *) big_break_insn,
-                                  sizeof big_break_insn);
-      else
-       val = target_write_memory (addr, (char *) little_break_insn,
-                                  sizeof little_break_insn);
-    }
-
-  return val;
-#else
   return memory_insert_breakpoint (bp_tgt);
-#endif /* DEPRECATED_REMOTE_BREAKPOINT */
 }
 
 static int
@@ -5216,12 +5165,7 @@ remote_remove_breakpoint (struct bp_target_info *bp_tgt)
       return (rs->buf[0] == 'E');
     }
 
-#ifdef DEPRECATED_REMOTE_BREAKPOINT
-  return target_write_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
-                             bp_tgt->shadow_len);
-#else
   return memory_remove_breakpoint (bp_tgt);
-#endif /* DEPRECATED_REMOTE_BREAKPOINT */
 }
 
 static int
@@ -5716,6 +5660,11 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
       return remote_read_qxfer (ops, "auxv", annex, readbuf, offset, len,
                                &remote_protocol_packets[PACKET_qXfer_auxv]);
 
+    case TARGET_OBJECT_AVAILABLE_FEATURES:
+      return remote_read_qxfer
+       (ops, "features", annex, readbuf, offset, len,
+        &remote_protocol_packets[PACKET_qXfer_features]);
+
     case TARGET_OBJECT_MEMORY_MAP:
       gdb_assert (annex == NULL);
       return remote_read_qxfer (ops, "memory-map", annex, readbuf, offset, len,
@@ -6401,20 +6350,12 @@ 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)
-    remote_new_objfile_chain (objfile);
+    remote_check_symbols (objfile);
 }
 
 void
@@ -6454,8 +6395,7 @@ _initialize_remote (void)
   add_target (&extended_async_remote_ops);
 
   /* Hook into new objfile notification.  */
-  remote_new_objfile_chain = deprecated_target_new_objfile_hook;
-  deprecated_target_new_objfile_hook  = remote_new_objfile;
+  observer_attach_new_objfile (remote_new_objfile);
 
 #if 0
   init_remote_threadtests ();
@@ -6589,6 +6529,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_auxv],
                         "qXfer:auxv:read", "read-aux-vector", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_features],
+                        "qXfer:features:read", "target-features", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_qXfer_memory_map],
                         "qXfer:memory-map:read", "memory-map", 0);
 
This page took 0.03045 seconds and 4 git commands to generate.