20f9f67
http://sourceware.org/ml/gdb-patches/2010-07/msg00184.html
20f9f67
Subject: Re: [0/4] RFC: add DWARF index support
20f9f67
44969d3
Jan Kratochvil: Fixed $d -> $dir.
44969d3
Jan Kratochvil: Remove /dev/null redirection.
44969d3
20f9f67
>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:
20f9f67
20f9f67
Tom> This patch series adds support for a DWARF index to gdb.
20f9f67
20f9f67
Roland suggested we wrap up the index-creation code into a helper
20f9f67
script.
20f9f67
20f9f67
I'm not sure if this is something people would want in gdb proper, but I
20f9f67
figured I would send it here just in case.
20f9f67
20f9f67
Tom
20f9f67
20f9f67
2010-07-09  Tom Tromey  <tromey@redhat.com>
20f9f67
20f9f67
	* Makefile.in (install-only): Install gdb-add-index.
20f9f67
	* gdb-add-index: New file.
20f9f67
20f9f67
2010-07-09  Tom Tromey  <tromey@redhat.com>
20f9f67
20f9f67
	* gdb.texinfo (Index Files): Mention gdb-add-index.
20f9f67
20f9f67
>From 30714fe719e61baea03d0dc5793eb0d564faebb7 Mon Sep 17 00:00:00 2001
20f9f67
From: Tom Tromey <tromey@redhat.com>
20f9f67
Date: Fri, 9 Jul 2010 11:17:54 -0600
20f9f67
Subject: [PATCH 4/4] add gdb-add-index
20f9f67
Subject: [PATCH 4/4] add gdb-add-index
20f9f67
20f9f67
---
20f9f67
 gdb/ChangeLog       |    5 +++++
20f9f67
 gdb/Makefile.in     |   11 ++++++++++-
20f9f67
 gdb/doc/ChangeLog   |    4 ++++
20f9f67
 gdb/doc/gdb.texinfo |    8 ++++++++
20f9f67
 gdb/gdb-add-index   |   30 ++++++++++++++++++++++++++++++
20f9f67
 5 files changed, 57 insertions(+), 1 deletions(-)
20f9f67
 create mode 100755 gdb/gdb-add-index
