1# Copyright 2021-2023 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# Lookup a type in a partial unit with DW_AT_stmt_list. 17# 18# The test-case is setup such that the partial symtab expansion route is 19# .h partial symtab -> shared partial symtab -> toplevel symtab. 20# 21# That is, the partial symtabs (as displayed by maint print objfiles) are: 22# 23# ../sysdeps/x86_64/crtn.S at 0x3d944e0^M 24# elf-init.c at 0x3d94440^M 25# dw2-symtab-includes.h at 0x3d7c7a0^M 26# <unknown> at 0x31ef870^M 27# bla.c at 0x33985f0^M 28# ../sysdeps/x86_64/crti.S at 0x33e9a00^M 29# init.c at 0x33fa600^M 30# ../sysdeps/x86_64/start.S at 0x33f3fd0^M 31# 32# and the expansion of dw2-symtab-includes.h triggers the expansion of its 33# includer <unknown>, which triggers expansion of user bla.c. 34# 35# The problem in PR28539 was that after expansion of dw2-symtab-includes.h 36# the expansion_notify function in psymbol_functions::expand_symtabs_matching 37# should be called with the bla.c symtab, but instead it got called with 38# nullptr, which caused a segfault. 39 40load_lib dwarf.exp 41 42# This test can only be run on targets which support DWARF-2 and use gas. 43require dwarf2_support 1 44 45standard_testfile main.c .S 46 47# Create the DWARF. 48set asm_file [standard_output_file $srcfile2] 49Dwarf::assemble $asm_file { 50 declare_labels partial_label lines_label 51 global srcdir subdir srcfile 52 53 cu {} { 54 partial_label: partial_unit { 55 {stmt_list ${lines_label} DW_FORM_sec_offset} 56 } { 57 DW_TAG_base_type { 58 {DW_AT_byte_size 4 DW_FORM_sdata} 59 {DW_AT_encoding @DW_ATE_signed} 60 {DW_AT_name myint} 61 } 62 } 63 } 64 65 cu {} { 66 compile_unit { 67 {language @DW_LANG_C} 68 {DW_AT_name bla.c} 69 } { 70 imported_unit { 71 {import $partial_label ref_addr} 72 } 73 } 74 } 75 76 lines {version 2} lines_label { 77 include_dir "${srcdir}/${subdir}" 78 file_name "dw2-symtab-includes.h" 1 79 program { 80 DW_LNS_advance_line 1 81 } 82 } 83} 84 85if { [prepare_for_testing "failed to prepare" $testfile \ 86 "${asm_file} ${srcfile}" {}] } { 87 return -1 88} 89 90# Check that no symtabs are expanded. 91set test "no symtabs expanded" 92if { [readnow] } { 93 unsupported $test 94} else { 95 gdb_test_no_output "maint info symtabs" $test 96} 97 98# Lookup myint. Regression test for PR28539. 99gdb_test "ptype myint" "type = myint" 100