Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH] mi_async_p: Use the default run target (PR gdb/18077)
Date: Tue, 03 Mar 2015 21:45:00 -0000	[thread overview]
Message-ID: <1425419133-7843-1-git-send-email-simon.marchi@ericsson.com> (raw)

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


             reply	other threads:[~2015-03-03 21:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-03 21:45 Simon Marchi [this message]
2015-03-04 10:18 ` Pedro Alves
2015-03-04 19:29   ` Simon Marchi
2015-03-04 19:32     ` Pedro Alves
2015-03-04 19:35       ` Simon Marchi
2015-03-04 19:45         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425419133-7843-1-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox