]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb-add-index: add --help and --version options
authorAndrew Burgess <aburgess@redhat.com>
Thu, 13 Mar 2025 16:29:07 +0000 (16:29 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 17 Mar 2025 17:32:36 +0000 (17:32 +0000)
Update the gdb-add-index script to offer --help and --version options.

The script currently accepts the argument '-dwarf-5' with a single
leading '-'.  As two '--' is more common for long options, the
preferred argument form is now '--dwarf-5', the docs have been
updated, and the new help text uses this form.

For backward compatibility, the old '-dwarf-5' form is still
accepted.

The new arguments are '--help' or '-h', but I also accept '-help' for
consistency with '-dwarf-5'.  And likewise for the version argument.

Handling of the gdb-add-index script is done basically the same as for
gcore and gstack; we use config.status to create a .in file within the
build directory, which is then processed by the Makefile to create the
final script.

The difference with gdb-add-index is that I left the original script
as gdb/contrib/gdb-add-index.sh rather than renaming it to something
like gdb/contrib/gdb-add-index-1.in, which is how gcore and gstack are
handled (though they are not in the contrib directory).

The reason for this is that the contrib/cc-with-tweaks.sh script looks
for gdb-add-index.sh within the gdb/contrib/ source directory.

As the only reason we process gdb-add-index.sh into the build
directory is to support the PKGVERSION and VERSION variables, allowing
cc-with-tweaks to continue using the unprocessed version seems
harmless, and avoids having to change cc-with-tweaks.sh at all.

I tested that I can still run tests using the cc-with-gdb-index target
board, and that the installed gdb-add-index script correctly shows a
version number when asked.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32325

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/Makefile.in
gdb/NEWS
gdb/configure
gdb/configure.ac
gdb/contrib/gdb-add-index.sh
gdb/doc/gdb.texinfo

index 8c5e2ff75100534027a32ce33a623fdce3d140c3..8f6df5ba7b6ce2d107cf3e5ddbe9e3258f6c2d3e 100644 (file)
@@ -1956,7 +1956,7 @@ generated_files = \
 # Flags needed to compile Python code
 PYTHON_CFLAGS = @PYTHON_CFLAGS@
 
-all: gdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.py gdb-gdb.gdb gcore gstack
+all: gdb$(EXEEXT) $(CONFIG_ALL) gdb-gdb.py gdb-gdb.gdb gcore gstack gdb-add-index
        @$(MAKE) $(FLAGS_TO_PASS) DO=all "DODIRS=$(SUBDIRS)" subdir_do
 
 # Rule for compiling .c files in the top-level gdb directory.
@@ -2135,7 +2135,7 @@ install-only: $(CONFIG_INSTALL)
        else \
          true ; \
        fi ; \
-       $(INSTALL_SCRIPT) $(srcdir)/contrib/gdb-add-index.sh \
+       $(INSTALL_SCRIPT) gdb-add-index \
                $(DESTDIR)$(bindir)/$$transformed_name
        @$(MAKE) DO=install "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
 
@@ -2355,7 +2355,10 @@ jit-reader.h: $(srcdir)/jit-reader.in config.status
 gstack.in gcore.in: %.in : $(srcdir)/%-1.in config.status
        $(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
 
-gstack gcore: % : %.in version.c
+gdb-add-index.in : $(srcdir)/contrib/gdb-add-index.sh config.status
+       $(ECHO_GEN) $(SHELL) config.status $(SILENT_FLAG) $@
+
+gstack gcore gdb-add-index: % : %.in version.c
        $(ECHO_GEN) \
        vv=`grep 'version\[\] = ' version.c | grep -o '".*"' | tr -d \"`; \
        sed -e "s,@VERSION@,$$vv," $< > $@
index 6573950c64f4ade003e9ceeae3f51f1b98735041..0aac7a7b13afd68a09a8eab60eccbbd8e8ca8d36 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
 
 * Linux checkpoint code has been updated to work with multiple inferiors.
 
-* The gcore script now has a -v or --version option, which prints the
-  version number, and then exits.  As well as a -h or --help option,
-  which prints each options and a brief description.
+* The gcore and gdb-add-index scripts now have a -v or --version
+  option, which prints the version number, and then exits.  As well as
+  a -h or --help option, which prints each options and a brief
+  description.
 
 * New commands
 
index 3e990064197fda54114c4d7b7642ef368a8b02d5..92adb53d4d2de29332f7199c74b270640724d120 100755 (executable)
@@ -33779,6 +33779,8 @@ ac_config_files="$ac_config_files gcore.in:gcore-1.in"
 
 ac_config_files="$ac_config_files gstack.in:gstack-1.in"
 
+ac_config_files="$ac_config_files gdb-add-index.in:contrib/gdb-add-index.sh"
+
 ac_config_files="$ac_config_files Makefile gdb-gdb.gdb gdb-gdb.py doc/Makefile data-directory/Makefile"
 
 
@@ -34880,6 +34882,7 @@ do
     "nm.h") CONFIG_LINKS="$CONFIG_LINKS nm.h:$GDB_NM_FILE" ;;
     "gcore.in") CONFIG_FILES="$CONFIG_FILES gcore.in:gcore-1.in" ;;
     "gstack.in") CONFIG_FILES="$CONFIG_FILES gstack.in:gstack-1.in" ;;
