[v2] gdb/configure.ac: Add option --with-additional-debug-dirs

Message ID 20231004183102.61669-1-thiago.bauermann@linaro.org
State New
Headers
Series [v2] gdb/configure.ac: Add option --with-additional-debug-dirs |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed

Commit Message

Thiago Jung Bauermann Oct. 4, 2023, 6:31 p.m. UTC
  If you want to install GDB in a custom prefix, have it look for debug info
in that prefix but also in the distro's default location (typically,
/usr/lib/debug) and run the GDB testsuite before doing "make install", you
have a bit of a problem:

Configuring GDB with '--prefix=$PREFIX' sets the GDB 'debug-file-directory'
parameter to $PREFIX/lib/debug.  Unfortunately this precludes GDB from
looking for distro-installed debug info in /usr/lib/debug.  For regular GDB
use you could set debug-file-directory to $PREFIX:/usr/lib/debug in
$PREFIX/etc/gdbinit so that GDB will look in both places, but if you want
to run the testsuite then that doesn't help because in that case GDB runs
with the '-nx' option.

There's the configure option '--with-separate-debug-dir' to set the default
value for 'debug-file-directory', but it accepts only one directory and not
a list.  I considered modifying it to accept a list, but it's not obvious
how to do that because its value is also used by BFD, as well as processed
for "relocatability".

I thought it was simpler to add a new option to specify a list of
additional directories that will be appended to the debug-file-directory
setting.
---
 gdb/NEWS            |  8 ++++++++
 gdb/config.in       |  3 +++
 gdb/configure       | 19 +++++++++++++++++--
 gdb/configure.ac    |  8 ++++++++
 gdb/doc/gdb.texinfo |  6 ++++--
 gdb/main.c          |  5 +++++
 gdb/top.c           |  6 ++++++
 7 files changed, 51 insertions(+), 4 deletions(-)

Changed since v1:
Addressed Tom Tromey's review comments:
- Added NEWS entry for the new configure option.
- Documented the new configure option in the GDB manual.
- Properly indented the body of AC_ARG_WITH.
- Added parentheses around RHS side of the assignment in gdb/main.c.


base-commit: 1181bcd0d2572aee2c0947040e56bc1f9af634e3
  

Comments

Eli Zaretskii Oct. 5, 2023, 5:05 a.m. UTC | #1
> Cc: Tom Tromey <tom@tromey.com>
> Date: Wed,  4 Oct 2023 15:31:02 -0300
> From: Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org>
> 
> If you want to install GDB in a custom prefix, have it look for debug info
> in that prefix but also in the distro's default location (typically,
> /usr/lib/debug) and run the GDB testsuite before doing "make install", you
> have a bit of a problem:
> 
> Configuring GDB with '--prefix=$PREFIX' sets the GDB 'debug-file-directory'
> parameter to $PREFIX/lib/debug.  Unfortunately this precludes GDB from
> looking for distro-installed debug info in /usr/lib/debug.  For regular GDB
> use you could set debug-file-directory to $PREFIX:/usr/lib/debug in
> $PREFIX/etc/gdbinit so that GDB will look in both places, but if you want
> to run the testsuite then that doesn't help because in that case GDB runs
> with the '-nx' option.
> 
> There's the configure option '--with-separate-debug-dir' to set the default
> value for 'debug-file-directory', but it accepts only one directory and not
> a list.  I considered modifying it to accept a list, but it's not obvious
> how to do that because its value is also used by BFD, as well as processed
> for "relocatability".
> 
> I thought it was simpler to add a new option to specify a list of
> additional directories that will be appended to the debug-file-directory
> setting.

Thanks, the documentation parts are okay.

However, I wonder: on MS-Windows, the "colon-separated list" becomes
"semi-colon separated list", and I have an old and annoying problem
with 2 similar configure-time options, --with-auto-load-safe-path= and
--with-auto-load-dir=, which fail to communicate semi-colon separated
lists to gdb/configure, and require me to manually edit gdb/config.h
and rebuild.  So I wonder whether this new option will have the same
problem, and whether we could perhaps take this opportunity for fixing
this?

