> From: Sergio Durigan Junior <sergiodj@redhat.com>
> Cc: Joel Brobecker <brobecker@adacore.com>,
> Yao Qi <qiyaoltc@gmail.com>,
> Pedro Alves <palves@redhat.com>,
> Eli Zaretskii <eliz@gnu.org>,
> Sergio Durigan Junior <sergiodj@redhat.com>
> Date: Fri, 24 Nov 2017 18:01:22 -0500
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 754ce103bd..32229d3cea 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -3,6 +3,10 @@
>
> *** Changes since GDB 8.0
>
> +* New "--readnever" command line option instructs GDB to not read each
> + symbol file's symbolic debug information. This makes startup faster
> + but at the expense of not being able to perform symbolic debugging.
> +
This part is okay, but I would add here as well a hint about the use
cases this supports. Like this, for example:
This option is intended for use cases where symbolic debugging will
not be used, e.g., when you only need to dump the debuggee's core.
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 00451d243d..f3eef8dfeb 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -1037,6 +1037,15 @@ Read each symbol file's entire symbol table immediately, rather than
> the default, which is to read it incrementally as it is needed.
> This makes startup slower, but makes future operations faster.
>
> +@item --readnever
> +@cindex @code{--readnever}
> +Do not read each symbol file's symbolic debug information. This makes
> +startup faster but at the expense of not being able to perform
> +symbolic debugging. DWARF unwind information is also not read,
> +meaning backtraces may become incomplete or inaccurate. One use of
> +this is when a user simply wants to do the following sequence: attach,
> +dump core, detach. Loading the debugging information in this case is
> +an unnecessary cause of delay.
> @end table
>
> @node Mode Options
> @@ -18486,6 +18495,14 @@ tables by using the @samp{-readnow} option with any of the commands that
> load symbol table information, if you want to be sure @value{GDBN} has the
> entire symbol table available.
>
> +@kindex readnever
> +@cindex never read symbols
> +@cindex symbols, never read
> +@item symbol-file @r{[} -readnever @r{]} @var{filename}
> +@itemx file @r{[} -readnever @r{]} @var{filename}
> +You can instruct @value{GDBN} to never read the symbolic information
> +contained in @var{filename} by using the @samp{-readnever} option.
> +
This will cause index entries about "readnever" point to 2 different
places, with no way for the reader to tell up front which place is
about where they want to go. So I suggest to change the index entries
as follows:
@cindex @code{--readnever}, command-line option
...
@cindex @code{-readnever}, option for symbol-file command
(Note that I switched from @kindex to @cindex, since @kindex is used
for command names, and -readnever isn't.)
Otherwise, the patch for the manual is OK.
> @@ -1183,6 +1213,9 @@ Selection of debuggee and its files:\n\n\
> --se=FILE Use FILE as symbol file and executable file.\n\
> --symbols=SYMFILE Read symbols from SYMFILE.\n\
> --readnow Fully read symbol files on first access.\n\
> + --readnever Do not read symbol files.\n\
> + There is currently a known limitation that this only\n\
> + has an effect on symbol files provided in DWARF format.\n\
The part about its being limited to DWARF should now go away, right?
Thanks.
Thanks for the review, Eli.
On Saturday, November 25 2017, Eli Zaretskii wrote:
>> From: Sergio Durigan Junior <sergiodj@redhat.com>
>> Cc: Joel Brobecker <brobecker@adacore.com>,
>> Yao Qi <qiyaoltc@gmail.com>,
>> Pedro Alves <palves@redhat.com>,
>> Eli Zaretskii <eliz@gnu.org>,
>> Sergio Durigan Junior <sergiodj@redhat.com>
>> Date: Fri, 24 Nov 2017 18:01:22 -0500
>>
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index 754ce103bd..32229d3cea 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -3,6 +3,10 @@
>>
>> *** Changes since GDB 8.0
>>
>> +* New "--readnever" command line option instructs GDB to not read each
>> + symbol file's symbolic debug information. This makes startup faster
>> + but at the expense of not being able to perform symbolic debugging.
>> +
>
> This part is okay, but I would add here as well a hint about the use
> cases this supports. Like this, for example:
>
> This option is intended for use cases where symbolic debugging will
> not be used, e.g., when you only need to dump the debuggee's core.
Good point. I added the text.
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index 00451d243d..f3eef8dfeb 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -1037,6 +1037,15 @@ Read each symbol file's entire symbol table immediately, rather than
>> the default, which is to read it incrementally as it is needed.
>> This makes startup slower, but makes future operations faster.
>>
>> +@item --readnever
>> +@cindex @code{--readnever}
>> +Do not read each symbol file's symbolic debug information. This makes
>> +startup faster but at the expense of not being able to perform
>> +symbolic debugging. DWARF unwind information is also not read,
>> +meaning backtraces may become incomplete or inaccurate. One use of
>> +this is when a user simply wants to do the following sequence: attach,
>> +dump core, detach. Loading the debugging information in this case is
>> +an unnecessary cause of delay.
>> @end table
>>
>> @node Mode Options
>> @@ -18486,6 +18495,14 @@ tables by using the @samp{-readnow} option with any of the commands that
>> load symbol table information, if you want to be sure @value{GDBN} has the
>> entire symbol table available.
>>
>> +@kindex readnever
>> +@cindex never read symbols
>> +@cindex symbols, never read
>> +@item symbol-file @r{[} -readnever @r{]} @var{filename}
>> +@itemx file @r{[} -readnever @r{]} @var{filename}
>> +You can instruct @value{GDBN} to never read the symbolic information
>> +contained in @var{filename} by using the @samp{-readnever} option.
>> +
>
> This will cause index entries about "readnever" point to 2 different
> places, with no way for the reader to tell up front which place is
> about where they want to go. So I suggest to change the index entries
> as follows:
>
> @cindex @code{--readnever}, command-line option
> ...
> @cindex @code{-readnever}, option for symbol-file command
>
> (Note that I switched from @kindex to @cindex, since @kindex is used
> for command names, and -readnever isn't.)
Hm, I see. To be clear, I copied the entry above, which uses @kindex
for the "readnow" symbol-file command. Maybe that should be fixed (in
another patch), too?
> Otherwise, the patch for the manual is OK.
>
>> @@ -1183,6 +1213,9 @@ Selection of debuggee and its files:\n\n\
>> --se=FILE Use FILE as symbol file and executable file.\n\
>> --symbols=SYMFILE Read symbols from SYMFILE.\n\
>> --readnow Fully read symbol files on first access.\n\
>> + --readnever Do not read symbol files.\n\
>> + There is currently a known limitation that this only\n\
>> + has an effect on symbol files provided in DWARF format.\n\
>
> The part about its being limited to DWARF should now go away, right?
Right, I forgot to remove this line. Did it now.
Thanks,
@@ -3,6 +3,10 @@
*** Changes since GDB 8.0
+* New "--readnever" command line option instructs GDB to not read each
+ symbol file's symbolic debug information. This makes startup faster
+ but at the expense of not being able to perform symbolic debugging.
+
* GDB now uses the GNU MPFR library, if available, to emulate target
floating-point arithmetic during expression evaluation when the target
uses different floating-point formats than the host. At least version
@@ -57,6 +57,7 @@
#include "aout/aout64.h"
#include "aout/stab_gnu.h" /* We always use GNU stabs, not
native, now. */
+#include "top.h"
/* Key for dbx-associated data. */
@@ -3068,6 +3069,9 @@ coffstab_build_psymtabs (struct objfile *objfile,
struct stab_section_list *stabsects,
file_ptr stabstroffset, unsigned int stabstrsize)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return;
+
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
@@ -3152,6 +3156,9 @@ void
elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
file_ptr stabstroffset, unsigned int stabstrsize)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return;
+
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
@@ -3228,6 +3235,9 @@ void
stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
char *stabstr_name, char *text_name)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return;
+
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
@@ -1037,6 +1037,15 @@ Read each symbol file's entire symbol table immediately, rather than
the default, which is to read it incrementally as it is needed.
This makes startup slower, but makes future operations faster.
+@item --readnever
+@cindex @code{--readnever}
+Do not read each symbol file's symbolic debug information. This makes
+startup faster but at the expense of not being able to perform
+symbolic debugging. DWARF unwind information is also not read,
+meaning backtraces may become incomplete or inaccurate. One use of
+this is when a user simply wants to do the following sequence: attach,
+dump core, detach. Loading the debugging information in this case is
+an unnecessary cause of delay.
@end table
@node Mode Options
@@ -18486,6 +18495,14 @@ tables by using the @samp{-readnow} option with any of the commands that
load symbol table information, if you want to be sure @value{GDBN} has the
entire symbol table available.
+@kindex readnever
+@cindex never read symbols
+@cindex symbols, never read
+@item symbol-file @r{[} -readnever @r{]} @var{filename}
+@itemx file @r{[} -readnever @r{]} @var{filename}
+You can instruct @value{GDBN} to never read the symbolic information
+contained in @var{filename} by using the @samp{-readnever} option.
+
@c FIXME: for now no mention of directories, since this seems to be in
@c flux. 13mar1992 status is that in theory GDB would look either in
@c current dir or in same dir as myprog; but issues like competing
@@ -82,6 +82,7 @@
#include <unordered_set>
#include <unordered_map>
#include "selftest.h"
+#include "top.h"
/* When == 1, print basic high level tracing messages.
When > 1, be more verbose.
@@ -2319,6 +2320,9 @@ int
dwarf2_has_info (struct objfile *objfile,
const struct dwarf2_debug_sections *names)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return 0;
+
dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
objfile_data (objfile, dwarf2_objfile_data_key));
if (!dwarf2_per_objfile)
@@ -402,6 +402,19 @@ symbol_file_add_main_adapter (const char *arg, int from_tty)
symbol_file_add_main (arg, add_flags);
}
+/* Perform validation of the '--readnow' and '--readnever' flags. */
+
+static void
+validate_readnow_readnever ()
+{
+ if (readnever_symbol_files && readnow_symbol_files)
+ {
+ error (_("%s: '--readnow' and '--readnever' cannot be "
+ "specified simultaneously"),
+ gdb_program_name);
+ }
+}
+
/* Type of this option. */
enum cmdarg_kind
{
@@ -579,14 +592,17 @@ captured_main_1 (struct captured_main_args *context)
OPT_NOWINDOWS,
OPT_WINDOWS,
OPT_IX,
- OPT_IEX
+ OPT_IEX,
+ OPT_READNOW,
+ OPT_READNEVER
};
static struct option long_options[] =
{
{"tui", no_argument, 0, OPT_TUI},
{"dbx", no_argument, &dbx_commands, 1},
- {"readnow", no_argument, &readnow_symbol_files, 1},
- {"r", no_argument, &readnow_symbol_files, 1},
+ {"readnow", no_argument, NULL, OPT_READNOW},
+ {"readnever", no_argument, NULL, OPT_READNEVER},
+ {"r", no_argument, NULL, OPT_READNOW},
{"quiet", no_argument, &quiet, 1},
{"q", no_argument, &quiet, 1},
{"silent", no_argument, &quiet, 1},
@@ -809,6 +825,20 @@ captured_main_1 (struct captured_main_args *context)
}
break;
+ case OPT_READNOW:
+ {
+ readnow_symbol_files = 1;
+ validate_readnow_readnever ();
+ }
+ break;
+
+ case OPT_READNEVER:
+ {
+ readnever_symbol_files = 1;
+ validate_readnow_readnever ();
+ }
+ break;
+
case '?':
error (_("Use `%s --help' for a complete list of options."),
gdb_program_name);
@@ -1183,6 +1213,9 @@ Selection of debuggee and its files:\n\n\
--se=FILE Use FILE as symbol file and executable file.\n\
--symbols=SYMFILE Read symbols from SYMFILE.\n\
--readnow Fully read symbol files on first access.\n\
+ --readnever Do not read symbol files.\n\
+ There is currently a known limitation that this only\n\
+ has an effect on symbol files provided in DWARF format.\n\
--write Set writing into executable and core files.\n\n\
"), stream);
fputs_unfiltered (_("\
@@ -67,6 +67,7 @@
#include "aout/stab_gnu.h" /* STABS information. */
#include "expression.h"
+#include "top.h"
/* Provide a way to test if we have both ECOFF and ELF symbol tables.
We use this define in order to know whether we should override a
@@ -340,6 +341,9 @@ mdebug_build_psymtabs (minimal_symbol_reader &reader,
const struct ecoff_debug_swap *swap,
struct ecoff_debug_info *info)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return;
+
cur_bfd = objfile->obfd;
debug_swap = swap;
debug_info = info;
@@ -4868,6 +4872,9 @@ void
elfmdebug_build_psymtabs (struct objfile *objfile,
const struct ecoff_debug_swap *swap, asection *sec)
{
+ if (readnever_symbol_files || (objfile->flags & OBJF_READNEVER))
+ return;
+
bfd *abfd = objfile->obfd;
struct ecoff_debug_info *info;
@@ -64,6 +64,10 @@ enum objfile_flag
unrelated to filesystem names. It can be for example
"<image in memory>". */
OBJF_NOT_FILENAME = 1 << 6,
+
+ /* User requested that we do not read this objfile's symbolic
+ information. */
+ OBJF_READNEVER = 1 << 7,
};
DEF_ENUM_FLAGS_TYPE (enum objfile_flag, objfile_flags);
@@ -81,6 +81,7 @@ static void clear_symtab_users_cleanup (void *ignore);
/* Global variables owned by this file. */
int readnow_symbol_files; /* Read full symbols immediately. */
+int readnever_symbol_files; /* Never read full symbols. */
/* Functions this file defines. */
@@ -1131,6 +1132,11 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
flags |= OBJF_READNOW;
add_flags &= ~SYMFILE_NO_READ;
}
+ else if (readnever_symbol_files)
+ {
+ flags |= OBJF_READNEVER;
+ add_flags |= SYMFILE_NO_READ;
+ }
/* Give user a chance to burp if we'd be
interactively wiping out any existing symbols. */
@@ -1594,6 +1600,16 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile)
return debugfile;
}
+/* Make sure that OBJF_{READNOW,READNEVER} are not set
+ simultaneously. */
+
+static void
+validate_readnow_readnever (objfile_flags flags)
+{
+ if ((flags & OBJF_READNOW) && (flags & OBJF_READNEVER))
+ error (_("-readnow and -readnever cannot be used simultaneously"));
+}
+
/* This is the symbol-file command. Read the file, analyze its
symbols, and add a struct symtab to a symtab list. The syntax of
the command is rather bizarre:
@@ -1631,17 +1647,20 @@ symbol_file_command (const char *args, int from_tty)
{
if (strcmp (arg, "-readnow") == 0)
flags |= OBJF_READNOW;
+ else if (strcmp (arg, "-readnever") == 0)
+ flags |= OBJF_READNEVER;
else if (*arg == '-')
error (_("unknown option `%s'"), arg);
else
- {
- symbol_file_add_main_1 (arg, add_flags, flags);
- name = arg;
- }
+ name = arg;
}
if (name == NULL)
error (_("no symbol file name was specified"));
+
+ validate_readnow_readnever (flags);
+
+ symbol_file_add_main_1 (name, add_flags, flags);
}
}
@@ -2238,6 +2257,8 @@ add_symbol_file_command (const char *args, int from_tty)
}
else if (strcmp (arg, "-readnow") == 0)
flags |= OBJF_READNOW;
+ else if (strcmp (arg, "-readnever") == 0)
+ flags |= OBJF_READNEVER;
else if (strcmp (arg, "-s") == 0)
{
expecting_sec_name = 1;
@@ -2245,10 +2266,12 @@ add_symbol_file_command (const char *args, int from_tty)
}
else
error (_("USAGE: add-symbol-file <filename> <textaddress>"
- " [-readnow] [-s <secname> <addr>]*"));
+ " [-readnow|-readnever] [-s <secname> <addr>]*"));
}
}
+ validate_readnow_readnever (flags);
+
/* This command takes at least two arguments. The first one is a
filename, and the second is the address where this file has been
loaded. Abort now if this address hasn't been provided by the
new file mode 100644
@@ -0,0 +1,43 @@
+/* Copyright 2016-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/>. */
+
+#include <stdio.h>
+
+static void
+fun_three (int a, char b, void *c)
+{
+ /* Do nothing. */
+}
+
+static void
+fun_two (unsigned int p, const char *y)
+{
+ fun_three ((int) p, '1', (void *) y);
+}
+
+static void
+fun_one (int *x)
+{
+ fun_two (10, (const char *) x);
+}
+
+int
+main (void)
+{
+ int a = 10;
+
+ fun_one (&a);
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,77 @@
+# Copyright 2016-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 .c
+
+if { [build_executable "failed to build" $testfile $srcfile { debug }] == -1 } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+}
+
+save_vars { GDBFLAGS } {
+ append GDBFLAGS " --readnever"
+ clean_restart ${binfile}
+}
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint"
+ continue
+}
+
+gdb_test "break fun_three" \
+ "Breakpoint $decimal at $hex"
+
+gdb_test "continue" \
+ "Breakpoint $decimal, $hex in fun_three \\(\\)"
+
+gdb_test "backtrace" \
+ [multi_line "#0 $hex in fun_three \\(\\)" \
+ "#1 $hex in fun_two \\(\\)" \
+ "#2 $hex in fun_one \\(\\)" \
+ "#3 $hex in main \\(\\)" ]
+
+gdb_test_no_output "maint info symtabs" \
+ "maint info symtabs no output for --readnever"
+gdb_test_no_output "maint info psymtabs" \
+ "maint info psymtabs no output for --readnever"
+
+# Test invalid combination of flags.
+save_vars { GDBFLAGS } {
+ append GDBFLAGS " --readnever --readnow"
+ gdb_exit
+ gdb_spawn_ignore_error
+
+ set test "test readnow and readnever at the same time"
+ gdb_test_multiple "" $test {
+ eof {
+ pass $test
+ }
+ }
+}
+
+
+# Test symbol-file's -readnever option.
+
+# Restart GDB without the --readnever option.
+gdb_exit
+gdb_start
+gdb_test "symbol-file ${binfile}0.o -readnever" \
+ "Reading symbols from ${binfile}0\.o\.\.\.\\\(no debugging symbols found\\\)\.\.\.done\." \
+ "use symbol-file -readnever"
+
+gdb_test_no_output "maint info symtabs" \
+ "maint info symtabs no output for symbol-file -readnever"
+gdb_test_no_output "maint info psymtabs" \
+ "maint info psymtabs no output for symbol-file -readnever"
@@ -1580,7 +1580,7 @@ proc gdb_file_cmd { arg } {
# Default gdb_spawn procedure.
-proc default_gdb_spawn { } {
+proc default_gdb_spawn { { ignore_error 0 } } {
global use_gdb_stub
global GDB
global INTERNAL_GDBFLAGS GDBFLAGS
@@ -1610,11 +1610,12 @@ proc default_gdb_spawn { } {
}
}
set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"]
- if { $res < 0 || $res == "" } {
- perror "Spawning $GDB failed."
- return 1
+ if { !$ignore_error } {
+ if { $res < 0 || $res == "" } {
+ perror "Spawning $GDB failed."
+ return 1
+ }
}
-
set gdb_spawn_id $res
return 0
}
@@ -4077,6 +4078,13 @@ proc gdb_spawn { } {
default_gdb_spawn
}
+# Spawn the gdb process, but ignore errors. This is useful if you
+# want GDB to fail, e.g. when testing invalid command line options.
+
+proc gdb_spawn_ignore_error { } {
+ default_gdb_spawn 1
+}
+
# Spawn GDB with CMDLINE_FLAGS appended to the GDBFLAGS global.
proc gdb_spawn_with_cmdline_opts { cmdline_flags } {
@@ -267,6 +267,7 @@ extern int gdb_in_secondary_prompt_p (struct ui *ui);
/* From random places. */
extern int readnow_symbol_files;
+extern int readnever_symbol_files;
/* Perform _initialize initialization. */
extern void gdb_init (char *);