DWARF-5: .debug_names index producer

This adds a new "-dwarf-5" switch to "save gdb-index" that makes it
generate index files with DWARF-5 .debug_names/.debug_str sections
instead of GDB's own .gdb_index.

We should probably add a command line option to
contrib/gdb-add-index.sh (incl. cc-with-tweaks.sh) for the new
-dwarf-5 GDB option, and a new target board to make it more convenient
to exercise this.  To be done later.

gdb/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>
	    Pedro Alves  <palves@redhat.com>

	* contrib/gdb-add-index.sh (index): Rename to ...
	(index4): ... here.
	(index5, debugstr, debugstrmerge, debugstrerr): New variables.
	Support also .debug_names and .debug_str.
	* dwarf2read.c: Include cmath, set, list.
	(INDEX_SUFFIX): Rename to ...
	(INDEX4_SUFFIX): ... here.
	(INDEX5_SUFFIX, DEBUG_STR_SUFFIX): New.
	(file_write(FILE *, const void *, size_t)): New.
	(file_write(FILE *, const std::vector<Elem, Alloc> &)): New.
	(data_buf::append_unsigned_leb128, data_buf::empty): New.
	(data_buf::file_write): Use ::file_write.
	(data_buf::c_str, dwarf5_djb_hash, debug_names)
	(check_dwarf64_offsets): New.
	(psyms_seen_size, write_gdbindex): New from
	write_psymtabs_to_index code.
	(dwarf5_gdb_augmentation, write_debug_names, assert_file_size)
	(enum dw_index_kind): New.
	(write_psymtabs_to_index): New parameter index_kind.  Support
	filename_str and out_file_str.  Move code to write_gdbindex,
	possibly call write_debug_names.
	(save_gdb_index_command): New parameter -dwarf-5.
	(_initialize_dwarf2_read): Document the new parameter -dwarf-5.

gdb/doc/ChangeLog
2017-12-08  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* gdb.texinfo (Index Files): Document .debug_names and -dwarf-5.
--

 gdb/contrib/gdb-add-index.sh |   53 ++
 gdb/doc/gdb.texinfo          |   24 +
 gdb/dwarf2read.c             |  919 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 935 insertions(+), 61 deletions(-)
This commit is contained in:
Jan Kratochvil 2017-12-08 22:44:10 +00:00 committed by Pedro Alves
parent 6432ec65a8
commit 437afbb81e
5 changed files with 965 additions and 61 deletions

View File

@ -1,3 +1,30 @@
2017-12-08 Jan Kratochvil <jan.kratochvil@redhat.com>
Pedro Alves <palves@redhat.com>
* contrib/gdb-add-index.sh (index): Rename to ...
(index4): ... here.
(index5, debugstr, debugstrmerge, debugstrerr): New variables.
Support also .debug_names and .debug_str.
* dwarf2read.c: Include cmath, set, list.
(INDEX_SUFFIX): Rename to ...
(INDEX4_SUFFIX): ... here.
(INDEX5_SUFFIX, DEBUG_STR_SUFFIX): New.
(file_write(FILE *, const void *, size_t)): New.
(file_write(FILE *, const std::vector<Elem, Alloc> &)): New.
(data_buf::append_unsigned_leb128, data_buf::empty): New.
(data_buf::file_write): Use ::file_write.
(data_buf::c_str, dwarf5_djb_hash, debug_names)
(check_dwarf64_offsets): New.
(psyms_seen_size, write_gdbindex): New from
write_psymtabs_to_index code.
(dwarf5_gdb_augmentation, write_debug_names, assert_file_size)
(enum dw_index_kind): New.
(write_psymtabs_to_index): New parameter index_kind. Support
filename_str and out_file_str. Move code to write_gdbindex,
possibly call write_debug_names.
(save_gdb_index_command): New parameter -dwarf-5.
(_initialize_dwarf2_read): Document the new parameter -dwarf-5.
2017-12-08 Jan Kratochvil <jan.kratochvil@redhat.com>
Pedro Alves <palves@redhat.com>

View File