This is https://sourceware.org/bugzilla/show_bug.cgi?id=18898, btw.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Tom Tromey Oct. 5, 2023, 3:16 p.m. UTC | #2
>>>>> "Thiago" == Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org> writes:

Thiago> If you want to install GDB in a custom prefix, have it look for debug info
Thiago> in that prefix but also in the distro's default location (typically,
Thiago> /usr/lib/debug) and run the GDB testsuite before doing "make install", you
Thiago> have a bit of a problem:

...

Thank you.  This is ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Thiago Jung Bauermann Oct. 5, 2023, 11:12 p.m. UTC | #3
Eli Zaretskii <eliz@gnu.org> writes:

>> Cc: Tom Tromey <tom@tromey.com>
>> Date: Wed,  4 Oct 2023 15:31:02 -0300
>> From: Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org>
>> 
>> If you want to install GDB in a custom prefix, have it look for debug info
>> in that prefix but also in the distro's default location (typically,
>> /usr/lib/debug) and run the GDB testsuite before doing "make install", you
>> have a bit of a problem:
>> 
>> Configuring GDB with '--prefix=$PREFIX' sets the GDB 'debug-file-directory'
>> parameter to $PREFIX/lib/debug.  Unfortunately this precludes GDB from
>> looking for distro-installed debug info in /usr/lib/debug.  For regular GDB
>> use you could set debug-file-directory to $PREFIX:/usr/lib/debug in
>> $PREFIX/etc/gdbinit so that GDB will look in both places, but if you want
>> to run the testsuite then that doesn't help because in that case GDB runs
>> with the '-nx' option.
>> 
>> There's the configure option '--with-separate-debug-dir' to set the default
>> value for 'debug-file-directory', but it accepts only one directory and not
>> a list.  I considered modifying it to accept a list, but it's not obvious
>> how to do that because its value is also used by BFD, as well as processed
>> for "relocatability".
>> 
>> I thought it was simpler to add a new option to specify a list of
>> additional directories that will be appended to the debug-file-directory
>> setting.
>
> Thanks, the documentation parts are okay.

Thank you!

> However, I wonder: on MS-Windows, the "colon-separated list" becomes
> "semi-colon separated list", and I have an old and annoying problem
> with 2 similar configure-time options, --with-auto-load-safe-path= and
> --with-auto-load-dir=, which fail to communicate semi-colon separated
> lists to gdb/configure, and require me to manually edit gdb/config.h
> and rebuild.  So I wonder whether this new option will have the same
> problem, and whether we could perhaps take this opportunity for fixing
> this?
>
> This is https://sourceware.org/bugzilla/show_bug.cgi?id=18898, btw.

I looked a bit into this, and I don't see an easy solution. The problem
is that shell scripting language is notoriously bad at keeping data from
leaking into the code.

If I do:

$ ~/src/binutils-gdb/configure \
    --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
    --with-auto-load-dir='foo;bar' && make

I get:

checking for default auto-load directory... /home/bauermann/src/binutils-gdb/gdb/configure: line 18004: bar: command not found
foo;bar
checking for default auto-load safe-path... /home/bauermann/src/binutils-gdb/gdb/configure: line 18031: bar: command not found
foo;bar

Line 18004 is:

ac_define_dir=`eval echo $escape_dir`

Line 18031 is identical.

If the configure script could use bash features instead of having to
assume a POSIX shell, we could use "printf %q" to escape the input. Is
there an equivalent solution that's in POSIX shell?

In any case, any solution would be in an autoconf macro, not in GDB.

As a workaround, I was able to get away with some escaping:

$ ~/src/binutils-gdb/configure \
    --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
    --with-auto-load-dir='foo\\\;bar\\\;baz' && make
    ⋮
checking for default auto-load directory... foo\\\;bar\\\;baz
checking for default auto-load safe-path... foo\\\;bar\\\;baz
    ⋮
