]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/remote: avoid SIGINT after calling remote_target::stop
authorAndrew Burgess <aburgess@redhat.com>
Thu, 20 Oct 2022 14:17:06 +0000 (15:17 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 25 Jan 2023 15:48:58 +0000 (15:48 +0000)
Currently, if the remote target is not running in non-stop mode, then,
when GDB calls remote_target::stop, we end up sending an interrupt
packet \x03 to the remote target.

If the user interrupts the inferior from the GDB prompt (e.g. by
typing Ctrl-c), then GDB calls remote_target::interrupt, which also
ends up sending the interrupt packet.

The problem here is that both of these mechanisms end up sending the
interrupt packet, which means, when the target stops with a SIGINT,
and this is reported back to GDB, we have no choice but to report this
to the user as a SIGINT stop event.

Now maybe this is the correct thing to do, after all the target has
been stopped with SIGINT.  However, this leads to an unfortunate
change in behaviour.

When running in non-stop mode, and remote_target::stop is called, the
target will be stopped with a vCont packet, and this stop is then
reported back to GDB as GDB_SIGNAL_0, this will cause GDB to print a
message like:

  Program stopped.

Or:

  Thread NN "binary name" stopped.

In contrast, when non-stop mode is off, we get messages like:

  Program received SIGINT, Segmentation fault.

Or:

  Thread NN "binary name" received SIGINT, Segmentation fault.

In this commit I propose a mechanism where we can track that a stop
has been requested for a particular thread through
remote_target::stop, then, when the stop arrives, we can convert the
SIGINT to a GDB_SIGNAL_0.  With this done GDB will now display the
"stopped" based messages rather than the "received SIGINT" messages.

Two of the tests added in the previous commit exposed this issue.  In
the previous commit the tests looked for either of the above
patterns.  In this commit I've updated these tests to only look for
the "stopped" based messages.

gdb/remote.c
gdb/testsuite/gdb.base/infcall-timeout.exp
gdb/testsuite/gdb.threads/infcall-from-bp-cond-timeout.exp

index aaac434bc2b74c14af4a85178961d8156787e3ad..d4f69a88a1240fcee33abc1e51ceab5420b2a1bb 100644 (file)
@@ -1138,6 +1138,10 @@ struct remote_thread_info : public private_thread_info
   std::string name;
   int core = -1;
 
+  /* Only used when not in non-stop mode.  Set to true when a stop is
+     requested for the thread.  */
+  bool stop_requested = false;
+
   /* Thread handle, perhaps a pthread_t or thread_t value, stored as a
      sequence of bytes.  */
   gdb::byte_vector thread_handle;
@@ -7113,6 +7117,12 @@ remote_target::stop (ptid_t ptid)
       /* We don't currently have a way to transparently pause the
         remote target in all-stop mode.  Interrupt it instead.  */
       remote_interrupt_as ();
+
+      /* Record that this thread's stop is a result of GDB asking for the
+        stop, rather than the user asking for an interrupt.  We can use
+        this information to adjust the waitstatus when it arrives.  */
+      remote_thread_info *remote_thr = get_remote_thread_info (this, ptid);
+      remote_thr->stop_requested = true;
     }
 }
 
@@ -8096,9 +8106,16 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
          /* If the target works in non-stop mode, a stop-reply indicates that
             only this thread stopped.  */
          remote_thr->set_not_resumed ();
+         gdb_assert (!remote_thr->stop_requested);
        }
       else
        {
+         if (status->kind () == TARGET_WAITKIND_STOPPED
+             && status->sig () == GDB_SIGNAL_INT
+             && remote_thr->stop_requested)
+           status->set_stopped (GDB_SIGNAL_0);
+         remote_thr->stop_requested = false;
+
          /* If the target works in all-stop mode, a stop-reply indicates that
             all the target's threads stopped.  */
          for (thread_info *tp : all_non_exited_threads (this))
index a5b0111ed040374621712cd60d27d87fd8343357..bd6b2bfac3e6e8654306b0fc92d664057d2d307f 100644 (file)
@@ -45,16 +45,9 @@ proc_with_prefix run_test { target_async target_non_stop } {
 
     gdb_test_no_output "set direct-call-timeout 5"
 
-    # When non-stop mode is off we get slightly different output from GDB.
-    if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } {
-       set stopped_line_pattern "Program received signal SIGINT, Interrupt\\."
-    } else {
-       set stopped_line_pattern "Program stopped\\."
-    }
-
     gdb_test "print function_that_never_returns ()" \
        [multi_line \
-            $stopped_line_pattern \
+            "Program stopped\\." \
             ".*" \
             "The program being debugged timed out while in a function called from GDB\\." \
             "GDB remains in the frame where the timeout occurred\\." \
index 3341ff33f19106ae1096a4efb0f285ba1dfbee65..9ba38e6896a422527eb72b667f506e7020a87f66 100644 (file)
@@ -92,16 +92,9 @@ proc run_test { target_async target_non_stop other_thread_bp } {
                                 "get number for segfault breakpoint"]
     }
 
-    # When non-stop mode is off we get slightly different output from GDB.
-    if { [gdb_is_remote_or_extended_remote_target] && $target_non_stop == "off" } {
-       set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" received signal SIGINT, Interrupt\\."
-    } else {
-       set stopped_line_pattern "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\."
-    }
-
     gdb_test "continue" \
        [multi_line \
-            $stopped_line_pattern \
+            "Thread ${::decimal} \"\[^\r\n\"\]+\" stopped\\." \
             ".*" \
             "Error in testing condition for breakpoint ${bp_num}:" \
             "The program being debugged timed out while in a function called from GDB\\." \