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