+2015-06-29 Pedro Alves <palves@redhat.com>
+
+ PR threads/18127
+ * infcall.c (run_inferior_call): On infcall success, if the thread
+ was marked stopped before, reset it back to stopped.
+ * infrun.c (resume): Don't suppress the set_running calls when
+ doing an infcall.
+ (normal_stop): Only discard the finish_thread_state cleanup if the
+ infcall succeeded.
+
2015-06-29 Pierre Langlois <pierre.langlois@arm.com>
* MAINTAINERS (Write After Approval): Update my email address.
int saved_in_infcall = call_thread->control.in_infcall;
ptid_t call_thread_ptid = call_thread->ptid;
int saved_sync_execution = sync_execution;
+ int was_running = call_thread->state == THREAD_RUNNING;
/* Infcalls run synchronously, in the foreground. */
if (target_can_async_p ())
CALL_THREAD as it could be invalid if its thread has exited. */
call_thread = find_thread_ptid (call_thread_ptid);
+ /* If the infcall does NOT succeed, normal_stop will have already
+ finished the thread states. However, on success, normal_stop
+ defers here, so that we can set back the thread states to what
+ they were before the call. Note that we must also finish the
+ state of new threads that might have spawned while the call was
+ running. The main cases to handle are:
+
+ - "(gdb) print foo ()", or any other command that evaluates an
+ expression at the prompt. (The thread was marked stopped before.)
+
+ - "(gdb) break foo if return_false()" or similar cases where we
+ do an infcall while handling an event (while the thread is still
+ marked running). In this example, whether the condition
+ evaluates true and thus we'll present a user-visible stop is
+ decided elsewhere. */
+ if (!was_running
+ && ptid_equal (call_thread_ptid, inferior_ptid)
+ && stop_stack_dummy == STOP_STACK_DUMMY)
+ finish_thread_state (user_visible_resume_ptid (0));
+
enable_watchpoints_after_interactive_call_stop ();
/* Call breakpoint_auto_delete on the current contents of the bpstat
requests finish. The thread is not executing at this
point, and the call to set_executing will be made later.
But we need to call set_running here, since from the
- user/frontend's point of view, threads were set running.
- Unless we're calling an inferior function, as in that
- case we pretend the inferior doesn't run at all. */
- if (!tp->control.in_infcall)
- set_running (user_visible_resume_ptid (user_step), 1);
+ user/frontend's point of view, threads were set running. */
+ set_running (user_visible_resume_ptid (user_step), 1);
discard_cleanups (old_cleanups);
return;
}
/* Even if RESUME_PTID is a wildcard, and we end up resuming less
(e.g., we might need to step over a breakpoint), from the
user/frontend's point of view, all threads in RESUME_PTID are now
- running. Unless we're calling an inferior function, as in that
- case pretend we inferior doesn't run at all. */
- if (!tp->control.in_infcall)
- set_running (resume_ptid, 1);
+ running. */
+ set_running (resume_ptid, 1);
/* Maybe resume a single thread after all. */
if ((step || thread_has_single_step_breakpoints_set (tp))
if (has_stack_frames () && !stop_stack_dummy)
set_current_sal_from_frame (get_current_frame ());
- /* Let the user/frontend see the threads as stopped, but do nothing
- if the thread was running an infcall. We may be e.g., evaluating
- a breakpoint condition. In that case, the thread had state
- THREAD_RUNNING before the infcall, and shall remain set to
- running, all without informing the user/frontend about state
- transition changes. If this is actually a call command, then the
- thread was originally already stopped, so there's no state to
- finish either. */
- if (target_has_execution && inferior_thread ()->control.in_infcall)
+ /* Let the user/frontend see the threads as stopped, but defer to
+ call_function_by_hand if the thread finished an infcall
+ successfully. We may be e.g., evaluating a breakpoint condition.
+ In that case, the thread had state THREAD_RUNNING before the
+ infcall, and shall remain marked running, all without informing
+ the user/frontend about state transition changes. */
+ if (target_has_execution
+ && inferior_thread ()->control.in_infcall
+ && stop_stack_dummy == STOP_STACK_DUMMY)
discard_cleanups (old_chain);
else
do_cleanups (old_chain);
+2015-06-29 Pedro Alves <palves@redhat.com>
+
+ PR threads/18127
+ * gdb.threads/hand-call-new-thread.c: New file.
+ * gdb.threads/hand-call-new-thread.c: New file.
+
2015-06-26 Keith Seitz <keiths@redhat.com>
Doug Evans <dje@google.com>
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2015 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <assert.h>
+
+static int
+foo (void)
+{
+ usleep (1);
+}
+
+static void *
+thread_function (void *arg)
+{
+ while (1)
+ foo ();
+}
+
+void
+new_thread (void)
+{
+ pthread_t thread;
+ int res;
+
+ res = pthread_create (&thread, NULL, thread_function, NULL);
+ assert (res == 0);
+}
+
+int
+main (int argc, char **argv)
+{
+ return 0;
+}
--- /dev/null
+# Copyright (C) 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Ensure that new threads created while an infcall is ongoing are set
+# to stopped state once the call finishes.
+
+standard_testfile
+
+if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug pthreads}] {
+ return -1
+}
+
+if ![runto_main] {
+ continue
+}
+
+# Set a thread-specific breakpoint that the wrong thread trips on
+# while running the infcall. Check that no thread ends up in stale
+# "running" state once the call finishes.
+gdb_test "b foo thread 1" "Breakpoint .*$srcfile.*"
+
+for {set i 0} {$i < 3} {incr i} {
+ with_test_prefix "iter $i" {
+ gdb_test "p new_thread ()" " = void"
+
+ set message "no thread marked running"
+ gdb_test_multiple "info threads" $message {
+ -re "\\\(running\\\).*$gdb_prompt $" {
+ fail $message
+ }
+ -re "$gdb_prompt $" {
+ pass $message
+ }
+ }
+ }
+}