public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFC/RFA] Add support for the --readnever command-line option (DWARF only)
@ 2016-07-06 20:54 Joel Brobecker
  2016-07-12 14:27 ` Yao Qi
                   ` (5 more replies)
  0 siblings, 6 replies; 58+ messages in thread
From: Joel Brobecker @ 2016-07-06 20:54 UTC (permalink / raw)
  To: gdb-patches

Hello,

One of our customers asked us about this option, which they could
see as being available in the version of GDB shipped by RedHat but
not in the version that AdaCore supports.

The purpose of this option is to turn the load of debugging information
off. The implementation proposed here is mostly a copy of the patch
distributed with RedHat Fedora, and looking at the patch itself and
the history, I can see some reasons why it was never submitted:
  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this 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.

I started looking at a more general way of implementing this feature.
For instance, I was hoping for a patch maybe at the objfile reader
level, or even better at the generic part of the objfile reader.
But it turns out this is not trivial at all.  The loading of debugging
information appears to be done as part of either the sym_fns->sym_read
(most cases), or during the sym_fns->sym_read_psymbols phase ("lazy
loading", ELF). Reading the code there, it wasn't obvious to me
what the consequence would be to add some code to ignore debugging
information, and since I would not be able to test those changes,
I opted towards touching only the targets that use DWARF.

This is why I ended up choosing the same approach as RedHat.
It's far from perfect, but has the benefit of working for
what I hope is the vast majority of people, and being fairly
unintrusive. I thought, since it's useful to AdaCore, and it's
been useful to RedHat, maybe others might find it useful, so
here it is.

The changes I made to the patch from Fedora are:

      - dwarf2_has_info: Return immediately if readnever_symbol_files
                         is set - faster return, and easier to read, IMO;
      - main.c: Update the --help output to mention that this feature
                only supports DWARF;
      - gdb.texinfo: Add a paragraph to explain that this option only
        supports DWARF.

If you guys don't think it's a good idea, then I'll understand
(hence the RFC).  At least we'll have it in the archives, in case
someone else wants it.

gdb/ChangeLog:

        Andrew Cagney  <cagney@redhat.com>
        Joel Brobecker  <brobecker@adacore.com>
        * symfile.c (readnever_symbol_files): New global.
        * top.h (readnever_symbol_files): New extern global.
        * main.c (captured_main): Add support for --readnever.
        (print_gdb_help): Document --readnever.
        * dwarf2read.c: #include "top.h".
        (dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.

gdb/doc/ChangeLog:

        Andrew Cagney  <cagney@redhat.com>
        Joel Brobecker  <brobecker@adacore.com>
        * gdb.texinfo (File Options): Document --readnever.

gdb/testsuite/ChangeLog:

        Joel Brobecker  <brobecker@adacore.com>
        * gdb.base/readnever.c, gdb.base/readnever.exp: New files.

Tested on x86_64-linux.


---
 gdb/doc/gdb.texinfo                  |  8 ++++++
 gdb/dwarf2read.c                     |  4 +++
 gdb/main.c                           |  4 +++
 gdb/symfile.c                        |  1 +
 gdb/testsuite/gdb.base/readnever.c   | 39 +++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 48 ++++++++++++++++++++++++++++++++++++
 gdb/top.h                            |  1 +
 7 files changed, 105 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index a068622..f2910e1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1032,6 +1032,14 @@ 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.
+
+This option is currently limited to debug information in DWARF format.
+For all other format, this option has no effect.
 @end table
 
 @node Mode Options
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 6658a38..b34b06f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -70,6 +70,7 @@
 #include "filestuff.h"
 #include "build-id.h"
 #include "namespace.h"
+#include "top.h"
 
 #include <fcntl.h>
 #include <sys/types.h>
@@ -2062,6 +2063,9 @@ int
 dwarf2_has_info (struct objfile *objfile,
                  const struct dwarf2_debug_sections *names)
 {
+  if (readnever_symbol_files)
+    return 0;
+
   dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
 			objfile_data (objfile, dwarf2_objfile_data_key));
   if (!dwarf2_per_objfile)
diff --git a/gdb/main.c b/gdb/main.c
index 5477379..3e8701b 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -601,6 +601,7 @@ captured_main (void *data)
       {"tui", no_argument, 0, OPT_TUI},
       {"dbx", no_argument, &dbx_commands, 1},
       {"readnow", no_argument, &readnow_symbol_files, 1},
+      {"readnever", no_argument, &readnever_symbol_files, 1},
       {"r", no_argument, &readnow_symbol_files, 1},
       {"quiet", no_argument, &quiet, 1},
       {"q", no_argument, &quiet, 1},
@@ -1199,6 +1200,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 (_("\
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d29e96c..bbc2c24 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -80,6 +80,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.  */
 
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000..803a554
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -0,0 +1,39 @@
+/* Copyright 2016 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/>.  */
+
+void
+fun_three (void)
+{
+  /* Do nothing.  */
+}
+
+void
+fun_two (void)
+{
+  fun_three ();
+}
+
+void
+fun_one (void)
+{
+  fun_two ();
+}
+
+int
+main (void)
+{
+  fun_one ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000..5bf31a8
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -0,0 +1,48 @@
+# Copyright 2016 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/>.
+
+# This file is part of the gdb testsuite.  It is intended to test that
+# gdb can correctly print arrays with indexes for each element of the
+# array.
+
+standard_testfile .c
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
+    untested "Couldn't compile ${srcfile}"
+    return -1
+}
+
+set saved_gdbflags $GDBFLAGS
+set GDBFLAGS "$GDBFLAGS --readnever"
+clean_restart ${binfile}
+set GDBFLAGS $saved_gdbflags
+
+
+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 \\(\\)" ]
diff --git a/gdb/top.h b/gdb/top.h
index 64f7211..6f75eea 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -241,6 +241,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 *);
-- 
2.5.0

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [RFC/RFA] Add support for the --readnever command-line option (DWARF only)
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
@ 2016-07-12 14:27 ` Yao Qi
  2016-10-04 18:07   ` Pedro Alves
  2016-10-04 18:06 ` [RFC/RFA] " Pedro Alves
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 58+ messages in thread
From: Yao Qi @ 2016-07-12 14:27 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Hi Joel,

On Wed, Jul 6, 2016 at 9:54 PM, Joel Brobecker <brobecker@adacore.com> wrote:
> Hello,
>
> One of our customers asked us about this option, which they could
> see as being available in the version of GDB shipped by RedHat but
> not in the version that AdaCore supports.
>
> The purpose of this option is to turn the load of debugging information
> off. The implementation proposed here is mostly a copy of the patch
> distributed with RedHat Fedora, and looking at the patch itself and
> the history, I can see some reasons why it was never submitted:

Andrew Cagney posted the patch
https://www.sourceware.org/ml/gdb/2004-11/msg00216.html

>   - The patch appears to have been introduced as a workaround, at
>     least initially;
>   - The patch is far from perfect, as it simply shunts the load of
>     DWARF debugging information, without really worrying about the
>     other debug format.
>   - Who really does non-symbolic debugging anyways?

The reason, IMO, it was posted is that people want GDB avoid reading
debug info and efficiently dump stack backtrace.  I think Red Hat people
must know why Fedora is shipping this patch.

I don't object to this approach.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [RFC/RFA] Add support for the --readnever command-line option (DWARF only)
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
  2016-07-12 14:27 ` Yao Qi
@ 2016-10-04 18:06 ` Pedro Alves
  2017-11-24 23:01 ` [PATCH v2] Add support for the --readnever command-line option Sergio Durigan Junior
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2016-10-04 18:06 UTC (permalink / raw)
  To: Joel Brobecker, gdb-patches

On 07/06/2016 09:54 PM, Joel Brobecker wrote:

>  #include <fcntl.h>
>  #include <sys/types.h>
> @@ -2062,6 +2063,9 @@ int
>  dwarf2_has_info (struct objfile *objfile,
>                   const struct dwarf2_debug_sections *names)
>  {
> +  if (readnever_symbol_files)
> +    return 0;

Guess that means '--readnever --readnow' is the same as
--readnever in practice?


> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
> +    untested "Couldn't compile ${srcfile}"
> +    return -1
> +}

Maybe use build_executable.

> +set saved_gdbflags $GDBFLAGS
> +set GDBFLAGS "$GDBFLAGS --readnever"
> +clean_restart ${binfile}
> +set GDBFLAGS $saved_gdbflags

Nowadays we have save_vars:

save_vars { GDBFLAGS } {
  append GDBFLAGS " --readnever"
  clean_restart ${binfile}
}

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [RFC/RFA] Add support for the --readnever command-line option (DWARF only)
  2016-07-12 14:27 ` Yao Qi
@ 2016-10-04 18:07   ` Pedro Alves
  2017-11-23  0:54     ` [PATCH v2] " Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2016-10-04 18:07 UTC (permalink / raw)
  To: Yao Qi, Joel Brobecker; +Cc: gdb-patches

On 07/12/2016 03:27 PM, Yao Qi wrote:
> Hi Joel,
> 
> On Wed, Jul 6, 2016 at 9:54 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>> Hello,
>>
>> One of our customers asked us about this option, which they could
>> see as being available in the version of GDB shipped by RedHat but
>> not in the version that AdaCore supports.
>>
>> The purpose of this option is to turn the load of debugging information
>> off. The implementation proposed here is mostly a copy of the patch
>> distributed with RedHat Fedora, and looking at the patch itself and
>> the history, I can see some reasons why it was never submitted:
> 
> Andrew Cagney posted the patch
> https://www.sourceware.org/ml/gdb/2004-11/msg00216.html
> 
>>   - The patch appears to have been introduced as a workaround, at
>>     least initially;
>>   - The patch is far from perfect, as it simply shunts the load of
>>     DWARF debugging information, without really worrying about the
>>     other debug format.
>>   - Who really does non-symbolic debugging anyways?
> 
> The reason, IMO, it was posted is that people want GDB avoid reading
> debug info and efficiently dump stack backtrace.  I think Red Hat people
> must know why Fedora is shipping this patch.
> 
> I don't object to this approach.
> 

This predates my gdb involvement, I don't really know the history.
Maybe Jan knows.

In any case, I don't object to the approach.

Is this skipping _unwind_ info as well though?  I think the
documentation should be clear on that, because if it does
skip dwarf info for unwinding as well, then you
may get a faster, but incorrect backtrace.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2016-10-04 18:07   ` Pedro Alves
@ 2017-11-23  0:54     ` Sergio Durigan Junior
  2017-11-23 12:09       ` Pedro Alves
  2017-11-23 15:59       ` Eli Zaretskii
  0 siblings, 2 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-23  0:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Joel Brobecker, gdb-patches

[ Reviving the thread.  ]

Hey there,

So, since I'm working on upstreaming most of the patches we carry on
Fedora GDB, this one caught my attention (thanks to Pedro for bringing
this to me).

I applied it to a local tree, did some tests and adjustments (see
below), and now I'm resubmitting it for another set of reviews.

I hope we can get it pushed this time :-).

Please see comments below.

On Tuesday, October 04 2016, Pedro Alves wrote:

> On 07/12/2016 03:27 PM, Yao Qi wrote:
>> Hi Joel,
>> 
>> On Wed, Jul 6, 2016 at 9:54 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>>> Hello,
>>>
>>> One of our customers asked us about this option, which they could
>>> see as being available in the version of GDB shipped by RedHat but
>>> not in the version that AdaCore supports.
>>>
>>> The purpose of this option is to turn the load of debugging information
>>> off. The implementation proposed here is mostly a copy of the patch
>>> distributed with RedHat Fedora, and looking at the patch itself and
>>> the history, I can see some reasons why it was never submitted:
>> 
>> Andrew Cagney posted the patch
>> https://www.sourceware.org/ml/gdb/2004-11/msg00216.html
>> 
>>>   - The patch appears to have been introduced as a workaround, at
>>>     least initially;
>>>   - The patch is far from perfect, as it simply shunts the load of
>>>     DWARF debugging information, without really worrying about the
>>>     other debug format.
>>>   - Who really does non-symbolic debugging anyways?
>> 
>> The reason, IMO, it was posted is that people want GDB avoid reading
>> debug info and efficiently dump stack backtrace.  I think Red Hat people
>> must know why Fedora is shipping this patch.
>> 
>> I don't object to this approach.
>> 
>
> This predates my gdb involvement, I don't really know the history.
> Maybe Jan knows.
>
> In any case, I don't object to the approach.
>
> Is this skipping _unwind_ info as well though?  I think the
> documentation should be clear on that, because if it does
> skip dwarf info for unwinding as well, then you
> may get a faster, but incorrect backtrace.

So, I looked a bit into this, and it seems that unwind information is
also skipped, which is unfortunate.  I am not an expert in this area of
GDB so by all means please comment if you have more details, but here's
the simple test I did.

I modified gdb.dwarf2/dw2-dup-frame.exp to use --readnever, and ran it.
The tests failed, and from what I checked this is because GDB was unable
to tell that the frame stack is corrupted (because there are two
identical frames in it).  By doing some debugging, I noticed that
gdb/dwarf2-frame.c:dwarf2_frame_sniffer is always returning 0 because it
can't find any FDE's, which are found by using DWARF information that
GDB hasn't read.

On Tuesday, October 04 2016, Pedro Alves wrote:

> On 07/06/2016 09:54 PM, Joel Brobecker wrote:
>
>>  #include <fcntl.h>
>>  #include <sys/types.h>
>> @@ -2062,6 +2063,9 @@ int
>>  dwarf2_has_info (struct objfile *objfile,
>>                   const struct dwarf2_debug_sections *names)
>>  {
>> +  if (readnever_symbol_files)
>> +    return 0;
>
> Guess that means '--readnever --readnow' is the same as
> --readnever in practice?

I've modified our main.c to detect whether --readnow and --readnever are
given at the same time, and print an error in this case.

>
>> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
>> +    untested "Couldn't compile ${srcfile}"
>> +    return -1
>> +}
>
> Maybe use build_executable.

Done.

>> +set saved_gdbflags $GDBFLAGS
>> +set GDBFLAGS "$GDBFLAGS --readnever"
>> +clean_restart ${binfile}
>> +set GDBFLAGS $saved_gdbflags
>
> Nowadays we have save_vars:
>
> save_vars { GDBFLAGS } {
>   append GDBFLAGS " --readnever"
>   clean_restart ${binfile}
> }

Done.

Here's the updated patch.  I've made a few cosmetic modifications
(s/RedHat/Red Hat/, for example) to the commit message, BTW.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

From 858798fa4ce56e05c24e86098072518950135b4f Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Wed, 6 Jul 2016 13:54:23 -0700
Subject: [PATCH] Add support for the --readnever command-line option (DWARF
 only)

Hello,

One of our customers asked us about this option, which they could see
as being available in the version of GDB shipped by Red Hat but not in
the version that AdaCore supports.

The purpose of this option is to turn the load of debugging
information off. The implementation proposed here is mostly a copy of
the patch distributed with Fedora, and looking at the patch itself and
the history, I can see some reasons why it was never submitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

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.

I started looking at a more general way of implementing this feature.
For instance, I was hoping for a patch maybe at the objfile reader
level, or even better at the generic part of the objfile reader.
But it turns out this is not trivial at all.  The loading of debugging
information appears to be done as part of either the sym_fns->sym_read
(most cases), or during the sym_fns->sym_read_psymbols phase ("lazy
loading", ELF). Reading the code there, it wasn't obvious to me
what the consequence would be to add some code to ignore debugging
information, and since I would not be able to test those changes,
I opted towards touching only the targets that use DWARF.

This is why I ended up choosing the same approach as Red Hat.  It's
far from perfect, but has the benefit of working for what I hope is
the vast majority of people, and being fairly unintrusive. I thought,
since it's useful to AdaCore, and it's been useful to Red Hat, maybe
others might find it useful, so here it is.

The changes I made to the patch from Fedora are:

      - dwarf2_has_info: Return immediately if readnever_symbol_files
                         is set - faster return, and easier to read, IMO;
      - main.c: Update the --help output to mention that this feature
                only supports DWARF;
      - gdb.texinfo: Add a paragraph to explain that this option only
        supports DWARF.

If you guys don't think it's a good idea, then I'll understand
(hence the RFC).  At least we'll have it in the archives, in case
someone else wants it.

gdb/ChangeLog:

	Andrew Cagney  <cagney@redhat.com>
	Joel Brobecker  <brobecker@adacore.com>
	Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (readnever_symbol_files): New global.
	* top.h (readnever_symbol_files): New extern global.
	* main.c (captured_main): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* dwarf2read.c: #include "top.h".
	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.

gdb/doc/ChangeLog:

	Andrew Cagney  <cagney@redhat.com>
	Joel Brobecker  <brobecker@adacore.com>

	* gdb.texinfo (File Options): Document --readnever.

gdb/testsuite/ChangeLog:

        Joel Brobecker  <brobecker@adacore.com>
	Sergio Durigan Junior  <sergiodj@redhat.com>

        * gdb.base/readnever.c, gdb.base/readnever.exp: New files.

Tested on x86_64-linux.
---
 gdb/doc/gdb.texinfo                  |  8 ++++++
 gdb/dwarf2read.c                     |  4 +++
 gdb/main.c                           | 32 +++++++++++++++++++++---
 gdb/symfile.c                        |  1 +
 gdb/testsuite/gdb.base/readnever.c   | 39 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 47 ++++++++++++++++++++++++++++++++++++
 gdb/top.h                            |  1 +
 7 files changed, 129 insertions(+), 3 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index ab05a3718d..7d3d651185 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1037,6 +1037,14 @@ 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.
+
+This option is currently limited to debug information in DWARF format.
+For all other format, this option has no effect.
 @end table
 
 @node Mode Options
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 334d8c2e05..686fa10148 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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)
+    return 0;
+
   dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
 			objfile_data (objfile, dwarf2_objfile_data_key));
   if (!dwarf2_per_objfile)
diff --git a/gdb/main.c b/gdb/main.c
index 61168faf50..3ca64f48ef 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -579,14 +579,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 +812,26 @@ captured_main_1 (struct captured_main_args *context)
 	    }
 	    break;
 
+	  case OPT_READNOW:
+	    {
+	      if (readnever_symbol_files)
+		error (_("%s: '--readnow' and '--readnever' cannot be "
+			 "specified simultaneously"),
+		       gdb_program_name);
+	      readnow_symbol_files = 1;
+	    }
+	    break;
+
+	  case OPT_READNEVER:
+	    {
+	      if (readnow_symbol_files)
+		error (_("%s: '--readnow' and '--readnever' cannot be "
+			 "specified simultaneously"),
+		       gdb_program_name);
+	      readnever_symbol_files = 1;
+	    }
+	    break;
+
 	  case '?':
 	    error (_("Use `%s --help' for a complete list of options."),
 		   gdb_program_name);
@@ -1183,6 +1206,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 (_("\
diff --git a/gdb/symfile.c b/gdb/symfile.c
index feb50f8b79..14d3d8a6da 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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.  */
 
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000000..803a5542f9
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -0,0 +1,39 @@
+/* Copyright 2016 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/>.  */
+
+void
+fun_three (void)
+{
+  /* Do nothing.  */
+}
+
+void
+fun_two (void)
+{
+  fun_three ();
+}
+
+void
+fun_one (void)
+{
+  fun_two ();
+}
+
+int
+main (void)
+{
+  fun_one ();
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000000..24220f85c6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -0,0 +1,47 @@
+# Copyright 2016 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/>.
+
+# This file is part of the gdb testsuite.  It is intended to test that
+# gdb can correctly print arrays with indexes for each element of the
+# array.
+
+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 \\(\\)" ]
diff --git a/gdb/top.h b/gdb/top.h
index 26fe87842f..a1df64f383 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -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 *);
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23  0:54     ` [PATCH v2] " Sergio Durigan Junior
@ 2017-11-23 12:09       ` Pedro Alves
  2017-11-23 17:21         ` Sergio Durigan Junior
  2017-11-23 15:59       ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-23 12:09 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On 11/23/2017 12:54 AM, Sergio Durigan Junior wrote:
> [ Reviving the thread.  ]
> 
> Hey there,
> 
> So, since I'm working on upstreaming most of the patches we carry on
> Fedora GDB, this one caught my attention (thanks to Pedro for bringing
> this to me).
> 
> I applied it to a local tree, did some tests and adjustments (see
> below), and now I'm resubmitting it for another set of reviews.
> 
> I hope we can get it pushed this time :-).
> 

Thanks for doing this.

> Please see comments below.

See my comments inline below.

> On Tuesday, October 04 2016, Pedro Alves wrote:

>> This predates my gdb involvement, I don't really know the history.
>> Maybe Jan knows.
>>
>> In any case, I don't object to the approach.
>>
>> Is this skipping _unwind_ info as well though?  I think the
>> documentation should be clear on that, because if it does
>> skip dwarf info for unwinding as well, then you
>> may get a faster, but incorrect backtrace.
> 
> So, I looked a bit into this, and it seems that unwind information is
> also skipped, which is unfortunate.  I am not an expert in this area of
> GDB so by all means please comment if you have more details, but here's
> the simple test I did.
> 
> I modified gdb.dwarf2/dw2-dup-frame.exp to use --readnever, and ran it.
> The tests failed, and from what I checked this is because GDB was unable
> to tell that the frame stack is corrupted (because there are two
> identical frames in it).  By doing some debugging, I noticed that
> gdb/dwarf2-frame.c:dwarf2_frame_sniffer is always returning 0 because it
> can't find any FDE's, which are found by using DWARF information that
> GDB hasn't read.

I think we should document this.

> 
> On Tuesday, October 04 2016, Pedro Alves wrote:
> 
>> On 07/06/2016 09:54 PM, Joel Brobecker wrote:
>>
>>>  #include <fcntl.h>
>>>  #include <sys/types.h>
>>> @@ -2062,6 +2063,9 @@ int
>>>  dwarf2_has_info (struct objfile *objfile,
>>>                   const struct dwarf2_debug_sections *names)
>>>  {
>>> +  if (readnever_symbol_files)
>>> +    return 0;
>>
>> Guess that means '--readnever --readnow' is the same as
>> --readnever in practice?
> 
> I've modified our main.c to detect whether --readnow and --readnever are
> given at the same time, and print an error in this case.

Sounds fine to me.

> 
>>
>>> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
>>> +    untested "Couldn't compile ${srcfile}"
>>> +    return -1
>>> +}
>>
>> Maybe use build_executable.
> 
> Done.
> 
>>> +set saved_gdbflags $GDBFLAGS
>>> +set GDBFLAGS "$GDBFLAGS --readnever"
>>> +clean_restart ${binfile}
>>> +set GDBFLAGS $saved_gdbflags
>>
>> Nowadays we have save_vars:
>>
>> save_vars { GDBFLAGS } {
>>   append GDBFLAGS " --readnever"
>>   clean_restart ${binfile}
>> }
> 
> Done.
> 
> Here's the updated patch.  I've made a few cosmetic modifications
> (s/RedHat/Red Hat/, for example) to the commit message, BTW.
> 

IMO, that commit message could/should be simplified further to
get it more to the point; there's text in there that is more
appropriate for a cover letter than for the commit log itself.
For example, the log of changes.  Also, certainly we don't
expect "git log" readers to be able to answer RFC/questions
in git logs.  :-)

On 11/23/2017 12:54 AM, Sergio Durigan Junior wrote:
> From 858798fa4ce56e05c24e86098072518950135b4f Mon Sep 17 00:00:00 2001
> From: Joel Brobecker <brobecker@adacore.com>
> Date: Wed, 6 Jul 2016 13:54:23 -0700
> Subject: [PATCH] Add support for the --readnever command-line option (DWARF
>  only)
> 
> Hello,
> 
> One of our customers asked us about this option, which they could see
> as being available in the version of GDB shipped by Red Hat but not in
> the version that AdaCore supports.
> 
> The purpose of this option is to turn the load of debugging
> information off. The implementation proposed here is mostly a copy of
> the patch distributed with Fedora, and looking at the patch itself and
> the history, I can see some reasons why it was never submitted:
> 
>   - The patch appears to have been introduced as a workaround, at
>     least initially;
>   - The patch is far from perfect, as it simply shunts the load of
>     DWARF debugging information, without really worrying about the
>     other debug format.
>   - Who really does non-symbolic debugging anyways?
> 
> 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.

I think this sentence about the use case could migrate to
the documentation.

BTW, this is missing a NEWS entry.

> 
> I started looking at a more general way of implementing this feature.
> For instance, I was hoping for a patch maybe at the objfile reader
> level, or even better at the generic part of the objfile reader.
> But it turns out this is not trivial at all.  The loading of debugging
> information appears to be done as part of either the sym_fns->sym_read
> (most cases), or during the sym_fns->sym_read_psymbols phase ("lazy
> loading", ELF). Reading the code there, it wasn't obvious to me
> what the consequence would be to add some code to ignore debugging
> information, and since I would not be able to test those changes,
> I opted towards touching only the targets that use DWARF.
> 
> This is why I ended up choosing the same approach as Red Hat.  It's
> far from perfect, but has the benefit of working for what I hope is
> the vast majority of people, and being fairly unintrusive. I thought,
> since it's useful to AdaCore, and it's been useful to Red Hat, maybe
> others might find it useful, so here it is.
> 
> The changes I made to the patch from Fedora are:
> 
>       - dwarf2_has_info: Return immediately if readnever_symbol_files
>                          is set - faster return, and easier to read, IMO;
>       - main.c: Update the --help output to mention that this feature
>                 only supports DWARF;
>       - gdb.texinfo: Add a paragraph to explain that this option only
>         supports DWARF.
> 
> If you guys don't think it's a good idea, then I'll understand
> (hence the RFC).  At least we'll have it in the archives, in case
> someone else wants it.
> 
> gdb/ChangeLog:
> 
> 	Andrew Cagney  <cagney@redhat.com>
> 	Joel Brobecker  <brobecker@adacore.com>
> 	Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* symfile.c (readnever_symbol_files): New global.
> 	* top.h (readnever_symbol_files): New extern global.
> 	* main.c (captured_main): Add support for --readnever.
> 	(print_gdb_help): Document --readnever.
> 	* dwarf2read.c: #include "top.h".
> 	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.
> 
> gdb/doc/ChangeLog:
> 
> 	Andrew Cagney  <cagney@redhat.com>
> 	Joel Brobecker  <brobecker@adacore.com>
> 
> 	* gdb.texinfo (File Options): Document --readnever.
> 
> gdb/testsuite/ChangeLog:
> 
>         Joel Brobecker  <brobecker@adacore.com>
> 	Sergio Durigan Junior  <sergiodj@redhat.com>
> 
>         * gdb.base/readnever.c, gdb.base/readnever.exp: New files.
> 
> Tested on x86_64-linux.
> ---
>  gdb/doc/gdb.texinfo                  |  8 ++++++
>  gdb/dwarf2read.c                     |  4 +++
>  gdb/main.c                           | 32 +++++++++++++++++++++---
>  gdb/symfile.c                        |  1 +
>  gdb/testsuite/gdb.base/readnever.c   | 39 ++++++++++++++++++++++++++++++
>  gdb/testsuite/gdb.base/readnever.exp | 47 ++++++++++++++++++++++++++++++++++++
>  gdb/top.h                            |  1 +
>  7 files changed, 129 insertions(+), 3 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.base/readnever.c
>  create mode 100644 gdb/testsuite/gdb.base/readnever.exp
> 
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index ab05a3718d..7d3d651185 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -1037,6 +1037,14 @@ 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.

Here I think it'd be good to say something about unwind info, mention
that backtraces may be inaccurate, or something.  For example, Fedora's
gstack used to use --readnever, but it no longer does; it relies
on .gdb_index for speed instead.

The sentence about the "attach + core" use case in the commit log
could go here, since it's the main use case -- the point being
to help users answer Joel's question "but why would I want that; who
wants non-symbolic debugging anyway?".  

So all in all, I'd suggest:

 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.


> +
> +This option is currently limited to debug information in DWARF format.
> +For all other format, this option has no effect.

How hard would it be to just make it work?  There's only stabs and mdebug
left, I think?  There should be a single a function somewhere that we can
add an early return.  And then we don't need to document this limitation...

For example, in elf_symfile_read, we could just skip the elf_locate_sections
call.  In coffread.c we could skip reading stabs right after 
  bfd_map_over_sections (abfd, coff_locate_sections....);

Looking for:

 $ grep -h "^[a-z]*_build_psymtabs" gdb/
 coffstab_build_psymtabs (struct objfile *objfile,
 elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
 stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
 mdebug_build_psymtabs (minimal_symbol_reader &reader,
 elfmdebug_build_psymtabs (struct objfile *objfile,

finds all the relevant places.

Maybe it wouldn't be that hard to make this be an objfile flag
afterall (like OBJF_READNOW is).  That'd make it possible
to add the location "-readnever" counterpart switch to add-symbol-file
too, BTW:

 symfile.c:        if (strcmp (arg, "-readnow") == 0)
 symfile.c:        else if (strcmp (arg, "-readnow") == 0)

>  @end table
>  
>  @node Mode Options
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
> index 334d8c2e05..686fa10148 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2read.c
> @@ -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)
> +    return 0;
> +
>    dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
>  			objfile_data (objfile, dwarf2_objfile_data_key));
>    if (!dwarf2_per_objfile)
> diff --git a/gdb/main.c b/gdb/main.c
> index 61168faf50..3ca64f48ef 100644
> --- a/gdb/main.c
> +++ b/gdb/main.c
> @@ -579,14 +579,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 +812,26 @@ captured_main_1 (struct captured_main_args *context)
>  	    }
>  	    break;
>  
> +	  case OPT_READNOW:
> +	    {
> +	      if (readnever_symbol_files)
> +		error (_("%s: '--readnow' and '--readnever' cannot be "
> +			 "specified simultaneously"),
> +		       gdb_program_name);
> +	      readnow_symbol_files = 1;
> +	    }
> +	    break;
> +
> +	  case OPT_READNEVER:
> +	    {
> +	      if (readnow_symbol_files)
> +		error (_("%s: '--readnow' and '--readnever' cannot be "
> +			 "specified simultaneously"),
> +		       gdb_program_name);
> +	      readnever_symbol_files = 1;

maybe move the error call to a shared function, like

static void
validate_readnow_readnever ()
{
   if (readnever_symbol_files && readnow_symbol_files)
     {
       error (_("%s: '--readnow' and '--readnever' cannot be "
  	       "specified simultaneously"),
               gdb_program_name);
      }
}

and then:

  case OPT_READNOW:
      readnow_symbol_files = 1;
      validate_readnow_readnever ();
      break;
  case OPT_READNEVER:
      readnever_symbol_files = 1;
      validate_readnow_readnever ();
      break;


> diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
> new file mode 100644
> index 0000000000..803a5542f9
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/readnever.c
> @@ -0,0 +1,39 @@
> +/* Copyright 2016 Free Software Foundation, Inc.

2016-2017

> +
> +   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/>.  */
> +
> +void
> +fun_three (void)
> +{
> +  /* Do nothing.  */
> +}
> +
> +void
> +fun_two (void)
> +{
> +  fun_three ();
> +}
> +
> +void
> +fun_one (void)
> +{
> +  fun_two ();
> +}
> +
> +int
> +main (void)
> +{
> +  fun_one ();
> +  return 0;
> +}
> diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
> new file mode 100644
> index 0000000000..24220f85c6
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/readnever.exp
> @@ -0,0 +1,47 @@
> +# Copyright 2016 Free Software Foundation, Inc.

Ditto.

> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +# This file is part of the gdb testsuite.  It is intended to test that
> +# gdb can correctly print arrays with indexes for each element of the
> +# array.

No it isn't.

> +
> +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}
> +}

I wonder, can we add tests ensuring that --readnever --readnow
errors out?  I think you can use gdb_test_multiple, expect the
error output, and then expect eof {}, meaning GDB exited.  Not
sure we have any testcase that tests invalid command line
options...  (we should!)

> +
> +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 \\(\\)" ]

It doesn't look like this testcase is actually testing
that --readnever actually worked as intended?  If GDB loads
debug info, then GDB shows the arguments.  Otherwise it
shows "()" like above.  But it also shows "()" if the function
is "(void)".  How about adding some non-void parameters to
the functions?  

Could also try printing some local variable and expect
an error.  

And also:

  gdb_test_no_output "maint info symtabs"
  gdb_test_no_output "maint info psymtabs"

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23  0:54     ` [PATCH v2] " Sergio Durigan Junior
  2017-11-23 12:09       ` Pedro Alves
@ 2017-11-23 15:59       ` Eli Zaretskii
  2017-11-23 19:36         ` Sergio Durigan Junior
  1 sibling, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2017-11-23 15:59 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: palves, qiyaoltc, brobecker, gdb-patches

> From: Sergio Durigan Junior <sergiodj@redhat.com>
> Cc: Yao Qi <qiyaoltc@gmail.com>,  Joel Brobecker <brobecker@adacore.com>,  "gdb-patches\@sourceware.org" <gdb-patches@sourceware.org>
> Date: Wed, 22 Nov 2017 19:54:53 -0500
> 
>   - The patch appears to have been introduced as a workaround, at
>     least initially;
>   - The patch is far from perfect, as it simply shunts the load of
>     DWARF debugging information, without really worrying about the
>     other debug format.
>   - Who really does non-symbolic debugging anyways?
> 
> 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.

This use case should be mentioned in the manual.  And I think if we
want to accept a patch that is DWARF specific, the name of the option
should reflect that; --readnever sounds misleading to me.

(Another possibility would be to have a "maint dwarf" command to do
the same; maybe it's better.)

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index ab05a3718d..7d3d651185 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -1037,6 +1037,14 @@ 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.
> +
> +This option is currently limited to debug information in DWARF format.
> +For all other format, this option has no effect.
   ^^^^^^^^^^^^^^^^^^^^
"For the others formats"

And I think we need a NEWS entry for this new feature.

Thanks.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23 12:09       ` Pedro Alves
@ 2017-11-23 17:21         ` Sergio Durigan Junior
  2017-11-23 17:29           ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-23 17:21 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On Thursday, November 23 2017, Pedro Alves wrote:

> On 11/23/2017 12:54 AM, Sergio Durigan Junior wrote:
>> [ Reviving the thread.  ]
>> 
>> Hey there,
>> 
>> So, since I'm working on upstreaming most of the patches we carry on
>> Fedora GDB, this one caught my attention (thanks to Pedro for bringing
>> this to me).
>> 
>> I applied it to a local tree, did some tests and adjustments (see
>> below), and now I'm resubmitting it for another set of reviews.
>> 
>> I hope we can get it pushed this time :-).
>> 
>
> Thanks for doing this.
>
>> Please see comments below.
>
> See my comments inline below.
>
>> On Tuesday, October 04 2016, Pedro Alves wrote:
>
>>> This predates my gdb involvement, I don't really know the history.
>>> Maybe Jan knows.
>>>
>>> In any case, I don't object to the approach.
>>>
>>> Is this skipping _unwind_ info as well though?  I think the
>>> documentation should be clear on that, because if it does
>>> skip dwarf info for unwinding as well, then you
>>> may get a faster, but incorrect backtrace.
>> 
>> So, I looked a bit into this, and it seems that unwind information is
>> also skipped, which is unfortunate.  I am not an expert in this area of
>> GDB so by all means please comment if you have more details, but here's
>> the simple test I did.
>> 
>> I modified gdb.dwarf2/dw2-dup-frame.exp to use --readnever, and ran it.
>> The tests failed, and from what I checked this is because GDB was unable
>> to tell that the frame stack is corrupted (because there are two
>> identical frames in it).  By doing some debugging, I noticed that
>> gdb/dwarf2-frame.c:dwarf2_frame_sniffer is always returning 0 because it
>> can't find any FDE's, which are found by using DWARF information that
>> GDB hasn't read.
>
> I think we should document this.

Yeah.  I will write something about it in the documentation.

WDYT of this?

  Due to the fact that @value{GDBN} uses DWARF information to perform
  frame unwinding, an unfortunate side effect of @code{--readnever} is
  to make backtrace information unreliable.

... after reading the rest of the e-mail...

Ops, I see you already proposed a text below.  I used your version,
then.

> [...]
>>>> +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
>>>> +    untested "Couldn't compile ${srcfile}"
>>>> +    return -1
>>>> +}
>>>
>>> Maybe use build_executable.
>> 
>> Done.
>> 
>>>> +set saved_gdbflags $GDBFLAGS
>>>> +set GDBFLAGS "$GDBFLAGS --readnever"
>>>> +clean_restart ${binfile}
>>>> +set GDBFLAGS $saved_gdbflags
>>>
>>> Nowadays we have save_vars:
>>>
>>> save_vars { GDBFLAGS } {
>>>   append GDBFLAGS " --readnever"
>>>   clean_restart ${binfile}
>>> }
>> 
>> Done.
>> 
>> Here's the updated patch.  I've made a few cosmetic modifications
>> (s/RedHat/Red Hat/, for example) to the commit message, BTW.
>> 
>
> IMO, that commit message could/should be simplified further to
> get it more to the point; there's text in there that is more
> appropriate for a cover letter than for the commit log itself.
> For example, the log of changes.  Also, certainly we don't
> expect "git log" readers to be able to answer RFC/questions
> in git logs.  :-)

Sure thing.  I was going to remove the parts about RFC (and also the
part about the "customer request") later, but thanks for pointing it
out.

>
> On 11/23/2017 12:54 AM, Sergio Durigan Junior wrote:
>> From 858798fa4ce56e05c24e86098072518950135b4f Mon Sep 17 00:00:00 2001
>> From: Joel Brobecker <brobecker@adacore.com>
>> Date: Wed, 6 Jul 2016 13:54:23 -0700
>> Subject: [PATCH] Add support for the --readnever command-line option (DWARF
>>  only)
>> 
>> Hello,
>> 
>> One of our customers asked us about this option, which they could see
>> as being available in the version of GDB shipped by Red Hat but not in
>> the version that AdaCore supports.
>> 
>> The purpose of this option is to turn the load of debugging
>> information off. The implementation proposed here is mostly a copy of
>> the patch distributed with Fedora, and looking at the patch itself and
>> the history, I can see some reasons why it was never submitted:
>> 
>>   - The patch appears to have been introduced as a workaround, at
>>     least initially;
>>   - The patch is far from perfect, as it simply shunts the load of
>>     DWARF debugging information, without really worrying about the
>>     other debug format.
>>   - Who really does non-symbolic debugging anyways?
>> 
>> 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.
>
> I think this sentence about the use case could migrate to
> the documentation.

Done.

> BTW, this is missing a NEWS entry.

Done.

>> I started looking at a more general way of implementing this feature.
>> For instance, I was hoping for a patch maybe at the objfile reader
>> level, or even better at the generic part of the objfile reader.
>> But it turns out this is not trivial at all.  The loading of debugging
>> information appears to be done as part of either the sym_fns->sym_read
>> (most cases), or during the sym_fns->sym_read_psymbols phase ("lazy
>> loading", ELF). Reading the code there, it wasn't obvious to me
>> what the consequence would be to add some code to ignore debugging
>> information, and since I would not be able to test those changes,
>> I opted towards touching only the targets that use DWARF.
>> 
>> This is why I ended up choosing the same approach as Red Hat.  It's
>> far from perfect, but has the benefit of working for what I hope is
>> the vast majority of people, and being fairly unintrusive. I thought,
>> since it's useful to AdaCore, and it's been useful to Red Hat, maybe
>> others might find it useful, so here it is.
>> 
>> The changes I made to the patch from Fedora are:
>> 
>>       - dwarf2_has_info: Return immediately if readnever_symbol_files
>>                          is set - faster return, and easier to read, IMO;
>>       - main.c: Update the --help output to mention that this feature
>>                 only supports DWARF;
>>       - gdb.texinfo: Add a paragraph to explain that this option only
>>         supports DWARF.
>> 
>> If you guys don't think it's a good idea, then I'll understand
>> (hence the RFC).  At least we'll have it in the archives, in case
>> someone else wants it.
>> 
>> gdb/ChangeLog:
>> 
>> 	Andrew Cagney  <cagney@redhat.com>
>> 	Joel Brobecker  <brobecker@adacore.com>
>> 	Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* symfile.c (readnever_symbol_files): New global.
>> 	* top.h (readnever_symbol_files): New extern global.
>> 	* main.c (captured_main): Add support for --readnever.
>> 	(print_gdb_help): Document --readnever.
>> 	* dwarf2read.c: #include "top.h".
>> 	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.
>> 
>> gdb/doc/ChangeLog:
>> 
>> 	Andrew Cagney  <cagney@redhat.com>
>> 	Joel Brobecker  <brobecker@adacore.com>
>> 
>> 	* gdb.texinfo (File Options): Document --readnever.
>> 
>> gdb/testsuite/ChangeLog:
>> 
>>         Joel Brobecker  <brobecker@adacore.com>
>> 	Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>>         * gdb.base/readnever.c, gdb.base/readnever.exp: New files.
>> 
>> Tested on x86_64-linux.
>> ---
>>  gdb/doc/gdb.texinfo                  |  8 ++++++
>>  gdb/dwarf2read.c                     |  4 +++
>>  gdb/main.c                           | 32 +++++++++++++++++++++---
>>  gdb/symfile.c                        |  1 +
>>  gdb/testsuite/gdb.base/readnever.c   | 39 ++++++++++++++++++++++++++++++
>>  gdb/testsuite/gdb.base/readnever.exp | 47 ++++++++++++++++++++++++++++++++++++
>>  gdb/top.h                            |  1 +
>>  7 files changed, 129 insertions(+), 3 deletions(-)
>>  create mode 100644 gdb/testsuite/gdb.base/readnever.c
>>  create mode 100644 gdb/testsuite/gdb.base/readnever.exp
>> 
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index ab05a3718d..7d3d651185 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -1037,6 +1037,14 @@ 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.
>
> Here I think it'd be good to say something about unwind info, mention
> that backtraces may be inaccurate, or something.  For example, Fedora's
> gstack used to use --readnever, but it no longer does; it relies
> on .gdb_index for speed instead.
>
> The sentence about the "attach + core" use case in the commit log
> could go here, since it's the main use case -- the point being
> to help users answer Joel's question "but why would I want that; who
> wants non-symbolic debugging anyway?".  
>
> So all in all, I'd suggest:
>
>  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.

Cool, I used this version, thanks.

>> +
>> +This option is currently limited to debug information in DWARF format.
>> +For all other format, this option has no effect.
>
> How hard would it be to just make it work?  There's only stabs and mdebug
> left, I think?  There should be a single a function somewhere that we can
> add an early return.  And then we don't need to document this limitation...
>
> For example, in elf_symfile_read, we could just skip the elf_locate_sections
> call.  In coffread.c we could skip reading stabs right after 
>   bfd_map_over_sections (abfd, coff_locate_sections....);
>
> Looking for:
>
>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>  coffstab_build_psymtabs (struct objfile *objfile,
>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>  elfmdebug_build_psymtabs (struct objfile *objfile,
>
> finds all the relevant places.
>
> Maybe it wouldn't be that hard to make this be an objfile flag
> afterall (like OBJF_READNOW is).  That'd make it possible
> to add the location "-readnever" counterpart switch to add-symbol-file
> too, BTW:
>
>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)

Hm, I'll look into this.  Just to make it clear: the idea is to have
both a --readnever global option and also a OBJF_READNEVER specific to
each objfile?

>>  @end table
>>  
>>  @node Mode Options
>> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
>> index 334d8c2e05..686fa10148 100644
>> --- a/gdb/dwarf2read.c
>> +++ b/gdb/dwarf2read.c
>> @@ -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)
>> +    return 0;
>> +
>>    dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
>>  			objfile_data (objfile, dwarf2_objfile_data_key));
>>    if (!dwarf2_per_objfile)
>> diff --git a/gdb/main.c b/gdb/main.c
>> index 61168faf50..3ca64f48ef 100644
>> --- a/gdb/main.c
>> +++ b/gdb/main.c
>> @@ -579,14 +579,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 +812,26 @@ captured_main_1 (struct captured_main_args *context)
>>  	    }
>>  	    break;
>>  
>> +	  case OPT_READNOW:
>> +	    {
>> +	      if (readnever_symbol_files)
>> +		error (_("%s: '--readnow' and '--readnever' cannot be "
>> +			 "specified simultaneously"),
>> +		       gdb_program_name);
>> +	      readnow_symbol_files = 1;
>> +	    }
>> +	    break;
>> +
>> +	  case OPT_READNEVER:
>> +	    {
>> +	      if (readnow_symbol_files)
>> +		error (_("%s: '--readnow' and '--readnever' cannot be "
>> +			 "specified simultaneously"),
>> +		       gdb_program_name);
>> +	      readnever_symbol_files = 1;
>
> maybe move the error call to a shared function, like
>
> static void
> validate_readnow_readnever ()
> {
>    if (readnever_symbol_files && readnow_symbol_files)
>      {
>        error (_("%s: '--readnow' and '--readnever' cannot be "
>   	       "specified simultaneously"),
>                gdb_program_name);
>       }
> }
>
> and then:
>
>   case OPT_READNOW:
>       readnow_symbol_files = 1;
>       validate_readnow_readnever ();
>       break;
>   case OPT_READNEVER:
>       readnever_symbol_files = 1;
>       validate_readnow_readnever ();
>       break;

I had a previous version of the patch that did a similar thing ;-).
Anyway, consider it done.

>
>> diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
>> new file mode 100644
>> index 0000000000..803a5542f9
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.base/readnever.c
>> @@ -0,0 +1,39 @@
>> +/* Copyright 2016 Free Software Foundation, Inc.
>
> 2016-2017

Fixed.

>> +
>> +   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/>.  */
>> +
>> +void
>> +fun_three (void)
>> +{
>> +  /* Do nothing.  */
>> +}
>> +
>> +void
>> +fun_two (void)
>> +{
>> +  fun_three ();
>> +}
>> +
>> +void
>> +fun_one (void)
>> +{
>> +  fun_two ();
>> +}
>> +
>> +int
>> +main (void)
>> +{
>> +  fun_one ();
>> +  return 0;
>> +}
>> diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
>> new file mode 100644
>> index 0000000000..24220f85c6
>> --- /dev/null
>> +++ b/gdb/testsuite/gdb.base/readnever.exp
>> @@ -0,0 +1,47 @@
>> +# Copyright 2016 Free Software Foundation, Inc.
>
> Ditto.

Done.

>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
>> +
>> +# This file is part of the gdb testsuite.  It is intended to test that
>> +# gdb can correctly print arrays with indexes for each element of the
>> +# array.
>
> No it isn't.

Removed.

>> +
>> +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}
>> +}
>
> I wonder, can we add tests ensuring that --readnever --readnow
> errors out?  I think you can use gdb_test_multiple, expect the
> error output, and then expect eof {}, meaning GDB exited.  Not
> sure we have any testcase that tests invalid command line
> options...  (we should!)

I'll give it a try.

>> +
>> +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 \\(\\)" ]
>
> It doesn't look like this testcase is actually testing
> that --readnever actually worked as intended?  If GDB loads
> debug info, then GDB shows the arguments.  Otherwise it
> shows "()" like above.  But it also shows "()" if the function
> is "(void)".  How about adding some non-void parameters to
> the functions?

Hm, I guess you're right.  It didn't catch my attention at first, but
now it seems strange that we're testing things with functions that don't
receive arguments.  I'll improve it.

> Could also try printing some local variable and expect
> an error.  
>
> And also:
>
>   gdb_test_no_output "maint info symtabs"
>   gdb_test_no_output "maint info psymtabs"

Will do.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23 17:21         ` Sergio Durigan Junior
@ 2017-11-23 17:29           ` Pedro Alves
  2017-11-24  4:54             ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-23 17:29 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:

>>> +This option is currently limited to debug information in DWARF format.
>>> +For all other format, this option has no effect.
>>
>> How hard would it be to just make it work?  There's only stabs and mdebug
>> left, I think?  There should be a single a function somewhere that we can
>> add an early return.  And then we don't need to document this limitation...
>>
>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>> call.  In coffread.c we could skip reading stabs right after 
>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>
>> Looking for:
>>
>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>  coffstab_build_psymtabs (struct objfile *objfile,
>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>
>> finds all the relevant places.
>>
>> Maybe it wouldn't be that hard to make this be an objfile flag
>> afterall (like OBJF_READNOW is).  That'd make it possible
>> to add the location "-readnever" counterpart switch to add-symbol-file
>> too, BTW:

I meant "logical" instead of "location".  I was staring at
gdb/location.c at that time.  :-P

>>
>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
> 
> Hm, I'll look into this.  Just to make it clear: the idea is to have
> both a --readnever global option and also a OBJF_READNEVER specific to
> each objfile?

Sure, the idea is to do something similar to what's done for --readnow.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23 15:59       ` Eli Zaretskii
@ 2017-11-23 19:36         ` Sergio Durigan Junior
  0 siblings, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-23 19:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: palves, qiyaoltc, brobecker, gdb-patches

On Thursday, November 23 2017, Eli Zaretskii wrote:

>> From: Sergio Durigan Junior <sergiodj@redhat.com>
>> Cc: Yao Qi <qiyaoltc@gmail.com>,  Joel Brobecker <brobecker@adacore.com>,  "gdb-patches\@sourceware.org" <gdb-patches@sourceware.org>
>> Date: Wed, 22 Nov 2017 19:54:53 -0500
>> 
>>   - The patch appears to have been introduced as a workaround, at
>>     least initially;
>>   - The patch is far from perfect, as it simply shunts the load of
>>     DWARF debugging information, without really worrying about the
>>     other debug format.
>>   - Who really does non-symbolic debugging anyways?
>> 
>> 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.
>
> This use case should be mentioned in the manual.  And I think if we
> want to accept a patch that is DWARF specific, the name of the option
> should reflect that; --readnever sounds misleading to me.
>
> (Another possibility would be to have a "maint dwarf" command to do
> the same; maybe it's better.)

Thanks for the review, Eli.

According to Pedro's comments, I am working on the patch to make the
feature available to other backends as well, so parts of the text will
be changed.

As for the use case, I've included it in the manual, as per Pedro's
suggestion.

>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index ab05a3718d..7d3d651185 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -1037,6 +1037,14 @@ 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.
>> +
>> +This option is currently limited to debug information in DWARF format.
>> +For all other format, this option has no effect.
>    ^^^^^^^^^^^^^^^^^^^^
> "For the others formats"

Thanks; this part will most likely change due to the extension of the
feature to the other backends.

> And I think we need a NEWS entry for this new feature.

Already added it.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-23 17:29           ` Pedro Alves
@ 2017-11-24  4:54             ` Sergio Durigan Junior
  2017-11-24 13:18               ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-24  4:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On Thursday, November 23 2017, Pedro Alves wrote:

> On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:
>
>>>> +This option is currently limited to debug information in DWARF format.
>>>> +For all other format, this option has no effect.
>>>
>>> How hard would it be to just make it work?  There's only stabs and mdebug
>>> left, I think?  There should be a single a function somewhere that we can
>>> add an early return.  And then we don't need to document this limitation...
>>>
>>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>>> call.  In coffread.c we could skip reading stabs right after 
>>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>>
>>> Looking for:
>>>
>>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>>  coffstab_build_psymtabs (struct objfile *objfile,
>>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>>
>>> finds all the relevant places.
>>>
>>> Maybe it wouldn't be that hard to make this be an objfile flag
>>> afterall (like OBJF_READNOW is).  That'd make it possible
>>> to add the location "-readnever" counterpart switch to add-symbol-file
>>> too, BTW:
>
> I meant "logical" instead of "location".  I was staring at
> gdb/location.c at that time.  :-P
>
>>>
>>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
>> 
>> Hm, I'll look into this.  Just to make it clear: the idea is to have
>> both a --readnever global option and also a OBJF_READNEVER specific to
>> each objfile?
>
> Sure, the idea is to do something similar to what's done for --readnow.

Sorry, but I guess I need a few more details on this.

The way I understand the code at elf_symfile_read, the very first thing
to do would be to check if OBJF_READNEVER is set and return early if it
is.  But it seems that you're proposing something a bit different when
you say that we should "... just skip the elf_locate_sections call."  It
doesn't seem to me that is worth continuing on that function if
OBJF_READNEVER is present.

As for the *_build_psymtabs functions, I am doing exactly that: if
objfile->flags contains OBJF_READNEVER, then just return and do nothing.

The patch is almost ready for resubmission (well, I still need to figure
out how to test the --readnow && --readnever scenario), but I want to
make sure I got this part right.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-24  4:54             ` Sergio Durigan Junior
@ 2017-11-24 13:18               ` Pedro Alves
  2017-11-24 20:27                 ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-24 13:18 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Yao Qi, Joel Brobecker, gdb-patches


On 11/24/2017 04:54 AM, Sergio Durigan Junior wrote:
> On Thursday, November 23 2017, Pedro Alves wrote:
> 
>> On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:
>>
>>>>> +This option is currently limited to debug information in DWARF format.
>>>>> +For all other format, this option has no effect.
>>>>
>>>> How hard would it be to just make it work?  There's only stabs and mdebug
>>>> left, I think?  There should be a single a function somewhere that we can
>>>> add an early return.  And then we don't need to document this limitation...
>>>>
>>>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>>>> call.  In coffread.c we could skip reading stabs right after 
>>>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>>>
>>>> Looking for:
>>>>
>>>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>>>  coffstab_build_psymtabs (struct objfile *objfile,
>>>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>>>
>>>> finds all the relevant places.
>>>>
>>>> Maybe it wouldn't be that hard to make this be an objfile flag
>>>> afterall (like OBJF_READNOW is).  That'd make it possible
>>>> to add the location "-readnever" counterpart switch to add-symbol-file
>>>> too, BTW:
>>
>> I meant "logical" instead of "location".  I was staring at
>> gdb/location.c at that time.  :-P
>>
>>>>
>>>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
>>>
>>> Hm, I'll look into this.  Just to make it clear: the idea is to have
>>> both a --readnever global option and also a OBJF_READNEVER specific to
>>> each objfile?
>>
>> Sure, the idea is to do something similar to what's done for --readnow.
> 
> Sorry, but I guess I need a few more details on this.
> 
> The way I understand the code at elf_symfile_read, the very first thing
> to do would be to check if OBJF_READNEVER is set and return early if it
> is.  But it seems that you're proposing something a bit different when
> you say that we should "... just skip the elf_locate_sections call."  It
> doesn't seem to me that is worth continuing on that function if
> OBJF_READNEVER is present.

No, you can't return early the very first thing, because
 --readnever is supposed to skip _debug_ info, not ELF/minimal symbols...
So the "return early" would have to be _after_ the
elf_read_minimal_symbols call:

 static void
 elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 {
   bfd *abfd = objfile->obfd;
   struct elfinfo ei;

   memset ((char *) &ei, 0, sizeof (ei));
   bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
 
   elf_read_minimal_symbols (objfile, symfile_flags, &ei);

I don't know whether we can reorder that.  Maybe we can.

When I looked at this quickly yesterday, I saw that elf_location_sections
is what finds the stabs and mdebug sections:

static void
elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
{
  struct elfinfo *ei;

  ei = (struct elfinfo *) eip;
  if (strcmp (sectp->name, ".stab") == 0)
    {
      ei->stabsect = sectp;
    }
  else if (strcmp (sectp->name, ".mdebug") == 0)
    {
      ei->mdebugsect = sectp;
    }
}

and it seemed to be that skipping the section location would make
the parts of  elf_symfile_read that actually read the symbols
be no-ops, because the stabsect/mdebusect pointers would be NULL.

But if returning early or something else works, that's fine.

> 
> As for the *_build_psymtabs functions, I am doing exactly that: if
> objfile->flags contains OBJF_READNEVER, then just return and do nothing.

Sure, that should work too.  It's just the difference between
skipping checking whether debug info is available (skipping before
calling into those), vs letting gdb do the work to figure out whether
debug info is available, but then ignore it.
The grep for "*_build_psymtabs" was intended as a pointer to find
what the relevant code is, including to look at the code that
is calling those functions, see if there's something to be done there.

> 
> The patch is almost ready for resubmission (well, I still need to figure
> out how to test the --readnow && --readnever scenario), but I want to
> make sure I got this part right.
> 

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-24 13:18               ` Pedro Alves
@ 2017-11-24 20:27                 ` Sergio Durigan Junior
  2017-11-27 19:13                   ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-24 20:27 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On Friday, November 24 2017, Pedro Alves wrote:

> On 11/24/2017 04:54 AM, Sergio Durigan Junior wrote:
>> On Thursday, November 23 2017, Pedro Alves wrote:
>> 
>>> On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:
>>>
>>>>>> +This option is currently limited to debug information in DWARF format.
>>>>>> +For all other format, this option has no effect.
>>>>>
>>>>> How hard would it be to just make it work?  There's only stabs and mdebug
>>>>> left, I think?  There should be a single a function somewhere that we can
>>>>> add an early return.  And then we don't need to document this limitation...
>>>>>
>>>>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>>>>> call.  In coffread.c we could skip reading stabs right after 
>>>>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>>>>
>>>>> Looking for:
>>>>>
>>>>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>>>>  coffstab_build_psymtabs (struct objfile *objfile,
>>>>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>>>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>>>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>>>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>>>>
>>>>> finds all the relevant places.
>>>>>
>>>>> Maybe it wouldn't be that hard to make this be an objfile flag
>>>>> afterall (like OBJF_READNOW is).  That'd make it possible
>>>>> to add the location "-readnever" counterpart switch to add-symbol-file
>>>>> too, BTW:
>>>
>>> I meant "logical" instead of "location".  I was staring at
>>> gdb/location.c at that time.  :-P
>>>
>>>>>
>>>>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>>>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
>>>>
>>>> Hm, I'll look into this.  Just to make it clear: the idea is to have
>>>> both a --readnever global option and also a OBJF_READNEVER specific to
>>>> each objfile?
>>>
>>> Sure, the idea is to do something similar to what's done for --readnow.
>> 
>> Sorry, but I guess I need a few more details on this.
>> 
>> The way I understand the code at elf_symfile_read, the very first thing
>> to do would be to check if OBJF_READNEVER is set and return early if it
>> is.  But it seems that you're proposing something a bit different when
>> you say that we should "... just skip the elf_locate_sections call."  It
>> doesn't seem to me that is worth continuing on that function if
>> OBJF_READNEVER is present.
>
> No, you can't return early the very first thing, because
>  --readnever is supposed to skip _debug_ info, not ELF/minimal symbols...
> So the "return early" would have to be _after_ the
> elf_read_minimal_symbols call:

Hm, OK, it makes sense and I confess I thought "why is Pedro mentioning
elf_symfile_read if the feature is about skipping DWARF, not ELF?".

>  static void
>  elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>  {
>    bfd *abfd = objfile->obfd;
>    struct elfinfo ei;
>
>    memset ((char *) &ei, 0, sizeof (ei));
>    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
>  
>    elf_read_minimal_symbols (objfile, symfile_flags, &ei);
>
> I don't know whether we can reorder that.  Maybe we can.
>
> When I looked at this quickly yesterday, I saw that elf_location_sections
> is what finds the stabs and mdebug sections:
>
> static void
> elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
> {
>   struct elfinfo *ei;
>
>   ei = (struct elfinfo *) eip;
>   if (strcmp (sectp->name, ".stab") == 0)
>     {
>       ei->stabsect = sectp;
>     }
>   else if (strcmp (sectp->name, ".mdebug") == 0)
>     {
>       ei->mdebugsect = sectp;
>     }
> }
>
> and it seemed to be that skipping the section location would make
> the parts of  elf_symfile_read that actually read the symbols
> be no-ops, because the stabsect/mdebusect pointers would be NULL.
>
> But if returning early or something else works, that's fine.

OK, thanks for clarifying.

>> As for the *_build_psymtabs functions, I am doing exactly that: if
>> objfile->flags contains OBJF_READNEVER, then just return and do nothing.
>
> Sure, that should work too.  It's just the difference between
> skipping checking whether debug info is available (skipping before
> calling into those), vs letting gdb do the work to figure out whether
> debug info is available, but then ignore it.
> The grep for "*_build_psymtabs" was intended as a pointer to find
> what the relevant code is, including to look at the code that
> is calling those functions, see if there's something to be done there.

I think it makes more sense, logically speaking, to not mess with
elf_symfile_read and instead modify the *_build_psymtabs functions.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v2] Add support for the --readnever command-line option
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
  2016-07-12 14:27 ` Yao Qi
  2016-10-04 18:06 ` [RFC/RFA] " Pedro Alves
@ 2017-11-24 23:01 ` Sergio Durigan Junior
  2017-11-25  7:33   ` Eli Zaretskii
  2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-24 23:01 UTC (permalink / raw)
  To: GDB Patches
  Cc: Joel Brobecker, Yao Qi, Pedro Alves, Eli Zaretskii,
	Sergio Durigan Junior

The purpose of this option is to turn the load of debugging
information off. The implementation proposed here is an extensio of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature 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.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

While implementing the code for the 'symbol-file' command, I noticed a
bug in 'symbol_file_command': GDB adds the symbol file before
finishing parsing all the options, which means that the position of an
option in the command impacts whether it will be considered or not.  I
changed the code there in order to only add the symbol file after all
options have been parsed.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.  We didn't have any infrastructure to test that, so I added a
new version of 'gdb_spawn', called 'gdb_spawn_ignore_error', which can
be used to start a GDB that will fail without compromising the entire
testcase.

Tested on the BuildBot.

gdb/ChangeLog:

2017-11-24  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* dbxread.c: Include 'top.h'.
	(coffstab_build_psymtabs): Return early if we shouldn't read
	symbols.
	(elfstab_build_psymtabs): Likewise.
	(stabsect_build_psymtabs): Likewise.
	* dwarf2read.c: Include "top.h".
	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* mdebugread.c: Include 'top.h'.
	(mdebug_build_psymtabs): Return early if we shouldn't read
	symbols.
	(elfmdebug_build_psymtabs): Likewise.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.  Move call
	to 'symbol_file_add_main_1' out of the argument parsing loop.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Document it.  Call 'validate_readnow_readnever'.
	* top.h (readnever_symbol_files): New extern global.

gdb/doc/ChangeLog:

2017-11-24  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file'.

gdb/testsuite/ChangeLog:

2017-11-24  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
	* lib/gdb.exp (default_gdb_spawn): Add 'ignore_error'
	parameter.  Handle case when 'ignore_error' is set.
	(gdb_spawn_ignore_error): New function.
---
 gdb/NEWS                             |  4 ++
 gdb/dbxread.c                        | 10 +++++
 gdb/doc/gdb.texinfo                  | 17 ++++++++
 gdb/dwarf2read.c                     |  4 ++
 gdb/main.c                           | 39 ++++++++++++++++--
 gdb/mdebugread.c                     |  7 ++++
 gdb/objfile-flags.h                  |  4 ++
 gdb/symfile.c                        | 33 +++++++++++++---
 gdb/testsuite/gdb.base/readnever.c   | 43 ++++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 77 ++++++++++++++++++++++++++++++++++++
 gdb/testsuite/lib/gdb.exp            | 18 ++++++---
 gdb/top.h                            |  1 +
 12 files changed, 244 insertions(+), 13 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

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.
+
 * 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
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 697aa6e8ed..74f0df1a58 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -57,6 +57,7 @@
 #include "aout/aout64.h"
 #include "aout/stab_gnu.h"	/* We always use GNU stabs, not
 				   native, now.  */
+#include "top.h"
 \f
 
 /* 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);
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.
+
 @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
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 334d8c2e05..0975d2bbe2 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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)
diff --git a/gdb/main.c b/gdb/main.c
index 61168faf50..2e23c1bf19 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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 (_("\
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index debf46dc61..b3b8eb98cb 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -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;
 
diff --git a/gdb/objfile-flags.h b/gdb/objfile-flags.h
index 43ba8aaefd..f2a2ccfa8c 100644
--- a/gdb/objfile-flags.h
+++ b/gdb/objfile-flags.h
@@ -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);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index feb50f8b79..4c0d207da6 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000000..7b2fe1cae4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -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;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000000..a6d48db9b6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -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"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8d6972ab1f..6a6326344a 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -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 } {
diff --git a/gdb/top.h b/gdb/top.h
index 26fe87842f..a1df64f383 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -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 *);
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option
  2017-11-24 23:01 ` [PATCH v2] Add support for the --readnever command-line option Sergio Durigan Junior
@ 2017-11-25  7:33   ` Eli Zaretskii
  2017-11-25 16:41     ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Eli Zaretskii @ 2017-11-25  7:33 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches, brobecker, qiyaoltc, palves

> 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.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option
  2017-11-25  7:33   ` Eli Zaretskii
@ 2017-11-25 16:41     ` Sergio Durigan Junior
  2017-11-25 17:16       ` Eli Zaretskii
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-25 16:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches, brobecker, qiyaoltc, palves

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,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option
  2017-11-25 16:41     ` Sergio Durigan Junior
@ 2017-11-25 17:16       ` Eli Zaretskii
  0 siblings, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2017-11-25 17:16 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches, brobecker, qiyaoltc, palves

> From: Sergio Durigan Junior <sergiodj@redhat.com>
> Cc: gdb-patches@sourceware.org,  brobecker@adacore.com,  qiyaoltc@gmail.com,  palves@redhat.com
> Date: Sat, 25 Nov 2017 11:41:04 -0500
> 
> > 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?

Yes, definitely.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-24 20:27                 ` Sergio Durigan Junior
@ 2017-11-27 19:13                   ` Pedro Alves
  2017-11-29  0:59                     ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-27 19:13 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On 11/24/2017 08:26 PM, Sergio Durigan Junior wrote:
> On Friday, November 24 2017, Pedro Alves wrote:
> 
>> On 11/24/2017 04:54 AM, Sergio Durigan Junior wrote:
>>> On Thursday, November 23 2017, Pedro Alves wrote:
>>>
>>>> On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:
>>>>
>>>>>>> +This option is currently limited to debug information in DWARF format.
>>>>>>> +For all other format, this option has no effect.
>>>>>>
>>>>>> How hard would it be to just make it work?  There's only stabs and mdebug
>>>>>> left, I think?  There should be a single a function somewhere that we can
>>>>>> add an early return.  And then we don't need to document this limitation...
>>>>>>
>>>>>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>>>>>> call.  In coffread.c we could skip reading stabs right after 
>>>>>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>>>>>
>>>>>> Looking for:
>>>>>>
>>>>>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>>>>>  coffstab_build_psymtabs (struct objfile *objfile,
>>>>>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>>>>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>>>>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>>>>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>>>>>
>>>>>> finds all the relevant places.
>>>>>>
>>>>>> Maybe it wouldn't be that hard to make this be an objfile flag
>>>>>> afterall (like OBJF_READNOW is).  That'd make it possible
>>>>>> to add the location "-readnever" counterpart switch to add-symbol-file
>>>>>> too, BTW:
>>>>
>>>> I meant "logical" instead of "location".  I was staring at
>>>> gdb/location.c at that time.  :-P
>>>>
>>>>>>
>>>>>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>>>>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
>>>>>
>>>>> Hm, I'll look into this.  Just to make it clear: the idea is to have
>>>>> both a --readnever global option and also a OBJF_READNEVER specific to
>>>>> each objfile?
>>>>
>>>> Sure, the idea is to do something similar to what's done for --readnow.
>>>
>>> Sorry, but I guess I need a few more details on this.
>>>
>>> The way I understand the code at elf_symfile_read, the very first thing
>>> to do would be to check if OBJF_READNEVER is set and return early if it
>>> is.  But it seems that you're proposing something a bit different when
>>> you say that we should "... just skip the elf_locate_sections call."  It
>>> doesn't seem to me that is worth continuing on that function if
>>> OBJF_READNEVER is present.
>>
>> No, you can't return early the very first thing, because
>>  --readnever is supposed to skip _debug_ info, not ELF/minimal symbols...
>> So the "return early" would have to be _after_ the
>> elf_read_minimal_symbols call:
> 
> Hm, OK, it makes sense and I confess I thought "why is Pedro mentioning
> elf_symfile_read if the feature is about skipping DWARF, not ELF?".
> 
>>  static void
>>  elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>>  {
>>    bfd *abfd = objfile->obfd;
>>    struct elfinfo ei;
>>
>>    memset ((char *) &ei, 0, sizeof (ei));
>>    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
>>  
>>    elf_read_minimal_symbols (objfile, symfile_flags, &ei);
>>
>> I don't know whether we can reorder that.  Maybe we can.
>>
>> When I looked at this quickly yesterday, I saw that elf_location_sections
>> is what finds the stabs and mdebug sections:
>>
>> static void
>> elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
>> {
>>   struct elfinfo *ei;
>>
>>   ei = (struct elfinfo *) eip;
>>   if (strcmp (sectp->name, ".stab") == 0)
>>     {
>>       ei->stabsect = sectp;
>>     }
>>   else if (strcmp (sectp->name, ".mdebug") == 0)
>>     {
>>       ei->mdebugsect = sectp;
>>     }
>> }
>>
>> and it seemed to be that skipping the section location would make
>> the parts of  elf_symfile_read that actually read the symbols
>> be no-ops, because the stabsect/mdebusect pointers would be NULL.
>>
>> But if returning early or something else works, that's fine.
> 
> OK, thanks for clarifying.
> 
>>> As for the *_build_psymtabs functions, I am doing exactly that: if
>>> objfile->flags contains OBJF_READNEVER, then just return and do nothing.
>>
>> Sure, that should work too.  It's just the difference between
>> skipping checking whether debug info is available (skipping before
>> calling into those), vs letting gdb do the work to figure out whether
>> debug info is available, but then ignore it.
>> The grep for "*_build_psymtabs" was intended as a pointer to find
>> what the relevant code is, including to look at the code that
>> is calling those functions, see if there's something to be done there.
> 
> I think it makes more sense, logically speaking, to not mess with
> elf_symfile_read and instead modify the *_build_psymtabs functions.

Yet, somehow that logic didn't carry to the DWARF reader
changes?  ;-)  dwarf2_has_info is the place that checks
whether the objfile has DWARF sections, 
see dwarf2_per_objfile::dwarf2_per_objfile.
So for DWARF, the patch is checking for readnever _before_
dwarf2_build_psymtabs is reached, by essentially skipping
the "locate_sections" call.  

A small advantage of checking before is that you can skip a little bit
more work.  See the comment in elf_read_minimal_symbols about skipping
work unless stabs, or this bit here:

  if (info->stabsects)
    {
      if (!info->stabstrsect)
	{
	  error (_("The debugging information in `%s' is corrupted.\nThe "
		   "file has a `.stabs' section, but no `.stabstr' section."),
		 name);
	}
      ...

It's really not a bit deal, but to me it'd be more
consistent have all readers do the same logically.

On another note: there's a symbol_file_add_separate call at the tail
end of elf_symfile_read, where we seem to read separate info.  It seems
like that'd end up reading debug info, with "add-symbol-file -readnever"?
Same in read_symbols, I guess.  Or is OBJF_READNEVER etc. somehow
propagated to the separate objfile?

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-27 19:13                   ` Pedro Alves
@ 2017-11-29  0:59                     ` Sergio Durigan Junior
  2017-11-29 12:23                       ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-29  0:59 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On Monday, November 27 2017, Pedro Alves wrote:

> On 11/24/2017 08:26 PM, Sergio Durigan Junior wrote:
>> On Friday, November 24 2017, Pedro Alves wrote:
>> 
>>> On 11/24/2017 04:54 AM, Sergio Durigan Junior wrote:
>>>> On Thursday, November 23 2017, Pedro Alves wrote:
>>>>
>>>>> On 11/23/2017 05:21 PM, Sergio Durigan Junior wrote:
>>>>>
>>>>>>>> +This option is currently limited to debug information in DWARF format.
>>>>>>>> +For all other format, this option has no effect.
>>>>>>>
>>>>>>> How hard would it be to just make it work?  There's only stabs and mdebug
>>>>>>> left, I think?  There should be a single a function somewhere that we can
>>>>>>> add an early return.  And then we don't need to document this limitation...
>>>>>>>
>>>>>>> For example, in elf_symfile_read, we could just skip the elf_locate_sections
>>>>>>> call.  In coffread.c we could skip reading stabs right after 
>>>>>>>   bfd_map_over_sections (abfd, coff_locate_sections....);
>>>>>>>
>>>>>>> Looking for:
>>>>>>>
>>>>>>>  $ grep -h "^[a-z]*_build_psymtabs" gdb/
>>>>>>>  coffstab_build_psymtabs (struct objfile *objfile,
>>>>>>>  elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
>>>>>>>  stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
>>>>>>>  mdebug_build_psymtabs (minimal_symbol_reader &reader,
>>>>>>>  elfmdebug_build_psymtabs (struct objfile *objfile,
>>>>>>>
>>>>>>> finds all the relevant places.
>>>>>>>
>>>>>>> Maybe it wouldn't be that hard to make this be an objfile flag
>>>>>>> afterall (like OBJF_READNOW is).  That'd make it possible
>>>>>>> to add the location "-readnever" counterpart switch to add-symbol-file
>>>>>>> too, BTW:
>>>>>
>>>>> I meant "logical" instead of "location".  I was staring at
>>>>> gdb/location.c at that time.  :-P
>>>>>
>>>>>>>
>>>>>>>  symfile.c:        if (strcmp (arg, "-readnow") == 0)
>>>>>>>  symfile.c:        else if (strcmp (arg, "-readnow") == 0)
>>>>>>
>>>>>> Hm, I'll look into this.  Just to make it clear: the idea is to have
>>>>>> both a --readnever global option and also a OBJF_READNEVER specific to
>>>>>> each objfile?
>>>>>
>>>>> Sure, the idea is to do something similar to what's done for --readnow.
>>>>
>>>> Sorry, but I guess I need a few more details on this.
>>>>
>>>> The way I understand the code at elf_symfile_read, the very first thing
>>>> to do would be to check if OBJF_READNEVER is set and return early if it
>>>> is.  But it seems that you're proposing something a bit different when
>>>> you say that we should "... just skip the elf_locate_sections call."  It
>>>> doesn't seem to me that is worth continuing on that function if
>>>> OBJF_READNEVER is present.
>>>
>>> No, you can't return early the very first thing, because
>>>  --readnever is supposed to skip _debug_ info, not ELF/minimal symbols...
>>> So the "return early" would have to be _after_ the
>>> elf_read_minimal_symbols call:
>> 
>> Hm, OK, it makes sense and I confess I thought "why is Pedro mentioning
>> elf_symfile_read if the feature is about skipping DWARF, not ELF?".
>> 
>>>  static void
>>>  elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>>>  {
>>>    bfd *abfd = objfile->obfd;
>>>    struct elfinfo ei;
>>>
>>>    memset ((char *) &ei, 0, sizeof (ei));
>>>    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
>>>  
>>>    elf_read_minimal_symbols (objfile, symfile_flags, &ei);
>>>
>>> I don't know whether we can reorder that.  Maybe we can.
>>>
>>> When I looked at this quickly yesterday, I saw that elf_location_sections
>>> is what finds the stabs and mdebug sections:
>>>
>>> static void
>>> elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
>>> {
>>>   struct elfinfo *ei;
>>>
>>>   ei = (struct elfinfo *) eip;
>>>   if (strcmp (sectp->name, ".stab") == 0)
>>>     {
>>>       ei->stabsect = sectp;
>>>     }
>>>   else if (strcmp (sectp->name, ".mdebug") == 0)
>>>     {
>>>       ei->mdebugsect = sectp;
>>>     }
>>> }
>>>
>>> and it seemed to be that skipping the section location would make
>>> the parts of  elf_symfile_read that actually read the symbols
>>> be no-ops, because the stabsect/mdebusect pointers would be NULL.
>>>
>>> But if returning early or something else works, that's fine.
>> 
>> OK, thanks for clarifying.
>> 
>>>> As for the *_build_psymtabs functions, I am doing exactly that: if
>>>> objfile->flags contains OBJF_READNEVER, then just return and do nothing.
>>>
>>> Sure, that should work too.  It's just the difference between
>>> skipping checking whether debug info is available (skipping before
>>> calling into those), vs letting gdb do the work to figure out whether
>>> debug info is available, but then ignore it.
>>> The grep for "*_build_psymtabs" was intended as a pointer to find
>>> what the relevant code is, including to look at the code that
>>> is calling those functions, see if there's something to be done there.
>> 
>> I think it makes more sense, logically speaking, to not mess with
>> elf_symfile_read and instead modify the *_build_psymtabs functions.
>
> Yet, somehow that logic didn't carry to the DWARF reader
> changes?  ;-)  dwarf2_has_info is the place that checks
> whether the objfile has DWARF sections, 
> see dwarf2_per_objfile::dwarf2_per_objfile.
> So for DWARF, the patch is checking for readnever _before_
> dwarf2_build_psymtabs is reached, by essentially skipping
> the "locate_sections" call.  

You're right, I never thought about making the changes for DWARF.

> A small advantage of checking before is that you can skip a little bit
> more work.  See the comment in elf_read_minimal_symbols about skipping
> work unless stabs, or this bit here:
>
>   if (info->stabsects)
>     {
>       if (!info->stabstrsect)
> 	{
> 	  error (_("The debugging information in `%s' is corrupted.\nThe "
> 		   "file has a `.stabs' section, but no `.stabstr' section."),
> 		 name);
> 	}
>       ...
>
> It's really not a bit deal, but to me it'd be more
> consistent have all readers do the same logically.

Understood.  I switched the logic and now I'm doing all the work on
elf_symfile_read (and consequently dwarf2_has_info, which now is the
right place to put the checks on).

I wasn't sure if I should modify other *_symfile_read functions to obey
the setting, so I left them alone.

> On another note: there's a symbol_file_add_separate call at the tail
> end of elf_symfile_read, where we seem to read separate info.  It seems
> like that'd end up reading debug info, with "add-symbol-file -readnever"?
> Same in read_symbols, I guess.  Or is OBJF_READNEVER etc. somehow
> propagated to the separate objfile?

"add-symbol-file -readnever" doesn't get propagated, the only thing that
does is the "--readnever" global option.  symbol_file_add_separate calls
symbol_file_add_with_addrs (responsible for created the objfile), so I
now propagate the OBJF_READNEVER flag if the main objfile has it.

I'll submit a new version soon.  Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v3] Add support for the readnever concept
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
                   ` (2 preceding siblings ...)
  2017-11-24 23:01 ` [PATCH v2] Add support for the --readnever command-line option Sergio Durigan Junior
@ 2017-11-29  1:21 ` Sergio Durigan Junior
  2017-11-29  3:39   ` Eli Zaretskii
  2017-11-29 12:25   ` Pedro Alves
  2017-11-30  0:25 ` [PATCH v4] Add support for the readnever concept Sergio Durigan Junior
  2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
  5 siblings, 2 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-29  1:21 UTC (permalink / raw)
  To: GDB Patches
  Cc: Joel Brobecker, Yao Qi, Pedro Alves, Eli Zaretskii,
	Sergio Durigan Junior

Changes from v2:

- Fixed a few nits pointed by Eli in the docs.

- Implemented Pedro's suggestion and moved the logic of readnever out
  of the "*_build_psymtabs" and into the elf_symfile_read function.

- Handle the propagation of the OBJF_READNEVER flag to the separate
  debuginfo file.

- Reword commit title, fix a few typos in the commit message.


The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature 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.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

While implementing the code for the 'symbol-file' command, I noticed a
bug in 'symbol_file_command': GDB adds the symbol file before
finishing parsing all the options, which means that the position of an
option in the command impacts whether it will be considered or not.  I
changed the code there in order to only add the symbol file after all
options have been parsed.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.  We didn't have any infrastructure to test that, so I added a
new version of 'gdb_spawn', called 'gdb_spawn_ignore_error', which can
be used to start a GDB that will fail without compromising the entire
testcase.

Tested on the BuildBot.

gdb/ChangeLog:

2017-11-28  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* dwarf2read.c: Include "top.h".
	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.
	* elfread.c: Include "top.h".
	(elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.  Move call
	to 'symbol_file_add_main_1' out of the argument parsing loop.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Document it.  Call 'validate_readnow_readnever'.
	* top.h (readnever_symbol_files): New extern global.

gdb/doc/ChangeLog:

2017-11-28  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file'.

gdb/testsuite/ChangeLog:

2017-11-28  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
	* lib/gdb.exp (default_gdb_spawn): Add 'ignore_error'
	parameter.  Handle case when 'ignore_error' is set.
	(gdb_spawn_ignore_error): New function.
---
 gdb/NEWS                             |  6 +++
 gdb/doc/gdb.texinfo                  | 17 ++++++++
 gdb/dwarf2read.c                     |  4 ++
 gdb/elfread.c                        |  3 +-
 gdb/main.c                           | 37 +++++++++++++++--
 gdb/objfile-flags.h                  |  4 ++
 gdb/symfile.c                        | 33 +++++++++++++---
 gdb/testsuite/gdb.base/readnever.c   | 43 ++++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 77 ++++++++++++++++++++++++++++++++++++
 gdb/testsuite/lib/gdb.exp            | 18 ++++++---
 gdb/top.h                            |  1 +
 11 files changed, 229 insertions(+), 14 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index 754ce103bd..22502df149 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,12 @@
 
 *** 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 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.
+
 * 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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 675f6e7bc8..2aca978d0f 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}, command-line option
+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
@@ -18492,6 +18501,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.
 
+@cindex @code{-readnever}, option for symbol-file command
+@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
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 334d8c2e05..0975d2bbe2 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index f2483025ba..e8b4e2a759 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1171,7 +1171,8 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   struct elfinfo ei;
 
   memset ((char *) &ei, 0, sizeof (ei));
-  bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
+  if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
 
   elf_read_minimal_symbols (objfile, symfile_flags, &ei);
 
diff --git a/gdb/main.c b/gdb/main.c
index 61168faf50..8f04da107a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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,7 @@ 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\
   --write            Set writing into executable and core files.\n\n\
 "), stream);
   fputs_unfiltered (_("\
diff --git a/gdb/objfile-flags.h b/gdb/objfile-flags.h
index 43ba8aaefd..f2a2ccfa8c 100644
--- a/gdb/objfile-flags.h
+++ b/gdb/objfile-flags.h
@@ -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);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index feb50f8b79..1be4a54024 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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 || (objfile->flags & OBJF_READNEVER))
+    {
+      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
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000000..7b2fe1cae4
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -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;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000000..a6d48db9b6
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -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"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8d6972ab1f..6a6326344a 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -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 } {
diff --git a/gdb/top.h b/gdb/top.h
index 26fe87842f..a1df64f383 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -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 *);
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Add support for the readnever concept
  2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
@ 2017-11-29  3:39   ` Eli Zaretskii
  2017-11-29 12:25   ` Pedro Alves
  1 sibling, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2017-11-29  3:39 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches, brobecker, qiyaoltc, palves

> 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: Tue, 28 Nov 2017 20:21:39 -0500
> 
> Changes from v2:
> 
> - Fixed a few nits pointed by Eli in the docs.
> 
> - Implemented Pedro's suggestion and moved the logic of readnever out
>   of the "*_build_psymtabs" and into the elf_symfile_read function.
> 
> - Handle the propagation of the OBJF_READNEVER flag to the separate
>   debuginfo file.
> 
> - Reword commit title, fix a few typos in the commit message.

OK for the docs.

Thanks.

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Add support for the --readnever command-line option (DWARF only)
  2017-11-29  0:59                     ` Sergio Durigan Junior
@ 2017-11-29 12:23                       ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2017-11-29 12:23 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: Yao Qi, Joel Brobecker, gdb-patches

On 11/29/2017 12:59 AM, Sergio Durigan Junior wrote:
> On Monday, November 27 2017, Pedro Alves wrote:

>> It's really not a bit deal, but to me it'd be more
>> consistent have all readers do the same logically.
> 
> Understood.  I switched the logic and now I'm doing all the work on
> elf_symfile_read (and consequently dwarf2_has_info, which now is the
> right place to put the checks on).
> 
> I wasn't sure if I should modify other *_symfile_read functions to obey
> the setting, so I left them alone.

Surely you should?  You'll need to modify coffread.c and xcoffread.c
accordingly.  In the earlier iteration you were changing coffstab_build_psymtabs,
for example.  Basically you're moving checks to the callers instead, so
you should end up with roughly the same number of checks as before, not fewer.
At least logically.  They'll just be in different places.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Add support for the readnever concept
  2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
  2017-11-29  3:39   ` Eli Zaretskii
@ 2017-11-29 12:25   ` Pedro Alves
  2017-11-29 18:43     ` Sergio Durigan Junior
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
  1 sibling, 2 replies; 58+ messages in thread
From: Pedro Alves @ 2017-11-29 12:25 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Joel Brobecker, Yao Qi, Eli Zaretskii

On 11/29/2017 01:21 AM, Sergio Durigan Junior wrote:
> Changes from v2:
> 
> - Fixed a few nits pointed by Eli in the docs.
> 
> - Implemented Pedro's suggestion and moved the logic of readnever out
>   of the "*_build_psymtabs" and into the elf_symfile_read function.

See my comments here:
  https://sourceware.org/ml/gdb-patches/2017-11/msg00766.html

> While implementing the code for the 'symbol-file' command, I noticed a
> bug in 'symbol_file_command': GDB adds the symbol file before
> finishing parsing all the options, which means that the position of an
> option in the command impacts whether it will be considered or not.  I
> changed the code there in order to only add the symbol file after all
> options have been parsed.

Is this the same as:

 https://sourceware.org/ml/gdb-patches/2017-11/msg00656.html

?

Sounds like something that would be better split off to
a precursor patch.

> +++ b/gdb/testsuite/gdb.base/readnever.c
> @@ -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>

This include isn't necessary.

> +
> +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;
> +}

> +# 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
> +	}
> +    }

I had suggested to match GDB's error output before the eof,
so I'm surprised to see only eof expected?

> +}
> +

>  # 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
> +	}
>      }

Hmm, I think I'm now confused on why this is needed in the first
place?  GDB-the-executable should be starting successfully, 
print some error output, and exit.  What error do you see
here, exactly?

> -
>      set gdb_spawn_id $res
>      return 0
>  }

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Add support for the readnever concept
  2017-11-29 12:25   ` Pedro Alves
@ 2017-11-29 18:43     ` Sergio Durigan Junior
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
  1 sibling, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-29 18:43 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On Wednesday, November 29 2017, Pedro Alves wrote:

> On 11/29/2017 01:21 AM, Sergio Durigan Junior wrote:
>> Changes from v2:
>> 
>> - Fixed a few nits pointed by Eli in the docs.
>> 
>> - Implemented Pedro's suggestion and moved the logic of readnever out
>>   of the "*_build_psymtabs" and into the elf_symfile_read function.
>
> See my comments here:
>   https://sourceware.org/ml/gdb-patches/2017-11/msg00766.html

I'll address them, thanks.

>> While implementing the code for the 'symbol-file' command, I noticed a
>> bug in 'symbol_file_command': GDB adds the symbol file before
>> finishing parsing all the options, which means that the position of an
>> option in the command impacts whether it will be considered or not.  I
>> changed the code there in order to only add the symbol file after all
>> options have been parsed.
>
> Is this the same as:
>
>  https://sourceware.org/ml/gdb-patches/2017-11/msg00656.html
>
> ?

No, it seems like a different issue, even though it's in the same part
of the code.

> Sounds like something that would be better split off to
> a precursor patch.

Sure, I can do that.

>> +++ b/gdb/testsuite/gdb.base/readnever.c
>> @@ -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>
>
> This include isn't necessary.

Removed.

>> +
>> +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;
>> +}
>
>> +# 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
>> +	}
>> +    }
>
> I had suggested to match GDB's error output before the eof,
> so I'm surprised to see only eof expected?

