1# Copyright 2020-2024 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/>.
15load_lib dwarf.exp
16
17# The function foo is encapsulated by two functions from CU
18# $srcfile (main and bar), but the debug info does not describe foo, so
19# foo should not be seen as part of CU $srcfile.
20# Run to foo, and check that the current language is the default auto/C.
21# If foo is considered part of CU $srcfile, the language will be auto/C++
22# instead.
23
24# This test can only be run on targets which support DWARF-2 and use gas.
25require dwarf2_support
26
27# The .c files use __attribute__.
28require is_c_compiler_gcc
29
30standard_testfile .c -dw.S
31
32set asm_file [standard_output_file $srcfile2]
33Dwarf::assemble $asm_file {
34    global srcdir subdir srcfile srcfile2
35    declare_labels ranges_label
36
37    # Find start address and length for our functions.
38    set foo_func \
39	[function_range foo [list ${srcdir}/${subdir}/$srcfile]]
40    set quux_func \
41	[function_range quux [list ${srcdir}/${subdir}/$srcfile]]
42    set bar_func \
43	[function_range bar [list ${srcdir}/${subdir}/$srcfile]]
44
45    cu {} {
46	compile_unit {
47	    {language @DW_LANG_C_plus_plus}
48	    {name $srcfile}
49	    {ranges ${ranges_label} DW_FORM_sec_offset}
50	} {
51	    subprogram {
52		{external 1 flag}
53		{name quux}
54	    }
55	}
56    }
57
58    ranges {is_64 [is_64_target]} {
59	ranges_label: sequence {
60	    base [lindex $quux_func 0]
61	    range 0 [lindex $quux_func 1]
62	    base [lindex $bar_func 0]
63	    range 0 [lindex $bar_func 1]
64	}
65    }
66}
67
68if { [prepare_for_testing "failed to prepare" ${testfile} \
69	  [list $srcfile $asm_file] {nodebug}] } {
70    return -1
71}
72
73if ![runto foo] {
74    return -1
75}
76
77gdb_test "show language" \
78    "The current source language is \"auto; currently c\"\."
79