$ grep AUTO_LOAD gdb/config.h
#define AUTO_LOAD_DIR "foo;bar;baz"
#define AUTO_LOAD_SAFE_PATH "foo;bar;baz"


> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  
Thiago Jung Bauermann Oct. 6, 2023, 2:03 a.m. UTC | #4
Tom Tromey <tom@tromey.com> writes:

>>>>>> "Thiago" == Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org>
> writes:
>
> Thiago> If you want to install GDB in a custom prefix, have it look for debug info
> Thiago> in that prefix but also in the distro's default location (typically,
> Thiago> /usr/lib/debug) and run the GDB testsuite before doing "make install", you
> Thiago> have a bit of a problem:
>
> ...
>
> Thank you.  This is ok.
> Approved-By: Tom Tromey <tom@tromey.com>

Thanks! Pushed as commit 740ce35025a5.
  
Eli Zaretskii Oct. 7, 2023, 7:01 a.m. UTC | #5
> From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> Cc: gdb-patches@sourceware.org, tom@tromey.com
> Date: Thu, 05 Oct 2023 20:12:17 -0300
> 
> As a workaround, I was able to get away with some escaping:
> 
> $ ~/src/binutils-gdb/configure \
>     --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
>     --with-auto-load-dir='foo\\\;bar\\\;baz' && make
>     ⋮
> checking for default auto-load directory... foo\\\;bar\\\;baz
> checking for default auto-load safe-path... foo\\\;bar\\\;baz
>     ⋮
> $ grep AUTO_LOAD gdb/config.h
> #define AUTO_LOAD_DIR "foo;bar;baz"
> #define AUTO_LOAD_SAFE_PATH "foo;bar;baz"

Thanks, will use these in my next build, and see if it works for me as
well.
  
Eli Zaretskii Oct. 26, 2023, 11:58 a.m. UTC | #6
> Date: Sat, 07 Oct 2023 10:01:52 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: gdb-patches@sourceware.org, tom@tromey.com
> X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH,
>  DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_PASS, SPF_PASS,
>  TXREP autolearn=ham autolearn_force=no version=3.4.6
> 
> > From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> > Cc: gdb-patches@sourceware.org, tom@tromey.com
> > Date: Thu, 05 Oct 2023 20:12:17 -0300
> > 
> > As a workaround, I was able to get away with some escaping:
> > 
> > $ ~/src/binutils-gdb/configure \
> >     --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
> >     --with-auto-load-dir='foo\\\;bar\\\;baz' && make
> >     ⋮
> > checking for default auto-load directory... foo\\\;bar\\\;baz
> > checking for default auto-load safe-path... foo\\\;bar\\\;baz
> >     ⋮
> > $ grep AUTO_LOAD gdb/config.h
> > #define AUTO_LOAD_DIR "foo;bar;baz"
> > #define AUTO_LOAD_SAFE_PATH "foo;bar;baz"
> 
> Thanks, will use these in my next build, and see if it works for me as
> well.

FTR: just tried this with the gdb-14.0.91 pretest, and it works just
fine.  Thank you very much for helping me avoid this annoying problem
(it previously required me to build GDB twice).

I've updated the Bugzilla bug with this information.

Thanks!
  
