* defs.h (error): Add printf format attribute.
[deliverable/binutils-gdb.git] / gdb / remote.c
index bd8e68e7c6efc72d154baad8b45443362f21c9f5..89bed2c3b184eeb47592d909c68533e8445fd820 100644 (file)
@@ -1,6 +1,7 @@
 /* Remote target communications for serial-line targets in custom GDB protocol
-   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-   1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+
+   Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
+   1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -222,6 +223,7 @@ struct packet_reg
   long offset; /* Offset into G packet.  */
   long regnum; /* GDB's internal register number.  */
   LONGEST pnum; /* Remote protocol register number.  */
+  int in_g_packet; /* Always part of G packet.  */
   /* long size in bytes;  == REGISTER_RAW_SIZE (regnum); at present.  */
   /* char *name; == REGISTER_NAME (regnum); at present.  */
 };
@@ -230,7 +232,10 @@ struct remote_state
 {
   /* Description of the remote protocol registers.  */
   long sizeof_g_packet;
-  struct packet_reg *g_packet; /* NULL terminated.  */
+
+  /* Description of the remote protocol registers indexed by REGNUM
+     (making an array of NUM_REGS + NUM_PSEUDO_REGS in size).  */
+  struct packet_reg *regs;
 
   /* This is the size (in chars) of the first response to the ``g''
      packet.  It is used as a heuristic when determining the maximum
@@ -264,16 +269,15 @@ init_remote_state (struct gdbarch *gdbarch)
      behavour - just copy in the description of the register cache.  */
   rs->sizeof_g_packet = REGISTER_BYTES; /* OK use.   */
 
-  /* Since, for the moment, the regcache is still being direct mapped,
-     there are exactly NUM_REGS.  Zero allocate a buffer adding space
-     for a sentinal.  */
-  rs->g_packet = xcalloc (NUM_REGS + 1, sizeof (struct packet_reg));
-  rs->g_packet[NUM_REGS].offset = -1;
-  for (regnum = 0; regnum < NUM_REGS; regnum++)
+  /* Assume a 1:1 regnum<->pnum table.  */
+  rs->regs = xcalloc (NUM_REGS + NUM_PSEUDO_REGS, sizeof (struct packet_reg));
+  for (regnum = 0; regnum < NUM_REGS + NUM_PSEUDO_REGS; regnum++)
     {
-      rs->g_packet[regnum].pnum = regnum;
-      rs->g_packet[regnum].regnum = regnum;
-      rs->g_packet[regnum].offset = REGISTER_BYTE (regnum);
+      struct packet_reg *r = &rs->regs[regnum];
+      r->pnum = regnum;
+      r->regnum = regnum;
+      r->offset = REGISTER_BYTE (regnum);
+      r->in_g_packet = (regnum < NUM_REGS);
       /* ...size = REGISTER_RAW_SIZE (regnum); */
       /* ...name = REGISTER_NAME (regnum); */
     }
@@ -306,30 +310,32 @@ static void
 free_remote_state (struct gdbarch *gdbarch, void *pointer)
 {
   struct remote_state *data = pointer;
-  xfree (data->g_packet);
+  xfree (data->regs);
   xfree (data);
 }
 
 static struct packet_reg *
 packet_reg_from_regnum (struct remote_state *rs, long regnum)
 {
-  struct packet_reg *reg;
-  for (reg = rs->g_packet; reg->offset >= 0; reg++)
+  if (regnum < 0 && regnum >= NUM_REGS + NUM_PSEUDO_REGS)
+    return NULL;
+  else
     {
-      if (reg->regnum == regnum)
-       return reg;
+      struct packet_reg *r = &rs->regs[regnum];
+      gdb_assert (r->regnum == regnum);
+      return r;
     }
-  return NULL;
 }
 
 static struct packet_reg *
 packet_reg_from_pnum (struct remote_state *rs, LONGEST pnum)
 {
-  struct packet_reg *reg;
-  for (reg = rs->g_packet; reg->offset >= 0; reg++)
+  int i;
+  for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
     {
-      if (reg->pnum == pnum)
-       return reg;
+      struct packet_reg *r = &rs->regs[i];
+      if (r->pnum == pnum)
+       return r;
     }
   return NULL;
 }
@@ -669,7 +675,7 @@ add_packet_config_cmd (struct packet_config *config,
   set_cmd = add_set_auto_boolean_cmd (cmd_name, class_obscure,
                                &config->detect, set_doc,
                                set_remote_list);
-  set_cmd->function.sfunc = set_func;
+  set_cmd_sfunc (set_cmd, set_func);
   show_cmd = add_cmd (cmd_name, class_obscure, show_func, show_doc,
                      show_remote_list);
   /* set/show remote NAME-packet {auto,on,off} -- legacy */
@@ -996,14 +1002,9 @@ record_currthread (int currthread)
   if (!in_thread_list (pid_to_ptid (currthread)))
     {
       add_thread (pid_to_ptid (currthread));
-#ifdef UI_OUT
       ui_out_text (uiout, "[New ");
       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 (pid_to_ptid (currthread)));
-#endif
     }
 }
 
@@ -2876,7 +2877,7 @@ interrupt_query (void)
 Give up (and stop debugging it)? "))
     {
       target_mourn_inferior ();
-      return_to_top_level (RETURN_QUIT);
+      throw_exception (RETURN_QUIT);
     }
 
   target_terminal_inferior ();
@@ -3406,6 +3407,16 @@ remote_fetch_registers (int regnum)
 
   set_thread (PIDGET (inferior_ptid), 1);
 