Wow, I spent a lot of time trying to make this work before and didn't
succeed, but now I think I managed to do it.  See below.

>> +}
>> +
>
>>  # 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
>> +	}
>>      }
>
> Hmm, I think I'm now confused on why this is needed in the first
> place?  GDB-the-executable should be starting successfully, 
> print some error output, and exit.  What error do you see
> here, exactly?

Here's what I see when I try to use gdb_start:

  spawn /home/sergio/work/src/git/binutils-gdb/readnever/build-64/gdb/testsuite/../../gdb/gdb -nw -nx -data-directory /home/sergio/work/src/git/binutils-gdb/readnever/build-64/gdb/testsuite/../data-directory --readnever --readnow
  /home/sergio/work/src/git/binutils-gdb/readnever/build-64/gdb/testsuite/../../gdb/gdb: '--readnow' and '--readnever' cannot be specified simultaneously
  ERROR: : spawn id exp8 not open
      while executing
  "expect {
  -i exp8 -timeout 10 
          -re "$gdb_prompt $" { 
              verbose "Setting height to 0." 2
          }
          timeout {
              warning "Couldn't set the height to 0"
  ..."
      ("uplevel" body line 1)
      invoked from within
  "uplevel $body" NONE : spawn id exp8 not open
  WARNING: Couldn't set the height to 0
  ERROR: : spawn id exp8 not open
      while executing
  "expect {
  -i exp8 -timeout 10 
          -re "$gdb_prompt $" {
              verbose "Setting width to 0." 2
          }
          timeout {
              warning "Couldn't set the width to 0."
          }..."
      ("uplevel" body line 1)
      invoked from within
  "uplevel $body" NONE : spawn id exp8 not open
  WARNING: Couldn't set the width to 0.
  ERROR: : spawn id exp8 not open
      while executing
  "expect {
  -i exp8 -timeout 10 
          -re ".*A problem internal to GDB has been detected" {
              fail "$message (GDB internal error)"
              gdb_internal_error..."
      ("uplevel" body line 1)
      invoked from within
  "uplevel $body" NONE : spawn id exp8 not open
  UNRESOLVED: gdb.base/readnever.exp: test readnow and readnever at the same time

It doesn't work because gdb_start does more than spawn GDB; it also sets
height/width and other things.  So I tried invoking gdb_spawn directly,
and it worked fine!  Thanks for poking me a bit more.

I'll send a v4 with the necessary adjustments.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-29 12:25   ` Pedro Alves
  2017-11-29 18:43     ` Sergio Durigan Junior
@ 2017-11-29 21:45     ` Sergio Durigan Junior
  2017-11-29 22:26       ` Pedro Alves
                         ` (3 more replies)
  1 sibling, 4 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-29 21:45 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Sergio Durigan Junior

This is a bug that's been detected while doing the readnever work.
Currently if you use the 'symbol-file' command you have to be careful
about the position of each argument you pass on the command line.
This is because while parsing its arguments, if the command detects a
filename, it promptly calls 'symbol_file_add_main_1' without waiting
to see if there are other args on the line.  This only affects the
'-readnow' argument so far, but while implementing the '-readnever'
command it also affected it.

gdb/ChangeLog:

2017-11-29  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
          'symbol_file_add_main_1' only after processing all command
          line options.
---
 gdb/symfile.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4bbe0b5a62..9565570734 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1634,14 +1634,13 @@ symbol_file_command (const char *args, int from_tty)
 	  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"));
+
+      symbol_file_add_main_1 (arg, add_flags, flags);
     }
 }
 
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
@ 2017-11-29 22:26       ` Pedro Alves
  2017-11-29 22:42         ` Sergio Durigan Junior
  2017-11-30  4:25       ` [PATCH v2] Make '{add-,}symbol-file' " Sergio Durigan Junior
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-29 22:26 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 11/29/2017 09:44 PM, Sergio Durigan Junior wrote:
> This is a bug that's been detected while doing the readnever work.
> Currently if you use the 'symbol-file' command you have to be careful
> about the position of each argument you pass on the command line.
> This is because while parsing its arguments, if the command detects a
> filename, it promptly calls 'symbol_file_add_main_1' without waiting
> to see if there are other args on the line.  This only affects the
> '-readnow' argument so far, but while implementing the '-readnever'
> command it also affected it.
> 

Testcase or it didn't happen?  :-)

I hadn't really understood what this was about in the other thread.
(Now I do.)  I wonder whether it's really desirable to make this
work.  It seems to me that it's much more usual in GDB for option
processing to stop at the first argument that doesn't start
with '-'?  I.e., like getopt on most platforms.  (The related
add-symbol-file command stands out as quite odd to me for
explicitly wanting '-'-options after non-'-' options...)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-29 22:26       ` Pedro Alves
@ 2017-11-29 22:42         ` Sergio Durigan Junior
  2017-11-29 23:15           ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-29 22:42 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Wednesday, November 29 2017, Pedro Alves wrote:

> On 11/29/2017 09:44 PM, Sergio Durigan Junior wrote:
>> This is a bug that's been detected while doing the readnever work.
>> Currently if you use the 'symbol-file' command you have to be careful
>> about the position of each argument you pass on the command line.
>> This is because while parsing its arguments, if the command detects a
>> filename, it promptly calls 'symbol_file_add_main_1' without waiting
>> to see if there are other args on the line.  This only affects the
>> '-readnow' argument so far, but while implementing the '-readnever'
>> command it also affected it.
>> 
>
> Testcase or it didn't happen?  :-)

Can we negotiate this?  :-)

I absolutely agree (and should have written about it in the commit log),
but it's easier to write a testcase for the -readnever.  Actually, I
have one already written.  So I'd like to "postpone" the testcase until
the readnever feature is in.  OK?

> I hadn't really understood what this was about in the other thread.
> (Now I do.)  I wonder whether it's really desirable to make this
> work.  It seems to me that it's much more usual in GDB for option
> processing to stop at the first argument that doesn't start
> with '-'?  I.e., like getopt on most platforms.  (The related
> add-symbol-file command stands out as quite odd to me for
> explicitly wanting '-'-options after non-'-' options...)

I didn't know getopt stopped processing after the first non-'-'
argument.  I've always considered that passing '--' is the de facto way
of telling getopt (or argp) to stop processing.

I find it very confusing to have positional arguments in a command line.
This is not intuitive, and there's usually no indication that the
command expects a fixed position for its arguments (as is the case with
'symbol-file', for example).  I consider this to be a bug, if you ask
me.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-29 22:42         ` Sergio Durigan Junior
@ 2017-11-29 23:15           ` Pedro Alves
  2017-11-30  0:08             ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-29 23:15 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 11/29/2017 10:42 PM, Sergio Durigan Junior wrote:
> On Wednesday, November 29 2017, Pedro Alves wrote:
> 
>> On 11/29/2017 09:44 PM, Sergio Durigan Junior wrote:
>>> This is a bug that's been detected while doing the readnever work.
>>> Currently if you use the 'symbol-file' command you have to be careful
>>> about the position of each argument you pass on the command line.
>>> This is because while parsing its arguments, if the command detects a
>>> filename, it promptly calls 'symbol_file_add_main_1' without waiting
>>> to see if there are other args on the line.  This only affects the
>>> '-readnow' argument so far, but while implementing the '-readnever'
>>> command it also affected it.
>>>
>>
>> Testcase or it didn't happen?  :-)
> 
> Can we negotiate this?  :-)
> 
> I absolutely agree (and should have written about it in the commit log),
> but it's easier to write a testcase for the -readnever.  Actually, I
> have one already written.  So I'd like to "postpone" the testcase until
> the readnever feature is in.  OK?

Doesn't -readnow work for that just the same?

>> I hadn't really understood what this was about in the other thread.
>> (Now I do.)  I wonder whether it's really desirable to make this
>> work.  It seems to me that it's much more usual in GDB for option
>> processing to stop at the first argument that doesn't start
>> with '-'?  I.e., like getopt on most platforms.  (The related
>> add-symbol-file command stands out as quite odd to me for
>> explicitly wanting '-'-options after non-'-' options...)
> 
> I didn't know getopt stopped processing after the first non-'-'
> argument.

Most implementations of getopt do.  GNU getopt is known for
reordering non-'-' arguments.  You can override that by
setting POSIXLY_CORRECT in the environment, for example.

> I've always considered that passing '--' is the de facto way
> of telling getopt (or argp) to stop processing.

"--" is used to stop processing options when you want to pass
a non-option argument that starts with "-", like imagine if you
wanted to pass a filename that starts with "-" to symbol-file
(the filename is not an option.)

> 
> I find it very confusing to have positional arguments in a command line.
> This is not intuitive, and there's usually no indication that the
> command expects a fixed position for its arguments (as is the case with
> 'symbol-file', for example).  I consider this to be a bug, if you ask
> me.

In this case it's right there in the online help (since Tom's patch):

 (gdb) help symbol-file
 Load symbol table from executable file FILE.
 Usage: symbol-file [-readnow] FILE

Note that supporting non-option arguments before options
is impossible for commands that need to handle raw arguments.
I.e., commands that want to supporting passing arguments
arguments with spaces, without forcing the user to wrap it
all in quotes.  Like "break -q function (int)", or
"print /x EXPRESSION_WITH_SPACES", etc.  (I have a WIP series
that adds '-'-options to "print", btw.)
It's good to keep the possibility of the command being extended
in that direction in mind.  It doesn't seem to be the case
here, but that's the angle I was coming from.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-29 23:15           ` Pedro Alves
@ 2017-11-30  0:08             ` Sergio Durigan Junior
  2017-11-30  0:34               ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30  0:08 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Wednesday, November 29 2017, Pedro Alves wrote:

> On 11/29/2017 10:42 PM, Sergio Durigan Junior wrote:
>> On Wednesday, November 29 2017, Pedro Alves wrote:
>> 
>>> On 11/29/2017 09:44 PM, Sergio Durigan Junior wrote:
>>>> This is a bug that's been detected while doing the readnever work.
>>>> Currently if you use the 'symbol-file' command you have to be careful
>>>> about the position of each argument you pass on the command line.
>>>> This is because while parsing its arguments, if the command detects a
>>>> filename, it promptly calls 'symbol_file_add_main_1' without waiting
>>>> to see if there are other args on the line.  This only affects the
>>>> '-readnow' argument so far, but while implementing the '-readnever'
>>>> command it also affected it.
>>>>
>>>
>>> Testcase or it didn't happen?  :-)
>> 
>> Can we negotiate this?  :-)
>> 
>> I absolutely agree (and should have written about it in the commit log),
>> but it's easier to write a testcase for the -readnever.  Actually, I
>> have one already written.  So I'd like to "postpone" the testcase until
>> the readnever feature is in.  OK?
>
> Doesn't -readnow work for that just the same?

Well, yeah, I've just confirmed that it's possible to match
"...expanding to full symbols..." when -readnow is used, so it's
possible to provide a testcase even now, indeed.

I'll wait until we reach a conclusion on whether this patch is useful or
not, and then submit the testcase along with v2.

>>> I hadn't really understood what this was about in the other thread.
>>> (Now I do.)  I wonder whether it's really desirable to make this
>>> work.  It seems to me that it's much more usual in GDB for option
>>> processing to stop at the first argument that doesn't start
>>> with '-'?  I.e., like getopt on most platforms.  (The related
>>> add-symbol-file command stands out as quite odd to me for
>>> explicitly wanting '-'-options after non-'-' options...)
>> 
>> I didn't know getopt stopped processing after the first non-'-'
>> argument.
>
> Most implementations of getopt do.  GNU getopt is known for
> reordering non-'-' arguments.  You can override that by
> setting POSIXLY_CORRECT in the environment, for example.
>
>> I've always considered that passing '--' is the de facto way
>> of telling getopt (or argp) to stop processing.
>
> "--" is used to stop processing options when you want to pass
> a non-option argument that starts with "-", like imagine if you
> wanted to pass a filename that starts with "-" to symbol-file
> (the filename is not an option.)

Ah, true, that makes sense.

>> 
>> I find it very confusing to have positional arguments in a command line.
>> This is not intuitive, and there's usually no indication that the
>> command expects a fixed position for its arguments (as is the case with
>> 'symbol-file', for example).  I consider this to be a bug, if you ask
>> me.
>
> In this case it's right there in the online help (since Tom's patch):
>
>  (gdb) help symbol-file
>  Load symbol table from executable file FILE.
>  Usage: symbol-file [-readnow] FILE

Sorry, but to me this doesn't say much.  I read this help and think "Oh,
-readnow can be passed as an option, OK."  Maybe that's my fault, but if
I was writing a command like "symbol-file FILE" and just remembered that
I wanted -readnow, I would include it in the end of the line.  In fact,
that's exactly what happened when I was testing -readnever.  I saw that
the flag had no effect when the last parameter, which made me go after
the cause.

> Note that supporting non-option arguments before options
> is impossible for commands that need to handle raw arguments.
> I.e., commands that want to supporting passing arguments
> arguments with spaces, without forcing the user to wrap it
> all in quotes.  Like "break -q function (int)", or
> "print /x EXPRESSION_WITH_SPACES", etc.  (I have a WIP series
> that adds '-'-options to "print", btw.)
> It's good to keep the possibility of the command being extended
> in that direction in mind.  It doesn't seem to be the case
> here, but that's the angle I was coming from.

I agree, but that's not the case with 'symbol-file' or
'add-symbol-file', right?  I mean, their only non-option argument is the
FILE, which won't have spaces (or will, but they'll be quoted like they
should).

Sorry for being so persistent, but I was bit by this bug and it wasn't
nice.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v4] Add support for the readnever concept
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
                   ` (3 preceding siblings ...)
  2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
