Commit | Line | Data |
---|---|---|
f6be8713 SDJ |
1 | # Copyright (C) 2020 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 | # Test for PR tui/25126. | |
17 | # | |
18 | # The bug is about a regression that makes GDB not reload its source | |
19 | # code cache when the inferior's symbols are reloaded, which leads to | |
20 | # wrong backtraces/listings. | |
21 | # | |
22 | # This bug is reproducible even without using the TUI. | |
23 | ||
24 | standard_testfile | |
25 | ||
26 | # Only run on native boards. | |
27 | if { [use_gdb_stub] || [target_info gdb_protocol] == "extended-remote" } { | |
28 | return -1 | |
29 | } | |
30 | ||
31 | # Because we need to modify the source file later, it's better if we | |
32 | # just copy it to our output directory (instead of messing with the | |
33 | # user's source directory). | |
34 | set newsrc [standard_output_file $testfile].c | |
35 | file copy -force -- $srcdir/$subdir/$srcfile $newsrc | |
36 | set srcfile $newsrc | |
37 | ||
38 | if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { | |
39 | return -1 | |
40 | } | |
41 | ||
42 | # Get the line number for the line with the "break-here" marker. | |
43 | set bp_line [gdb_get_line_number "break-here" $srcfile] | |
44 | ||
45 | gdb_assert { [runto "$srcfile:$bp_line"] } \ | |
2078dbb2 | 46 | "run to break-here marker" |
f6be8713 SDJ |
47 | |
48 | # Do a "list" and check that the printed line matches the line of the | |
49 | # original source file. | |
50 | gdb_test_no_output "set listsize 1" | |
51 | gdb_test "list" "$bp_line\[ \t\]+printf \\(\"hello\\\\n\"\\); /\\* break-here \\*/" \ | |
52 | "check the first version of the source file" | |
53 | ||
54 | # Modify the original source file, and add an extra line into it. | |
55 | # This only works locally because of the TCL commands. | |
56 | set bkpsrc [standard_output_file $testfile].c.bkp | |
57 | set bkpsrcfd [open $bkpsrc w] | |
58 | set srcfd [open $srcfile r] | |
59 | ||
60 | while { [gets $srcfd line] != -1 } { | |
61 | if { [string first "break-here" $line] != -1 } { | |
62 | # Put a "printf" line before the "break-here" line. | |
63 | puts $bkpsrcfd " printf (\"foo\\n\"); /* new-marker */" | |
64 | } | |
65 | puts $bkpsrcfd $line | |
66 | } | |
67 | ||
68 | close $bkpsrcfd | |
69 | close $srcfd | |
70 | file rename -force -- $bkpsrc $srcfile | |
71 | # We have to wait 1 second because of the way GDB checks whether the | |
72 | # binary has changed or not. GDB uses stat(2) and currently checks | |
73 | # 'st_mtime', whose precision is measured in seconds. Since the copy, | |
74 | # rename, and rebuild can take less than 1 second, GDB might mistakenly | |
75 | # assume that the binary is unchanged. | |
76 | sleep 1 | |
77 | ||
78 | # Recompile the modified source. We use "gdb_compile" here instead of | |
79 | # "prepare_for_testing" because we don't want to call "clean_restart". | |
80 | if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } { | |
81 | return -1 | |
82 | } | |
83 | ||
84 | # Rerun the program. This should not only force GDB to reload the | |
85 | # source cache, but also to break at BP_LINE again, which now has | |
86 | # different contents. | |
87 | gdb_test_multiple "run" "rerun program" { | |
88 | -re {The program being debugged has been started already\.\r\nStart it from the beginning\? \(y or n\) $} { | |
89 | set binregex [string_to_regexp $binfile] | |
90 | gdb_test "y" "\\`$binregex\\' has changed; re-reading symbols\.\r\nStarting program: ${binregex}.*" \ | |
91 | "rerun program" | |
92 | } | |
93 | } | |
94 | ||
95 | # Again, perform the listing and check that the line indeed has | |
96 | # changed for GDB. | |
97 | gdb_test "list" "${bp_line}\[ \t\]+printf \\(\"foo\\\\n\"\\); /\\\* new-marker \\\*/.*" \ | |
98 | "verify that the source code is properly reloaded" |