]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
make dprintf.exp pass in target async mode
authorPedro Alves <palves@redhat.com>
Thu, 20 Mar 2014 17:03:43 +0000 (17:03 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 20 Mar 2014 17:49:51 +0000 (17:49 +0000)
When target-async is enabled, dprintf.exp fails:

 Running ../../../src/gdb/testsuite/gdb.base/dprintf.exp ...
 FAIL: gdb.base/dprintf.exp: 1st dprintf, call
 FAIL: gdb.base/dprintf.exp: 2nd dprintf, call
 FAIL: gdb.base/dprintf.exp: Set dprintf function
 FAIL: gdb.base/dprintf.exp: 1st dprintf, fprintf
 FAIL: gdb.base/dprintf.exp: 2nd dprintf, fprintf

 Breakpoint 2, main (argc=1, argv=0x7fffffffd3f8) at ../../../src/gdb/testsuite/gdb.base/dprintf.c:33
 33        int loc = 1234;
 (gdb) continue
 Continuing.
 kickoff 1234
 also to stderr 1234
 At foo entry
 (gdb) FAIL: gdb.base/dprintf.exp: 1st dprintf, call

The problem is that GDB gave the prompt back to the user too early.

This happens when calling functions while handling an event that
doesn't cause a user visible stop.  dprintf with "set dprintf-style
gdb" is one such case.  This patch adds a test case that has a
breakpoint with a condition that calls a function that returns false,
so that regression testing isn't dependent on the implementation of
dprintf.

The problem happens because run_inferior_call causes GDB to forget
that it is running in sync_execution mode, so any event that runs an
inferior call causes fetch_inferior_event to display the prompt, even
if the event should not result in a user visible stop (that is, gdb
resumes the inferior and waits for the next event).

This patch fixes the issue by noticing when GDB was in sync_execution
mode in run_inferior_call, and taking care to restore this state
afterward.

gdb/
2014-03-20  Tom Tromey  <tromey@redhat.com>

PR cli/15718
* infcall.c: Include event-top.h.
(run_inferior_call): Call async_disable_stdin if needed.

gdb/testsuite/
2014-03-20  Tom Tromey  <tromey@redhat.com>
    Pedro Alves  <palves@redhat.com>

PR cli/15718
* gdb.base/condbreak-call-false.c: New file.
* gdb.base/condbreak-call-false.exp: New file.

gdb/ChangeLog
gdb/infcall.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/condbreak-call-false.c [new file with mode: 0644]
gdb/testsuite/gdb.base/condbreak-call-false.exp [new file with mode: 0644]

index 814be2c52d41d0ad609bde6c64a82505491d899e..acb25f8f191c45cb7c6bfcf671e7d72d6031fe44 100644 (file)
@@ -1,3 +1,9 @@
+2014-03-20  Tom Tromey  <tromey@redhat.com>
+
+       PR cli/15718
+       * infcall.c: Include event-top.h.
+       (run_inferior_call): Call async_disable_stdin if needed.
+
 2014-03-20  Pedro Alves  <palves@redhat.com>
 
        * infrun.c (prepare_to_proceed): Delete.
index ad18ff1540e8aa5750bd0a9ca364f4e25beca31a..9907263326b6d05e8558e1c12aa7c8be0ae83d18 100644 (file)
@@ -36,6 +36,7 @@
 #include "ada-lang.h"
 #include "gdbthread.h"
 #include "exceptions.h"
+#include "event-top.h"
 
 /* If we can't find a function's name from its address,
    we print this instead.  */
@@ -398,6 +399,8 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
 
   TRY_CATCH (e, RETURN_MASK_ALL)
     {
+      int was_sync = sync_execution;
+
       proceed (real_pc, GDB_SIGNAL_0, 0);
 
       /* Inferior function calls are always synchronous, even if the
@@ -407,6 +410,13 @@ run_inferior_call (struct thread_info *call_thread, CORE_ADDR real_pc)
        {
          wait_for_inferior ();
          normal_stop ();
+         /* If GDB was previously in sync execution mode, then ensure
+            that it remains so.  normal_stop calls
+            async_enable_stdin, so reset it again here.  In other
+            cases, stdin will be re-enabled by
+            inferior_event_handler, when an exception is thrown.  */
+         if (was_sync)
+           async_disable_stdin ();
        }
     }
 
index 31e0e5dffd082c0bd6650fef5d37982e52a56ed3..d6fb1dc7648b35efb28012ff209485df6f6f1206 100644 (file)
@@ -1,3 +1,10 @@
+2014-03-20  Tom Tromey  <tromey@redhat.com>
+           Pedro Alves  <palves@redhat.com>
+
+       PR cli/15718
+       * gdb.base/condbreak-call-false.c: New file.
+       * gdb.base/condbreak-call-false.exp: New file.
+
 2014-03-20  Pedro Alves  <palves@redhat.com>
 
        * gdb.threads/signal-while-stepping-over-bp-other-thread.c (pid):
diff --git a/gdb/testsuite/gdb.base/condbreak-call-false.c b/gdb/testsuite/gdb.base/condbreak-call-false.c
new file mode 100644 (file)
index 0000000..ed9a3f4
--- /dev/null
@@ -0,0 +1,39 @@
+/* Copyright 2013-2014 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/>.  */
+
+int
+zero (void)
+{
+  return 0;
+}
+
+int
+foo (void)
+{
+  return 23;
+}
+
+void
+bar (void)
+{
+}
+
+
+int
+main (void)
+{
+  foo ();
+  bar ();
+}
diff --git a/gdb/testsuite/gdb.base/condbreak-call-false.exp b/gdb/testsuite/gdb.base/condbreak-call-false.exp
new file mode 100644 (file)
index 0000000..d1cb2bb
--- /dev/null
@@ -0,0 +1,33 @@
+# Copyright 2013-2014 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/>.
+
+# Test that a breakpoint condition with a function call that returns
+# false works as expected.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+if ![runto_main] then {
+    fail "Can't run to main"
+    return 0
+}
+
+gdb_test "break foo if zero()" "Breakpoint .*"
+gdb_test "break bar" "Breakpoint .*"
+
+gdb_test "c" "Breakpoint .* bar .*"