This test checks that GDB is able to load DWARF information when
.debug_aranges has a section address size that is set to 0.
This test was originally written by Jan Kratochvil to test commit
927aa2e778d from 2017, titled "DWARF-5: .debug_names index consumer".
This test was originally written using a static .S file and has
been present in the Fedora tree for a long time.
If dwarf2/aranges.c is modified to turn off the address_size check,
GDB will crash with SIGFPE when loading the executable with address
size set to zero.
I modified the DWARF assembler to make it possible to set the address
size to zero in a .debug_aranges section and used the DWARF assembler
to produce the assembly file.
Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
Approved-by: Kevin Buettner <kevinb@redhat.com>
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2024 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/>. */
+
+/* Dummy main function. */
+
+int
+main (void)
+{
+ return 0;
+}
--- /dev/null
+# Copyright 2004-2024 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/>.
+
+# Test .debug_aranges containing zero address_size.
+
+# This test can only be run on targets which support DWARF-2 and use gas.
+# For now pick a sampling of likely targets.
+load_lib dwarf.exp
+require dwarf2_support
+
+standard_testfile .c -2.S
+set asm_file [standard_output_file $srcfile2]
+
+Dwarf::assemble $asm_file {
+ cu { label cu_start } {
+ compile_unit {{language @DW_LANG_C}} {
+ }
+ }
+ aranges { addr_zero true } cu_start {
+ }
+}
+
+if { [prepare_for_testing "failed to prepare" $binfile [list $asm_file $srcfile ]] } {
+ return -1
+}
+
+# Failed gdb_load would abort the testcase execution earlier.
+pass "file loaded"
set addr_op .4byte
}
- _op $addr_op $arange_start "Address range start$comment"
- _op $addr_op $arange_length "Address range length$comment"
+ # Do not emit address ranges when the Address size is set to 0.
+ if { $_addr_size > 0 } {
+ _op $addr_op $arange_start "Address range start$comment"
+ _op $addr_op $arange_length "Address range length$comment"
+ }
}
# Emit a DWARF .debug_aranges unit.
{ cu_is_64 0 }
{ section_version 2 }
{ seg_size 0 }
+ { addr_zero false }
}
set _seg_size $seg_size
set _addr_size 4
}
+ if { $addr_zero } {
+ set _addr_size 0
+ }
+
# Switch to .debug_aranges section.
_section .debug_aranges
# Padding.
set tuple_size [expr 2 * $_addr_size + $_seg_size]
+ if {$tuple_size == 0} {
+ set tuple_size 1
+ }
while { 1 } {
if { [expr $offset % $tuple_size] == 0 } {
break