This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] gdb-add-index tweaks


This patch makes a (teensy) bit more robust
and restores the changes (the latter with
a few tweaks).

Tom, if you still want to delete, it's your call.

2010-09-03  Tom Tromey  <>
	    Doug Evans  <>

	* (install-only): Install gdb-add-index.
	* Verify correct number of parameters passed.
	Flag error if FILE isn't accessible.
	Catch error exit from gdb and objcopy.

	* gdb.texinfo (Index Files): Mention gdb-add-index.

RCS file: /cvs/src/src/gdb/,v
retrieving revision 1.1133
diff -u -p -r1.1133
---	2 Sep 2010 13:58:06 -0000	1.1133
+++	3 Sep 2010 17:53:19 -0000
@@ -1019,7 +1019,16 @@ install-only: $(CONFIG_INSTALL) xml-sysc
 		$(SHELL) $(srcdir)/../mkinstalldirs \
 			$(DESTDIR)$(man1dir) ; \
 		$(INSTALL_DATA) $(srcdir)/gdb.1 \
-			$(DESTDIR)$(man1dir)/$$transformed_name.1
+			$(DESTDIR)$(man1dir)/$$transformed_name.1; \
+	transformed_name=`t='$(program_transform_name)'; \
+			  echo gdb-add-index | sed -e "$$t"` ; \
+		if test "x$$transformed_name" = x; then \
+		  transformed_name=gdb-add-index ; \
+		else \
+		  true ; \
+		fi ; \
+		$(INSTALL_PROGRAM) $(srcdir)/ \
+			$(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT)
 	@$(MAKE) DO=install "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
 .PHONY: install-tui
RCS file: /cvs/src/src/gdb/,v
retrieving revision 1.1
diff -u -p -r1.1
---	30 Jul 2010 20:46:34 -0000	1.1
+++	3 Sep 2010 17:53:19 -0000
@@ -16,14 +16,47 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <>.
+# This program assumes gdb and objcopy are in $PATH.
+# For documentation: info -f -n "Index Files"
+if test $# != 1; then
+    echo "usage: $myname FILE" 1>&2
+    exit 1
+if test ! -r "$file"; then
+    echo "$myname: unable to access: $file" 1>&2
+    exit 1
+test "$dir" = "$file" && dir="."
+# Ensure intermediate index file is removed when we exit.
+trap "rm -f $index" 0
+gdb --batch-silent -nx -ex "file $file" -ex "save gdb-index $dir" || {
+    # Just in case.
+    status=$?
+    echo "$myname: gdb error generating index"
+    exit $status
-gdb --batch-silent -ex "file $file" -ex "save gdb-index $dir"
+# In some situations gdb can exit without creating an index.  This is
+# not an error.
+# E.g., if $file is stripped.  This behaviour is akin to stripping an
+# already stripped binary, it's a no-op.
-if test -f "${file}.gdb-index"; then
-   objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags .gdb_index=readonly "$file" "$file"
-   rm -f "${file}.gdb-index"
+if test -f "$index"; then
+    objcopy --add-section .gdb_index="$index" \
+	--set-section-flags .gdb_index=readonly "$file" "$file"
+    status=$?
-exit 0
+exit $status
Index: doc/gdb.texinfo
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.762
diff -u -p -r1.762 gdb.texinfo
--- doc/gdb.texinfo	1 Sep 2010 19:03:51 -0000	1.762
+++ doc/gdb.texinfo	3 Sep 2010 17:53:22 -0000
@@ -15230,8 +15230,8 @@ This computation does not apply to the `
 When @value{GDBN} finds a symbol file, it scans the symbols in the
 file in order to construct an internal symbol table.  This lets most
 @value{GDBN} operations work quickly---at the cost of a delay early
-on.  For large programs, this delay can be quite lengthy, so
-@value{GDBN} provides a way to build an index, which speeds up
+on.  For large programs this delay can be quite lengthy, so
+@value{GDBN} provides a way to build an index which speeds up
 The index is stored as a section in the symbol file.  @value{GDBN} can
@@ -15258,8 +15258,22 @@ $ objcopy --add-section .gdb_index=symfi
 @end smallexample
 There are currently some limitation on indices.  They only work when
-for DWARF debugging information, not stabs.  And, they do not
-currently work for programs using Ada.
+using DWARF debugging information, not stabs.  And, they do not
+currently work for programs written in Ada.
+@pindex gdb-add-index
+@value{GDBN} comes with a program, @command{gdb-add-index}, which can
+be used to add the index to a symbol file.  It takes the symbol file
+as its only argument:
+$ gdb-add-index symfile
+@end smallexample
+@command{gdb-add-index} is a simple script, with minimal error checking.
+If @file{symfile} does not contain sufficient debugging information,
+or no debugging information at all, it will exit without an error.
 @node Symbol Errors
 @section Errors Reading Symbol Files

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]