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