20f9f67
Jan Kratochvil 872aab0
Index: gdb-7.6.50.20130731-cvs/gdb/Makefile.in
Jan Kratochvil e00e5ea
===================================================================
Jan Kratochvil 872aab0
--- gdb-7.6.50.20130731-cvs.orig/gdb/Makefile.in	2013-08-02 16:31:59.603674194 +0200
Jan Kratochvil 872aab0
+++ gdb-7.6.50.20130731-cvs/gdb/Makefile.in	2013-08-02 16:32:08.260690156 +0200
Jan Kratochvil 872aab0
@@ -1070,6 +1070,15 @@ install-only: install-gstack $(CONFIG_IN
Jan Kratochvil cf0b61a
 		  $(INSTALL_PROGRAM) gcore \
Jan Kratochvil cf0b61a
 			  $(DESTDIR)$(bindir)/$$transformed_name; \
Jan Kratochvil cf0b61a
 	fi
20f9f67
+	transformed_name=`t='$(program_transform_name)'; \
20f9f67
+			  echo gdb-add-index | sed -e "$$t"` ; \
20f9f67
+		if test "x$$transformed_name" = x; then \
20f9f67
+		  transformed_name=gdb-add-index ; \
20f9f67
+		else \
20f9f67
+		  true ; \
20f9f67
+		fi ; \
20f9f67
+		$(INSTALL_PROGRAM) $(srcdir)/gdb-add-index \
20f9f67
+			$(DESTDIR)$(bindir)/$$transformed_name$(EXEEXT)
20f9f67
 	@$(MAKE) DO=install "DODIRS=$(SUBDIRS)" $(FLAGS_TO_PASS) subdir_do
Jan Kratochvil 254f0e9
 
Jan Kratochvil 254f0e9
 install-python:
Jan Kratochvil 872aab0
Index: gdb-7.6.50.20130731-cvs/gdb/doc/gdb.texinfo
Jan Kratochvil e00e5ea
===================================================================
Jan Kratochvil 872aab0
--- gdb-7.6.50.20130731-cvs.orig/gdb/doc/gdb.texinfo	2013-08-02 16:31:59.616674218 +0200
Jan Kratochvil 872aab0
+++ gdb-7.6.50.20130731-cvs/gdb/doc/gdb.texinfo	2013-08-02 16:32:08.271690176 +0200
Jan Kratochvil 872aab0
@@ -17447,6 +17447,14 @@ There are currently some limitation on i
20f9f67
 for DWARF debugging information, not stabs.  And, they do not
20f9f67
 currently work for programs using Ada.
20f9f67
 
20f9f67
+@value{GDBN} comes with a program, @command{gdb-add-index}, which can
20f9f67
+be used to add the index to a symbol file.  It takes the symbol file
20f9f67
+as its only argument:
20f9f67
+
20f9f67
+@smallexample
20f9f67
+$ gdb-add-index symfile
20f9f67
+@end smallexample
20f9f67
+
20f9f67
 @node Symbol Errors
20f9f67
 @section Errors Reading Symbol Files
Jan Kratochvil e00e5ea
 
Jan Kratochvil 872aab0
@@ -43044,6 +43052,7 @@ switch (die->tag)
Jan Kratochvil cf0b61a
 * gdbserver man::               Remote Server for the GNU Debugger man page
Jan Kratochvil cf0b61a
 * gcore man::                   Generate a core file of a running program
Jan Kratochvil cf0b61a
 * gdbinit man::                 gdbinit scripts
Jan Kratochvil cf0b61a
+* gdb-add-index man::           Add index files to speed up GDB
Jan Kratochvil cf0b61a
 @end menu
Jan Kratochvil cf0b61a
 
Jan Kratochvil cf0b61a
 @node gdb man
Jan Kratochvil 872aab0
@@ -43696,6 +43705,54 @@ gdb(1), @code{info -f gdb -n Startup}
Jan Kratochvil cf0b61a
 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
Jan Kratochvil cf0b61a
 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
Jan Kratochvil cf0b61a
 documentation are properly installed at your site, the command
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@smallexample
Jan Kratochvil cf0b61a
+info gdb
Jan Kratochvil cf0b61a
+@end smallexample
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+should give you access to the complete manual.
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
Jan Kratochvil cf0b61a
+Richard M. Stallman and Roland H. Pesch, July 1991.
Jan Kratochvil cf0b61a
+@end ifset
Jan Kratochvil cf0b61a
+@c man end
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@node gdb-add-index man
Jan Kratochvil cf0b61a
+@heading gdb-add-index
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@c man title gdb-add-index Add index files to speed up GDB
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@c man begin SYNOPSIS gdb-add-index
Jan Kratochvil cf0b61a
+gdb-add-index @var{filename}
Jan Kratochvil cf0b61a
+@c man end
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@c man begin DESCRIPTION gdb-add-index
Jan Kratochvil cf0b61a
+When GDB finds a symbol file, it scans the symbols in the file in order
Jan Kratochvil cf0b61a
+to construct an internal symbol table.  This lets most GDB operations
Jan Kratochvil cf0b61a
+work quickly--at the cost of a delay early on.  For large programs,
Jan Kratochvil cf0b61a
+this delay can be quite lengthy, so GDB provides a way to build an
Jan Kratochvil cf0b61a
+index, which speeds up startup.
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+To determine whether a file contains such an index, use the command
Jan Kratochvil cf0b61a
+@command{readelf -S filename}: the index is stored in a section named
Jan Kratochvil cf0b61a
+@code{.gdb_index}.  Note that the index is never generated for files that do
Jan Kratochvil cf0b61a
+not contain DWARF debug information (sections named @code{.debug_*}).
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+See more in
Jan Kratochvil cf0b61a
+@ifset man
Jan Kratochvil cf0b61a
+the @value{GDBN} manual in node @code{Index Files}
Jan Kratochvil cf0b61a
+-- shell command @code{info -f gdb -n 'Index Files'}.
Jan Kratochvil cf0b61a
+@end ifset
Jan Kratochvil cf0b61a
+@ifclear man
Jan Kratochvil cf0b61a
+@ref{Index Files}.
Jan Kratochvil cf0b61a
+@end ifclear
Jan Kratochvil cf0b61a
+@c man end
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
+@c man begin SEEALSO gdb-add-index
Jan Kratochvil cf0b61a
+@ifset man
Jan Kratochvil cf0b61a
+The full documentation for @value{GDBN} is maintained as a Texinfo manual.
Jan Kratochvil cf0b61a
+If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
Jan Kratochvil cf0b61a
+documentation are properly installed at your site, the command
Jan Kratochvil cf0b61a
 
Jan Kratochvil cf0b61a
 @smallexample
Jan Kratochvil cf0b61a
 info gdb
Jan Kratochvil 872aab0
Index: gdb-7.6.50.20130731-cvs/gdb/gdb-add-index
Jan Kratochvil e00e5ea
===================================================================
Jan Kratochvil e00e5ea
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
Jan Kratochvil 872aab0
+++ gdb-7.6.50.20130731-cvs/gdb/gdb-add-index	2013-08-02 16:32:08.271690176 +0200
20f9f67
@@ -0,0 +1,30 @@
20f9f67
+#! /bin/sh
20f9f67
+
20f9f67
+# Add a .gdb_index section to a file.
20f9f67
+
20f9f67
+# Copyright (C) 2010 Free Software Foundation, Inc.
20f9f67
+# This program is free software; you can redistribute it and/or modify
20f9f67
+# it under the terms of the GNU General Public License as published by
20f9f67
+# the Free Software Foundation; either version 3 of the License, or
20f9f67
+# (at your option) any later version.
20f9f67
+#
20f9f67
+# This program is distributed in the hope that it will be useful,
20f9f67
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20f9f67
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20f9f67
+# GNU General Public License for more details.
20f9f67
+#
20f9f67
+# You should have received a copy of the GNU General Public License
20f9f67
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20f9f67
+
20f9f67
+file="$1"
20f9f67
+dir="${file%/*}"
20f9f67
+
20f9f67
+# We don't care if gdb gives an error.
Jan Kratochvil 1bcf9b6
+gdb -nx --batch-silent -ex "file $file" -ex "save gdb-index $dir"
20f9f67
+
20f9f67
+if test -f "${file}.gdb-index"; then
20f9f67
+   objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags .gdb_index=readonly "$file" "$file"
20f9f67
+   rm -f "${file}.gdb-index"
20f9f67
+fi
20f9f67
+
20f9f67
+exit 0
Jan Kratochvil 872aab0
Index: gdb-7.6.50.20130731-cvs/gdb/doc/Makefile.in
Jan Kratochvil cf0b61a
===================================================================
Jan Kratochvil 872aab0
--- gdb-7.6.50.20130731-cvs.orig/gdb/doc/Makefile.in	2013-08-02 16:31:59.618674222 +0200
Jan Kratochvil 872aab0
+++ gdb-7.6.50.20130731-cvs/gdb/doc/Makefile.in	2013-08-02 16:32:28.828727314 +0200
Jan Kratochvil cf0b61a
@@ -177,7 +177,7 @@ POD2MAN5 = pod2man --center="GNU Develop
Jan Kratochvil 872aab0
 		   --release="gdb-`sed q version.subst`" --section=5
Jan Kratochvil cf0b61a
 
Jan Kratochvil cf0b61a
 # List of man pages generated from gdb.texi
Jan Kratochvil cf0b61a
-MAN1S = gdb.1 gdbserver.1 gcore.1
Jan Kratochvil cf0b61a
+MAN1S = gdb.1 gdbserver.1 gcore.1 gdb-add-index.1
Jan Kratochvil cf0b61a
 MAN5S = gdbinit.5
Jan Kratochvil cf0b61a
 MANS = $(MAN1S) $(MAN5S)
Jan Kratochvil cf0b61a
 
Jan Kratochvil 872aab0
@@ -630,6 +630,13 @@ gcore.1: $(GDB_DOC_FILES)
Jan Kratochvil cf0b61a
 		mv -f $@.T$$$$ $@) || (rm -f $@.T$$$$ && exit 1)
Jan Kratochvil cf0b61a
 	rm -f gcore.pod
Jan Kratochvil cf0b61a
 
Jan Kratochvil cf0b61a
+gdb-add-index.1: $(GDB_DOC_FILES)
Jan Kratochvil cf0b61a
+	touch $@
Jan Kratochvil cf0b61a
+	-$(TEXI2POD) $(MANCONF) -Dgdb-add-index < $(srcdir)/gdb.texinfo > gdb-add-index.pod
Jan Kratochvil cf0b61a
+	-($(POD2MAN1) gdb-add-index.pod | sed -e '/^.if n .na/d' > $@.T$$$$ && \
Jan Kratochvil cf0b61a
+		mv -f $@.T$$$$ $@) || (rm -f $@.T$$$$ && exit 1)
Jan Kratochvil cf0b61a
+	rm -f gdb-add-index.pod
Jan Kratochvil cf0b61a
+
Jan Kratochvil cf0b61a
 gdbinit.5: $(GDB_DOC_FILES)
Jan Kratochvil cf0b61a
 	touch $@
Jan Kratochvil cf0b61a
 	-$(TEXI2POD) $(MANCONF) -Dgdbinit < $(srcdir)/gdb.texinfo > gdbinit.pod