@ -37,11 +37,15 @@ fi
dir="${file%/*}"
test "$dir" = "$file" && dir="."
index="${file}.gdb-index"
index4="${file}.gdb-index"
index5="${file}.debug_names"
debugstr="${file}.debug_str"
debugstrmerge="${file}.debug_str.merge"
debugstrerr="${file}.debug_str.err"
rm -f $index
rm -f $index4 $index5 $debugstr $debugstrmerge $debugstrerr
# Ensure intermediate index file is removed when we exit.
trap "rm -f $index" 0
trap "rm -f $index4 $index5 $debugstr $debugstrmerge $debugstrerr" 0
$GDB --batch -nx -iex 'set auto-load no' \
-ex "file $file" -ex "save gdb-index $dir" || {
@ -57,9 +61,46 @@ $GDB --batch -nx -iex 'set auto-load no' \
# already stripped binary, it's a no-op.
status=0
if test -f "$index"; then
$OBJCOPY --add-section .gdb_index="$index" \
--set-section-flags .gdb_index=readonly "$file" "$file"
if test -f "$index4" -a -f "$index5"; then
echo "$myname: Both index types were created for $file" 1>&2
status=1
elif test -f "$index4" -o -f "$index5"; then
if test -f "$index4"; then
index="$index4"
section=".gdb_index"
else
index="$index5"
section=".debug_names"
fi
debugstradd=false
debugstrupdate=false
if test -s "$debugstr"; then
if ! $OBJCOPY --dump-section .debug_str="$debugstrmerge" "$file" /dev/null \
2>$debugstrerr; then
cat >&2 $debugstrerr
exit 1
fi
if grep -q "can't dump section '.debug_str' - it does not exist" \
$debugstrerr; then
debugstradd=true
else
debugstrupdate=true
cat >&2 $debugstrerr
fi
cat "$debugstr" >>"$debugstrmerge"
fi
$OBJCOPY --add-section $section="$index" \
--set-section-flags $section=readonly \
$(if $debugstradd; then \
echo --add-section .debug_str="$debugstrmerge"; \
echo --set-section-flags .debug_str=readonly; \
fi; \
if $debugstrupdate; then \
echo --update-section .debug_str="$debugstrmerge"; \
fi) \
"$file" "$file"
status=$?
else
echo "$myname: No index was created for $file" 1>&2

View File

@ -1,3 +1,7 @@
2017-12-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Index Files): Document .debug_names and -dwarf-5.
2017-12-07 Keith Seitz <keiths@redhat.com>
* gdb.texinfo (Symbols): Document "set print type nested-type-limit"

View File

@ -19565,12 +19565,16 @@ using @command{objcopy}.
To create an index file, use the @code{save gdb-index} command:
@table @code
@item save gdb-index @var{directory}
@item save gdb-index [-dwarf-5] @var{directory}
@kindex save gdb-index
Create an index file for each symbol file currently known by
@value{GDBN}. Each file is named after its corresponding symbol file,
with @samp{.gdb-index} appended, and is written into the given
@var{directory}.
Create index files for all symbol files currently known by
@value{GDBN}. For each known @var{symbol-file}, this command by
default creates it produces a single file
@file{@var{symbol-file}.gdb-index}. If you invoke this command with
the @option{-dwarf-5} option, it produces 2 files:
@file{@var{symbol-file}.debug_names} and
@file{@var{symbol-file}.debug_str}. The files are created in the
given @var{directory}.
@end table
Once you have created an index file you can merge it into your symbol
@ -19581,6 +19585,16 @@ $ objcopy --add-section .gdb_index=symfile.gdb-index \
--set-section-flags .gdb_index=readonly symfile symfile
@end smallexample
Or for @code{-dwarf-5}:
@smallexample
$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
$ cat symfile.debug_str >>symfile.debug_str.new
$ objcopy --add-section .debug_names=symfile.gdb-index \
--set-section-flags .debug_names=readonly \
--update-section .debug_str=symfile.debug_str.new symfile symfile
@end smallexample
@value{GDBN} will normally ignore older versions of @file{.gdb_index}
sections that have been deprecated. Usually they are deprecated because
they are missing a new feature or have performance issues.

File diff suppressed because it is too large Load Diff