This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA+doco/NEWS-RFA] Add support for --start option in -exec-run GDB/MI command.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: gdb-patches at sourceware dot org
- Date: Wed, 2 Oct 2013 15:24:06 +0200
- Subject: [RFA+doco/NEWS-RFA] Add support for --start option in -exec-run GDB/MI command.
- Authentication-results: sourceware.org; auth=none
- References: <1380618763-27926-1-git-send-email-brobecker at adacore dot com> <87fvsl80gz dot fsf at fleche dot redhat dot com> <20131001155303 dot GG2840 at adacore dot com>
Hello again,
Attached is an updated patch, which includes cleaned-up implementation,
doco + NEWS, and testing.
Again, to summarize, the intent is to provide the GDB/MI equivalent
of the "start" CLI command. The latter searches the executable for
the name of the main subprogram, and inserts a temporary breakpoint
at that location, before then running the program. This feature is
implemented by adding a "--start" command option to the "-exec-run"
GDB/MI command.
Example of use with an Ada program, where the name of the main
subprogram can be different from "main" (in our example, "simple_main"),
slightly reformatted for easier reading:
> (gdb)
> -exec-run --start
> =breakpoint-created,bkpt={number="1",type="breakpoint",disp="del",
> enabled="y",addr="0x0000000000401d70",
> func="simple_main",file="simple_main.adb",
> fullname="/[...]/simple_main.adb",line="4",
> thread-groups=["i1"],times="0",
> original-location="_ada_simple_main"}
> =thread-group-started,id="i1",pid="30180"
> =thread-created,id="1",group-id="i1"
> ^running
> *running,thread-id="all"
> (gdb)
> *stopped,reason="breakpoint-hit",disp="del",bkptno="1",
> frame={addr="0x0000000000401d70",func="simple_main",args=[],
> file="simple_main.adb",fullname="/[...]/simple_main.adb",
> line="4"},
> thread-id="1",stopped-threads="all",core="6"
> =breakpoint-deleted,id="1"
The important elements are the "=breakpoint-created" notification,
as well as the "*stopped" output.
gdb/ChangeLog:
* mi/mi-main.c (run_one_inferior): Add function description.
Make ARG a pointer to an integer whose value determines whether
we should "run" or "start" the program.
(mi_cmd_exec_run): Add handling of the "--start" option.
Reject all other command-line options.
* NEWS: Add entry for "-exec-run"'s new "--start" option.
gdb/doc/ChangeLog:
* gdb.texinfo (GDB/MI Program Execution): Document "-exec-run"'s
new "--start" option.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-start.c, gdb.mi/mi-start.exp: New files.
Tested on x86_64-linux, no regression.
The new testcase was also tested with native-gdbserver.exp, to verify
that it returns untested.
OK to apply?
Thanks,
--
Joel
>From 3f8d9cf5b9d05cd51936d14cc2f6de42fb2b36cc Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Tue, 1 Oct 2013 09:55:58 +0200
Subject: [PATCH] Add support for --start option in -exec-run GDB/MI command.
gdb/ChangeLog:
* mi/mi-main.c (run_one_inferior): Add function description.
Make ARG a pointer to an integer whose value determines whether
we should "run" or "start" the program.
(mi_cmd_exec_run): Add handling of the "--start" option.
Reject all other command-line options.
* NEWS: Add entry for "-exec-run"'s new "--start" option.
gdb/doc/ChangeLog:
* gdb.texinfo (GDB/MI Program Execution): Document "-exec-run"'s
new "--start" option.
gdb/testsuite/ChangeLog:
* gdb.mi/mi-start.c, gdb.mi/mi-start.exp: New files.
---
gdb/NEWS | 5 ++++
gdb/doc/gdb.texinfo | 10 ++++++--
gdb/mi/mi-main.c | 54 ++++++++++++++++++++++++++++++++++++---
gdb/testsuite/gdb.mi/mi-start.c | 22 ++++++++++++++++
gdb/testsuite/gdb.mi/mi-start.exp | 47 ++++++++++++++++++++++++++++++++++
5 files changed, 133 insertions(+), 5 deletions(-)
create mode 100644 gdb/testsuite/gdb.mi/mi-start.c
create mode 100644 gdb/testsuite/gdb.mi/mi-start.exp
diff --git a/gdb/NEWS b/gdb/NEWS
index b44eb25..c60732d 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -123,6 +123,11 @@ show range-stepping
-stack-list-variables now accept an option "--skip-unavailable".
When used, only the available locals or arguments are displayed.
+ ** The -exec-run command now accepts an optional "--start" option.
+ When used, the command follows the same semantics as the "start"
+ command, stopping the program's execution at the start of its
+ main subprogram.
+
* New system-wide configuration scripts
A GDB installation now provides scripts suitable for use as system-wide
configuration scripts for the following systems:
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 07d5068..ca68e30 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -31034,7 +31034,7 @@ fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
@subsubheading Synopsis
@smallexample
- -exec-run [--all | --thread-group N]
+ -exec-run [ --all | --thread-group N ] [ --start ]
@end smallexample
Starts execution of the inferior from the beginning. The inferior
@@ -31042,11 +31042,17 @@ executes until either a breakpoint is encountered or the program
exits. In the latter case the output will include an exit code, if
the program has exited exceptionally.
-When no option is specified, the current inferior is started. If the
+When neither the @samp{--all} nor the @samp{--thread-group} option
+is specified, the current inferior is started. If the
@samp{--thread-group} option is specified, it should refer to a thread
group of type @samp{process}, and that thread group will be started.
If the @samp{--all} option is specified, then all inferiors will be started.
+Using the @samp{--start} option instructs the debugger to stop
+the execution at the start of the inferior's main subprogram,
+following the same behavior as the @code{start} command
+(@pxref{Starting}).
+
@subsubheading @value{GDBN} Command
The corresponding @value{GDBN} command is @samp{run}.
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index a840579..0867e2f 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -364,9 +364,19 @@ mi_cmd_exec_interrupt (char *command, char **argv, int argc)
}
}
+/* Callback for iterate_over_inferiors which starts the execution
+ of the given inferior.
+
+ ARG is a pointer to an integer whose value, if non-zero, indicates
+ that the program should be stopped when reaching the main subprogram
+ (similar to what the CLI "start" command does). */
+
static int
run_one_inferior (struct inferior *inf, void *arg)
{
+ int start_p = *(int *) arg;
+ const char *run_cmd = start_p ? "start" : "run";
+
if (inf->pid != 0)
{
if (inf->pid != ptid_get_pid (inferior_ptid))
@@ -386,7 +396,7 @@ run_one_inferior (struct inferior *inf, void *arg)
switch_to_thread (null_ptid);
set_current_program_space (inf->pspace);
}
- mi_execute_cli_command ("run", target_can_async_p (),
+ mi_execute_cli_command (run_cmd, target_can_async_p (),
target_can_async_p () ? "&" : NULL);
return 0;
}
@@ -394,16 +404,54 @@ run_one_inferior (struct inferior *inf, void *arg)
void
mi_cmd_exec_run (char *command, char **argv, int argc)
{
+ int i;
+ int start_p = 0;
+
+ /* Parse the command options. */
+ enum opt
+ {
+ START_OPT,
+ };
+ static const struct mi_opt opts[] =
+ {
+ {"-start", START_OPT, 0},
+ {NULL, 0, 0},
+ };
+
+ int oind = 0;
+ char *oarg;
+
+ while (1)
+ {
+ int opt = mi_getopt ("-exec-run", argc, argv, opts, &oind, &oarg);
+
+ if (opt < 0)
+ break;
+ switch ((enum opt) opt)
+ {
+ case START_OPT:
+ start_p = 1;
+ break;
+ }
+ }
+
+ /* This command does not accept any argument. Make sure the user
+ did not provide any. */
+ if (oind != argc)
+ error (_("Invalid argument: %s"), argv[oind]);
+
if (current_context->all)
{
struct cleanup *back_to = save_current_space_and_thread ();
- iterate_over_inferiors (run_one_inferior, NULL);
+ iterate_over_inferiors (run_one_inferior, &start_p);
do_cleanups (back_to);
}
else
{
- mi_execute_cli_command ("run", target_can_async_p (),
+ const char *run_cmd = start_p ? "start" : "run";
+
+ mi_execute_cli_command (run_cmd, target_can_async_p (),
target_can_async_p () ? "&" : NULL);
}
}
diff --git a/gdb/testsuite/gdb.mi/mi-start.c b/gdb/testsuite/gdb.mi/mi-start.c
new file mode 100644
index 0000000..13d1ac2
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-start.c
@@ -0,0 +1,22 @@
+/* Copyright 2013 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/>. */
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.mi/mi-start.exp b/gdb/testsuite/gdb.mi/mi-start.exp
new file mode 100644
index 0000000..98dfef4
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-start.exp
@@ -0,0 +1,47 @@
+# Copyright 2013 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/>.
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+# The purpose of this testcase is to test the --start option of
+# the -exec-run command. If we cannot use the -exec-run command,
+# then there is no point in running this testcase...
+if [target_info exists use_gdb_stub] {
+ untested "cannot use -exec-run command"
+ return -1
+}
+
+gdb_exit
+if [mi_gdb_start] {
+ continue
+}
+
+standard_testfile mi-start.c
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+ untested "could not build mi-start"
+ return -1
+}
+
+mi_delete_breakpoints
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_reinitialize_dir $srcdir/$subdir
+mi_gdb_load ${binfile}
+
+mi_run_cmd "--start"
+mi_expect_stop "breakpoint-hit" "main" "" ".*mi-start.c" "$decimal" \
+{ "" "disp=\"del\"" } "run to main"
+
--
1.8.1.2