@ 2017-11-30  0:25 ` Sergio Durigan Junior
  2017-11-30 11:53   ` Pedro Alves
  2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
  5 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30  0:25 UTC (permalink / raw)
  To: GDB Patches
  Cc: Joel Brobecker, Yao Qi, Pedro Alves, Eli Zaretskii,
	Sergio Durigan Junior

Changes from v3:

- Implement readnever logic on gdb/coffread.c and gdb/xcoffread.c.

- Cleanup and improve testsuite (specifically the test to make sure
  that passing '--readnever' and '--readnow' simultaneously fails).

- Split off the fix to 'symbol-file' command argument parsing.  This
  patch depends on it
  (<https://sourceware.org/ml/gdb-patches/2017-11/msg00799.html>).


[ The documentation parts have already been approved by Eli.  ]

The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature 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.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

While implementing the code for the 'symbol-file' command, I noticed a
bug in 'symbol_file_command': GDB adds the symbol file before
finishing parsing all the options, which means that the position of an
option in the command impacts whether it will be considered or not.  I
changed the code there in order to only add the symbol file after all
options have been parsed.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.  We didn't have any infrastructure to test that, so I added a
new version of 'gdb_spawn', called 'gdb_spawn_ignore_error', which can
be used to start a GDB that will fail without compromising the entire
testcase.

Tested on the BuildBot.

gdb/ChangeLog:

2017-11-29  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c: Include "top.h".
	(coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c: Include "top.h".
	(dwarf2_has_info): Return 0 if READNEVER_SYMBOL_FILES is set.
	* elfread.c: Include "top.h".
	(elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.  Move call
	to 'symbol_file_add_main_1' out of the argument parsing loop.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Document it.  Call 'validate_readnow_readnever'.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-11-29  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file'.

gdb/testsuite/ChangeLog:

2017-11-29  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
	* lib/gdb.exp (default_gdb_spawn): Add 'ignore_error'
	parameter.  Handle case when 'ignore_error' is set.
	(gdb_spawn_ignore_error): New function.
---
 gdb/NEWS                             |  6 +++
 gdb/coffread.c                       |  4 +-
 gdb/doc/gdb.texinfo                  | 17 ++++++++
 gdb/dwarf2read.c                     |  4 ++
 gdb/elfread.c                        |  4 +-
 gdb/main.c                           | 37 ++++++++++++++--
 gdb/objfile-flags.h                  |  4 ++
 gdb/symfile.c                        | 47 ++++++++++++++++----
 gdb/testsuite/gdb.base/readnever.c   | 41 ++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 83 ++++++++++++++++++++++++++++++++++++
 gdb/top.h                            |  1 +
 gdb/xcoffread.c                      | 49 +++++++++++----------
 12 files changed, 260 insertions(+), 37 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index 06df52819b..ff9a819918 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,12 @@
 
 *** 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 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.
+
 * 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
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 62b6d7945a..ffe36f8751 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -42,6 +42,7 @@
 
 #include "psymtab.h"
 #include "build-id.h"
+#include "top.h"
 
 /* Key for COFF-associated data.  */
 
@@ -699,7 +700,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	}
     }
 
-  bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
+  if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
 
   if (info->stabsects)
     {
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4f552225aa..a3127dd637 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}, command-line option
+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
@@ -18576,6 +18585,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.
 
+@cindex @code{-readnever}, option for symbol-file command
+@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
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2572179a75..a30fea0865 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index f2483025ba..167fee25e1 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -47,6 +47,7 @@
 #include "build-id.h"
 #include "location.h"
 #include "auxv.h"
+#include "top.h"
 
 /* Forward declarations.  */
 extern const struct sym_fns elf_sym_fns_gdb_index;
@@ -1171,7 +1172,8 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   struct elfinfo ei;
 
   memset ((char *) &ei, 0, sizeof (ei));
-  bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
+  if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
 
   elf_read_minimal_symbols (objfile, symfile_flags, &ei);
 
diff --git a/gdb/main.c b/gdb/main.c
index 61168faf50..8f04da107a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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,7 @@ 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\
   --write            Set writing into executable and core files.\n\n\
 "), stream);
   fputs_unfiltered (_("\
diff --git a/gdb/objfile-flags.h b/gdb/objfile-flags.h
index 43ba8aaefd..f2a2ccfa8c 100644
--- a/gdb/objfile-flags.h
+++ b/gdb/objfile-flags.h
@@ -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);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4bbe0b5a62..95314829d0 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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,12 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
       flags |= OBJF_READNOW;
       add_flags &= ~SYMFILE_NO_READ;
     }
+  else if (readnever_symbol_files
+	   || (parent != NULL && (parent->flags & OBJF_READNEVER)))
+    {
+      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 +1601,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 +1648,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 +2258,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;
@@ -2248,6 +2270,8 @@ add_symbol_file_command (const char *args, int from_tty)
 	}
     }
 