Thiago Jung Bauermann Oct. 26, 2023, 11:48 p.m. UTC | #7
Hello Eli,

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sat, 07 Oct 2023 10:01:52 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>> Cc: gdb-patches@sourceware.org, tom@tromey.com
>> X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH,
>>  DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_PASS, SPF_PASS,
>>  TXREP autolearn=ham autolearn_force=no version=3.4.6
>> 
>> > From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
>> > Cc: gdb-patches@sourceware.org, tom@tromey.com
>> > Date: Thu, 05 Oct 2023 20:12:17 -0300
>> > 
>> > As a workaround, I was able to get away with some escaping:
>> > 
>> > $ ~/src/binutils-gdb/configure \
>> >     --disable-{binutils,ld,gold,gas,sim,gprof,gprofng} \
>> >     --with-auto-load-dir='foo\\\;bar\\\;baz' && make
>> >     ⋮
>> > checking for default auto-load directory... foo\\\;bar\\\;baz
>> > checking for default auto-load safe-path... foo\\\;bar\\\;baz
>> >     ⋮
>> > $ grep AUTO_LOAD gdb/config.h
>> > #define AUTO_LOAD_DIR "foo;bar;baz"
>> > #define AUTO_LOAD_SAFE_PATH "foo;bar;baz"
>> 
>> Thanks, will use these in my next build, and see if it works for me as
>> well.
>
> FTR: just tried this with the gdb-14.0.91 pretest, and it works just
> fine.  Thank you very much for helping me avoid this annoying problem
> (it previously required me to build GDB twice).

Excellent! I poked at it some more today and I noticed two things:

1. We provide the definition of AC_DEFINE_DIR ourselves in
   gdb/acinclude.m4, so what I said earlier about the fix having to be
   in Autoconf was wrong. Too bad, it's always a relief when the blame
   lies somewhere else. :-)

2. We can do the escape trick above automatically in gdb/configure.ac.

So I just sent a patch to do that:

https://inbox.sourceware.org/gdb-patches/20231026234013.937210-1-thiago.bauermann@linaro.org/

> I've updated the Bugzilla bug with this information.

Thanks. I will also update the bugzilla with my findings.
  
Eli Zaretskii Oct. 27, 2023, 5:59 a.m. UTC | #8
> From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> Cc: gdb-patches@sourceware.org, tom@tromey.com
> Date: Thu, 26 Oct 2023 20:48:58 -0300
> 
> > FTR: just tried this with the gdb-14.0.91 pretest, and it works just
> > fine.  Thank you very much for helping me avoid this annoying problem
> > (it previously required me to build GDB twice).
> 
> Excellent! I poked at it some more today and I noticed two things:
> 
> 1. We provide the definition of AC_DEFINE_DIR ourselves in
>    gdb/acinclude.m4, so what I said earlier about the fix having to be
>    in Autoconf was wrong. Too bad, it's always a relief when the blame
>    lies somewhere else. :-)
> 
> 2. We can do the escape trick above automatically in gdb/configure.ac.
> 
> So I just sent a patch to do that:
> 
> https://inbox.sourceware.org/gdb-patches/20231026234013.937210-1-thiago.bauermann@linaro.org/

Thanks, this is even better!
  

Patch

diff --git a/gdb/NEWS b/gdb/NEWS
index 20f53a0d542d..9fe46b5b2e32 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -110,6 +110,14 @@ 
   'inferior' keyword with either the 'thread' or 'task' keywords when
   creating a breakpoint.
 
+* Configure changes
+
+--additional-debug-dirs=PATHs
+
+  Provide a colon-separated list of additional directories to search for
+  separate debug info.  These directories are added to the default value of
+  the 'debug-file-directory' GDB parameter.
+
 * New commands
 
 set debug breakpoint on|off
diff --git a/gdb/config.in b/gdb/config.in
index f67d3029d829..e17245156d8d 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -3,6 +3,9 @@ 
 /* Define if building universal (internal helper macro) */
 #undef AC_APPLE_UNIVERSAL_BUILD
 
+/* Additional directories to look for separate debug info. */
+#undef ADDITIONAL_DEBUG_DIRS
+
 /* Directories from which to load auto-loaded scripts. */
 #undef AUTO_LOAD_DIR
 
diff --git a/gdb/configure b/gdb/configure
index 2d07e0cb596e..1cbc356cb967 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -906,6 +906,7 @@  enable_fast_install
 with_gnu_ld
 enable_libtool_lock
 with_separate_debug_dir
+with_additional_debug_dirs
 with_gdb_datadir
 with_relocated_sources
 with_auto_load_dir
@@ -1660,6 +1661,9 @@  Optional Packages:
   --with-separate-debug-dir=PATH
                           look for global separate debug info in this path
                           [LIBDIR/debug]
