1# Copyright 2019-2021 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# Regression test to ensure that the order of DW_AT_name and
17# DW_AT_linkage_name does not affect Ada.
18
19load_lib dwarf.exp
20
21# This test can only be run on targets which support DWARF-2 and use gas.
22if {![dwarf2_support]} {
23    return 0
24}
25
26standard_testfile .c -debug.S
27
28# Set up the DWARF for the test.
29
30set asm_file [standard_output_file $srcfile2]
31Dwarf::assemble $asm_file {
32    global srcdir subdir srcfile
33
34    cu {} {
35	DW_TAG_compile_unit {
36                {DW_AT_language @DW_LANG_Ada95}
37                {DW_AT_name     $srcfile}
38                {DW_AT_comp_dir /tmp}
39
40        } {
41	    declare_labels b_l
42
43	    b_l: DW_TAG_base_type {
44		{DW_AT_byte_size 1 DW_FORM_sdata}
45		{DW_AT_encoding  @DW_ATE_signed}
46		{DW_AT_name      bool}
47	    }
48	    # Here the name comes first and the linkage name second.
49            DW_TAG_subprogram {
50                {name system__namefirst}
51		{linkage_name __gnat_namefirst}
52		{MACRO_AT_range {first}}
53                {type :$b_l}
54	    }
55	    # Here the linkage name comes first and the name second.
56            DW_TAG_subprogram {
57		{linkage_name __gnat_namesecond}
58                {name system__namesecond}
59                {MACRO_AT_range {second}}
60                {type :$b_l}
61	    }
62	}
63    }
64}
65
66if { [prepare_for_testing "failed to prepare" ${testfile} \
67	  [list $srcfile $asm_file] {nodebug}] } {
68    return -1
69}
70
71with_test_prefix "first first" {
72    gdb_test_no_output "set language ada"
73    gdb_breakpoint "<__gnat_namefirst>" message
74    gdb_breakpoint "<__gnat_namesecond>" message
75}
76
77# Run the test again, but this time check the symbols in the other
78# order.  This ensures we are really testing all the paths --
79# otherwise if the first symbol is found, it will cause symtab
80# expansion, which might cause the other symbol to be found.
81clean_restart ${testfile}
82
83with_test_prefix "second first" {
84    gdb_test_no_output "set language ada"
85    gdb_breakpoint "<__gnat_namesecond>" message
86    gdb_breakpoint "<__gnat_namefirst>" message
87}
88