+  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
@@ -3881,23 +3905,28 @@ _initialize_symfile (void)
 #define READNOW_HELP \
   "The '-readnow' option will cause GDB to read the entire symbol file\n\
 immediately.  This makes the command slower, but may make future operations\n\
-faster."
+faster.\n"
+
+#define READNEVER_HELP \
+  "The '-readnever' option will prevent GDB from reading the symbol file's\n\
+symbolic debug information."
 
   c = add_cmd ("symbol-file", class_files, symbol_file_command, _("\
 Load symbol table from executable file FILE.\n\
-Usage: symbol-file [-readnow] FILE\n\
+Usage: symbol-file [-readnow | -readnever] FILE\n\
 The `file' command can also load symbol tables, as well as setting the file\n\
-to execute.\n" READNOW_HELP), &cmdlist);
+to execute.\n" READNOW_HELP READNEVER_HELP), &cmdlist);
   set_cmd_completer (c, filename_completer);
 
   c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\
 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
-Usage: add-symbol-file FILE ADDR [-readnow | -s SECT-NAME SECT-ADDR]...\n\
+Usage: add-symbol-file FILE ADDR [-readnow | -readnever | \
+-s SECT-NAME SECT-ADDR]...\n\
 ADDR is the starting address of the file's text.\n\
 Each '-s' argument provides a section name and address, and\n\
 should be specified if the data and bss segments are not contiguous\n\
 with the text.  SECT-NAME is a section name to be loaded at SECT-ADDR.\n"
