This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] mi_async_p: Use the default run target (PR gdb/18077)
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: Simon Marchi <simon dot marchi at ericsson dot com>
- Date: Tue, 3 Mar 2015 16:45:33 -0500
- Subject: [PATCH] mi_async_p: Use the default run target (PR gdb/18077)
- Authentication-results: sourceware.org; auth=none
When using -exec-run in mi-async mode on a fresh gdb launch, we can see
that it is not actually done asynchronously.
The problem is that when we issue -exec-run, the linux native target is
not pushed yet. So when the code in mi_cmd_exec-run checks if we support
async (by calling mi_async_p), tdefault_can_async_p from the dummy
target answers 0.
I am not certain of the conceptual correctness of this solution, but it
seems to work. It changes mi_async_p so that it uses find_run_target()
instead of using the current_target. When -exec-run is used before the
native target is pushed, mi_async_p will now report that the target that
will eventually be used for running supports async, instead of saying
that the current target (dummy) does not.
I added a small testcase that I copied from mi-async.exp. Please
indicate if you think it should be integrated to an existing test rather
than in a new test.
I have two questions regarding the test:
- Why do we have mi_expect_stop and mi_expect_interrupt? It seems like
the functionality of _interrupt could be integrated in _stop.
- The signal reported when interrupting a thread changes when in non-stop vs all-stop:
non-stop: *stopped,reason="signal-received",signal-name="0",signal-meaning="Signal 0",..
all-stop: *stopped,reason="signal-received",signal-name="SIGINT",signal-meaning="Interrupt",...
As a consequence, mi_expect_interrupt only works with non-stop.
gdb/ChangeLog:
* mi/mi-main.c (mi_async_p): Use find_run_target to check for async
support.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-async-run.c: New file.
* gdb.mi/mi-async-run.exp: New file.
---
gdb/mi/mi-main.c | 9 +++++-
gdb/testsuite/gdb.mi/mi-async-run.c | 30 ++++++++++++++++++
gdb/testsuite/gdb.mi/mi-async-run.exp | 60 +++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 1 deletion(-)
create mode 100644 gdb/testsuite/gdb.mi/mi-async-run.c
create mode 100644 gdb/testsuite/gdb.mi/mi-async-run.exp
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 7412f7d..c296bf3 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -140,7 +140,14 @@ show_mi_async_command (struct ui_file *file, int from_tty,
int
mi_async_p (void)
{
- return mi_async && target_can_async_p ();
+ struct target_ops *ops;
+
+ if (!mi_async)
+ return 0;
+
+ ops = find_run_target ();
+ gdb_assert (ops != NULL);
+ return ops->to_can_async_p (ops);
}
/* Command implementations. FIXME: Is this libgdb? No. This is the MI
diff --git a/gdb/testsuite/gdb.mi/mi-async-run.c b/gdb/testsuite/gdb.mi/mi-async-run.c
new file mode 100644
index 0000000..760e7e6
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-async-run.c
@@ -0,0 +1,30 @@
+/* Copyright 2015 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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>
+
+int main ()
+{
+ int i;
+
+ for (i = 0; i < 30; i++)
+ {
+ sleep (1);
+ }
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/mi-async-run.exp b/gdb/testsuite/gdb.mi/mi-async-run.exp
new file mode 100644
index 0000000..c1bbbcc
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-async-run.exp
@@ -0,0 +1,60 @@
+# 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/>.
+
+# The purpose of this test if to verify that -exec-run with mi-async on
+# results in asynchronous execution (PR 18077).
+
+# The plan is for async mode to become the default but toggle for now.
+set saved_gdbflags $GDBFLAGS
+set GDBFLAGS [concat $GDBFLAGS " -ex \"set mi-async on\""]
+
+load_lib mi-support.exp
+
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
+
+standard_testfile
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested mi-async.exp
+ return -1
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+# Necessary for mi_expect_interrupt to work, as the reported signal is not the
+# same in all-stop.
+mi_gdb_test "-gdb-set non-stop 1" ".*"
+
+proc linux_async_run_test {} {
+ global mi_gdb_prompt
+ global hex
+
+ mi_run_cmd
+ mi_gdb_test "123-exec-interrupt --all" "123\\^done" "send interrupt command"
+ mi_expect_interrupt "expect interrupt"
+}
+
+linux_async_run_test
+
+mi_gdb_exit
+
+set GDBFLAGS $saved_gdbflags
+
+return 0
--
2.1.4