+    "gdb-add-index.in") CONFIG_FILES="$CONFIG_FILES gdb-add-index.in:contrib/gdb-add-index.sh" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "gdb-gdb.gdb") CONFIG_FILES="$CONFIG_FILES gdb-gdb.gdb" ;;
     "gdb-gdb.py") CONFIG_FILES="$CONFIG_FILES gdb-gdb.py" ;;
index 4604a2d8e87c0b8fbf73151723dca1db319626c8..eafbf5ac358becc0e2b196054def809c8e4a0798 100644 (file)
@@ -2280,6 +2280,7 @@ GDB_AC_TRANSFORM([gdb], [GDB_TRANSFORM_NAME])
 GDB_AC_TRANSFORM([gcore], [GCORE_TRANSFORM_NAME])
 AC_CONFIG_FILES([gcore.in:gcore-1.in])
 AC_CONFIG_FILES([gstack.in:gstack-1.in])
+AC_CONFIG_FILES([gdb-add-index.in:contrib/gdb-add-index.sh])
 AC_CONFIG_FILES([Makefile gdb-gdb.gdb gdb-gdb.py doc/Makefile data-directory/Makefile])
 
 AC_OUTPUT
index 00a9bea5779c5310b9129e190a6b650c54ea0190..4db123492f8b6669f379b830c55f2295c36fc48d 100755 (executable)
@@ -22,16 +22,73 @@ GDB=${GDB:=gdb}
 OBJCOPY=${OBJCOPY:=objcopy}
 READELF=${READELF:=readelf}
 
+PKGVERSION=@PKGVERSION@
+VERSION=@VERSION@
+
 myname="${0##*/}"
 
+print_usage() {
+    prefix="Usage: $myname"
+    echo "$prefix [-h|--help] [-v|--version] [--dwarf-5] FILENAME"
+}
+
+print_try_help() {
+    echo "Try '$myname --help' for more information."
+}
+
+print_help() {
+    print_usage
+    echo
+    echo "Add a .gdb_index section to FILENAME to facilitate faster debug"
+    echo "information loading by GDB."
+    echo
+    echo "  -h, --help         Print this message then exit."
+    echo "  -v, --version      Print version information then exit."
+    echo "  --dwarf-5          Add the DWARF-5 style .debug_names section"
+    echo "                       instead of .gdb_index."
+}
+
+print_version() {
+    echo "GNU gdb-add-index (${PKGVERSION}) ${VERSION}"
+}
+
 dwarf5=""
-if [ "$1" = "-dwarf-5" ]; then
-    dwarf5="$1"
+
+# Parse options.
+until
+opt=$1
+case ${opt} in
+    --dwarf-5 | -dwarf-5)
+       dwarf5="-dwarf-5"
+       ;;
+
+    --help | -help | -h)
+       print_help
+       exit 0
+       ;;
+
+    --version | -version | -v)
+       print_version
+       exit 0
+       ;;
+
+    -?*)
+       print_try_help 1>&2
+       exit 2
+       ;;
+
+    *)
+       # No arguments remaining.
+       ;;
+esac
+# Break from loop if the first character of OPT is not '-'.
+[ "x$(printf %.1s "$opt")" != "x-" ]
+do
     shift
-fi
+done
 
 if test $# != 1; then
-    echo "usage: $myname [-dwarf-5] FILE" 1>&2
+    print_try_help
     exit 1
 fi
 
index 96d624eacac2ed5afd8feb3c1d9aa20553c5b9fa..473431011d1af0c8e4aaaefcf5028f6f9d7ff07d 100644 (file)
@@ -51643,7 +51643,7 @@ Richard M. Stallman and Roland H. Pesch, July 1991.
 @c man title gdb-add-index Add index files to speed up GDB
 
 @c man begin SYNOPSIS gdb-add-index
-gdb-add-index [-dwarf-5] @var{filename}
+gdb-add-index [-h | --help] [-v | --version] [--dwarf-5] @var{filename}
 @c man end
 
 @c man begin DESCRIPTION gdb-add-index
@@ -51661,8 +51661,8 @@ which use ELF binaries and DWARF debug information (i.e., sections
 named @code{.debug_*}).
 
 By default @command{gdb-add-index} will add a pre-DWARF 5
-@code{.gdb_index} section to @var{filename}.  With @option{-dwarf-5}
-DWARF 5 sections are added instead.
+@code{.gdb_index} section to @var{filename}.  With @option{--dwarf-5}
+the DWARF 5 section @code{.debug_names} is added instead.
 
 @var{filename} must be writable.
 
@@ -51686,9 +51686,16 @@ the @value{GDBN} manual in node @code{Index Files}
 
 @c man begin OPTIONS gdb-add-index
 @table @env
-@item -dwarf-5
+@item --dwarf-5
 Add DWARF 5 sections instead of previous @code{.gdb_index} section.
 
+@item --help
+@itemx -h
+List all options, with brief explanations.
+
+@item --version
+@itemx -v
+Print version information and then exit.
 @end table
 @c man end