-READNOW_HELP),
+READNOW_HELP READNEVER_HELP),
 	       &cmdlist);
   set_cmd_completer (c, filename_completer);
 
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000000..6489e891de
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -0,0 +1,41 @@
+/* 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/>.  */
+
+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;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000000..151f12a6bb
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -0,0 +1,83 @@
+# 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
+
+    set test "test readnow and readnever at the same time"
+    gdb_test_multiple "" $test {
+	"'--readnow' and '--readnever' cannot be specified simultaneously" {
+	    pass $test
+	    set test "expect eof after failure"
+	    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"
diff --git a/gdb/top.h b/gdb/top.h
index 26fe87842f..a1df64f383 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -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 *);
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 46a43bc9ae..e84a2f93e8 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -48,6 +48,7 @@
 #include "psympriv.h"
 
 #include "gdb-stabs.h"
+#include "top.h"
 
 /* For interface with stabsread.c.  */
 #include "aout/stab_gnu.h"
@@ -2975,31 +2976,33 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
       /* Read the string table.  */
       init_stringtab (abfd, stringtab_offset, objfile);
 
-      /* Read the .debug section, if present.  */
-      {
-	struct bfd_section *secp;
-	bfd_size_type length;
-	bfd_byte *debugsec = NULL;
+      /* Read the .debug section, if present and if we're not ignoring
+	 it.  */
+      if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
+	{
+	  struct bfd_section *secp;
+	  bfd_size_type length;
+	  bfd_byte *debugsec = NULL;
 
-	secp = bfd_get_section_by_name (abfd, ".debug");
-	if (secp)
-	  {
-	    length = bfd_section_size (abfd, secp);
-	    if (length)
-	      {
-		debugsec
-		  = (bfd_byte *) obstack_alloc (&objfile->objfile_obstack,
-						length);
+	  secp = bfd_get_section_by_name (abfd, ".debug");
+	  if (secp)
+	    {
+	      length = bfd_section_size (abfd, secp);
+	      if (length)
+		{
+		  debugsec
+		    = (bfd_byte *) obstack_alloc (&objfile->objfile_obstack,
+						  length);
 
-		if (!bfd_get_full_section_contents (abfd, secp, &debugsec))
-		  {
-		    error (_("Error reading .debug section of `%s': %s"),
-			   name, bfd_errmsg (bfd_get_error ()));
-		  }
-	      }
-	  }
-	info->debugsec = (char *) debugsec;
-      }
+		  if (!bfd_get_full_section_contents (abfd, secp, &debugsec))
+		    {
+		      error (_("Error reading .debug section of `%s': %s"),
+			     name, bfd_errmsg (bfd_get_error ()));
+		    }
+		}
+	    }
+	  info->debugsec = (char *) debugsec;
+	}
     }
 
   /* Read the symbols.  We keep them in core because we will want to
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-30  0:08             ` Sergio Durigan Junior
@ 2017-11-30  0:34               ` Pedro Alves
  2017-11-30  4:07                 ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30  0:34 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 11/30/2017 12:08 AM, Sergio Durigan Junior wrote:
> On Wednesday, November 29 2017, Pedro Alves wrote:
> 
> I'll wait until we reach a conclusion on whether this patch is useful or
> not, and then submit the testcase along with v2.

I don't mind this going in, provided it comes with a testcase.

>>> I've always considered that passing '--' is the de facto way
>>> of telling getopt (or argp) to stop processing.
>>
>> "--" is used to stop processing options when you want to pass
>> a non-option argument that starts with "-", like imagine if you
>> wanted to pass a filename that starts with "-" to symbol-file
>> (the filename is not an option.)
>
> Ah, true, that makes sense.
>

... which points out that we should really handle "--", for
the possibility of such filenames.

(At some point we should really come up with some getopt-like
API that can be used by all the commands that also use gdb_argv,
to help with normalizing the interface, and also to make it
easier to add new options to commands.)

>> Note that supporting non-option arguments before options
>> is impossible for commands that need to handle raw arguments.
>> I.e., commands that want to supporting passing arguments
>> arguments with spaces, without forcing the user to wrap it
>> all in quotes.  Like "break -q function (int)", or
>> "print /x EXPRESSION_WITH_SPACES", etc.  (I have a WIP series
>> that adds '-'-options to "print", btw.)
>> It's good to keep the possibility of the command being extended
>> in that direction in mind.  It doesn't seem to be the case
>> here, but that's the angle I was coming from.
> 
> I agree, but that's not the case with 'symbol-file' or
> 'add-symbol-file', right?  

Yes, that's what I said - "it doesn't seem to be the case here".

Are we still negotiating?  Can I get you to make
"add-symbol-file" process options in any position too?  :-)

> I mean, their only non-option argument is the
> FILE, which won't have spaces (or will, but they'll be quoted like they
> should).
> 
> Sorry for being so persistent, but I was bit by this bug and it wasn't
> nice.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH] Make 'symbol-file' not care about the position of command line arguments
  2017-11-30  0:34               ` Pedro Alves
@ 2017-11-30  4:07                 ` Sergio Durigan Junior
  0 siblings, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30  4:07 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Wednesday, November 29 2017, Pedro Alves wrote:

> On 11/30/2017 12:08 AM, Sergio Durigan Junior wrote:
>> On Wednesday, November 29 2017, Pedro Alves wrote:
>> 
>> I'll wait until we reach a conclusion on whether this patch is useful or
>> not, and then submit the testcase along with v2.
>
> I don't mind this going in, provided it comes with a testcase.

I'm working on it right now.

>>>> I've always considered that passing '--' is the de facto way
>>>> of telling getopt (or argp) to stop processing.
>>>
>>> "--" is used to stop processing options when you want to pass
>>> a non-option argument that starts with "-", like imagine if you
>>> wanted to pass a filename that starts with "-" to symbol-file
>>> (the filename is not an option.)
>>
>> Ah, true, that makes sense.
>>
>
> ... which points out that we should really handle "--", for
> the possibility of such filenames.
>
> (At some point we should really come up with some getopt-like
> API that can be used by all the commands that also use gdb_argv,
> to help with normalizing the interface, and also to make it
> easier to add new options to commands.)

That'd be super.  It's been on my mind for quite some time, too.  I'm
impressed such interface doesn't exist yet.

>>> Note that supporting non-option arguments before options
>>> is impossible for commands that need to handle raw arguments.
>>> I.e., commands that want to supporting passing arguments
>>> arguments with spaces, without forcing the user to wrap it
>>> all in quotes.  Like "break -q function (int)", or
>>> "print /x EXPRESSION_WITH_SPACES", etc.  (I have a WIP series
>>> that adds '-'-options to "print", btw.)
>>> It's good to keep the possibility of the command being extended
>>> in that direction in mind.  It doesn't seem to be the case
>>> here, but that's the angle I was coming from.
>> 
>> I agree, but that's not the case with 'symbol-file' or
>> 'add-symbol-file', right?  
>
> Yes, that's what I said - "it doesn't seem to be the case here".
>
> Are we still negotiating?  Can I get you to make
> "add-symbol-file" process options in any position too?  :-)

Sure thing!  I'll give it a try.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
  2017-11-29 22:26       ` Pedro Alves
@ 2017-11-30  4:25       ` Sergio Durigan Junior
  2017-11-30 10:57         ` Pedro Alves
  2017-11-30 13:33       ` [PATCH v3] " Sergio Durigan Junior
  2017-11-30 20:00       ` [PATCH v4] " Sergio Durigan Junior
  3 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30  4:25 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Sergio Durigan Junior

Changes from v1:

- Commit message has been rewritten.

- Implemented position-independent argument parsing for
  'add-symbol-file'.

- Added testcases.


This is a bug that's been detected while doing the readnever work.

If you use 'symbol-file' or 'add-symbol-file', the position of each
argument passed to the command matters.  This means that if you do:

  (gdb) symbol-file -readnow /foo/bar

The symbol file specified will (correctly) have all of its symbols
read by GDB (because of the -readnow flag).  However, if you do:

  (gdb) symbol-file /foo/bar -readnow

GDB will silently ignore the -readnow flag, because it was specified
after the filename.  This is not a good thing to do and may confuse
the user.

To address that, I've modified the argument parsing mechanisms of
symbol_file_command and add_symbol_file_command to be
"position-independent".  I have also added one error call at the end
of add_symbol_file_command's argument parsing logic, which now clearly
complains if no filename has been specified.

This patch provides a testcase for both commands, in order to make
sure that the argument order does not matter.  It has been
regression-tested on BuildBot.

gdb/ChangeLog:

2017-11-29  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
	'symbol_file_add_main_1' only after processing all command
	line options.
	(add_symbol_file_command): Modify logic to make arguments
	position-independent.

gdb/testsuite/ChangeLog:

2017-11-29  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/relocate.exp: Add tests to guarantee that arguments
	to 'symbol-file' and 'add-symbol-file' can be
	position-independent.
---
 gdb/symfile.c                       | 61 +++++++++++++++++++------------------
 gdb/testsuite/gdb.base/relocate.exp | 38 +++++++++++++++++++++++
 2 files changed, 70 insertions(+), 29 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4bbe0b5a62..1d6989c1b9 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1634,14 +1634,13 @@ symbol_file_command (const char *args, int from_tty)
 	  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"));
+
+      symbol_file_add_main_1 (name, add_flags, flags);
     }
 }
 
@@ -2180,8 +2179,9 @@ add_symbol_file_command (const char *args, int from_tty)
   char *arg;
   int argcnt = 0;
   int sec_num = 0;
-  int expecting_sec_name = 0;
-  int expecting_sec_addr = 0;
+  bool expecting_sec_name = false;
+  bool expecting_sec_addr = false;
+  bool seen_addr = false;
   struct objfile *objf;
   objfile_flags flags = OBJF_USERLOADED | OBJF_SHARED;
   symfile_add_flags add_flags = 0;
@@ -2208,46 +2208,49 @@ add_symbol_file_command (const char *args, int from_tty)
 
   for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt])
     {
-      /* Process the argument.  */
-      if (argcnt == 0)
-	{
-	  /* The first argument is the file name.  */
-	  filename.reset (tilde_expand (arg));
-	}
-      else if (argcnt == 1)
-	{
-	  /* The second argument is always the text address at which
-	     to load the program.  */
-	  sect_opt sect = { ".text", arg };
-	  sect_opts.push_back (sect);
-	}
-      else
+      if (*arg != '-')
 	{
-	  /* It's an option (starting with '-') or it's an argument
-	     to an option.  */
 	  if (expecting_sec_name)
 	    {
 	      sect_opt sect = { arg, NULL };
 	      sect_opts.push_back (sect);
-	      expecting_sec_name = 0;
+	      expecting_sec_name = false;
 	    }
 	  else if (expecting_sec_addr)
 	    {
 	      sect_opts.back ().value = arg;
-	      expecting_sec_addr = 0;
+	      expecting_sec_addr = false;
 	    }
-	  else if (strcmp (arg, "-readnow") == 0)
-	    flags |= OBJF_READNOW;
-	  else if (strcmp (arg, "-s") == 0)
+	  else if (filename == NULL)
+	    {
+	      /* First non-option argument is always the filename.  */
+	      filename.reset (tilde_expand (arg));
+	    }
+	  else if (!seen_addr)
 	    {
-	      expecting_sec_name = 1;
-	      expecting_sec_addr = 1;
+	      /* The second non-option argument is always the text
+		 address at which to load the program.  */
+	      sect_opt sect = { ".text", arg };
+	      sect_opts.push_back (sect);
+	      seen_addr = true;
 	    }
 	  else
 	    error (_("Unrecognized argument \"%s\""), arg);
 	}
+      else if (strcmp (arg, "-readnow") == 0)
+	flags |= OBJF_READNOW;
+      else if (strcmp (arg, "-s") == 0)
+	{
+	  expecting_sec_name = true;
+	  expecting_sec_addr = true;
+	}
+      else
+	error (_("Unrecognized argument \"%s\""), arg);
     }
 
+  if (filename == NULL)
+    error (_("You must provide a filename to be loaded."));
+
   /* 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
diff --git a/gdb/testsuite/gdb.base/relocate.exp b/gdb/testsuite/gdb.base/relocate.exp
index 6eef15fb20..6a5ec5e201 100644
--- a/gdb/testsuite/gdb.base/relocate.exp
+++ b/gdb/testsuite/gdb.base/relocate.exp
@@ -37,6 +37,44 @@ foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
 	"add-symbol-file: unknown option $word"
 }
 
+# Check that we can pass parameters using any position in the command
+# line.
+gdb_test "add-symbol-file -readnow $binfile 0x0 -s .bss 0x3" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -readnow" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
+    "n"
+# When we use -s as the first argument, the section will be printed
+# first as well.
+gdb_test "add-symbol-file -s .bss 0x3 -readnow $binfile 0x0" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -s" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.bss_addr = 0x3\r\n\t\.text_addr = 0x0\r\n\\(y or n\\) " \
+    "n"
+gdb_test "add-symbol-file $binfile 0x0 -s .bss 0x3" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -s, no -readnow" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
+    "n"
+# Since we're here, might as well test the 'symbol-file' command and
+# if its arguments can also be passed at any position.
+gdb_test "symbol-file -readnow $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow first"
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_test "symbol-file $binfile -readnow" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow second"
+gdb_test "symbol-file -readnow" \
+    "no symbol file name was specified" \
+    "symbol-file without filename"
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
 gdb_test "add-symbol-file ${binfile} 0 -s" \
     "Missing section name after .-s." \
     "add-symbol-file bare -s"
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30  4:25       ` [PATCH v2] Make '{add-,}symbol-file' " Sergio Durigan Junior
@ 2017-11-30 10:57         ` Pedro Alves
  2017-11-30 12:38           ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 10:57 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 11/30/2017 04:24 AM, Sergio Durigan Junior wrote:
> Changes from v1:
> 
> - Commit message has been rewritten.
> 
> - Implemented position-independent argument parsing for
>   'add-symbol-file'.
> 
> - Added testcases.

Looks like you missed the comment about "--".  Take a look at
maintenance_print_symbols for an example of a command
that supports ending options with "--".  Can you add that
while you're at it, please?  For a test, I'd suggest
e.g., "symbol-file -- -non-existent-file" and confirming
gdb errors out.  That's simpler than actually creating a file.


> +      if (*arg != '-')
>  	{
> -	  /* It's an option (starting with '-') or it's an argument
> -	     to an option.  */
>  	  if (expecting_sec_name)
>  	    {
>  	      sect_opt sect = { arg, NULL };
>  	      sect_opts.push_back (sect);
> -	      expecting_sec_name = 0;
> +	      expecting_sec_name = false;
>  	    }
>  	  else if (expecting_sec_addr)
>  	    {
>  	      sect_opts.back ().value = arg;
> -	      expecting_sec_addr = 0;
> +	      expecting_sec_addr = false;
>  	    }
> -	  else if (strcmp (arg, "-readnow") == 0)
> -	    flags |= OBJF_READNOW;
> -	  else if (strcmp (arg, "-s") == 0)
> +	  else if (filename == NULL)
> +	    {
> +	      /* First non-option argument is always the filename.  */
> +	      filename.reset (tilde_expand (arg));
> +	    }
> +	  else if (!seen_addr)
>  	    {
> -	      expecting_sec_name = 1;
> -	      expecting_sec_addr = 1;
> +	      /* The second non-option argument is always the text
> +		 address at which to load the program.  */
> +	      sect_opt sect = { ".text", arg };
> +	      sect_opts.push_back (sect);
> +	      seen_addr = true;

Does this push_back directly here mean that these
two commands end up with different semantics?

 (gdb) add-symbol-file FILE 0 -s .text 0x1000
 (gdb) add-symbol-file -s .text 0x1000 FILE 0

Not sure that's a good idea.

Please add a test with "-s .text"...

> +# Check that we can pass parameters using any position in the command
> +# line.
> +gdb_test "add-symbol-file -readnow $binfile 0x0 -s .bss 0x3" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -readnow" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
> +    "n"
> +# When we use -s as the first argument, the section will be printed
> +# first as well.
> +gdb_test "add-symbol-file -s .bss 0x3 -readnow $binfile 0x0" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -s" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.bss_addr = 0x3\r\n\t\.text_addr = 0x0\r\n\\(y or n\\) " \
> +    "n"
> +gdb_test "add-symbol-file $binfile 0x0 -s .bss 0x3" \
> +    "Not confirmed\." \
> +    "add-symbol-file positionless -s, no -readnow" \
> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
> +    "n"

Using a number != 0x0 is a little better, since its easy for
a variable to end up always zero-initialized / zero-propagated
by mistake, and the test wouldn't notice.

> +# Since we're here, might as well test the 'symbol-file' command and
> +# if its arguments can also be passed at any position.
> +gdb_test "symbol-file -readnow $binfile" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow first"
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir

Just use clean_restart with no argument.

> +gdb_test "symbol-file $binfile -readnow" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow second"
> +gdb_test "symbol-file -readnow" \
> +    "no symbol file name was specified" \
> +    "symbol-file without filename"
> +
> +gdb_exit
> +gdb_start
> +gdb_reinitialize_dir $srcdir/$subdir

Ditto.

> +
>  gdb_test "add-symbol-file ${binfile} 0 -s" \
>      "Missing section name after .-s." \
>      "add-symbol-file bare -s"
> 

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-11-30  0:25 ` [PATCH v4] Add support for the readnever concept Sergio Durigan Junior
@ 2017-11-30 11:53   ` Pedro Alves
  2017-12-01  4:35     ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 11:53 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Joel Brobecker, Yao Qi, Eli Zaretskii

On 11/30/2017 12:25 AM, Sergio Durigan Junior wrote:

> - Split off the fix to 'symbol-file' command argument parsing.  This
>   patch depends on it
>   (<https://sourceware.org/ml/gdb-patches/2017-11/msg00799.html>).

This info above conflicts with ...

> While implementing the code for the 'symbol-file' command, I noticed a
> bug in 'symbol_file_command': GDB adds the symbol file before
> finishing parsing all the options, which means that the position of an
> option in the command impacts whether it will be considered or not.  I
> changed the code there in order to only add the symbol file after all
> options have been parsed.

... this info here.  The patch still has that bit...

> 
> It's also worth mentioning that this patch tests whether GDB correctly
> fails to initialize if both '--readnow' and '--readnever' options are
> passed.  We didn't have any infrastructure to test that, so I added a
> new version of 'gdb_spawn', called 'gdb_spawn_ignore_error', which can
> be used to start a GDB that will fail without compromising the entire
> testcase.

This is stale.

> gdb/testsuite/ChangeLog:
> 
> 2017-11-29  Joel Brobecker  <brobecker@adacore.com>
> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
> 	    Pedro Alves  <palves@redhat.com>
> 
> 	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
> 	* lib/gdb.exp (default_gdb_spawn): Add 'ignore_error'
> 	parameter.  Handle case when 'ignore_error' is set.
> 	(gdb_spawn_ignore_error): New function.

Also stale...

> @@ -699,7 +700,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>  	}
>      }
>  
> -  bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
> +  if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
> +    bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);

I realized something: is it really ever possible to get here with

 readnever_symbol_files && !(objfile->flags & OBJF_READNEVER)

??

If readnever_symbol_files is set, then it'll have been propagated to
objfile->flags before we get here, no?

So references to the global readnever_symbol_files can (and should)
be removed from the readers, right?  This removes the need for
the new '#include "top.h"'s too, so please remove those from
the patch along the way.

>  
>    if (info->stabsects)
>      {
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 4f552225aa..a3127dd637 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}, command-line option
> +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
> @@ -18576,6 +18585,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.
>  
> +@cindex @code{-readnever}, option for symbol-file command
> +@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.

Maybe copy the rationale for this found in "--readnever" here
or xref the "--readnever" command line option?


>  #define READNOW_HELP \
>    "The '-readnow' option will cause GDB to read the entire symbol file\n\
>  immediately.  This makes the command slower, but may make future operations\n\
> -faster."
> +faster.\n"
> +
> +#define READNEVER_HELP \
> +  "The '-readnever' option will prevent GDB from reading the symbol file's\n\
> +symbolic debug information."
>  