+  if (regnum >= 0)
+    {
+      struct packet_reg *reg = packet_reg_from_regnum (rs, regnum);
+      gdb_assert (reg != NULL);
+      if (!reg->in_g_packet)
+       internal_error (__FILE__, __LINE__,
+                       "Attempt to fetch a non G-packet register when this "
+                       "remote.c does not support the p-packet.");
+    }
+
   sprintf (buf, "g");
   remote_send (buf, (rs->remote_packet_size));
 
@@ -3462,14 +3473,18 @@ remote_fetch_registers (int regnum)
        warning ("Remote reply is too short: %s", buf);
     }
 
-supply_them:
+ supply_them:
   {
-    struct packet_reg *g;
-    for (g = rs->g_packet; g->offset >= 0; g++)
+    int i;
+    for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
       {
-       supply_register (g->regnum, regs + g->offset);
-       if (buf[g->offset * 2] == 'x')
-         set_register_cached (i, -1);
+       struct packet_reg *r = &rs->regs[i];
+       if (r->in_g_packet)
+         {
+           supply_register (r->regnum, regs + r->offset);
+           if (buf[r->offset * 2] == 'x')
+             set_register_cached (i, -1);
+         }
       }
   }
 }
@@ -3566,12 +3581,14 @@ remote_store_registers (int regnum)
   /* Extract all the registers in the regcache copying them into a
      local buffer.  */
   {
-    struct packet_reg *g;
+    int i;
     regs = alloca (rs->sizeof_g_packet);
     memset (regs, rs->sizeof_g_packet, 0);
-    for (g = rs->g_packet; g->offset >= 0; g++)
+    for (i = 0; i < NUM_REGS + NUM_PSEUDO_REGS; i++)
       {
-       regcache_collect (g->regnum, regs + g->offset);
+       struct packet_reg *r = &rs->regs[i];
+       if (r->in_g_packet)
+         regcache_collect (r->regnum, regs + r->offset);
       }
   }
 
@@ -3922,8 +3939,7 @@ remote_read_bytes (CORE_ADDR memaddr, char *myaddr, int len)
 /* ARGSUSED */
 static int
 remote_xfer_memory (CORE_ADDR mem_addr, char *buffer, int mem_len,
-                   int should_write,
-                   struct mem_attrib *attrib ATTRIBUTE_UNUSED,
+                   int should_write, struct mem_attrib *attrib,
                    struct target_ops *target)
 {
   CORE_ADDR targ_addr;
@@ -4660,7 +4676,7 @@ remote_insert_breakpoint (CORE_ADDR addr, char *contents_cache)
 
   if (val == 0)
     {
-      if (TARGET_BYTE_ORDER == BIG_ENDIAN)
+      if (TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
        val = target_write_memory (addr, (char *) big_break_insn,
                                   sizeof big_break_insn);
       else
@@ -4997,8 +5013,8 @@ compare_sections_command (char *args, int from_tty)
 
       getpkt (buf, (rs->remote_packet_size), 0);
       if (buf[0] == 'E')
-       error ("target memory fault, section %s, range 0x%08x -- 0x%08x",
-              sectname, lma, lma + size);
+       error ("target memory fault, section %s, range 0x%s -- 0x%s",
+              sectname, paddr (lma), paddr (lma + size));
       if (buf[0] != 'C')
        error ("remote target does not support this operation");
 
@@ -5701,7 +5717,7 @@ minitelnet (void)
              if (query ("Interrupt GDB? "))
                {
                  printf_filtered ("Interrupted by user.\n");
-                 return_to_top_level (RETURN_QUIT);
+                 throw_exception (RETURN_QUIT);
                }
              quit_count = 0;
            }
@@ -6083,6 +6099,10 @@ in a memory packet.\n",
                         show_remote_protocol_e_packet_cmd,
                         &remote_set_cmdlist, &remote_show_cmdlist,
                         0);
+  /* Disable by default.  The ``e'' packet has nasty interactions with
+     the threading code - it relies on global state.  */
+  remote_protocol_e.detect = CMD_AUTO_BOOLEAN_FALSE;
+  update_packet_config (&remote_protocol_e);
 
   add_packet_config_cmd (&remote_protocol_E,
                         "E", "step-over-range-w-signal",
@@ -6090,6 +6110,10 @@ in a memory packet.\n",
                         show_remote_protocol_E_packet_cmd,
                         &remote_set_cmdlist, &remote_show_cmdlist,
                         0);
+  /* Disable by default.  The ``e'' packet has nasty interactions with
+     the threading code - it relies on global state.  */
+  remote_protocol_E.detect = CMD_AUTO_BOOLEAN_FALSE;
+  update_packet_config (&remote_protocol_E);
 
   add_packet_config_cmd (&remote_protocol_P,
                         "P", "set-register",
@@ -6138,7 +6162,7 @@ in a memory packet.\n",
                                     &remote_Z_packet_detect,
                                     "\
 Set use of remote protocol `Z' packets", &remote_set_cmdlist);
-  tmpcmd->function.sfunc = set_remote_protocol_Z_packet_cmd;
+  set_cmd_sfunc (tmpcmd, set_remote_protocol_Z_packet_cmd);
   add_cmd ("Z-packet", class_obscure, show_remote_protocol_Z_packet_cmd,
           "Show use of remote protocol `Z' packets ",
           &remote_show_cmdlist);
This page took 0.027271 seconds and 4 git commands to generate.