Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1 # Copyright 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/>.
     15 
     16 # Create a file with an artificially short (1-byte) build-id, and
     17 # check that GDB doesn't try to load debug information.  If we do try
     18 # then we end up loading from: `debug-directory/.build-id/xx/.debug`
     19 # which isn't right.
     20 
     21 load_lib dwarf.exp
     22 
     23 # This test can only be run on targets which support DWARF-2 and use gas.
     24 require dwarf2_support
     25 
     26 # No remote host testing either.
     27 require {!is_remote host}
     28 
     29 standard_testfile main.c
     30 
     31 # Create an assembler file which encodes BUILDID as the build-id.  Compile
     32 # this along with the global SRCFILE to create a test executable.
     33 #
     34 # Split the debug information out from the newly created executable and place
     35 # it into the debug file directory.
     36 #
     37 # Load the executable into GDB and check to see if the debug information was
     38 # loaded or not.  For this test we are expecting that the debug information
     39 # was not loaded.  The reason is that, with short values for BUILDID, GDB ends
     40 # up looking for the debug information in weird locations.
     41 proc run_test { buildid } {
     42     set len [string length $buildid]
     43 
     44     set asm_file [standard_output_file "$::testfile.$len.S"]
     45     Dwarf::assemble $asm_file {
     46 	declare_labels int_label int_label2
     47 
     48 	upvar buildid buildid
     49 
     50 	build_id $buildid
     51 
     52 	cu { label cu_start } {
     53 	    compile_unit {{language @DW_LANG_C}} {
     54 		int_label2: base_type {
     55 		    {name int}
     56 		    {byte_size 4 sdata}
     57 		    {encoding @DW_ATE_signed}
     58 		}
     59 
     60 		constant {
     61 		    {name the_int}
     62 		    {type :$int_label2}
     63 		    {const_value 99 data1}
     64 		}
     65 	    }
     66 	}
     67 
     68 	aranges {} cu_start {
     69 	    arange {} 0 0
     70 	}
     71     }
     72 
     73     set execfile [standard_output_file $::testfile.$len]
     74 
     75     if { [build_executable_from_specs "failed to build" \
     76 	      $execfile {debug no-build-id} \
     77 	      $::srcfile debug \
     78 	      $asm_file {}] } {
     79 	return
     80     }
     81 
     82     # Create the debug directory.
     83     set debugdir [standard_output_file "debugdir.$len"]
     84     set build_id_dir $debugdir/.build-id/$buildid
     85     remote_exec host "mkdir -p $build_id_dir"
     86 
     87     # Split out the debug information.
     88     if {[gdb_gnu_strip_debug $execfile no-debuglink]} {
     89 	unresolved "failed to split out debug information"
     90 	return
     91     }
     92 
     93     # Move the debug information into the debug directory.  We place the debug
     94     # information into a file called just '.debug'.  GDB should not check this
     95     # file, but at one point GDB would check this file, even though this
     96     # doesn't make much sense.
     97     set execfile_debug ${execfile}.debug
     98     remote_exec host "mv $execfile_debug $build_id_dir/.debug"
     99 
    100     # Start GDB, set the debug-file-directory, and try loading the file.
    101     clean_restart
    102 
    103     gdb_test_no_output "set debug-file-directory $debugdir" \
    104 	"set debug-file-directory"
    105 
    106     gdb_file_cmd $execfile
    107 
    108     gdb_assert { $::gdb_file_cmd_debug_info eq "nodebug" } \
    109 	"no debug should be loaded"
    110 
    111     # For sanity, read something that was encoded in the debug
    112     # information, this should fail.
    113     gdb_test "print the_int" \
    114 	"(?:No symbol table is loaded|No symbol \"the_int\" in current context).*"
    115 }
    116 
    117 foreach_with_prefix buildid { a4 "" } {
    118     run_test $buildid
    119 }
    120