Home | History | Annotate | Line # | Download | only in gdb.dwarf2
dw2-ranges-overlap.exp revision 1.1
      1 # Copyright 2020-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 load_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.
     25 if {![dwarf2_support]} {
     26     verbose "Skipping $gdb_test_file_name."
     27     return 0
     28 }
     29 
     30 # The .c files use __attribute__.
     31 if ![is_c_compiler_gcc] {
     32     verbose "Skipping $gdb_test_file_name."
     33     return 0
     34 }
     35 
     36 standard_testfile .c -dw.S
     37 
     38 set asm_file [standard_output_file $srcfile2]
     39 Dwarf::assemble $asm_file {
     40     global srcdir subdir srcfile srcfile2
     41     declare_labels ranges_label
     42 
     43     # Find start address and length for our functions.
     44     set foo_func \
     45 	[function_range foo [list ${srcdir}/${subdir}/$srcfile]]
     46     set quux_func \
     47 	[function_range quux [list ${srcdir}/${subdir}/$srcfile]]
     48     set bar_func \
     49 	[function_range bar [list ${srcdir}/${subdir}/$srcfile]]
     50 
     51     cu {} {
     52 	compile_unit {
     53 	    {language @DW_LANG_C_plus_plus}
     54 	    {name $srcfile}
     55 	    {ranges ${ranges_label} DW_FORM_sec_offset}
     56 	} {
     57 	    subprogram {
     58 		{external 1 flag}
     59 		{name quux}
     60 	    }
     61 	}
     62     }
     63 
     64     ranges {is_64 [is_64_target]} {
     65 	ranges_label: sequence {
     66 	    base [lindex $quux_func 0]
     67 	    range 0 [lindex $quux_func 1]
     68 	    base [lindex $bar_func 0]
     69 	    range 0 [lindex $bar_func 1]
     70 	}
     71     }
     72 }
     73 
     74 if { [prepare_for_testing "failed to prepare" ${testfile} \
     75 	  [list $srcfile $asm_file] {nodebug}] } {
     76     return -1
     77 }
     78 
     79 if ![runto foo] {
     80     return -1
     81 }
     82 
     83 gdb_test "show language" \
     84     "The current source language is \"auto; currently c\"\."
     85