Don't call clear_quit_flag after check_quit_flag
[external/binutils.git] / gdb / remote.c
index b0303f6..443beac 100644 (file)
@@ -766,7 +766,6 @@ int
 remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
                                   int *pnum, int *poffset)
 {
-  int sizeof_g_packet;
   struct packet_reg *regs;
   struct cleanup *old_chain;
 
@@ -775,7 +774,7 @@ remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
   regs = XCNEWVEC (struct packet_reg, gdbarch_num_regs (gdbarch));
   old_chain = make_cleanup (xfree, regs);
 
-  sizeof_g_packet = map_regcache_remote_table (gdbarch, regs);
+  map_regcache_remote_table (gdbarch, regs);
 
   *pnum = regs[regnum].pnum;
   *poffset = regs[regnum].offset;
@@ -1802,7 +1801,7 @@ remote_add_inferior (int fake_pid_p, int pid, int attached,
    according to RUNNING.  */
 
 static void
-remote_add_thread (ptid_t ptid, int running)
+remote_add_thread (ptid_t ptid, int running, int executing)
 {
   struct remote_state *rs = get_remote_state ();
 
@@ -1817,7 +1816,7 @@ remote_add_thread (ptid_t ptid, int running)
   else
     add_thread (ptid);
 
-  set_executing (ptid, running);
+  set_executing (ptid, executing);
   set_running (ptid, running);
 }
 
@@ -1825,11 +1824,17 @@ remote_add_thread (ptid_t ptid, int running)
    It may be the first time we hear about such thread, so take the
    opportunity to add it to GDB's thread list.  In case this is the
    first time we're noticing its corresponding inferior, add it to
-   GDB's inferior list as well.  */
+   GDB's inferior list as well.  EXECUTING indicates whether the
+   thread is (internally) executing or stopped.  */
 
 static void
-remote_notice_new_inferior (ptid_t currthread, int running)
+remote_notice_new_inferior (ptid_t currthread, int executing)
 {
+  /* In non-stop mode, we assume new found threads are (externally)
+     running until proven otherwise with a stop reply.  In all-stop,
+     we can only get here if all threads are stopped.  */
+  int running = target_is_non_stop_p () ? 1 : 0;
+
   /* 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.  */
 
@@ -1837,7 +1842,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
     {
       /* We're seeing an event on a thread id we knew had exited.
         This has to be a new thread reusing the old id.  Add it.  */
-      remote_add_thread (currthread, running);
+      remote_add_thread (currthread, running, executing);
       return;
     }
 
@@ -1858,7 +1863,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
            thread_change_ptid (inferior_ptid, currthread);
          else
            {
-             remote_add_thread (currthread, running);
+             remote_add_thread (currthread, running, executing);
              inferior_ptid = currthread;
            }
          return;
@@ -1889,7 +1894,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
        }
 
       /* This is really a new thread.  Add it.  */
-      remote_add_thread (currthread, running);
+      remote_add_thread (currthread, running, executing);
 
       /* If we found a new inferior, let the common code do whatever
         it needs to with it (e.g., read shared libraries, insert
@@ -1900,7 +1905,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
          struct remote_state *rs = get_remote_state ();
 
          if (!rs->starting_up)
-           notice_new_inferior (currthread, running, 0);
+           notice_new_inferior (currthread, executing, 0);
        }
     }
 }
@@ -2202,9 +2207,6 @@ set_general_process (void)
 static int
 remote_thread_always_alive (struct target_ops *ops, ptid_t ptid)
 {
-  struct remote_state *rs = get_remote_state ();
-  char *p, *endp;
-
   if (ptid_equal (ptid, magic_null_ptid))
     /* The main thread is always alive.  */
     return 1;
@@ -3197,7 +3199,6 @@ remote_get_threads_with_qthreadinfo (struct target_ops *ops,
 static void
 remote_update_thread_list (struct target_ops *ops)
 {
-  struct remote_state *rs = get_remote_state ();
   struct threads_listing_context context;
   struct cleanup *old_chain;
   int got_list = 0;
@@ -3264,12 +3265,12 @@ remote_update_thread_list (struct target_ops *ops)
            {
              struct private_thread_info *info;
              /* In non-stop mode, we assume new found threads are
-                running until proven otherwise with a stop reply.  In
-                all-stop, we can only get here if all threads are
+                executing until proven otherwise with a stop reply.
+                In all-stop, we can only get here if all threads are
                 stopped.  */
-             int running = target_is_non_stop_p () ? 1 : 0;
+             int executing = target_is_non_stop_p () ? 1 : 0;
 
-             remote_notice_new_inferior (item->ptid, running);
+             remote_notice_new_inferior (item->ptid, executing);
 
              info = demand_private_info (item->ptid);
              info->core = item->core;
@@ -3953,8 +3954,6 @@ process_initial_stop_replies (int from_tty)
      that as current.  */
   ALL_NON_EXITED_THREADS (thread)
     {
-      struct target_waitstatus *ws;
-
       if (first == NULL)
        first = thread;
 
@@ -3963,8 +3962,6 @@ process_initial_stop_replies (int from_tty)
       else if (thread->state != THREAD_STOPPED)
        continue;
 
-      ws = &thread->suspend.waitstatus;
-
       if (selected == NULL
          && thread->suspend.waitstatus_pending_p)
        selected = thread;
@@ -4118,10 +4115,6 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 
   if (!target_is_non_stop_p ())
     {
-      ptid_t ptid;
-      int fake_pid_p = 0;
-      struct inferior *inf;
-
       if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
        {
          if (!extended_p)
@@ -4341,8 +4334,8 @@ remote_check_symbols (void)
 {
   struct remote_state *rs = get_remote_state ();
   char *msg, *reply, *tmp;
-  struct bound_minimal_symbol sym;
   int end;
+  long reply_size;
   struct cleanup *old_chain;
 
   /* The remote side has no concept of inferiors that aren't running
@@ -4364,13 +4357,15 @@ remote_check_symbols (void)
      because we need both at the same time.  */
   msg = (char *) xmalloc (get_remote_packet_size ());
   old_chain = make_cleanup (xfree, msg);
+  reply = (char *) xmalloc (get_remote_packet_size ());
+  make_cleanup (free_current_contents, &reply);
+  reply_size = get_remote_packet_size ();
 
   /* Invite target to request symbol lookups.  */
 
   putpkt ("qSymbol::");
-  getpkt (&rs->buf, &rs->buf_size, 0);
-  packet_ok (rs->buf, &remote_protocol_packets[PACKET_qSymbol]);
-  reply = rs->buf;
+  getpkt (&reply, &reply_size, 0);
+  packet_ok (reply, &remote_protocol_packets[PACKET_qSymbol]);
 
   while (startswith (reply, "qSymbol:"))
     {
@@ -4398,8 +4393,7 @@ remote_check_symbols (void)
        }
   
       putpkt (msg);
-      getpkt (&rs->buf, &rs->buf_size, 0);
-      reply = rs->buf;
+      getpkt (&reply, &reply_size, 0);
     }
 
   do_cleanups (old_chain);
@@ -6180,7 +6174,12 @@ remove_new_fork_children (struct threads_listing_context *context)
      fork child threads from the CONTEXT list.  */
   ALL_NON_EXITED_THREADS (thread)
     {
-      struct target_waitstatus *ws = &thread->pending_follow;
+      struct target_waitstatus *ws;
+
+      if (thread->suspend.waitstatus_pending_p)
+       ws = &thread->suspend.waitstatus;
+      else
+       ws = &thread->pending_follow;
 
       if (is_pending_fork_parent (ws, pid, thread->ptid))
        {
@@ -6224,7 +6223,6 @@ remove_stop_reply_for_inferior (QUEUE (stop_reply_p) *q,
 static void
 discard_pending_stop_replies (struct inferior *inf)
 {
-  int i;
   struct queue_iter_param param;
   struct stop_reply *reply;
   struct remote_state *rs = get_remote_state ();
@@ -6387,16 +6385,6 @@ peek_stop_reply (ptid_t ptid)
                         stop_reply_match_ptid_and_ws, &ptid);
 }
 
-/* Skip PACKET until the next semi-colon (or end of string).  */
-
-static char *
-skip_to_semicolon (char *p)
-{
-  while (*p != '\0' && *p != ';')
-    p++;
-  return p;
-}
-
 /* Helper for remote_parse_stop_reply.  Return nonzero if the substring
    starting with P and ending with PEND matches PREFIX.  */
 
@@ -6499,7 +6487,7 @@ Packet: '%s'\n"),
              /* The value part is documented as "must be empty",
                 though we ignore it, in case we ever decide to make
                 use of it in a backward compatible way.  */
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else if (strprefix (p, p1, "hwbreak"))
            {
@@ -6511,19 +6499,19 @@ Packet: '%s'\n"),
                error (_("Unexpected hwbreak stop reason"));
 
              /* See above.  */
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else if (strprefix (p, p1, "library"))
            {
              event->ws.kind = TARGET_WAITKIND_LOADED;
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else if (strprefix (p, p1, "replaylog"))
            {
              event->ws.kind = TARGET_WAITKIND_NO_HISTORY;
              /* p1 will indicate "begin" or "end", but it makes
                 no difference for now, so ignore it.  */
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else if (strprefix (p, p1, "core"))
            {
@@ -6545,7 +6533,7 @@ Packet: '%s'\n"),
          else if (strprefix (p, p1, "vforkdone"))
            {
              event->ws.kind = TARGET_WAITKIND_VFORK_DONE;
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else if (strprefix (p, p1, "exec"))
            {
@@ -6574,7 +6562,7 @@ Packet: '%s'\n"),
          else if (strprefix (p, p1, "create"))
            {
              event->ws.kind = TARGET_WAITKIND_THREAD_CREATED;
-             p = skip_to_semicolon (p1 + 1);
+             p = strchrnul (p1 + 1, ';');
            }
          else
            {
@@ -6583,7 +6571,7 @@ Packet: '%s'\n"),
 
              if (skipregs)
                {
-                 p = skip_to_semicolon (p1 + 1);
+                 p = strchrnul (p1 + 1, ';');
                  p++;
                  continue;
                }
@@ -6620,7 +6608,7 @@ Packet: '%s'\n"),
                {
                  /* Not a number.  Silently skip unknown optional
                     info.  */
-                 p = skip_to_semicolon (p1 + 1);
+                 p = strchrnul (p1 + 1, ';');
                }
            }
 
@@ -6821,7 +6809,6 @@ process_stop_reply (struct stop_reply *stop_reply,
       && status->kind != TARGET_WAITKIND_SIGNALLED
       && status->kind != TARGET_WAITKIND_NO_RESUMED)
     {
-      struct remote_state *rs = get_remote_state ();
       struct private_thread_info *remote_thr;
 
       /* Expedited registers.  */
@@ -6950,10 +6937,7 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
          /* If the user hit C-c before this packet, or between packets,
             pretend that it was hit right here.  */
          if (check_quit_flag ())
-           {
-             clear_quit_flag ();
-             sync_remote_interrupt (SIGINT);
-           }
+           sync_remote_interrupt (SIGINT);
        }
 
       /* FIXME: cagney/1999-09-27: If we're in async mode we should
@@ -6994,8 +6978,16 @@ remote_wait_as (ptid_t ptid, struct target_waitstatus *status, int options)
       status->value.sig = GDB_SIGNAL_0;
       break;
     case 'F':          /* File-I/O request.  */
+      /* GDB may access the inferior memory while handling the File-I/O
+        request, but we don't want GDB accessing memory while waiting
+        for a stop reply.  See the comments in putpkt_binary.  Set
+        waiting_for_stop_reply to 0 temporarily.  */
+      rs->waiting_for_stop_reply = 0;
       remote_fileio_request (buf, rs->ctrlc_pending_p);
       rs->ctrlc_pending_p = 0;
+      /* GDB handled the File-I/O request, and the target is running
+        again.  Keep waiting for events.  */
+      rs->waiting_for_stop_reply = 1;
       break;
     case 'N': case 'T': case 'S': case 'X': case 'W':
       {
@@ -8291,7 +8283,6 @@ putpkt_binary (const char *buf, int cnt)
   int ch;
   int tcount = 0;
   char *p;
-  char *message;
 
   /* Catch cases like trying to read memory or listing threads while
      we're waiting for a stop reply.  The remote server wouldn't be
@@ -8671,9 +8662,7 @@ getpkt (char **buf,
        long *sizeof_buf,
        int forever)
 {
-  int timed_out;
-
-  timed_out = getpkt_sane (buf, sizeof_buf, forever);
+  getpkt_sane (buf, sizeof_buf, forever);
 }
 
 
@@ -9236,8 +9225,6 @@ remote_add_target_side_condition (struct gdbarch *gdbarch,
 {
   struct agent_expr *aexpr = NULL;
   int i, ix;
-  char *pkt;
-  char *buf_start = buf;
 
   if (VEC_empty (agent_expr_p, bp_tgt->conditions))
     return 0;
@@ -9309,7 +9296,6 @@ remote_insert_breakpoint (struct target_ops *ops,
       struct remote_state *rs;
       char *p, *endbuf;
       int bpsize;
-      struct condition_list *cond = NULL;
 
       /* Make sure the remote is pointing at the right process, if
         necessary.  */
@@ -9564,8 +9550,6 @@ remote_stopped_by_sw_breakpoint (struct target_ops *ops)
 static int
 remote_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
 {
-  struct remote_state *rs = get_remote_state ();
-
   return (packet_support (PACKET_swbreak_feature) == PACKET_ENABLE);
 }
 
@@ -9586,8 +9570,6 @@ remote_stopped_by_hw_breakpoint (struct target_ops *ops)
 static int
 remote_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
 {
-  struct remote_state *rs = get_remote_state ();
-
   return (packet_support (PACKET_hwbreak_feature) == PACKET_ENABLE);
 }
 
@@ -10053,8 +10035,6 @@ remote_xfer_partial (struct target_ops *ops, enum target_object object,
   /* Only handle flash writes.  */
   if (writebuf != NULL)
     {
-      LONGEST xfered;
-
       switch (object)
        {
        case TARGET_OBJECT_FLASH:
@@ -12922,7 +12902,6 @@ remote_read_btrace (struct target_ops *self,
                    enum btrace_read_type type)
 {
   struct packet_config *packet = &remote_protocol_packets[PACKET_qXfer_btrace];
-  struct remote_state *rs = get_remote_state ();
   struct cleanup *cleanup;
   const char *annex;
   char *xml;
@@ -13249,8 +13228,6 @@ static serial_event_ftype remote_async_serial_handler;
 static void
 remote_async_serial_handler (struct serial *scb, void *context)
 {
-  struct remote_state *rs = (struct remote_state *) context;
-
   /* Don't propogate error information up to the client.  Instead let
      the client find out about the error by querying the target.  */
   inferior_event_handler (INF_REG_EVENT, NULL);
@@ -13302,7 +13279,6 @@ remote_thread_events (struct target_ops *ops, int enable)
 {
   struct remote_state *rs = get_remote_state ();
   size_t size = get_remote_packet_size ();
-  char *p = rs->buf;
 
   if (packet_support (PACKET_QThreadEvents) == PACKET_DISABLE)
     return;
@@ -13468,7 +13444,6 @@ set_range_stepping (char *ignore_args, int from_tty,
 void
 _initialize_remote (void)
 {
-  struct remote_state *rs;
   struct cmd_list_element *cmd;
   const char *cmd_name;