This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] 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.

gdb/ChangeLog:

	* NEWS (Changes since GDB 8.0): Add starti.
	* infcmd.c (enum run_break): New.
	(run_command_1): Insert temporary breakpoint at current PC for
	FIRST_INSTR case.
	(run_command): Use enum run_break.
	(start_command): Likewise.
	(starti_command): New function.
	(_initialize_infcmd): 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/ChangeLog       | 11 +++++++++++
 gdb/NEWS            |  3 +++
 gdb/doc/ChangeLog   |  6 ++++++
 gdb/doc/gdb.texinfo | 18 ++++++++++++++----
 gdb/infcmd.c        | 34 ++++++++++++++++++++++++++++++----
 5 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5559bc2907..0c2cd39c15 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
 2017-08-29  John Baldwin  <jhb@FreeBSD.org>
 
+	* NEWS (Changes since GDB 8.0): Add starti.
+	* infcmd.c (enum run_break): New.
+	(run_command_1): Insert temporary breakpoint at current PC for
+	FIRST_INSTR case.
+	(run_command): Use enum run_break.
+	(start_command): Likewise.
+	(starti_command): New function.
+	(_initialize_infcmd): Add starti command.
+
+2017-08-29  John Baldwin  <jhb@FreeBSD.org>
+
 	* mips-fbsd-nat.c (getfpregs_supplies): Return true for FIR.
 	* mips-fbsd-tdep.c (mips_fbsd_supply_fpregs): Split supply of FSR
 	out of loop and add supply of FIR.
diff --git a/gdb/NEWS b/gdb/NEWS
index 735415495e..c0b2a909ca 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -35,6 +35,9 @@ set debug separate-debug-file
 show debug separate-debug-file
   Control the display of debug output about separate debug file search.
 
+starti
+  Start the debugged program stopping at the first instruction.
+
 * TUI Single-Key mode now supports two new shortcut keys: `i' for stepi and
   `o' for nexti.
 
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index bf82730830..17428020a2 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,9 @@
+2017-08-29  John Baldwin  <jhb@FreeBSD.org>
+
+	* gdb.texinfo (Starting your Program): Add description of
+	starti command.  Mention starti command as an alternative for
+	debugging the elaboration phase.
+
 2017-08-23  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	* gdb.texinfo (Compiling and Injecting Code): Add to subsection
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index d977b234d0..2bf2cb6f1b 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -2117,10 +2117,20 @@ reused if no argument is provided during subsequent calls to
 @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
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index bd9ead8a45..5e9173ff44 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -520,12 +520,14 @@ prepare_execution_command (struct target_ops *target, int background)
     }
 }
 
+enum run_break { NONE, MAIN, FIRST_INSTR };
+
 /* 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.  */
 
 static void
-run_command_1 (char *args, int from_tty, int tbreak_at_main)
+run_command_1 (char *args, int from_tty, enum run_break run_break)
 {
   const char *exec_file;
   struct cleanup *old_chain;
@@ -572,7 +574,7 @@ 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)
+  if (run_break == MAIN)
     tbreak_command (main_name (), 0);
 
   exec_file = get_exec_file (0);
@@ -632,6 +634,14 @@ 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);
 
+  if (run_break == FIRST_INSTR)
+    {
+      gdb::unique_xmalloc_ptr<char> loc
+	(xstrdup (("*" + std::to_string (regcache_read_pc
+					 (get_current_regcache ()))).c_str ()));
+      tbreak_command (loc.get (), 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);
@@ -644,7 +654,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, NONE);
 }
 
 /* Start the execution of the program up until the beginning of the main
@@ -660,7 +670,17 @@ 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, MAIN);
+}
+
+/* Start the execution of the program until the first instruction.  */
+
+static void
+starti_command (char *args, int from_tty)
+{
+
+  /* Run the program until reaching the first instruction...  */
+  run_command_1 (args, from_tty, FIRST_INSTR);
 } 
 
 static int
@@ -3415,6 +3435,12 @@ You may specify arguments to give to your program, just as with the\n\
 \"run\" command."));
   set_cmd_completer (c, filename_completer);
 
+  c = add_com ("starti", class_run, starti_command, _("\
+Start the debugged program stopping at the first instruction.\n\
+You may specify arguments to give to your program, just as with the\n\
+\"run\" command."));
+  set_cmd_completer (c, filename_completer);
+
   add_com ("interrupt", class_run, interrupt_command,
 	   _("Interrupt the execution of the debugged program.\n\
 If non-stop mode is enabled, interrupt only the current thread,\n\
-- 
2.13.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]