Why not merge these two macros in one?  We'll always want to
use them together, in the same order?  You could rename the
macro to READNOW_READNEVER_HELP for example.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 10:57         ` Pedro Alves
@ 2017-11-30 12:38           ` Sergio Durigan Junior
  2017-11-30 12:49             ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 12:38 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Thursday, November 30 2017, Pedro Alves wrote:

> On 11/30/2017 04:24 AM, Sergio Durigan Junior wrote:
>> Changes from v1:
>> 
>> - Commit message has been rewritten.
>> 
>> - Implemented position-independent argument parsing for
>>   'add-symbol-file'.
>> 
>> - Added testcases.
>
> Looks like you missed the comment about "--".  Take a look at
> maintenance_print_symbols for an example of a command
> that supports ending options with "--".  Can you add that
> while you're at it, please?  For a test, I'd suggest
> e.g., "symbol-file -- -non-existent-file" and confirming
> gdb errors out.  That's simpler than actually creating a file.

Oh, I didn't understand that you were asking me to implement it.  I
thought it was a comment for "something to be done later".  I'll do it,
then.

>> +      if (*arg != '-')
>>  	{
>> -	  /* It's an option (starting with '-') or it's an argument
>> -	     to an option.  */
>>  	  if (expecting_sec_name)
>>  	    {
>>  	      sect_opt sect = { arg, NULL };
>>  	      sect_opts.push_back (sect);
>> -	      expecting_sec_name = 0;
>> +	      expecting_sec_name = false;
>>  	    }
>>  	  else if (expecting_sec_addr)
>>  	    {
>>  	      sect_opts.back ().value = arg;
>> -	      expecting_sec_addr = 0;
>> +	      expecting_sec_addr = false;
>>  	    }
>> -	  else if (strcmp (arg, "-readnow") == 0)
>> -	    flags |= OBJF_READNOW;
>> -	  else if (strcmp (arg, "-s") == 0)
>> +	  else if (filename == NULL)
>> +	    {
>> +	      /* First non-option argument is always the filename.  */
>> +	      filename.reset (tilde_expand (arg));
>> +	    }
>> +	  else if (!seen_addr)
>>  	    {
>> -	      expecting_sec_name = 1;
>> -	      expecting_sec_addr = 1;
>> +	      /* The second non-option argument is always the text
>> +		 address at which to load the program.  */
>> +	      sect_opt sect = { ".text", arg };
>> +	      sect_opts.push_back (sect);
>> +	      seen_addr = true;
>
> Does this push_back directly here mean that these
> two commands end up with different semantics?
>
>  (gdb) add-symbol-file FILE 0 -s .text 0x1000
>  (gdb) add-symbol-file -s .text 0x1000 FILE 0

The arguments are printed in a different order, yes:

(gdb) add-symbol-file -s .text 0x100 ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0
add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
        .text_addr = 0x100
        .text_addr = 0x0
(y or n) n
Not confirmed.
(gdb) add-symbol-file  ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0 -s .text 0x100
add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
        .text_addr = 0x0
        .text_addr = 0x100
(y or n) n
Not confirmed.

> Not sure that's a good idea.

I'll work on it and make sure they're always printed in the same way.

> Please add a test with "-s .text"...

Will do.

>> +# Check that we can pass parameters using any position in the command
>> +# line.
>> +gdb_test "add-symbol-file -readnow $binfile 0x0 -s .bss 0x3" \
>> +    "Not confirmed\." \
>> +    "add-symbol-file positionless -readnow" \
>> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
>> +    "n"
>> +# When we use -s as the first argument, the section will be printed
>> +# first as well.
>> +gdb_test "add-symbol-file -s .bss 0x3 -readnow $binfile 0x0" \
>> +    "Not confirmed\." \
>> +    "add-symbol-file positionless -s" \
>> +    "add symbol table from file \"${binfile}\" at\r\n\t\.bss_addr = 0x3\r\n\t\.text_addr = 0x0\r\n\\(y or n\\) " \
>> +    "n"
>> +gdb_test "add-symbol-file $binfile 0x0 -s .bss 0x3" \
>> +    "Not confirmed\." \
>> +    "add-symbol-file positionless -s, no -readnow" \
>> +    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x0\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
>> +    "n"
>
> Using a number != 0x0 is a little better, since its easy for
> a variable to end up always zero-initialized / zero-propagated
> by mistake, and the test wouldn't notice.

OK.

>> +# Since we're here, might as well test the 'symbol-file' command and
>> +# if its arguments can also be passed at any position.
>> +gdb_test "symbol-file -readnow $binfile" \
>> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
>> +    "symbol-file with -readnow first"
>> +gdb_exit
>> +gdb_start
>> +gdb_reinitialize_dir $srcdir/$subdir
>
> Just use clean_restart with no argument.

Done.

>> +gdb_test "symbol-file $binfile -readnow" \
>> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
>> +    "symbol-file with -readnow second"
>> +gdb_test "symbol-file -readnow" \
>> +    "no symbol file name was specified" \
>> +    "symbol-file without filename"
>> +
>> +gdb_exit
>> +gdb_start
>> +gdb_reinitialize_dir $srcdir/$subdir
>
> Ditto.

Done.

>> +
>>  gdb_test "add-symbol-file ${binfile} 0 -s" \
>>      "Missing section name after .-s." \
>>      "add-symbol-file bare -s"
>> 
>
> Thanks,
> Pedro Alves

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 12:38           ` Sergio Durigan Junior
@ 2017-11-30 12:49             ` Pedro Alves
  2017-11-30 13:06               ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 12:49 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 11/30/2017 12:38 PM, Sergio Durigan Junior wrote:
> On Thursday, November 30 2017, Pedro Alves wrote:
> 
>> On 11/30/2017 04:24 AM, Sergio Durigan Junior wrote:
>>> Changes from v1:
>>>
>>> - Commit message has been rewritten.
>>>
>>> - Implemented position-independent argument parsing for
>>>   'add-symbol-file'.
>>>
>>> - Added testcases.
>>
>> Looks like you missed the comment about "--".  Take a look at
>> maintenance_print_symbols for an example of a command
>> that supports ending options with "--".  Can you add that
>> while you're at it, please?  For a test, I'd suggest
>> e.g., "symbol-file -- -non-existent-file" and confirming
>> gdb errors out.  That's simpler than actually creating a file.
> 
> Oh, I didn't understand that you were asking me to implement it.  I
> thought it was a comment for "something to be done later".  I'll do it,
> then.

I'd rather do it at the same time because there's the possibility
that implementing it suggests implementing any-position arguments
differently.  Or maybe not.  But I'd rather that we didn't have
to redo any-position support later on again.

>>
>> Does this push_back directly here mean that these
>> two commands end up with different semantics?
>>
>>  (gdb) add-symbol-file FILE 0 -s .text 0x1000
>>  (gdb) add-symbol-file -s .text 0x1000 FILE 0
> 
> The arguments are printed in a different order, yes:
> 
> (gdb) add-symbol-file -s .text 0x100 ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0
> add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
>         .text_addr = 0x100
>         .text_addr = 0x0
> (y or n) n
> Not confirmed.
> (gdb) add-symbol-file  ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0 -s .text 0x100
> add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
>         .text_addr = 0x0
>         .text_addr = 0x100
> (y or n) n
> Not confirmed.
> 
>> Not sure that's a good idea.
> 
> I'll work on it and make sure they're always printed in the same way.

TBC, the worry was not really about the printing (that's minor),
but what is the actual resulting .text address that the symbol file
it loaded at in the end.  But sounds like the printing order can
be used as proxy for checking that.  It's not as robust as
actually loading the symbols and then checking what happened
(with e.g., printing a symbol's address), but it's good
enough.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v2] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 12:49             ` Pedro Alves
@ 2017-11-30 13:06               ` Sergio Durigan Junior
  0 siblings, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 13:06 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Thursday, November 30 2017, Pedro Alves wrote:

>>> Does this push_back directly here mean that these
>>> two commands end up with different semantics?
>>>
>>>  (gdb) add-symbol-file FILE 0 -s .text 0x1000
>>>  (gdb) add-symbol-file -s .text 0x1000 FILE 0
>> 
>> The arguments are printed in a different order, yes:
>> 
>> (gdb) add-symbol-file -s .text 0x100 ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0
>> add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
>>         .text_addr = 0x100
>>         .text_addr = 0x0
>> (y or n) n
>> Not confirmed.
>> (gdb) add-symbol-file  ./gdb/testsuite/outputs/gdb.base/relocate/relocate.o 0 -s .text 0x100
>> add symbol table from file "./gdb/testsuite/outputs/gdb.base/relocate/relocate.o" at
>>         .text_addr = 0x0
>>         .text_addr = 0x100
>> (y or n) n
>> Not confirmed.
>> 
>>> Not sure that's a good idea.
>> 
>> I'll work on it and make sure they're always printed in the same way.
>
> TBC, the worry was not really about the printing (that's minor),
> but what is the actual resulting .text address that the symbol file
> it loaded at in the end.  But sounds like the printing order can
> be used as proxy for checking that.  It's not as robust as
> actually loading the symbols and then checking what happened
> (with e.g., printing a symbol's address), but it's good
> enough.

Right, I got it.

The way I made it now, the address provided as .text will always be the
first to be set/printed, even if the user provides a "-s .text" later.
This maintains compatibility with the current way of doing things.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
  2017-11-29 22:26       ` Pedro Alves
  2017-11-30  4:25       ` [PATCH v2] Make '{add-,}symbol-file' " Sergio Durigan Junior
@ 2017-11-30 13:33       ` Sergio Durigan Junior
  2017-11-30 15:01         ` Pedro Alves
  2017-11-30 20:00       ` [PATCH v4] " Sergio Durigan Junior
  3 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 13:33 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Sergio Durigan Junior

Changes from v2:

- Make .text address always be the first set on 'add-symbol-file'
  command.

- Add support for "--" on both commands.

- Extend testcases.


This is a bug that's been detected while doing the readnever work.

If you use 'symbol-file' or 'add-symbol-file', the position of each
argument passed to the command matters.  This means that if you do:

  (gdb) symbol-file -readnow /foo/bar

The symbol file specified will (correctly) have all of its symbols
read by GDB (because of the -readnow flag).  However, if you do:

  (gdb) symbol-file /foo/bar -readnow

GDB will silently ignore the -readnow flag, because it was specified
after the filename.  This is not a good thing to do and may confuse
the user.

To address that, I've modified the argument parsing mechanisms of
symbol_file_command and add_symbol_file_command to be
"position-independent".  I have also added one error call at the end
of add_symbol_file_command's argument parsing logic, which now clearly
complains if no filename has been specified.  Both commands now
support the "--" option to stop argument processing.

This patch provides a testcase for both commands, in order to make
sure that the argument order does not matter.  It has been
regression-tested on BuildBot.

gdb/ChangeLog:

2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
	'symbol_file_add_main_1' only after processing all command
	line options.
	(add_symbol_file_command): Modify logic to make arguments
	position-independent.

gdb/testsuite/ChangeLog:

2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/relocate.exp: Add tests to guarantee that arguments
	to 'symbol-file' and 'add-symbol-file' can be
	position-independent.
---
 gdb/symfile.c                       | 85 ++++++++++++++++++++++---------------
 gdb/testsuite/gdb.base/relocate.exp | 60 ++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 35 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4bbe0b5a62..28b292e7fa 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1622,26 +1622,35 @@ symbol_file_command (const char *args, int from_tty)
       objfile_flags flags = OBJF_USERLOADED;
       symfile_add_flags add_flags = 0;
       char *name = NULL;
+      bool stop_processing_options = false;
+      int idx;
+      char *arg;
 
       if (from_tty)
 	add_flags |= SYMFILE_VERBOSE;
 
       gdb_argv built_argv (args);
-      for (char *arg : built_argv)
+      for (arg = built_argv[0], idx = 0; arg != NULL; arg = built_argv[++idx])
 	{
-	  if (strcmp (arg, "-readnow") == 0)
-	    flags |= OBJF_READNOW;
-	  else if (*arg == '-')
-	    error (_("unknown option `%s'"), arg);
-	  else
+	  if (stop_processing_options || *arg != '-')
 	    {
-	      symbol_file_add_main_1 (arg, add_flags, flags);
-	      name = arg;
+	      if (name == NULL)
+		name = arg;
+	      else
+		error (_("Unrecognized argument \"%s\""), arg);
 	    }
+	  else if (strcmp (arg, "-readnow") == 0)
+	    flags |= OBJF_READNOW;
+	  else if (strcmp (arg, "--") == 0)
+	    stop_processing_options = true;
+	  else
+	    error (_("Unrecognized argument \"%s\""), arg);
 	}
 
       if (name == NULL)
 	error (_("no symbol file name was specified"));
+
+      symbol_file_add_main_1 (name, add_flags, flags);
     }
 }
 
@@ -2180,8 +2189,9 @@ add_symbol_file_command (const char *args, int from_tty)
   char *arg;
   int argcnt = 0;
   int sec_num = 0;
-  int expecting_sec_name = 0;
-  int expecting_sec_addr = 0;
+  bool expecting_sec_name = false;
+  bool expecting_sec_addr = false;
+  bool seen_addr = false;
   struct objfile *objf;
   objfile_flags flags = OBJF_USERLOADED | OBJF_SHARED;
   symfile_add_flags add_flags = 0;
@@ -2196,7 +2206,8 @@ add_symbol_file_command (const char *args, int from_tty)
   };
 
   struct section_addr_info *section_addrs;
-  std::vector<sect_opt> sect_opts;
+  std::vector<sect_opt> sect_opts = { { ".text", NULL } };
+  bool stop_processing_options = false;
   struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
 
   dont_repeat ();
@@ -2208,51 +2219,55 @@ add_symbol_file_command (const char *args, int from_tty)
 
   for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt])
     {
-      /* Process the argument.  */
-      if (argcnt == 0)
-	{
-	  /* The first argument is the file name.  */
-	  filename.reset (tilde_expand (arg));
-	}
-      else if (argcnt == 1)
-	{
-	  /* The second argument is always the text address at which
-	     to load the program.  */
-	  sect_opt sect = { ".text", arg };
-	  sect_opts.push_back (sect);
-	}
-      else
+      if (stop_processing_options || *arg != '-')
 	{
-	  /* It's an option (starting with '-') or it's an argument
-	     to an option.  */
 	  if (expecting_sec_name)
 	    {
 	      sect_opt sect = { arg, NULL };
 	      sect_opts.push_back (sect);
-	      expecting_sec_name = 0;
+	      expecting_sec_name = false;
 	    }
 	  else if (expecting_sec_addr)
 	    {
 	      sect_opts.back ().value = arg;
-	      expecting_sec_addr = 0;
+	      expecting_sec_addr = false;
 	    }
-	  else if (strcmp (arg, "-readnow") == 0)
-	    flags |= OBJF_READNOW;
-	  else if (strcmp (arg, "-s") == 0)
+	  else if (filename == NULL)
+	    {
+	      /* First non-option argument is always the filename.  */
+	      filename.reset (tilde_expand (arg));
+	    }
+	  else if (!seen_addr)
 	    {
-	      expecting_sec_name = 1;
-	      expecting_sec_addr = 1;
+	      /* The second non-option argument is always the text
+		 address at which to load the program.  */
+	      sect_opts[0].value = arg;
+	      seen_addr = true;
 	    }
 	  else
 	    error (_("Unrecognized argument \"%s\""), arg);
 	}
+      else if (strcmp (arg, "-readnow") == 0)
+	flags |= OBJF_READNOW;
+      else if (strcmp (arg, "-s") == 0)
+	{
+	  expecting_sec_name = true;
+	  expecting_sec_addr = true;
+	}
+      else if (strcmp (arg, "--") == 0)
+	stop_processing_options = true;
+      else
+	error (_("Unrecognized argument \"%s\""), arg);
     }
 
+  if (filename == NULL)
+    error (_("You must provide a filename to be loaded."));
+
   /* 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
      user.  */
-  if (sect_opts.empty ())
+  if (!seen_addr)
     error (_("The address where %s has been loaded is missing"),
 	   filename.get ());
 
diff --git a/gdb/testsuite/gdb.base/relocate.exp b/gdb/testsuite/gdb.base/relocate.exp
index 6eef15fb20..246e4b8282 100644
--- a/gdb/testsuite/gdb.base/relocate.exp
+++ b/gdb/testsuite/gdb.base/relocate.exp
@@ -37,6 +37,66 @@ foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
 	"add-symbol-file: unknown option $word"
 }
 
+# Check that we can pass parameters using any position in the command
+# line.
+gdb_test "add-symbol-file -readnow $binfile 0x100 -s .bss 0x3" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -readnow" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
+    "n"
+# When we use -s as the first argument, the section will be printed
+# first as well.
+gdb_test "add-symbol-file -s .bss 0x3 -readnow $binfile 0x100" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -s" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
+    "n"
+gdb_test "add-symbol-file $binfile 0x100 -s .bss 0x3" \
+    "Not confirmed\." \
+    "add-symbol-file positionless -s, no -readnow" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " \
+    "n"
+# Check that passing "-s .text", no matter the position, always has
+# the same result.
+gdb_test "add-symbol-file $binfile 0x100 -s .text 0x200" \
+    "Not confirmed\." \
+    "add-symbol-file different -s .text, after file" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " \
+    "n"
+gdb_test "add-symbol-file -s .text 0x200 $binfile 0x100" \
+    "Not confirmed\." \
+    "add-symbol-file different -s .text, before file" \
+    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " \
+    "n"
+# Test that passing "--" disables option processing.
+gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
+    "Unrecognized argument \"-s\"" \
+    "add-symbol-file with -- disables option processing"
+# Since we're here, might as well test the 'symbol-file' command and
+# if its arguments can also be passed at any position.
+gdb_test "symbol-file -readnow $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow first"
+clean_restart
+gdb_test "symbol-file $binfile -readnow" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow second"
+gdb_test "symbol-file -readnow" \
+    "no symbol file name was specified" \
+    "symbol-file without filename"
+gdb_test "symbol-file -- non-existent-file" \
+    "non-existent-file: No such file or directory\." \
+    "symbol-file with -- disables option processing"
+clean_restart
+gdb_test "symbol-file -readnow -- $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -- and -readnow"
+gdb_test "symbol-file -- $binfile -readnow" \
+    "Unrecognized argument \"-readnow\"" \
+    "symbol-file with -- and -readnow, invalid option"
+
+clean_restart
+
 gdb_test "add-symbol-file ${binfile} 0 -s" \
     "Missing section name after .-s." \
     "add-symbol-file bare -s"
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 13:33       ` [PATCH v3] " Sergio Durigan Junior
@ 2017-11-30 15:01         ` Pedro Alves
  2017-11-30 17:26           ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 15:01 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 11/30/2017 01:33 PM, Sergio Durigan Junior wrote:

> +# Since we're here, might as well test the 'symbol-file' command and
> +# if its arguments can also be passed at any position.
> +gdb_test "symbol-file -readnow $binfile" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow first"
> +clean_restart
> +gdb_test "symbol-file $binfile -readnow" \
> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
> +    "symbol-file with -readnow second"
> +gdb_test "symbol-file -readnow" \
> +    "no symbol file name was specified" \
> +    "symbol-file without filename"
> +gdb_test "symbol-file -- non-existent-file" \
> +    "non-existent-file: No such file or directory\." \
> +    "symbol-file with -- disables option processing"

This should be "-non-existent-file", with leading "-" ...

Missing the same test with "add-symbol-file".

Another thing I wondered is why do we have the
expecting_sec_name/expecting_sec_addr variables instead of
simply reading the arguments in the argv ahead inline
like maintenance_print_symbols does?

As is, the patch essentially forbids section names
that start with '-':

 (gdb) add-symbol-file ./gdb 0 -s -funnysection 0
 add symbol table from file "./gdb" at
         .text_addr = 0x0
         -funnysection_addr = 0x0
 (y or n) 

=>

 (gdb) add-symbol-file ./gdb 0 -s -funnysection 0
 Missing section address after "-s"

and I'm not sure that's really a good idea.  I don't think
we should really interpret/require section names to be in any
way/format.

(Another thing that I noticed but I'm kind of ignoring is the fact
that gdb_test treats the question as optional gdb output, so
pedantically gdb could stop outputting the question and answer
"n" automatically and the testcase wouldn't notice.)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 15:01         ` Pedro Alves
@ 2017-11-30 17:26           ` Sergio Durigan Junior
  2017-11-30 17:37             ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 17:26 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Thursday, November 30 2017, Pedro Alves wrote:

> On 11/30/2017 01:33 PM, Sergio Durigan Junior wrote:
>
>> +# Since we're here, might as well test the 'symbol-file' command and
>> +# if its arguments can also be passed at any position.
>> +gdb_test "symbol-file -readnow $binfile" \
>> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
>> +    "symbol-file with -readnow first"
>> +clean_restart
>> +gdb_test "symbol-file $binfile -readnow" \
>> +    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
>> +    "symbol-file with -readnow second"
>> +gdb_test "symbol-file -readnow" \
>> +    "no symbol file name was specified" \
>> +    "symbol-file without filename"
>> +gdb_test "symbol-file -- non-existent-file" \
>> +    "non-existent-file: No such file or directory\." \
>> +    "symbol-file with -- disables option processing"
>
> This should be "-non-existent-file", with leading "-" ...
>
> Missing the same test with "add-symbol-file".

Right, fixed.

> Another thing I wondered is why do we have the
> expecting_sec_name/expecting_sec_addr variables instead of
> simply reading the arguments in the argv ahead inline
> like maintenance_print_symbols does?
>
> As is, the patch essentially forbids section names
> that start with '-':
>
>  (gdb) add-symbol-file ./gdb 0 -s -funnysection 0
>  add symbol table from file "./gdb" at
>          .text_addr = 0x0
>          -funnysection_addr = 0x0
>  (y or n) 
>
> =>
>
>  (gdb) add-symbol-file ./gdb 0 -s -funnysection 0
>  Missing section address after "-s"
>
> and I'm not sure that's really a good idea.  I don't think
> we should really interpret/require section names to be in any
> way/format.

I agree; I hadn't thought of this case before.  I implemented the
argument reading ahead, as proposed.

> (Another thing that I noticed but I'm kind of ignoring is the fact
> that gdb_test treats the question as optional gdb output, so
> pedantically gdb could stop outputting the question and answer
> "n" automatically and the testcase wouldn't notice.)

Would you prefer if I made the tests answer "y" instead?  Or maybe I'm
misunderstanding your concern.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 17:26           ` Sergio Durigan Junior
@ 2017-11-30 17:37             ` Pedro Alves
  2017-11-30 17:43               ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 17:37 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 11/30/2017 05:26 PM, Sergio Durigan Junior wrote:

>> (Another thing that I noticed but I'm kind of ignoring is the fact
>> that gdb_test treats the question as optional gdb output, so
>> pedantically gdb could stop outputting the question and answer
>> "n" automatically and the testcase wouldn't notice.)
> 
> Would you prefer if I made the tests answer "y" instead?  Or maybe I'm
> misunderstanding your concern.
> 

Take a look at how gdb_test implements the question/response.  The
question argument is a question that GDB _may_ ask, not one that
GDB _must_ ask.  

So pedantically if add-symbol-file's query ever becomes broken in a way 
that makes GDB simply automatically assume "n" without GDB printing
the question in the first place, like:

 (gdb) add-symbol-file -s .text 0x200 $binfile 0x100
 Not confirmed.
 (gdb)

then this:

gdb_test "add-symbol-file -s .text 0x200 $binfile 0x100" \
    "Not confirmed\." \
    "add-symbol-file different -s .text, before file" \
    "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " \
    "n"

won't notice it, it'll still PASS.

The usual way to test must-ask questions is to use
one gdb_test_multiple up to the question, and another gdb_test for
answering the question.  Something like (untested):

set test "add-symbol-file different -s .text, before file"
gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
   -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
       gdb_test "n" "Not confirmed\." $test
    }
}

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 17:37             ` Pedro Alves
@ 2017-11-30 17:43               ` Sergio Durigan Junior
  2017-11-30 17:50                 ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 17:43 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Thursday, November 30 2017, Pedro Alves wrote:

> On 11/30/2017 05:26 PM, Sergio Durigan Junior wrote:
>
>>> (Another thing that I noticed but I'm kind of ignoring is the fact
>>> that gdb_test treats the question as optional gdb output, so
>>> pedantically gdb could stop outputting the question and answer
>>> "n" automatically and the testcase wouldn't notice.)
>> 
>> Would you prefer if I made the tests answer "y" instead?  Or maybe I'm
>> misunderstanding your concern.
>> 
>
> Take a look at how gdb_test implements the question/response.  The
> question argument is a question that GDB _may_ ask, not one that
> GDB _must_ ask.  
>
> So pedantically if add-symbol-file's query ever becomes broken in a way 
> that makes GDB simply automatically assume "n" without GDB printing
> the question in the first place, like:
>
>  (gdb) add-symbol-file -s .text 0x200 $binfile 0x100
>  Not confirmed.
>  (gdb)
>
> then this:
>
> gdb_test "add-symbol-file -s .text 0x200 $binfile 0x100" \
>     "Not confirmed\." \
>     "add-symbol-file different -s .text, before file" \
>     "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " \
>     "n"
>
> won't notice it, it'll still PASS.
>
> The usual way to test must-ask questions is to use
> one gdb_test_multiple up to the question, and another gdb_test for
> answering the question.  Something like (untested):
>
> set test "add-symbol-file different -s .text, before file"
> gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
>    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
>        gdb_test "n" "Not confirmed\." $test
>     }
> }

OK, I see what you mean.  You obviously know that I copied the same
pattern present at gdb.base/relocate.exp (and many other tests, which
makes me frown a bit when I read "The usual way to test must-ask...").

I'll rewrite my tests to use the suggested way, then.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v3] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 17:43               ` Sergio Durigan Junior
@ 2017-11-30 17:50                 ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2017-11-30 17:50 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 11/30/2017 05:43 PM, Sergio Durigan Junior wrote:

> OK, I see what you mean.  You obviously know that I copied the same
> pattern present at gdb.base/relocate.exp (and many other tests, which
> makes me frown a bit when I read "The usual way to test must-ask...").

I didn't know that, no, I've only been reading the patch without
looking at the original source.  I did say I was ignoring this.  ;-)

