]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2022-2024 Free Software Foundation, Inc. |
6647f05d AH |
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 | # This test compiles two executables: crc_mismatch and crc_mismatch-2 | |
17 | # and then strips them of debuginfo creating separate debug files. The test | |
18 | # then replaces crc_mismatch-2.debug with crc_mismatch.debug to trigger | |
19 | # "CRC mismatch" warning. A local debuginfod server is setup to supply | |
20 | # the correct debug file, now when GDB looks up the debug info no warning | |
21 | # is given. | |
22 | ||
23 | standard_testfile .c -2.c | |
24 | ||
25 | load_lib debuginfod-support.exp | |
26 | ||
27 | require allow_debuginfod_tests | |
28 | ||
29 | if {[build_executable "build executable" $testfile $srcfile debug] == -1} { | |
30 | untested "failed to compile" | |
31 | return -1 | |
32 | } | |
33 | ||
34 | # The procedure gdb_gnu_strip_debug will produce an executable called | |
35 | # ${binfile}, which is just like the executable ($binfile) but without | |
36 | # the debuginfo. Instead $binfile has a .gnu_debuglink section which | |
37 | # contains the name of a debuginfo only file. | |
38 | if {[gdb_gnu_strip_debug $binfile]} { | |
39 | # Check that you have a recent version of strip and objcopy installed. | |
40 | unsupported "cannot produce separate debug info files" | |
41 | return -1 | |
42 | } | |
43 | ||
14317f7f | 44 | set debugfile [standard_output_file ${testfile}.debug] |
6647f05d AH |
45 | set debugdir [standard_output_file "debug"] |
46 | remote_exec build "mkdir $debugdir" | |
47 | remote_exec build "mkdir -p [file dirname $debugfile]" | |
48 | remote_exec build "mv -f [standard_output_file ${testfile}.debug] $debugfile" | |
49 | ||
50 | # Test CRC mismatch is reported. | |
51 | if {[build_executable crc_mismatch.exp crc_mismatch-2 crc_mismatch-2.c debug] != -1 | |
52 | && ![gdb_gnu_strip_debug [standard_output_file crc_mismatch-2]]} { | |
53 | ||
54 | # Copy the correct debug file for crc_mismatch-2 to the debugdir | |
55 | # which is going to be used by local debuginfod. | |
56 | remote_exec build "cp [standard_output_file crc_mismatch-2.debug] ${debugdir}" | |
57 | # Move the unmatching debug file for crc_mismatch-2 instead of its real one | |
58 | # to trigger the "CRC mismatch" warning. | |
59 | remote_exec build "mv ${debugfile} [standard_output_file crc_mismatch-2.debug]" | |
60 | ||
34f997c8 | 61 | clean_restart |
6647f05d AH |
62 | |
63 | set escapedobjdirsubdir [string_to_regexp [standard_output_file {}]] | |
34f997c8 AB |
64 | gdb_test "file [standard_output_file crc_mismatch-2]" \ |
65 | [multi_line \ | |
66 | "Reading symbols from ${escapedobjdirsubdir}/crc_mismatch-2\\.\\.\\." \ | |
67 | "warning: the debug information found in \"${escapedobjdirsubdir}/crc_mismatch-2\\.debug\" does not match \"${escapedobjdirsubdir}/crc_mismatch-2\" \\(CRC mismatch\\)\\." \ | |
68 | "\\(No debugging symbols found in .*\\)"] \ | |
69 | "CRC mismatch is reported" | |
70 | ||
71 | # Do the same thing again, but this time check that the styling is | |
72 | # correct. | |
73 | with_test_prefix "check styling" { | |
4ebfd53d | 74 | with_ansi_styling_terminal { |
34f997c8 AB |
75 | clean_restart |
76 | ||
77 | set debug_file_re [style "${escapedobjdirsubdir}/crc_mismatch-2\\.debug" file] | |
78 | set exe_file_re [style "${escapedobjdirsubdir}/crc_mismatch-2" file] | |
79 | ||
80 | gdb_test "file [standard_output_file crc_mismatch-2]" \ | |
81 | [multi_line \ | |
82 | "Reading symbols from ${exe_file_re}\\.\\.\\." \ | |
83 | "warning: the debug information found in \"${debug_file_re}\" does not match \"${exe_file_re}\" \\(CRC mismatch\\)\\." \ | |
84 | "\\(No debugging symbols found in \[^\r\n\]+\\)"] \ | |
85 | "CRC mismatch is reported" | |
86 | } | |
87 | } | |
6647f05d | 88 | |
34f997c8 AB |
89 | # Restart GDB with styling disabled. |
90 | clean_restart | |
6647f05d AH |
91 | } |
92 | ||
93 | # Create CACHE and DB directories ready for debuginfod to use. | |
94 | prepare_for_debuginfod cache db | |
95 | ||
96 | # Start debuginfod server, test the correct debuginfo was fetched | |
97 | # from the server so there're not warnings anymore. | |
98 | proc_with_prefix local_debuginfod { } { | |
99 | global binfile db debugdir cache | |
100 | set escapedobjdirsubdir [string_to_regexp [standard_output_file {}]] | |
101 | ||
102 | set url [start_debuginfod $db $debugdir] | |
103 | if {$url eq ""} { | |
104 | unresolved "failed to start debuginfod server" | |
105 | return | |
106 | } | |
107 | ||
108 | # Point the client to the server. | |
109 | setenv DEBUGINFOD_URLS $url | |
110 | ||
111 | # GDB should now find the symbol and source files. | |
112 | clean_restart | |
113 | ||
114 | # Enable debuginfod and fetch the debuginfo. | |
115 | gdb_test_no_output "set debuginfod enabled on" | |
116 | gdb_test "file $binfile" ".*Reading symbols from.*debuginfo.*" \ | |
117 | "file [file tail $binfile] cmd on" | |
118 | ||
119 | # CRC mismatch should not be reported now because the correct debuginfo | |
120 | # should be fetched from debuginfod. | |
121 | gdb_test "file [standard_output_file crc_mismatch-2]" \ | |
122 | [multi_line \ | |
123 | "Reading symbols from ${escapedobjdirsubdir}/crc_mismatch-2\\.\\.\\." \ | |
b7ea736a | 124 | "Downloading.*separate debug info for ${escapedobjdirsubdir}/crc_mismatch-2\\.\\.\\." \ |
6647f05d AH |
125 | "Reading symbols from ${cache}/\[^\r\n\]+\\.\\.\\.(?:\r\nExpanding full symbols from \[^\r\n\]+)*"] \ |
126 | "debuginfod running, info downloaded, no CRC mismatch" | |
127 | } | |
128 | ||
129 | with_debuginfod_env $cache { | |
130 | local_debuginfod | |
131 | } | |
132 | ||
133 | stop_debuginfod | |
134 | # Spare debug files may confuse testsuite runs in the future. | |
135 | remote_exec build "rm -f $debugfile" |