aboutsummaryrefslogtreecommitdiff
path: root/gdb/infcmd.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2017-09-11 14:57:37 -0700
committerJohn Baldwin <jhb@FreeBSD.org>2017-09-19 12:15:35 -0700
commit4e5a4f5850487740eb7549f1d0b8625ce577faab (patch)
tree0c55f26272032824250d95c45865592c340ccd52 /gdb/infcmd.c
parentb7f54058d9cd409ada192bfefd4c99c98caaef2e (diff)
downloadgdb-4e5a4f5850487740eb7549f1d0b8625ce577faab.zip
gdb-4e5a4f5850487740eb7549f1d0b8625ce577faab.tar.gz
gdb-4e5a4f5850487740eb7549f1d0b8625ce577faab.tar.bz2
Add a 'starti' command.
This works like 'start' but it stops at the first instruction rather than the first line in main(). This is useful if one wants to single step through runtime linker startup. While here, introduce a RUN_ARGS_HELP macro for shared help text between run, start, and starti. This includes expanding the help for start and starti to include details from run's help text. gdb/ChangeLog: * NEWS (Changes since GDB 8.0): Add starti. * infcmd.c (enum run_break): New. (run_command_1): Queue pending event for RUN_STOP_AT_FIRST_INSN case. (run_command): Use enum run_how. (start_command): Likewise. (starti_command): New function. (RUN_ARGS_HELP): New macro. (_initialize_infcmd): Use RUN_ARGS_HELP for run and start commands. Add starti command. gdb/doc/ChangeLog: * gdb.texinfo (Starting your Program): Add description of starti command. Mention starti command as an alternative for debugging the elaboration phase. gdb/testsuite/ChangeLog: * gdb.base/starti.c: New file. * gdb.base/starti.exp: New file. * lib/gdb.exp (gdb_starti_cmd): New procedure.
Diffstat (limited to 'gdb/infcmd.c')
-rw-r--r--gdb/infcmd.c87
1 files changed, 65 insertions, 22 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 25cf025..c38b00a 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -518,12 +518,25 @@ prepare_execution_command (struct target_ops *target, int background)
}
}
-/* 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;
@@ -532,6 +545,7 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
struct target_ops *run_target;
int async_exec;
struct cleanup *args_chain;
+ CORE_ADDR pc;
dont_repeat ();
@@ -569,8 +583,8 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
/* 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);
@@ -630,6 +644,15 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
has done its thing; now we are setting up the running program. */
post_create_inferior (&current_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);
@@ -642,7 +665,7 @@ run_command_1 (char *args, int from_tty, int tbreak_at_main)
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
@@ -658,7 +681,16 @@ start_command (char *args, int from_tty)
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
@@ -3178,6 +3210,22 @@ info_proc_cmd_all (char *args, int from_tty)
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)
{
@@ -3384,24 +3432,19 @@ Specifying -a and an ignore count simultaneously is an error."));
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,