1 1.1 christos # Copyright 2022-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 # This test triggers the "separate debug info file has no debug info" warning by replacing 17 1.1 christos # the build-id based .debug file with the stripped binary and then loading it to gdb. 18 1.1 christos # It then also sets up local debuginfod server with the correct debug file to download 19 1.1.1.2 christos # to make sure no warnings are emitted. 20 1.1 christos 21 1.1 christos 22 1.1 christos standard_testfile 23 1.1 christos 24 1.1 christos load_lib debuginfod-support.exp 25 1.1 christos 26 1.1 christos require allow_debuginfod_tests 27 1.1 christos 28 1.1 christos if {[build_executable "build executable" ${testfile} ${srcfile} \ 29 1.1 christos {debug build-id}] == -1} { 30 1.1 christos return -1 31 1.1 christos } 32 1.1 christos 33 1.1.1.2 christos # Split debug information from BINFILE into BINFILE.debug. 34 1.1 christos # 35 1.1.1.2 christos # By passing the "no-debuglink" flag we prevent this proc from adding 36 1.1.1.2 christos # a .gnu_debuglink section to BINFILE. Any lookup of the debug 37 1.1.1.2 christos # information by GDB will need to be done based on the build-id. 38 1.1 christos if {[gdb_gnu_strip_debug $binfile no-debuglink]} { 39 1.1 christos unsupported "cannot produce separate debug info files" 40 1.1 christos return -1 41 1.1 christos } 42 1.1 christos 43 1.1 christos # Get the .build-id/PREFIX/SUFFIX.debug file name, and convert it to 44 1.1 christos # an absolute path, this is where we will place the debug information. 45 1.1 christos set build_id_debug_file \ 46 1.1 christos [standard_output_file [build_id_debug_filename_get $binfile]] 47 1.1 christos 48 1.1 christos # Get the BINFILE.debug filename. This is the file we should be 49 1.1 christos # moving to the BUILD_ID_DEBUG_FILE location, but we wont, we're going 50 1.1 christos # to move something else there instead. 51 1.1 christos set debugfile [standard_output_file "${binfile}.debug"] 52 1.1 christos 53 1.1 christos # Move debugfile to the directory to be used by the debuginfod 54 1.1 christos # server. 55 1.1 christos set debuginfod_debugdir [standard_output_file "debug"] 56 1.1 christos remote_exec build "mkdir $debuginfod_debugdir" 57 1.1 christos remote_exec build "mv $debugfile $debuginfod_debugdir" 58 1.1 christos 59 1.1 christos # Create the .build-id/PREFIX directory name from 60 1.1 christos # .build-id/PREFIX/SUFFIX.debug filename. 61 1.1 christos set debugdir [file dirname ${build_id_debug_file}] 62 1.1 christos remote_exec build "mkdir -p $debugdir" 63 1.1 christos 64 1.1 christos # Now move the stripped executable into the .build-id directory 65 1.1 christos # instead of the debug information. Later on we're going to try and 66 1.1 christos # load this into GDB. GDB will then try to find the separate debug 67 1.1 christos # information, which will point back at this file, which also doesn't 68 1.1 christos # have debug information, which could cause a loop. But GDB will spot 69 1.1 christos # this and give a warning. 70 1.1.1.2 christos remote_exec build "mv ${binfile} ${build_id_debug_file}" 71 1.1 christos 72 1.1 christos # Now start GDB. 73 1.1 christos clean_restart 74 1.1 christos 75 1.1 christos # Tell GDB where to look for the .build-id directory. 76 1.1 christos set debug_file_directory [standard_output_file ""] 77 1.1 christos gdb_test_no_output "set debug-file-directory ${debug_file_directory}" \ 78 1.1 christos "set debug-file-directory" 79 1.1 christos 80 1.1 christos # Now load the file into GDB, and look for the warning. 81 1.1 christos set debug_file_re [string_to_regexp $build_id_debug_file] 82 1.1 christos gdb_test "file ${build_id_debug_file}" \ 83 1.1 christos [multi_line \ 84 1.1 christos "Reading symbols from $debug_file_re\\.\\.\\." \ 85 1.1 christos "warning: \"$debug_file_re\": separate debug info file has no debug info" \ 86 1.1 christos "\\(No debugging symbols found in \[^\r\n\]+\\)"] \ 87 1.1 christos "load test file, expect a warning" 88 1.1 christos 89 1.1 christos # Do the same thing again, but this time check that the styling is 90 1.1 christos # correct. 91 1.1 christos with_test_prefix "check styling" { 92 1.1 christos with_ansi_styling_terminal { 93 1.1 christos clean_restart 94 1.1 christos 95 1.1 christos gdb_test_no_output "set debug-file-directory ${debug_file_directory}" \ 96 1.1 christos "set debug-file-directory" 97 1.1 christos 98 1.1 christos # Now load the file into GDB, and look for the warning. 99 1.1 christos set debug_file_re [style [string_to_regexp $build_id_debug_file] file] 100 1.1 christos 101 1.1 christos gdb_test "file ${build_id_debug_file}" \ 102 1.1 christos [multi_line \ 103 1.1 christos "Reading symbols from $debug_file_re\\.\\.\\." \ 104 1.1 christos "warning: \"$debug_file_re\": separate debug info file has no debug info" \ 105 1.1 christos "\\(No debugging symbols found in \[^\r\n\]+\\)"] \ 106 1.1 christos "load test file, expect a warning" 107 1.1 christos } 108 1.1 christos } 109 1.1 christos 110 1.1 christos # Now we should close GDB. 111 1.1 christos gdb_exit 112 1.1 christos 113 1.1 christos # Create CACHE and DB directories ready for debuginfod to use. 114 1.1 christos prepare_for_debuginfod cache db 115 1.1 christos 116 1.1 christos # Start debuginfod server and test debuginfo is downloaded from 117 1.1 christos # it and we can se no warnings anymore. 118 1.1 christos proc_with_prefix local_debuginfod { } { 119 1.1 christos global db debuginfod_debugdir cache build_id_debug_file 120 1.1 christos 121 1.1 christos set url [start_debuginfod $db $debuginfod_debugdir] 122 1.1 christos if {$url eq ""} { 123 1.1 christos unresolved "failed to start debuginfod server" 124 1.1 christos return 125 1.1 christos } 126 1.1 christos 127 1.1 christos # Point the client to the server. 128 1.1 christos setenv DEBUGINFOD_URLS $url 129 1.1 christos 130 1.1 christos # GDB should now find the symbol and source files. 131 1.1 christos clean_restart 132 1.1 christos 133 1.1 christos # Enable debuginfod and fetch the debuginfo. 134 1.1 christos gdb_test_no_output "set debuginfod enabled on" 135 1.1 christos 136 1.1 christos # "separate debug info file has no debug info" warning should not be 137 1.1 christos # reported now because the correct debuginfo should be fetched from 138 1.1 christos # debuginfod. 139 1.1 christos gdb_test "file ${build_id_debug_file}" \ 140 1.1 christos [multi_line \ 141 1.1 christos "Reading symbols from ${build_id_debug_file}\\.\\.\\." \ 142 1.1.1.2 christos "Downloading\[^\r\n\]*separate debug info for ${build_id_debug_file}\\.\\.\\." \ 143 1.1 christos "Reading symbols from ${cache}/\[^\r\n\]+\\.\\.\\.(?:\r\nExpanding full symbols from \[^\r\n\]+)*"] \ 144 1.1 christos "debuginfod running, info downloaded, no warnings" 145 1.1 christos } 146 1.1 christos 147 1.1 christos # Restart GDB, and load the file, this time we should correctly get 148 1.1 christos # the debug symbols from the server, and should not see the warning. 149 1.1 christos with_debuginfod_env $cache { 150 1.1 christos local_debuginfod 151 1.1 christos } 152 1.1 christos 153 1.1 christos stop_debuginfod 154 1.1 christos # Spare debug files may confuse testsuite runs in the future. 155 1.1 christos remote_exec build "rm -f $debugfile" 156 1.1 christos 157