> I'll rewrite my tests to use the suggested way, then.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v4] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
                         ` (2 preceding siblings ...)
  2017-11-30 13:33       ` [PATCH v3] " Sergio Durigan Junior
@ 2017-11-30 20:00       ` Sergio Durigan Junior
  2017-12-01 12:11         ` Pedro Alves
  3 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-11-30 20:00 UTC (permalink / raw)
  To: GDB Patches; +Cc: Pedro Alves, Sergio Durigan Junior

Changes from v3:

- 'add-symbol-file -s' now accepts sections whose names start with a
  dash.

- Use a better way to test must-ask questions on the testsuite.


This is a bug that's been detected while doing the readnever work.

If you use 'symbol-file' or 'add-symbol-file', the position of each
argument passed to the command matters.  This means that if you do:

  (gdb) symbol-file -readnow /foo/bar

The symbol file specified will (correctly) have all of its symbols
read by GDB (because of the -readnow flag).  However, if you do:

  (gdb) symbol-file /foo/bar -readnow

GDB will silently ignore the -readnow flag, because it was specified
after the filename.  This is not a good thing to do and may confuse
the user.

To address that, I've modified the argument parsing mechanisms of
symbol_file_command and add_symbol_file_command to be
"position-independent".  I have also added one error call at the end
of add_symbol_file_command's argument parsing logic, which now clearly
complains if no filename has been specified.  Both commands now
support the "--" option to stop argument processing.

This patch provides a testcase for both commands, in order to make
sure that the argument order does not matter.  It has been
regression-tested on BuildBot.

gdb/ChangeLog:

2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	* symfile.c (symbol_file_command): Call
	'symbol_file_add_main_1' only after processing all command
	line options.
	(add_symbol_file_command): Modify logic to make arguments
	position-independent.

gdb/testsuite/ChangeLog:

2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.base/relocate.exp: Add tests to guarantee that arguments
	to 'symbol-file' and 'add-symbol-file' can be
	position-independent.
---
 gdb/symfile.c                       | 98 +++++++++++++++++++------------------
 gdb/testsuite/gdb.base/relocate.exp | 86 ++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 47 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 4bbe0b5a62..1c9f836eb3 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1622,26 +1622,35 @@ symbol_file_command (const char *args, int from_tty)
       objfile_flags flags = OBJF_USERLOADED;
       symfile_add_flags add_flags = 0;
       char *name = NULL;
+      bool stop_processing_options = false;
+      int idx;
+      char *arg;
 
       if (from_tty)
 	add_flags |= SYMFILE_VERBOSE;
 
       gdb_argv built_argv (args);
-      for (char *arg : built_argv)
+      for (arg = built_argv[0], idx = 0; arg != NULL; arg = built_argv[++idx])
 	{
-	  if (strcmp (arg, "-readnow") == 0)
-	    flags |= OBJF_READNOW;
-	  else if (*arg == '-')
-	    error (_("unknown option `%s'"), arg);
-	  else
+	  if (stop_processing_options || *arg != '-')
 	    {
-	      symbol_file_add_main_1 (arg, add_flags, flags);
-	      name = arg;
+	      if (name == NULL)
+		name = arg;
+	      else
+		error (_("Unrecognized argument \"%s\""), arg);
 	    }
+	  else if (strcmp (arg, "-readnow") == 0)
+	    flags |= OBJF_READNOW;
+	  else if (strcmp (arg, "--") == 0)
+	    stop_processing_options = true;
+	  else
+	    error (_("Unrecognized argument \"%s\""), arg);
 	}
 
       if (name == NULL)
 	error (_("no symbol file name was specified"));
+
+      symbol_file_add_main_1 (name, add_flags, flags);
     }
 }
 
@@ -2180,8 +2189,6 @@ add_symbol_file_command (const char *args, int from_tty)
   char *arg;
   int argcnt = 0;
   int sec_num = 0;
-  int expecting_sec_name = 0;
-  int expecting_sec_addr = 0;
   struct objfile *objf;
   objfile_flags flags = OBJF_USERLOADED | OBJF_SHARED;
   symfile_add_flags add_flags = 0;
@@ -2196,7 +2203,8 @@ add_symbol_file_command (const char *args, int from_tty)
   };
 
   struct section_addr_info *section_addrs;
-  std::vector<sect_opt> sect_opts;
+  std::vector<sect_opt> sect_opts = { { ".text", NULL } };
+  bool stop_processing_options = false;
   struct cleanup *my_cleanups = make_cleanup (null_cleanup, NULL);
 
   dont_repeat ();
@@ -2204,63 +2212,59 @@ add_symbol_file_command (const char *args, int from_tty)
   if (args == NULL)
     error (_("add-symbol-file takes a file name and an address"));
 
+  bool seen_addr = false;
   gdb_argv argv (args);
 
   for (arg = argv[0], argcnt = 0; arg != NULL; arg = argv[++argcnt])
     {
-      /* Process the argument.  */
-      if (argcnt == 0)
-	{
-	  /* The first argument is the file name.  */
-	  filename.reset (tilde_expand (arg));
-	}
-      else if (argcnt == 1)
-	{
-	  /* The second argument is always the text address at which
-	     to load the program.  */
-	  sect_opt sect = { ".text", arg };
-	  sect_opts.push_back (sect);
-	}
-      else
+      if (stop_processing_options || *arg != '-')
 	{
-	  /* It's an option (starting with '-') or it's an argument
-	     to an option.  */
-	  if (expecting_sec_name)
+	  if (filename == NULL)
 	    {
-	      sect_opt sect = { arg, NULL };
-	      sect_opts.push_back (sect);
-	      expecting_sec_name = 0;
+	      /* First non-option argument is always the filename.  */
+	      filename.reset (tilde_expand (arg));
 	    }
-	  else if (expecting_sec_addr)
+	  else if (!seen_addr)
 	    {
-	      sect_opts.back ().value = arg;
-	      expecting_sec_addr = 0;
-	    }
-	  else if (strcmp (arg, "-readnow") == 0)
-	    flags |= OBJF_READNOW;
-	  else if (strcmp (arg, "-s") == 0)
-	    {
-	      expecting_sec_name = 1;
-	      expecting_sec_addr = 1;
+	      /* The second non-option argument is always the text
+		 address at which to load the program.  */
+	      sect_opts[0].value = arg;
+	      seen_addr = true;
 	    }
 	  else
 	    error (_("Unrecognized argument \"%s\""), arg);
 	}
+      else if (strcmp (arg, "-readnow") == 0)
+	flags |= OBJF_READNOW;
+      else if (strcmp (arg, "-s") == 0)
+	{
+	  if (argv[argcnt + 1] == NULL)
+	    error (_("Missing section name after \"-s\""));
+	  else if (argv[argcnt + 2] == NULL)
+	    error (_("Missing section address after \"-s\""));
+
+	  sect_opt sect = { argv[argcnt + 1], argv[argcnt + 2] };
+
+	  sect_opts.push_back (sect);
+	  argcnt += 2;
+	}
+      else if (strcmp (arg, "--") == 0)
+	stop_processing_options = true;
+      else
+	error (_("Unrecognized argument \"%s\""), arg);
     }
 
+  if (filename == NULL)
+    error (_("You must provide a filename to be loaded."));
+
   /* 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
      user.  */
-  if (sect_opts.empty ())
+  if (!seen_addr)
     error (_("The address where %s has been loaded is missing"),
 	   filename.get ());
 
