@samp{start} or @samp{run}.
It is sometimes necessary to debug the program during elaboration. In
-these cases, using the @code{start} command would stop the execution of
-your program too late, as the program would have already completed the
-elaboration phase. Under these circumstances, insert breakpoints in your
-elaboration code before running your program.
+these cases, using the @code{start} command would stop the execution
+of your program too late, as the program would have already completed
+the elaboration phase. Under these circumstances, either insert
+breakpoints in your elaboration code before running your program or
+use the @code{starti} command.
+
+@kindex starti
+@item starti
+@cindex run to first instruction
+The @samp{starti} command does the equivalent of setting a temporary
+breakpoint at the first instruction of a program's execution and then
+invoking the @samp{run} command. For programs containing an
+elaboration phase, the @code{starti} command will stop execution at
+the start of the elaboration phase.
@anchor{set exec-wrapper}
@kindex set exec-wrapper
}
}
-/* Implement the "run" command. If TBREAK_AT_MAIN is set, then insert
- a temporary breakpoint at the begining of the main program before
- running the program. */
+/* Determine how the new inferior will behave. */
+
+enum run_how
+ {
+ /* Run program without any explicit stop during startup. */
+ RUN_NORMAL,
+
+ /* Stop at the beginning of the program's main function. */
+ RUN_STOP_AT_MAIN,
+
+ /* Stop at the first instruction of the program. */
+ RUN_STOP_AT_FIRST_INSN
+ };
+
+/* Implement the "run" command. Force a stop during program start if
+ requested by RUN_HOW. */
static void
-run_command_1 (char *args, int from_tty, int tbreak_at_main)
+run_command_1 (char *args, int from_tty, enum run_how run_how)
{
const char *exec_file;
struct cleanup *old_chain;
struct target_ops *run_target;
int async_exec;
struct cleanup *args_chain;
+ CORE_ADDR pc;
dont_repeat ();
/* Done. Can now set breakpoints, change inferior args, etc. */
- /* Insert the temporary breakpoint if a location was specified. */
- if (tbreak_at_main)
+ /* Insert temporary breakpoint in main function if requested. */
+ if (run_how == RUN_STOP_AT_MAIN)
tbreak_command (main_name (), 0);
exec_file = get_exec_file (0);
has done its thing; now we are setting up the running program. */
post_create_inferior (¤t_target, 0);
+ /* Queue a pending event so that the program stops immediately. */
+ if (run_how == RUN_STOP_AT_FIRST_INSN)
+ {
+ thread_info *thr = inferior_thread ();
+ thr->suspend.waitstatus_pending_p = 1;
+ thr->suspend.waitstatus.kind = TARGET_WAITKIND_STOPPED;
+ thr->suspend.waitstatus.value.sig = GDB_SIGNAL_0;
+ }
+
/* Start the target running. Do not use -1 continuation as it would skip
breakpoint right at the entry point. */
proceed (regcache_read_pc (get_current_regcache ()), GDB_SIGNAL_0);
static void
run_command (char *args, int from_tty)
{
- run_command_1 (args, from_tty, 0);
+ run_command_1 (args, from_tty, RUN_NORMAL);
}
/* Start the execution of the program up until the beginning of the main
error (_("No symbol table loaded. Use the \"file\" command."));
/* Run the program until reaching the main procedure... */
- run_command_1 (args, from_tty, 1);
+ run_command_1 (args, from_tty, RUN_STOP_AT_MAIN);
+}
+
+/* Start the execution of the program stopping at the first
+ instruction. */
+
+static void
+starti_command (char *args, int from_tty)
+{
+ run_command_1 (args, from_tty, RUN_STOP_AT_FIRST_INSN);
}
static int
info_proc_cmd_1 (args, IP_ALL, from_tty);
}
+/* This help string is used for the run, start, and starti commands.
+ It is defined as a macro to prevent duplication. */
+
+#define RUN_ARGS_HELP \
+"You may specify arguments to give it.\n\
+Args may include \"*\", or \"[...]\"; they are expanded using the\n\
+shell that will start the program (specified by the \"$SHELL\" environment\n\
+variable). Input and output redirection with \">\", \"<\", or \">>\"\n\
+are also allowed.\n\
+\n\
+With no arguments, uses arguments last specified (with \"run\" or \n\
+\"set args\"). To cancel previous arguments and run with no arguments,\n\
+use \"set args\" without arguments.\n\
+\n\
+To start the inferior without using a shell, use \"set startup-with-shell off\"."
+
void
_initialize_infcmd (void)
{
add_com_alias ("fg", "cont", class_run, 1);
c = add_com ("run", class_run, run_command, _("\
-Start debugged program. You may specify arguments to give it.\n\
-Args may include \"*\", or \"[...]\"; they are expanded using the\n\
-shell that will start the program (specified by the \"$SHELL\"\
-environment\nvariable). Input and output redirection with \">\",\
-\"<\", or \">>\"\nare also allowed.\n\n\
-With no arguments, uses arguments last specified (with \"run\" \
-or \"set args\").\n\
-To cancel previous arguments and run with no arguments,\n\
-use \"set args\" without arguments.\n\
-To start the inferior without using a shell, use \"set \
-startup-with-shell off\"."));
+Start debugged program.\n"
+RUN_ARGS_HELP));
set_cmd_completer (c, filename_completer);
add_com_alias ("r", "run", class_run, 1);
c = add_com ("start", class_run, start_command, _("\
-Run the debugged program until the beginning of the main procedure.\n\
-You may specify arguments to give to your program, just as with the\n\
-\"run\" command."));
+Start the debugged program stopping at the beginning of the main procedure.\n"
+RUN_ARGS_HELP));
+ set_cmd_completer (c, filename_completer);
+
+ c = add_com ("starti", class_run, starti_command, _("\
+Start the debugged program stopping at the first instruction.\n"
+RUN_ARGS_HELP));
set_cmd_completer (c, filename_completer);
add_com ("interrupt", class_run, interrupt_command,
--- /dev/null
+# Copyright 2017 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/>.
+
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+# Define a stop hook that outputs the value of 'x'
+
+gdb_test_multiple "define hook-stop" "hook-stop" {
+ -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" {
+ gdb_test "print x\nend" "" "hook-stop"
+ }
+}
+
+if { [gdb_starti_cmd] < 0 } {
+ untested starti
+ return -1
+}
+
+# The program should stop at the first instruction, so the constructor
+# should not have run yet and 'x' should be 0.
+
+gdb_test_sequence "" "starti" {
+ "Program stopped."
+ "\\$1 = 0"
+}
+
+# Continue to the start of main(). The constructor should have run so
+# 'x' should be 1.
+
+gdb_breakpoint main
+gdb_test_sequence "continue" "" {
+ "\\$2 = 1"
+ ".*Breakpoint .*main \\(\\) at .*starti.c.*"
+}