From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124784 invoked by alias); 29 Aug 2017 22:55:08 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 124775 invoked by uid 89); 29 Aug 2017 22:55:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=Under, HX-Greylist:succeeded, HX-Greylist:SMTP, HX-Greylist:AUTH X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 22:55:05 +0000 Received: from ralph.baldwin.cx.com (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by mail.baldwin.cx (Postfix) with ESMTPSA id 17A3710AB01 for ; Tue, 29 Aug 2017 18:55:03 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH] Add a 'starti' command. Date: Tue, 29 Aug 2017 22:55:00 -0000 Message-Id: <20170829225457.66096-1-jhb@FreeBSD.org> X-IsSubscribed: yes X-SW-Source: 2017-08/txt/msg00526.txt.bz2 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 + * 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 + * 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 + + * 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 * 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 (¤t_target, 0); + if (run_break == FIRST_INSTR) + { + gdb::unique_xmalloc_ptr 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