-  if (expecting_sec_name)
-    error (_("Missing section name after \"-s\""));
-  else if (expecting_sec_addr)
-    error (_("Missing section address after \"-s\""));
-
   /* Print the prompt for the query below.  And save the arguments into
      a sect_addr_info structure to be passed around to other
      functions.  We have to split this up into separate print
diff --git a/gdb/testsuite/gdb.base/relocate.exp b/gdb/testsuite/gdb.base/relocate.exp
index 6eef15fb20..d0a839ae59 100644
--- a/gdb/testsuite/gdb.base/relocate.exp
+++ b/gdb/testsuite/gdb.base/relocate.exp
@@ -37,6 +37,92 @@ foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
 	"add-symbol-file: unknown option $word"
 }
 
+# Check that we can pass parameters using any position in the command
+# line.
+set test "add-symbol-file positionless -readnow"
+gdb_test_multiple "add-symbol-file -readnow $binfile 0x100 -s .bss 0x3" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+# When we use -s as the first argument, the section will be printed
+# first as well.
+set test "add-symbol-file positionless -s"
+gdb_test_multiple "add-symbol-file -s .bss 0x3 -readnow $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+set test "add-symbol-file positionless -s, no -readnow"
+gdb_test_multiple "add-symbol-file $binfile 0x100 -s .bss 0x3" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Check that passing "-s .text", no matter the position, always has
+# the same result.
+set test "add-symbol-file different -s .text, after file"
+gdb_test_multiple "add-symbol-file $binfile 0x100 -s .text 0x200" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+set test "add-symbol-file different -s .text, before file"
+gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Test that passing "--" disables option processing.
+gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
+    "Unrecognized argument \"-s\"" \
+    "add-symbol-file with -- disables option processing"
+set test "add-symbol-file with -- disables option processing, non-existent filename"
+gdb_test_multiple "add-symbol-file -- -non-existent-file 0x100" $test {
+    -re "add symbol table from file \"-non-existent-file\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " {
+	gdb_test "y" "-non-existent-file: No such file or directory\." $test
+    }
+}
+# Test that passing the wrong number of arguments to '-s' leads to an
+# error.
+gdb_test "add-symbol-file $binfile -s" \
+    "Missing section name after \"-s\"" \
+    "add-symbol-file with -s without section name"
+gdb_test "add-symbol-file $binfile -s .bss" \
+    "Missing section address after \"-s\"" \
+    "add-symbol-file with -s without section address"
+# Test that '-s' accepts section names with '-'
+set test "add-symbol-file with -s using section name starting with dash"
+gdb_test_multiple "add-symbol-file -s -section-name 0x200 $binfile 0x100" $test {
+    -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\-section-name_addr = 0x200\r\n\\(y or n\\) " {
+	gdb_test "n" "Not confirmed\." $test
+    }
+}
+# Since we're here, might as well test the 'symbol-file' command and
+# if its arguments can also be passed at any position.
+gdb_test "symbol-file -readnow $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow first"
+clean_restart
+gdb_test "symbol-file $binfile -readnow" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -readnow second"
+gdb_test "symbol-file -readnow" \
+    "no symbol file name was specified" \
+    "symbol-file without filename"
+gdb_test "symbol-file -- -non-existent-file" \
+    "-non-existent-file: No such file or directory\." \
+    "symbol-file with -- disables option processing"
+clean_restart
+gdb_test "symbol-file -readnow -- $binfile" \
+    "Reading symbols from ${binfile}\.\.\.expanding to full symbols\.\.\.done\." \
+    "symbol-file with -- and -readnow"
+gdb_test "symbol-file -- $binfile -readnow" \
+    "Unrecognized argument \"-readnow\"" \
+    "symbol-file with -- and -readnow, invalid option"
+
+clean_restart
+
 gdb_test "add-symbol-file ${binfile} 0 -s" \
     "Missing section name after .-s." \
     "add-symbol-file bare -s"
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-11-30 11:53   ` Pedro Alves
@ 2017-12-01  4:35     ` Sergio Durigan Junior
  2017-12-01 12:43       ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-01  4:35 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On Thursday, November 30 2017, Pedro Alves wrote:

> On 11/30/2017 12:25 AM, Sergio Durigan Junior wrote:
>
>> - Split off the fix to 'symbol-file' command argument parsing.  This
>>   patch depends on it
>>   (<https://sourceware.org/ml/gdb-patches/2017-11/msg00799.html>).
>
> This info above conflicts with ...
>
>> While implementing the code for the 'symbol-file' command, I noticed a
>> bug in 'symbol_file_command': GDB adds the symbol file before
>> finishing parsing all the options, which means that the position of an
>> option in the command impacts whether it will be considered or not.  I
>> changed the code there in order to only add the symbol file after all
>> options have been parsed.
>
> ... this info here.  The patch still has that bit...

You're right, I'll remove this bit since there's a whole new patch (with
all its glorious versions) to implement that.

>> 
>> It's also worth mentioning that this patch tests whether GDB correctly
>> fails to initialize if both '--readnow' and '--readnever' options are
>> passed.  We didn't have any infrastructure to test that, so I added a
>> new version of 'gdb_spawn', called 'gdb_spawn_ignore_error', which can
>> be used to start a GDB that will fail without compromising the entire
>> testcase.
>
> This is stale.

Removed the part that refers to 'gdb_spawn_ignore_error'.

>> gdb/testsuite/ChangeLog:
>> 
>> 2017-11-29  Joel Brobecker  <brobecker@adacore.com>
>> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
>> 	    Pedro Alves  <palves@redhat.com>
>> 
>> 	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
>> 	* lib/gdb.exp (default_gdb_spawn): Add 'ignore_error'
>> 	parameter.  Handle case when 'ignore_error' is set.
>> 	(gdb_spawn_ignore_error): New function.
>
> Also stale...

Removed the part about lib/gdb.exp.

>> @@ -699,7 +700,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>>  	}
>>      }
>>  
>> -  bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
>> +  if (!readnever_symbol_files && !(objfile->flags & OBJF_READNEVER))
>> +    bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
>
> I realized something: is it really ever possible to get here with
>
>  readnever_symbol_files && !(objfile->flags & OBJF_READNEVER)
>
> ??
>
> If readnever_symbol_files is set, then it'll have been propagated to
> objfile->flags before we get here, no?

Hm, I think so, yes.  I mean, assuming that objfile != NULL when we call
the readers, then yes; we always call symbol_file_add_with_addrs which
is responsible for propagating the flag.

> So references to the global readnever_symbol_files can (and should)
> be removed from the readers, right?  This removes the need for
> the new '#include "top.h"'s too, so please remove those from
> the patch along the way.

OK, done.

>>  
>>    if (info->stabsects)
>>      {
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index 4f552225aa..a3127dd637 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}, command-line option
>> +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
>> @@ -18576,6 +18585,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.
>>  
>> +@cindex @code{-readnever}, option for symbol-file command
>> +@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.
>
> Maybe copy the rationale for this found in "--readnever" here
> or xref the "--readnever" command line option?

I used an xref.

>
>>  #define READNOW_HELP \
>>    "The '-readnow' option will cause GDB to read the entire symbol file\n\
>>  immediately.  This makes the command slower, but may make future operations\n\
>> -faster."
>> +faster.\n"
>> +
>> +#define READNEVER_HELP \
>> +  "The '-readnever' option will prevent GDB from reading the symbol file's\n\
>> +symbolic debug information."
>>  
>
> Why not merge these two macros in one?  We'll always want to
> use them together, in the same order?  You could rename the
> macro to READNOW_READNEVER_HELP for example.

Did it.

I'll wait until we sort out the patch to extend the argument parser of
'{add-,}symbol-file' before I submit v5.

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-11-30 20:00       ` [PATCH v4] " Sergio Durigan Junior
@ 2017-12-01 12:11         ` Pedro Alves
  2017-12-01 17:41           ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-12-01 12:11 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches

On 11/30/2017 07:59 PM, Sergio Durigan Junior wrote:
> Changes from v3:
> 
> - 'add-symbol-file -s' now accepts sections whose names start with a
>   dash.
> 
> - Use a better way to test must-ask questions on the testsuite.
> 
> 
> This is a bug that's been detected while doing the readnever work.
> 
> If you use 'symbol-file' or 'add-symbol-file', the position of each
> argument passed to the command matters.  This means that if you do:
> 
>   (gdb) symbol-file -readnow /foo/bar
> 
> The symbol file specified will (correctly) have all of its symbols
> read by GDB (because of the -readnow flag).  However, if you do:
> 
>   (gdb) symbol-file /foo/bar -readnow
> 
> GDB will silently ignore the -readnow flag, because it was specified
> after the filename.  This is not a good thing to do and may confuse
> the user.
> 
> To address that, I've modified the argument parsing mechanisms of
> symbol_file_command and add_symbol_file_command to be
> "position-independent".  I have also added one error call at the end
> of add_symbol_file_command's argument parsing logic, which now clearly
> complains if no filename has been specified.  Both commands now
> support the "--" option to stop argument processing.
> 
> This patch provides a testcase for both commands, in order to make
> sure that the argument order does not matter.  It has been
> regression-tested on BuildBot.
> 
> gdb/ChangeLog:
> 
> 2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* symfile.c (symbol_file_command): Call
> 	'symbol_file_add_main_1' only after processing all command
> 	line options.
> 	(add_symbol_file_command): Modify logic to make arguments
> 	position-independent.
> 
> gdb/testsuite/ChangeLog:
> 
> 2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* gdb.base/relocate.exp: Add tests to guarantee that arguments
> 	to 'symbol-file' and 'add-symbol-file' can be
> 	position-independent.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-12-01  4:35     ` Sergio Durigan Junior
@ 2017-12-01 12:43       ` Pedro Alves
  2017-12-01 17:19         ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-12-01 12:43 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On 12/01/2017 04:35 AM, Sergio Durigan Junior wrote:

>> If readnever_symbol_files is set, then it'll have been propagated to
>> objfile->flags before we get here, no?
> 
> Hm, I think so, yes.  I mean, assuming that objfile != NULL when we call
> the readers, then yes; 

Certainly you can assume that.  A reader's job is to read
in the passed in objfile.  The very first line of elf_symfile_read
would immediately crash otherwise, for example.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-12-01 12:43       ` Pedro Alves
@ 2017-12-01 17:19         ` Tom Tromey
  2017-12-01 17:21           ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2017-12-01 17:19 UTC (permalink / raw)
  To: Pedro Alves
  Cc: Sergio Durigan Junior, GDB Patches, Joel Brobecker, Yao Qi,
	Eli Zaretskii

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> On 12/01/2017 04:35 AM, Sergio Durigan Junior wrote:
>>> If readnever_symbol_files is set, then it'll have been propagated to
objfile-> flags before we get here, no?
>> 
>> Hm, I think so, yes.  I mean, assuming that objfile != NULL when we call
>> the readers, then yes; 

Pedro> Certainly you can assume that.  A reader's job is to read
Pedro> in the passed in objfile.  The very first line of elf_symfile_read
Pedro> would immediately crash otherwise, for example.

Perhaps an ATTRIBUTE_NONNULL is in order somewhere.

Tom

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-12-01 17:19         ` Tom Tromey
@ 2017-12-01 17:21           ` Sergio Durigan Junior
  2017-12-01 20:00             ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-01 17:21 UTC (permalink / raw)
  To: Tom Tromey
  Cc: Pedro Alves, GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On Friday, December 01 2017, Tom Tromey wrote:

>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> On 12/01/2017 04:35 AM, Sergio Durigan Junior wrote:
>>>> If readnever_symbol_files is set, then it'll have been propagated to
> objfile-> flags before we get here, no?
>>> 
>>> Hm, I think so, yes.  I mean, assuming that objfile != NULL when we call
>>> the readers, then yes; 
>
> Pedro> Certainly you can assume that.  A reader's job is to read
> Pedro> in the passed in objfile.  The very first line of elf_symfile_read
> Pedro> would immediately crash otherwise, for example.
>
> Perhaps an ATTRIBUTE_NONNULL is in order somewhere.

I thought about a gdb_assert, actually.  But yeah, I agree.  I'll push
what Pedro has approved, and if he's OK with it, I'll prepare a patch
with a gdb_assert.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-12-01 12:11         ` Pedro Alves
@ 2017-12-01 17:41           ` Sergio Durigan Junior
  2017-12-01 21:45             ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-01 17:41 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Friday, December 01 2017, Pedro Alves wrote:

> On 11/30/2017 07:59 PM, Sergio Durigan Junior wrote:
>> Changes from v3:
>> 
>> - 'add-symbol-file -s' now accepts sections whose names start with a
>>   dash.
>> 
>> - Use a better way to test must-ask questions on the testsuite.
>> 
>> 
>> This is a bug that's been detected while doing the readnever work.
>> 
>> If you use 'symbol-file' or 'add-symbol-file', the position of each
>> argument passed to the command matters.  This means that if you do:
>> 
>>   (gdb) symbol-file -readnow /foo/bar
>> 
>> The symbol file specified will (correctly) have all of its symbols
>> read by GDB (because of the -readnow flag).  However, if you do:
>> 
>>   (gdb) symbol-file /foo/bar -readnow
>> 
>> GDB will silently ignore the -readnow flag, because it was specified
>> after the filename.  This is not a good thing to do and may confuse
>> the user.
>> 
>> To address that, I've modified the argument parsing mechanisms of
>> symbol_file_command and add_symbol_file_command to be
>> "position-independent".  I have also added one error call at the end
>> of add_symbol_file_command's argument parsing logic, which now clearly
>> complains if no filename has been specified.  Both commands now
>> support the "--" option to stop argument processing.
>> 
>> This patch provides a testcase for both commands, in order to make
>> sure that the argument order does not matter.  It has been
>> regression-tested on BuildBot.
>> 
>> gdb/ChangeLog:
>> 
>> 2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* symfile.c (symbol_file_command): Call
>> 	'symbol_file_add_main_1' only after processing all command
>> 	line options.
>> 	(add_symbol_file_command): Modify logic to make arguments
>> 	position-independent.
>> 
>> gdb/testsuite/ChangeLog:
>> 
>> 2017-11-30  Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* gdb.base/relocate.exp: Add tests to guarantee that arguments
>> 	to 'symbol-file' and 'add-symbol-file' can be
>> 	position-independent.
>
> OK.

Pushed.

e2e321740ce2e36a97be2a410cd56eebaa2304aa

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Add support for the readnever concept
  2017-12-01 17:21           ` Sergio Durigan Junior
@ 2017-12-01 20:00             ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2017-12-01 20:00 UTC (permalink / raw)
  To: Sergio Durigan Junior, Tom Tromey
  Cc: GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On 12/01/2017 05:21 PM, Sergio Durigan Junior wrote:
> On Friday, December 01 2017, Tom Tromey wrote:
> 
>>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>>
>> Pedro> On 12/01/2017 04:35 AM, Sergio Durigan Junior wrote:
>>>>> If readnever_symbol_files is set, then it'll have been propagated to
>> objfile-> flags before we get here, no?
>>>>
>>>> Hm, I think so, yes.  I mean, assuming that objfile != NULL when we call
>>>> the readers, then yes; 
>>
>> Pedro> Certainly you can assume that.  A reader's job is to read
>> Pedro> in the passed in objfile.  The very first line of elf_symfile_read
>> Pedro> would immediately crash otherwise, for example.
>>
>> Perhaps an ATTRIBUTE_NONNULL is in order somewhere.
> 
> I thought about a gdb_assert, actually.  But yeah, I agree.  I'll push
> what Pedro has approved, and if he's OK with it, I'll prepare a patch
> with a gdb_assert.
> 

gdb_assert (objfile != NULL) sprinkled around in the readers would be
pointless IMO.  It's not like there's any real risk that you'd
be sometimes passing a NULL pointer down to the readers in some
corner cases.  That'd be pretty gross mistake.  The objfile is kind of
like a "this" pointer here:

static void
read_symbols (struct objfile *objfile, symfile_add_flags add_flags)
{
  (*objfile->sf->sym_read) (objfile, add_flags);
...

(obviously the above crashes with a NULL objfile.  And up the
call stack, there are many other places that'd crash first
before you even get here.)

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-12-01 17:41           ` Sergio Durigan Junior
@ 2017-12-01 21:45             ` Pedro Alves
  2017-12-01 22:02               ` Sergio Durigan Junior
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-12-01 21:45 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: GDB Patches

On 12/01/2017 05:41 PM, Sergio Durigan Junior wrote:
> On Friday, December 01 2017, Pedro Alves wrote:

> e2e321740ce2e36a97be2a410cd56eebaa2304aa

Looks like you actually pushed some version of the readnever
patch with the old fix for symbol-file instead of this one?

commit e2e321740ce2e36a97be2a410cd56eebaa2304aa
Author:     Sergio Durigan Junior <sergiodj@redhat.com>
AuthorDate: Fri Nov 24 16:56:08 2017 -0500

    Add support for the readnever concept

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v4] Make '{add-,}symbol-file' not care about the position of command line arguments
  2017-12-01 21:45             ` Pedro Alves
@ 2017-12-01 22:02               ` Sergio Durigan Junior
  0 siblings, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-01 22:02 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches

On Friday, December 01 2017, Pedro Alves wrote:

> On 12/01/2017 05:41 PM, Sergio Durigan Junior wrote:
>> On Friday, December 01 2017, Pedro Alves wrote:
>
>> e2e321740ce2e36a97be2a410cd56eebaa2304aa
>
> Looks like you actually pushed some version of the readnever
> patch with the old fix for symbol-file instead of this one?
>
> commit e2e321740ce2e36a97be2a410cd56eebaa2304aa
> Author:     Sergio Durigan Junior <sergiodj@redhat.com>
> AuthorDate: Fri Nov 24 16:56:08 2017 -0500
>
>     Add support for the readnever concept

I was about to revert it.  Sorry about that.

Reverted the readnever commit:

7f0f8ac8b15f5f5327116614b4137e5dd533ada2

And pushed the right one:

40fc416f4e22913ba2a2bafcc8da05f59c677b7d

Thanks,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* [PATCH v5] Add support for the readnever concept
  2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
                   ` (4 preceding siblings ...)
  2017-11-30  0:25 ` [PATCH v4] Add support for the readnever concept Sergio Durigan Junior
@ 2017-12-01 22:16 ` Sergio Durigan Junior
  2017-12-01 23:19   ` Pedro Alves
  2017-12-02  8:21   ` Eli Zaretskii
  5 siblings, 2 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-01 22:16 UTC (permalink / raw)
  To: GDB Patches
  Cc: Joel Brobecker, Yao Qi, Pedro Alves, Eli Zaretskii,
	Sergio Durigan Junior

Changes from v4:

- Cleaned-up the commit message and ChangeLogs.

- Simplified condition when checking for readnever.  Removed "top.h"
  from files that didn't need it.

- Added xref to "-readnever" option (on symbol-file command) pointing
  to "--readnever".

- Merged READNOW_HELP and READNEVER_HELP.


The purpose of this concept is to turn the load of debugging
information off, either globally (via the '--readnever' option), or
objfile-specific.  The implementation proposed here is an extension of
the patch distributed with Fedora GDB; looking at the Fedora patch
itself and the history, one can see some reasons why it was never
resubmitted:

  - The patch appears to have been introduced as a workaround, at
    least initially;
  - The patch is far from perfect, as it simply shunts the load of
    DWARF debugging information, without really worrying about the
    other debug format.
  - Who really does non-symbolic debugging anyways?

One use of this feature 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.

This patch expands the version shipped with Fedora GDB in order to
make the feature available for all the debuginfo backends, not only
for DWARF.  It also implements a per-objfile flag which can be
activated by using the "-readnever" command when using the
'add-symbol-file' or 'symbol-file' commands.

It's also worth mentioning that this patch tests whether GDB correctly
fails to initialize if both '--readnow' and '--readnever' options are
passed.

Tested on the BuildBot.

gdb/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
	feature.
	* coffread.c (coff_symfile_read): Do not map over sections with
	'coff_locate_sections' if readnever is on.
	* dwarf2read.c (dwarf2_has_info): Return 0 if
	readnever is on.
	* elfread.c (elf_symfile_read): Do not map over sections with
	'elf_locate_sections' if readnever is on.
	* main.c (validate_readnow_readnever): New function.
	(captured_main_1): Add support for --readnever.
	(print_gdb_help): Document --readnever.
	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
	flag.
	* symfile.c (readnever_symbol_files): New global.
	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
	'READNEVER_SYMBOL_FILES' is set.
	(validate_readnow_readnever): New function.
	(symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(add_symbol_file_command): Handle '-readnever' option.
	Call 'validate_readnow_readnever'.
	(_initialize_symfile): Document new '-readnever' option for
	both 'symbol-file' and 'add-symbol-file' commands.
	* top.h (readnever_symbol_files): New extern global.
	* xcoffread.c (xcoff_initial_scan): Do not read debug
	information if readnever is on.

gdb/doc/ChangeLog:

2017-12-01  Andrew Cagney  <cagney@redhat.com>
	    Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>

	* gdb.texinfo (File Options): Document --readnever.
	(Commands to Specify Files): Likewise, for 'symbol-file' and
	'add-symbol-file'.

gdb/testsuite/ChangeLog:

2017-12-01  Joel Brobecker  <brobecker@adacore.com>
	    Sergio Durigan Junior  <sergiodj@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
---
 gdb/NEWS                             |  6 +++
 gdb/coffread.c                       |  3 +-
 gdb/doc/gdb.texinfo                  | 21 ++++++++-
 gdb/dwarf2read.c                     |  3 ++
 gdb/elfread.c                        |  3 +-
 gdb/main.c                           | 37 ++++++++++++++--
 gdb/objfile-flags.h                  |  4 ++
 gdb/symfile.c                        | 40 ++++++++++++++---
 gdb/testsuite/gdb.base/readnever.c   | 41 ++++++++++++++++++
 gdb/testsuite/gdb.base/readnever.exp | 83 ++++++++++++++++++++++++++++++++++++
 gdb/top.h                            |  1 +
 gdb/xcoffread.c                      | 48 +++++++++++----------
 12 files changed, 255 insertions(+), 35 deletions(-)
 create mode 100644 gdb/testsuite/gdb.base/readnever.c
 create mode 100644 gdb/testsuite/gdb.base/readnever.exp

diff --git a/gdb/NEWS b/gdb/NEWS
index 06df52819b..ff9a819918 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,12 @@
 
 *** 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 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.
+
 * 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
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 62b6d7945a..98f6eec820 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -699,7 +699,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 	}
     }
 
-  bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
+  if (!(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
 
   if (info->stabsects)
     {
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4f552225aa..005fed89c5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1037,6 +1037,16 @@ 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
+@anchor{--readnever}
+@cindex @code{--readnever}, command-line option
+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
@@ -18576,6 +18586,15 @@ 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.
 
+@cindex @code{-readnever}, option for symbol-file command
+@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.
+@xref{--readnever}.
+
 @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
@@ -18604,7 +18623,7 @@ the program is running.  To do this, use the @code{kill} command
 @kindex add-symbol-file
 @cindex dynamic linking
 @item add-symbol-file @var{filename} @var{address}
-@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
+@itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{|} -readnever @r{]}
 @itemx add-symbol-file @var{filename} @var{address} -s @var{section} @var{address} @dots{}
 The @code{add-symbol-file} command reads additional symbol table
 information from the file @var{filename}.  You would use this command
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2572179a75..78c663c49b 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2319,6 +2319,9 @@ int
 dwarf2_has_info (struct objfile *objfile,
                  const struct dwarf2_debug_sections *names)
 {
+  if (objfile->flags & OBJF_READNEVER)
+    return 0;
+
   dwarf2_per_objfile = ((struct dwarf2_per_objfile *)
 			objfile_data (objfile, dwarf2_objfile_data_key));
   if (!dwarf2_per_objfile)
diff --git a/gdb/elfread.c b/gdb/elfread.c
index f2483025ba..b806ca3b40 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1171,7 +1171,8 @@ elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   struct elfinfo ei;
 
   memset ((char *) &ei, 0, sizeof (ei));
-  bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
+  if (!(objfile->flags & OBJF_READNEVER))
+    bfd_map_over_sections (abfd, elf_locate_sections, (void *) & ei);
 
   elf_read_minimal_symbols (objfile, symfile_flags, &ei);
 
diff --git a/gdb/main.c b/gdb/main.c
index 61168faf50..8f04da107a 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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,7 @@ 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\
   --write            Set writing into executable and core files.\n\n\
 "), stream);
   fputs_unfiltered (_("\
diff --git a/gdb/objfile-flags.h b/gdb/objfile-flags.h
index 43ba8aaefd..f2a2ccfa8c 100644
--- a/gdb/objfile-flags.h
+++ b/gdb/objfile-flags.h
@@ -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);
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 1c9f836eb3..8f45d45d85 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -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,12 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
       flags |= OBJF_READNOW;
       add_flags &= ~SYMFILE_NO_READ;
     }
+  else if (readnever_symbol_files
+	   || (parent != NULL && (parent->flags & OBJF_READNEVER)))
+    {
+      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 +1601,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:
@@ -1641,6 +1658,8 @@ 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, "--") == 0)
 	    stop_processing_options = true;
 	  else
@@ -1650,6 +1669,8 @@ symbol_file_command (const char *args, int from_tty)
       if (name == NULL)
 	error (_("no symbol file name was specified"));
 
+      validate_readnow_readnever (flags);
+
       symbol_file_add_main_1 (name, add_flags, flags);
     }
 }
@@ -2236,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)
 	{
 	  if (argv[argcnt + 1] == NULL)
@@ -2257,6 +2280,8 @@ add_symbol_file_command (const char *args, int from_tty)
   if (filename == NULL)
     error (_("You must provide a filename to be loaded."));
 
+  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
@@ -3882,26 +3907,29 @@ _initialize_symfile (void)
 
   observer_attach_free_objfile (symfile_free_objfile);
 
-#define READNOW_HELP \
+#define READNOW_READNEVER_HELP \
   "The '-readnow' option will cause GDB to read the entire symbol file\n\
 immediately.  This makes the command slower, but may make future operations\n\
-faster."
+faster.\n\
+The '-readnever' option will prevent GDB from reading the symbol file's\n\
+symbolic debug information."
 
   c = add_cmd ("symbol-file", class_files, symbol_file_command, _("\
 Load symbol table from executable file FILE.\n\
-Usage: symbol-file [-readnow] FILE\n\
+Usage: symbol-file [-readnow | -readnever] FILE\n\
 The `file' command can also load symbol tables, as well as setting the file\n\
-to execute.\n" READNOW_HELP), &cmdlist);
+to execute.\n" READNOW_READNEVER_HELP), &cmdlist);
   set_cmd_completer (c, filename_completer);
 
   c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\
 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
-Usage: add-symbol-file FILE ADDR [-readnow | -s SECT-NAME SECT-ADDR]...\n\
+Usage: add-symbol-file FILE ADDR [-readnow | -readnever | \
+-s SECT-NAME SECT-ADDR]...\n\
 ADDR is the starting address of the file's text.\n\
 Each '-s' argument provides a section name and address, and\n\
 should be specified if the data and bss segments are not contiguous\n\
 with the text.  SECT-NAME is a section name to be loaded at SECT-ADDR.\n"
-READNOW_HELP),
+READNOW_READNEVER_HELP),
 	       &cmdlist);
   set_cmd_completer (c, filename_completer);
 
diff --git a/gdb/testsuite/gdb.base/readnever.c b/gdb/testsuite/gdb.base/readnever.c
new file mode 100644
index 0000000000..6489e891de
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.c
@@ -0,0 +1,41 @@
+/* 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/>.  */
+
+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;
+}
diff --git a/gdb/testsuite/gdb.base/readnever.exp b/gdb/testsuite/gdb.base/readnever.exp
new file mode 100644
index 0000000000..151f12a6bb
--- /dev/null
+++ b/gdb/testsuite/gdb.base/readnever.exp
@@ -0,0 +1,83 @@
+# 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
+
+    set test "test readnow and readnever at the same time"
+    gdb_test_multiple "" $test {
+	"'--readnow' and '--readnever' cannot be specified simultaneously" {
+	    pass $test
+	    set test "expect eof after failure"
+	    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"
diff --git a/gdb/top.h b/gdb/top.h
index 26fe87842f..a1df64f383 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -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 *);
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 46a43bc9ae..b1c634c93b 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2975,31 +2975,33 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
       /* Read the string table.  */
       init_stringtab (abfd, stringtab_offset, objfile);
 
-      /* Read the .debug section, if present.  */
-      {
-	struct bfd_section *secp;
-	bfd_size_type length;
-	bfd_byte *debugsec = NULL;
+      /* Read the .debug section, if present and if we're not ignoring
+	 it.  */
+      if (!(objfile->flags & OBJF_READNEVER))
+	{
+	  struct bfd_section *secp;
+	  bfd_size_type length;
+	  bfd_byte *debugsec = NULL;
 
-	secp = bfd_get_section_by_name (abfd, ".debug");
-	if (secp)
-	  {
-	    length = bfd_section_size (abfd, secp);
-	    if (length)
-	      {
-		debugsec
-		  = (bfd_byte *) obstack_alloc (&objfile->objfile_obstack,
-						length);
+	  secp = bfd_get_section_by_name (abfd, ".debug");
+	  if (secp)
+	    {
+	      length = bfd_section_size (abfd, secp);
+	      if (length)
+		{
+		  debugsec
+		    = (bfd_byte *) obstack_alloc (&objfile->objfile_obstack,
+						  length);
 
-		if (!bfd_get_full_section_contents (abfd, secp, &debugsec))
-		  {
-		    error (_("Error reading .debug section of `%s': %s"),
-			   name, bfd_errmsg (bfd_get_error ()));
-		  }
-	      }
-	  }
-	info->debugsec = (char *) debugsec;
-      }
+		  if (!bfd_get_full_section_contents (abfd, secp, &debugsec))
+		    {
+		      error (_("Error reading .debug section of `%s': %s"),
+			     name, bfd_errmsg (bfd_get_error ()));
+		    }
+		}
+	    }
+	  info->debugsec = (char *) debugsec;
+	}
     }
 
   /* Read the symbols.  We keep them in core because we will want to
-- 
2.13.3

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v5] Add support for the readnever concept
  2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
@ 2017-12-01 23:19   ` Pedro Alves
  2017-12-02  2:31     ` Sergio Durigan Junior
  2017-12-02  8:21   ` Eli Zaretskii
  1 sibling, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2017-12-01 23:19 UTC (permalink / raw)
  To: Sergio Durigan Junior, GDB Patches; +Cc: Joel Brobecker, Yao Qi, Eli Zaretskii

On 12/01/2017 10:16 PM, Sergio Durigan Junior wrote:
> Changes from v4:
> 
> - Cleaned-up the commit message and ChangeLogs.
> 
> - Simplified condition when checking for readnever.  Removed "top.h"
>   from files that didn't need it.
> 
> - Added xref to "-readnever" option (on symbol-file command) pointing
>   to "--readnever".
> 
> - Merged READNOW_HELP and READNEVER_HELP.
> 
> 
> The purpose of this concept is to turn the load of debugging
> information off, either globally (via the '--readnever' option), or
> objfile-specific.  The implementation proposed here is an extension of
> the patch distributed with Fedora GDB; looking at the Fedora patch
> itself and the history, one can see some reasons why it was never
> resubmitted:
> 
>   - The patch appears to have been introduced as a workaround, at
>     least initially;
>   - The patch is far from perfect, as it simply shunts the load of
>     DWARF debugging information, without really worrying about the
>     other debug format.
>   - Who really does non-symbolic debugging anyways?
> 
> One use of this feature 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.
> 
> This patch expands the version shipped with Fedora GDB in order to
> make the feature available for all the debuginfo backends, not only
> for DWARF.  It also implements a per-objfile flag which can be
> activated by using the "-readnever" command when using the
> 'add-symbol-file' or 'symbol-file' commands.
> 
> It's also worth mentioning that this patch tests whether GDB correctly
> fails to initialize if both '--readnow' and '--readnever' options are
> passed.
> 
> Tested on the BuildBot.
> 
> gdb/ChangeLog:
> 
> 2017-12-01  Andrew Cagney  <cagney@redhat.com>
> 	    Joel Brobecker  <brobecker@adacore.com>
> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
> 	feature.
> 	* coffread.c (coff_symfile_read): Do not map over sections with
> 	'coff_locate_sections' if readnever is on.
> 	* dwarf2read.c (dwarf2_has_info): Return 0 if
> 	readnever is on.
> 	* elfread.c (elf_symfile_read): Do not map over sections with
> 	'elf_locate_sections' if readnever is on.
> 	* main.c (validate_readnow_readnever): New function.
> 	(captured_main_1): Add support for --readnever.
> 	(print_gdb_help): Document --readnever.
> 	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
> 	flag.
> 	* symfile.c (readnever_symbol_files): New global.
> 	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
> 	'READNEVER_SYMBOL_FILES' is set.
> 	(validate_readnow_readnever): New function.
> 	(symbol_file_command): Handle '-readnever' option.
> 	Call 'validate_readnow_readnever'.
> 	(add_symbol_file_command): Handle '-readnever' option.
> 	Call 'validate_readnow_readnever'.
> 	(_initialize_symfile): Document new '-readnever' option for
> 	both 'symbol-file' and 'add-symbol-file' commands.
> 	* top.h (readnever_symbol_files): New extern global.
> 	* xcoffread.c (xcoff_initial_scan): Do not read debug
> 	information if readnever is on.
> 
> gdb/doc/ChangeLog:
> 
> 2017-12-01  Andrew Cagney  <cagney@redhat.com>
> 	    Joel Brobecker  <brobecker@adacore.com>
> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
> 
> 	* gdb.texinfo (File Options): Document --readnever.
> 	(Commands to Specify Files): Likewise, for 'symbol-file' and
> 	'add-symbol-file'.
> 
> gdb/testsuite/ChangeLog:
> 
> 2017-12-01  Joel Brobecker  <brobecker@adacore.com>
> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
> 	    Pedro Alves  <palves@redhat.com>
> 
> 	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.

OK.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v5] Add support for the readnever concept
  2017-12-01 23:19   ` Pedro Alves
@ 2017-12-02  2:31     ` Sergio Durigan Junior
  0 siblings, 0 replies; 58+ messages in thread
From: Sergio Durigan Junior @ 2017-12-02  2:31 UTC (permalink / raw)
  To: Pedro Alves; +Cc: GDB Patches, Joel Brobecker, Yao Qi, Eli Zaretskii

On Friday, December 01 2017, Pedro Alves wrote:

> On 12/01/2017 10:16 PM, Sergio Durigan Junior wrote:
>> Changes from v4:
>> 
>> - Cleaned-up the commit message and ChangeLogs.
>> 
>> - Simplified condition when checking for readnever.  Removed "top.h"
>>   from files that didn't need it.
>> 
>> - Added xref to "-readnever" option (on symbol-file command) pointing
>>   to "--readnever".
>> 
>> - Merged READNOW_HELP and READNEVER_HELP.
>> 
>> 
>> The purpose of this concept is to turn the load of debugging
>> information off, either globally (via the '--readnever' option), or
>> objfile-specific.  The implementation proposed here is an extension of
>> the patch distributed with Fedora GDB; looking at the Fedora patch
>> itself and the history, one can see some reasons why it was never
>> resubmitted:
>> 
>>   - The patch appears to have been introduced as a workaround, at
>>     least initially;
>>   - The patch is far from perfect, as it simply shunts the load of
>>     DWARF debugging information, without really worrying about the
>>     other debug format.
>>   - Who really does non-symbolic debugging anyways?
>> 
>> One use of this feature 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.
>> 
>> This patch expands the version shipped with Fedora GDB in order to
>> make the feature available for all the debuginfo backends, not only
>> for DWARF.  It also implements a per-objfile flag which can be
>> activated by using the "-readnever" command when using the
>> 'add-symbol-file' or 'symbol-file' commands.
>> 
>> It's also worth mentioning that this patch tests whether GDB correctly
>> fails to initialize if both '--readnow' and '--readnever' options are
>> passed.
>> 
>> Tested on the BuildBot.
>> 
>> gdb/ChangeLog:
>> 
>> 2017-12-01  Andrew Cagney  <cagney@redhat.com>
>> 	    Joel Brobecker  <brobecker@adacore.com>
>> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* NEWS (Changes since GDB 8.0: Mention new '--readnever'
>> 	feature.
>> 	* coffread.c (coff_symfile_read): Do not map over sections with
>> 	'coff_locate_sections' if readnever is on.
>> 	* dwarf2read.c (dwarf2_has_info): Return 0 if
>> 	readnever is on.
>> 	* elfread.c (elf_symfile_read): Do not map over sections with
>> 	'elf_locate_sections' if readnever is on.
>> 	* main.c (validate_readnow_readnever): New function.
>> 	(captured_main_1): Add support for --readnever.
>> 	(print_gdb_help): Document --readnever.
>> 	* objfile-flags.h (enum objfile_flag) <OBJF_READNEVER>: New
>> 	flag.
>> 	* symfile.c (readnever_symbol_files): New global.
>> 	(symbol_file_add_with_addrs): Set 'OBJF_READNEVER' when
>> 	'READNEVER_SYMBOL_FILES' is set.
>> 	(validate_readnow_readnever): New function.
>> 	(symbol_file_command): Handle '-readnever' option.
>> 	Call 'validate_readnow_readnever'.
>> 	(add_symbol_file_command): Handle '-readnever' option.
>> 	Call 'validate_readnow_readnever'.
>> 	(_initialize_symfile): Document new '-readnever' option for
>> 	both 'symbol-file' and 'add-symbol-file' commands.
>> 	* top.h (readnever_symbol_files): New extern global.
>> 	* xcoffread.c (xcoff_initial_scan): Do not read debug
>> 	information if readnever is on.
>> 
>> gdb/doc/ChangeLog:
>> 
>> 2017-12-01  Andrew Cagney  <cagney@redhat.com>
>> 	    Joel Brobecker  <brobecker@adacore.com>
>> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
>> 
>> 	* gdb.texinfo (File Options): Document --readnever.
>> 	(Commands to Specify Files): Likewise, for 'symbol-file' and
>> 	'add-symbol-file'.
>> 
>> gdb/testsuite/ChangeLog:
>> 
>> 2017-12-01  Joel Brobecker  <brobecker@adacore.com>
>> 	    Sergio Durigan Junior  <sergiodj@redhat.com>
>> 	    Pedro Alves  <palves@redhat.com>
>> 
>> 	* gdb.base/readnever.c, gdb.base/readnever.exp: New files.
>
> OK.

Pushed:

97cbe998d0dd5c13a0317fbb24d745da367d8caa

Thanks.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 58+ messages in thread

* Re: [PATCH v5] Add support for the readnever concept
  2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
  2017-12-01 23:19   ` Pedro Alves
@ 2017-12-02  8:21   ` Eli Zaretskii
  1 sibling, 0 replies; 58+ messages in thread
From: Eli Zaretskii @ 2017-12-02  8:21 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches, brobecker, qiyaoltc, palves

> 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,  1 Dec 2017 17:16:00 -0500
> 
> +@cindex @code{-readnever}, option for symbol-file command

"symbol-file" should be in @code here.

The documentation parts are OK with this nit fixed.

Thanks.

^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2017-12-02  8:21 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-06 20:54 [RFC/RFA] Add support for the --readnever command-line option (DWARF only) Joel Brobecker
2016-07-12 14:27 ` Yao Qi
2016-10-04 18:07   ` Pedro Alves
2017-11-23  0:54     ` [PATCH v2] " Sergio Durigan Junior
2017-11-23 12:09       ` Pedro Alves
2017-11-23 17:21         ` Sergio Durigan Junior
2017-11-23 17:29           ` Pedro Alves
2017-11-24  4:54             ` Sergio Durigan Junior
2017-11-24 13:18               ` Pedro Alves
2017-11-24 20:27                 ` Sergio Durigan Junior
2017-11-27 19:13                   ` Pedro Alves
2017-11-29  0:59                     ` Sergio Durigan Junior
2017-11-29 12:23                       ` Pedro Alves
2017-11-23 15:59       ` Eli Zaretskii
2017-11-23 19:36         ` Sergio Durigan Junior
2016-10-04 18:06 ` [RFC/RFA] " Pedro Alves
2017-11-24 23:01 ` [PATCH v2] Add support for the --readnever command-line option Sergio Durigan Junior
2017-11-25  7:33   ` Eli Zaretskii
2017-11-25 16:41     ` Sergio Durigan Junior
2017-11-25 17:16       ` Eli Zaretskii
2017-11-29  1:21 ` [PATCH v3] Add support for the readnever concept Sergio Durigan Junior
2017-11-29  3:39   ` Eli Zaretskii
2017-11-29 12:25   ` Pedro Alves
2017-11-29 18:43     ` Sergio Durigan Junior
2017-11-29 21:45     ` [PATCH] Make 'symbol-file' not care about the position of command line arguments Sergio Durigan Junior
2017-11-29 22:26       ` Pedro Alves
2017-11-29 22:42         ` Sergio Durigan Junior
2017-11-29 23:15           ` Pedro Alves
2017-11-30  0:08             ` Sergio Durigan Junior
2017-11-30  0:34               ` Pedro Alves
2017-11-30  4:07                 ` Sergio Durigan Junior
2017-11-30  4:25       ` [PATCH v2] Make '{add-,}symbol-file' " Sergio Durigan Junior
2017-11-30 10:57         ` Pedro Alves
2017-11-30 12:38           ` Sergio Durigan Junior
2017-11-30 12:49             ` Pedro Alves
2017-11-30 13:06               ` Sergio Durigan Junior
2017-11-30 13:33       ` [PATCH v3] " Sergio Durigan Junior
2017-11-30 15:01         ` Pedro Alves
2017-11-30 17:26           ` Sergio Durigan Junior
2017-11-30 17:37             ` Pedro Alves
2017-11-30 17:43               ` Sergio Durigan Junior
2017-11-30 17:50                 ` Pedro Alves
2017-11-30 20:00       ` [PATCH v4] " Sergio Durigan Junior
2017-12-01 12:11         ` Pedro Alves
2017-12-01 17:41           ` Sergio Durigan Junior
2017-12-01 21:45             ` Pedro Alves
2017-12-01 22:02               ` Sergio Durigan Junior
2017-11-30  0:25 ` [PATCH v4] Add support for the readnever concept Sergio Durigan Junior
2017-11-30 11:53   ` Pedro Alves
2017-12-01  4:35     ` Sergio Durigan Junior
2017-12-01 12:43       ` Pedro Alves
2017-12-01 17:19         ` Tom Tromey
2017-12-01 17:21           ` Sergio Durigan Junior
2017-12-01 20:00             ` Pedro Alves
2017-12-01 22:16 ` [PATCH v5] " Sergio Durigan Junior
2017-12-01 23:19   ` Pedro Alves
2017-12-02  2:31     ` Sergio Durigan Junior
2017-12-02  8:21   ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).