binutils-gdb/gdb/testsuite/gdb.dwarf2/dwznolink.exp
Tom Tromey a7308ce01e Avoid crash on missing dwz file
If DWARF contains a reference to a "dwz" file, but there is no
.gnu_debugaltlink section, then gdb will crash.  This happens because
dwarf2_get_dwz_file will return NULL, but some callers do not expect
this.

This patch changes dwarf2_get_dwz_file so that callers can require a
dwz file.  Then, it updates the callers that are attempting to process
references to the dwz file to require one.

This includes a new testcase.  The dwarf.exp changes don't handle the
new forms exactly correctly -- they are only handled well enough to
let this test case complete.

gdb/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (dwarf2_get_dwz_file): Add 'require' parameter.
	* dwarf2/read.c (dwarf2_get_dwz_file): Add 'require' parameter.
	(get_abbrev_section_for_cu, read_attribute_value)
	(get_debug_line_section): Update.
	* dwarf2/macro.c (dwarf_decode_macro_bytes): Update.

gdb/testsuite/ChangeLog
2021-03-06  Tom Tromey  <tom@tromey.com>

	* lib/dwarf.exp (_handle_DW_FORM): Treat DW_FORM_GNU_ref_alt and
	DW_FORM_GNU_strp_alt like DW_FORM_sec_offset.
	* gdb.dwarf2/dwznolink.exp: New file.
2021-03-06 09:26:39 -07:00

60 lines
1.7 KiB
Text

# Copyright 2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
load_lib dwarf.exp
# This test can only be run on targets which support DWARF-2 and use gas.
if {![dwarf2_support]} {
return 0
}
# No remote host testing either.
if {[is_remote host]} {
return 0
}
standard_testfile main.c dwznolink.S
set asm_file [standard_output_file $srcfile2]
# The DWARF should contain a reference to a supplementary ("dwz")
# file, but the section that links to the file should be missing. At
# one point, this caused gdb crashes.
Dwarf::assemble $asm_file {
cu {} {
compile_unit {{language @DW_LANG_C}} {
constant {
{name 0 DW_FORM_GNU_strp_alt}
{type 97 DW_FORM_GNU_ref_alt}
{const_value 99 data1}
}
}
}
}
# We can't use prepare_for_testing here because we need to check the
# 'file' command's output.
if {[build_executable $testfile.exp $testfile \
[list $srcfile $asm_file] {nodebug quiet}]} {
return -1
}
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_test "file -readnow $binfile" \
"could not read '.gnu_debugaltlink' section" \
"file $testfile"