+  --with-additional-debug-dirs=PATHs
+                          colon-separated list of additional directories to
+                          search for separate debug info
   --with-gdb-datadir=PATH look for global separate data files in this path
                           [DATADIR/gdb]
   --with-relocated-sources=PATH
@@ -11479,7 +11483,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11482 "configure"
+#line 11486 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11585,7 +11589,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11588 "configure"
+#line 11592 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17886,6 +17890,17 @@  _ACEOF
 
 
 
+
+# Check whether --with-additional-debug-dirs was given.
+if test "${with_additional_debug_dirs+set}" = set; then :
+  withval=$with_additional_debug_dirs;
+cat >>confdefs.h <<_ACEOF
+#define ADDITIONAL_DEBUG_DIRS "${withval}"
+_ACEOF
+
+fi
+
+
 # We can't pass paths as command line arguments.
 # Mingw32 tries to be clever and will convert the paths for us.
 # For example -DBINDIR="/usr/local/bin" passed on the command line may get
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 97c6bf0ed5f9..0264199b9481 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -119,6 +119,14 @@  GDB_AC_WITH_DIR(DEBUGDIR, separate-debug-dir,
     [look for global separate debug info in this path @<:@LIBDIR/debug@:>@],
     [${libdir}/debug])
 
+AC_ARG_WITH(additional-debug-dirs,
+	    AS_HELP_STRING([--with-additional-debug-dirs=PATHs],
+			   [colon-separated list of additional directories to
+			    search for separate debug info]),
+	    [AC_DEFINE_UNQUOTED(ADDITIONAL_DEBUG_DIRS, "${withval}",
+				Additional directories to look for separate
+				debug info.)])
+
 # We can't pass paths as command line arguments.
 # Mingw32 tries to be clever and will convert the paths for us.
 # For example -DBINDIR="/usr/local/bin" passed on the command line may get
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index e1385cfb5192..168c4f7cc016 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -22275,8 +22275,10 @@  file from @code{debuginfod} servers.
 
 @anchor{debug-file-directory}
 Global debugging info directories default to what is set by @value{GDBN}
-configure option @option{--with-separate-debug-dir}.  During @value{GDBN} run
-you can also set the global debugging info directories, and view the list
+configure option @option{--with-separate-debug-dir} and augmented by the
+colon-separated list of directories provided via @value{GDBN} configure
+option @option{--additional-debug-dirs}.  During @value{GDBN} run you can
+also set the global debugging info directories, and view the list
 @value{GDBN} is currently using.
 
 @table @code
diff --git a/gdb/main.c b/gdb/main.c
index 97e04f5b5d8e..99468e0853ed 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -723,6 +723,11 @@  captured_main_1 (struct captured_main_args *context)
   debug_file_directory
     = relocate_gdb_directory (DEBUGDIR, DEBUGDIR_RELOCATABLE);
 
+#ifdef ADDITIONAL_DEBUG_DIRS
+  debug_file_directory = (debug_file_directory + DIRNAME_SEPARATOR
+			  + ADDITIONAL_DEBUG_DIRS);
+#endif
+
   gdb_datadir = relocate_gdb_directory (GDB_DATADIR,
 					GDB_DATADIR_RELOCATABLE);
 
diff --git a/gdb/top.c b/gdb/top.c
index cbe14b010466..5028440b6711 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1587,6 +1587,12 @@  This GDB was configured as follows:\n\
 	     --with-separate-debug-dir=%s%s\n\
 "), DEBUGDIR, DEBUGDIR_RELOCATABLE ? " (relocatable)" : "");
 
+#ifdef ADDITIONAL_DEBUG_DIRS
+  gdb_printf (stream, _ ("\
+	     --with-additional-debug-dirs=%s\n\
+"), ADDITIONAL_DEBUG_DIRS);
+#endif
+
   if (TARGET_SYSTEM_ROOT[0])
     gdb_printf (stream, _("\
 	     --with-sysroot=%s%s\n\