Re: [PATCH] Display configuration details in --help

Doug Evans
2013-03-21T17:54:59Z

On Wed, Mar 20, 2013 at 10:39 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> GDB has a lot of configuration options, but once you've built and
> installed it, it is hard to know which ones where specified and/or
> auto-detected, and which weren't. And if you, like me, keep several
> prior versions of GDB around, but not necessarily keep their build
> trees, about the only way to find out these configuration details is
> by using 'strings' or by running GDB under a debugger, which is really
> gross and also inefficient.
>
> So I made a patch to display the important configuration parameters as
> part of --help. The patched GDB produces information like this on my
> system:
>
> This GDB is configured as follows:
> configure --host=i686-pc-mingw32 --target=i686-pc-mingw32
> --with-auto-load-dir=$debugdir:$datadir/auto-load
> --with-auto-load-safe-path=$debugdir:$datadir/auto-load
> --with-expat
> --with-gdb-datadir=d:/usr/share/gdb (relocatable)
> --with-jit-reader-dir=d:/usr/lib/gdb (relocatable)
> --without-libunwind-ia64
> --with-lzma
> --with-python=d:/usr/Python26 (relocatable)
> --with-separate-debug-dir=d:/usr/lib/debug (relocatable)
> --with-system-gdbinit=d:/usr/etc/gdbinit (relocatable)
> --with-zlib
>
> I think this will also be useful for when users report problems,
> because some solutions depend on how GDB was configured.
>
> Do people think this will be useful? The patch is below.
>
> 2013-03-20 Eli Zaretskii <eliz@gnu.org>
>
> * main.c (print_gdb_help): Display configuration details.
>
>
> --- gdb/main.c~1 2013-03-20 13:15:01.737639100 +0200
> +++ gdb/main.c 2013-03-20 19:27:51.103852400 +0200
> @@ -48,6 +48,8 @@
> #include "windows-nat.h"
> #endif
>
> +#include "version.h"
> +
> /* The selected interpreter. This will be used as a set command
> variable, so it should always be malloc'ed - since
> do_setshow_command will free it. */
> @@ -1142,6 +1144,85 @@
> --write Set writing into executable and core files.\n\
> --xdb XDB compatibility mode.\n\
> "), stream);
> + fprintf_unfiltered (stream, _("\n\
> +This GDB is configured as follows:\n\
> + configure --host=%s --target=%s\n\
> +"), host_name, target_name);
> + fprintf_unfiltered (stream, _("\
> + --with-auto-load-dir=%s\n\
> + --with-auto-load-safe-path=%s\n\
> +"), AUTO_LOAD_DIR, AUTO_LOAD_SAFE_PATH);
> +#if HAVE_LIBEXPAT
> + fprintf_unfiltered (stream, _("\
> + --with-expat\n\
> +"));
> +#else
> + fprintf_unfiltered (stream, _("\
> + --without-expat\n\
> +"));
> +#endif
> + if (GDB_DATADIR[0])
> + fprintf_unfiltered (stream, _("\
> + --with-gdb-datadir=%s%s\n\
> +"), GDB_DATADIR, GDB_DATADIR_RELOCATABLE ? " (relocatable)" : "");
> +#ifdef ICONV_BIN
> + fprintf_unfiltered (stream, _("\
> + --with-iconv-bin=%s%s\n\
> +"), ICONV_BIN, ICONV_BIN_RELOCATABLE ? " (relocatable)" : "");
> +#endif
> + if (JIT_READER_DIR[0])
> + fprintf_unfiltered (stream, _("\
> + --with-jit-reader-dir=%s%s\n\
> +"), JIT_READER_DIR, JIT_READER_DIR_RELOCATABLE ? " (relocatable)" : "");
> +#if HAVE_LIBUNWIND_IA64_H
> + fprintf_unfiltered (stream, _("\
> + --with-libunwind-ia64\n\
> +"));
> +#else
> + fprintf_unfiltered (stream, _("\
> + --without-libunwind-ia64\n\
> +"));
> +#endif
> +#if HAVE_LIBLZMA
> + fprintf_unfiltered (stream, _("\
> + --with-lzma\n\
> +"));
> +#else
> + fprintf_unfiltered (stream, _("\
> + --without-lzma\n\
> +"));
> +#endif
> +#ifdef WITH_PYTHON_PATH
> + fprintf_unfiltered (stream, _("\
> + --with-python=%s%s\n\
> +"), WITH_PYTHON_PATH, PYTHON_PATH_RELOCATABLE ? " (relocatable)" : "");
> +#endif
> +#ifdef RELOC_SRCDIR
> + fprintf_unfiltered (stream, _("\
> + --with-relocated-sources=%s\n\
> +"), RELOC_SRCDIR);
> +#endif
> + if (DEBUGDIR[0])
> + fprintf_unfiltered (stream, _("\
> + --with-separate-debug-dir=%s%s\n\
> +"), DEBUGDIR, DEBUGDIR_RELOCATABLE ? " (relocatable)" : "");
> + if (TARGET_SYSTEM_ROOT[0])
> + fprintf_unfiltered (stream, _("\
> + --with-sysroot=%s%s\n\
> +"), TARGET_SYSTEM_ROOT, TARGET_SYSTEM_ROOT_RELOCATABLE ? " (relocatable)" : "");
> + if (SYSTEM_GDBINIT[0])
> + fprintf_unfiltered (stream, _("\
> + --with-system-gdbinit=%s%s\n\
> +"), SYSTEM_GDBINIT, SYSTEM_GDBINIT_RELOCATABLE ? " (relocatable)" : "");
> +#if HAVE_ZLIB_H
> + fprintf_unfiltered (stream, _("\
> + --with-zlib\n\
> +"));
> +#else
> + fprintf_unfiltered (stream, _("\
> + --without-zlib\n\
> +"));
> +#endif
> fputs_unfiltered (_("\n\
> At startup, GDB reads the following init files and executes their commands:\n\
> "), stream);

Hi. I like the idea, but the implementation imposes a future
maintenance burden.
Would it be sufficient to just store the original string somewhere and
print that?
I believe that's what gcc does (at least it's configure.ac that
computes a string and saves that in a global, and gcc just prints that
global, instead of a series of #if/#ifdefs).