Add support for --start option in -exec-run GDB/MI command.
authorJoel Brobecker <brobecker@gnat.com>
Fri, 4 Oct 2013 08:35:31 +0000 (08:35 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Fri, 4 Oct 2013 08:35:31 +0000 (08:35 +0000)
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/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/mi/mi-main.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.mi/mi-start.c [new file with mode: 0644]
gdb/testsuite/gdb.mi/mi-start.exp [new file with mode: 0644]

index 53359ddeec2f4c903574ad7146f9a3e6112b2aaf..1f88eb62aab7bd1566bfe856c6bd775378455c1d 100644 (file)
@@ -1,3 +1,12 @@
+2013-10-04  Joel Brobecker  <brobecker@adacore.com>
+
+       * 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.
+
 2013-10-04  Yao Qi  <yao@codesourcery.com>
 
        * remote-notif.h (REMOTE_NOTIF_ID): New enum.
index 5a9f8db69a61a20258586eed5beec92487bdf50d..2ac92445c583ae6b85602cacc8835ff254121e32 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -137,6 +137,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:
index 705af69599f9d958b44dabdfeec3a274ddf41fb1..04e291bce356999be257fbb8d63ab819bb74f15a 100644 (file)
@@ -1,3 +1,8 @@
+2013-10-04  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.texinfo (GDB/MI Program Execution): Document "-exec-run"'s
+       new "--start" option.
+
 2013-10-02  Pedro Alves  <palves@redhat.com>
 
        * gdb.texinfo (Registers): Expand description of saved registers
index cf6f7d30a88b3acabf0562aa78b21d3390d9b79c..a68556b08720a29c9d90fa28b413b906a60e66c8 100644 (file)
@@ -31057,7 +31057,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
@@ -31065,11 +31065,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}.
index ea31367a825042023fe9cc13e4d7d1f710a0e9b1..24ac1e0751bcbc07b69140b234f380c614083709 100644 (file)
@@ -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);
     }
 }
index 991e677f710c038bf3a7f736882ad8e5f587d89b..4f077770653218f960001fa44ba96d4e1254e830 100644 (file)
@@ -1,3 +1,7 @@
+2013-10-04  Joel Brobecker  <brobecker@adacore.com>
+
+       * gdb.mi/mi-start.c, gdb.mi/mi-start.exp: New files.
+
 2013-10-02  Vidya Praveen  <vidyapraveen@arm.com>
 
        * gdb.trace/entry-values.exp: Modify regular expression to scan for
diff --git a/gdb/testsuite/gdb.mi/mi-start.c b/gdb/testsuite/gdb.mi/mi-start.c
new file mode 100644 (file)
index 0000000..13d1ac2
--- /dev/null
@@ -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 (file)
index 0000000..98dfef4
--- /dev/null
@@ -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"
+
This page took 0.065362 seconds and 4 git commands to generate.