]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2020-2024 Free Software Foundation, Inc. |
1d5d29e7 SV |
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 checks if gdb can handle missing source files gracefully. | |
17 | # Testing steps are: | |
18 | # 1. Have a main() in main.c that calls an external function f2(). | |
19 | # 2. Have f2() implemented in f2.c. | |
20 | # 3. Build the two files into one executable. | |
21 | # 4. Remove main.c. | |
22 | # 5. Open the executable inside gdb while having gdb in source layout. | |
23 | # No source is found for the moment. | |
24 | # 6. After a little bit of playing, we enter f2() and now the source | |
25 | # layout must show the contents of f2.c. | |
26 | # 7. Going back to main() shall result in no contents again. | |
27 | ||
2786ef85 | 28 | # Check if start command is supported. |
793862d2 | 29 | require !use_gdb_stub |
2786ef85 | 30 | |
8c74a764 | 31 | tuiterm_env |
1d5d29e7 SV |
32 | |
33 | standard_testfile | |
34 | ||
35 | set mainfile [standard_output_file main.c] | |
36 | set f2file [standard_output_file f2.c] | |
37 | set srcfiles [list $mainfile $f2file] | |
38 | ||
39 | # Step 1: Write the main.c file into the output directory. | |
40 | # This file will be removed after compilation. | |
41 | set fd [open "$mainfile" w] | |
42 | puts $fd { | |
43 | extern int f2(int); | |
44 | int | |
45 | main () | |
46 | { | |
47 | int a = 4; | |
48 | a = f2(a); | |
49 | return a - a; | |
50 | } | |
51 | } | |
52 | close $fd | |
53 | ||
54 | # Step 2: Write the f2.c file into the output directory. | |
55 | set fd [open "$f2file" w] | |
56 | puts $fd { | |
57 | int | |
58 | f2 (int x) | |
59 | { | |
60 | x <<= 1; | |
61 | return x+5; | |
62 | } | |
63 | } | |
64 | close $fd | |
65 | ||
66 | # Step 3: Compile the source files. | |
67 | if { [gdb_compile "${srcfiles}" "${binfile}" \ | |
68 | executable {debug additional_flags=-O0}] != "" } { | |
69 | untested "failed to compile" | |
70 | return -1 | |
71 | } | |
72 | ||
73 | # Step 4: Remove the main.c file. | |
74 | file delete $mainfile | |
75 | ||
76 | # Step 5: Load the executable into GDB. | |
77 | # There shall be no source content. | |
78 | Term::clean_restart 24 80 $testfile | |
79 | if {![Term::enter_tui]} { | |
80 | unsupported "TUI not supported" | |
581bea2c | 81 | return |
1d5d29e7 SV |
82 | } |
83 | # There must exist a source layout with the size 80x15 and | |
84 | # there should be nothing in it. | |
85 | Term::check_box_contents "check source box is empty" \ | |
86 | 0 0 80 15 "No Source Available" | |
87 | ||
88 | # Step 6: Go to main and after one next, enter f2(). | |
89 | Term::command "set pagination off" | |
90 | Term::command "start" | |
91 | Term::command "next" | |
92 | Term::command "step" | |
93 | Term::check_contents "checking if inside f2 ()" "f2 \\(x=4\\)" | |
94 | Term::check_box_contents "f2.c must be displayed in source window" \ | |
95 | 0 0 80 15 "return x\\+5" | |
96 | ||
97 | # Step 7: Back in main | |
98 | Term::command "finish" | |
99 | Term::check_box_contents "check source box is empty after return" \ | |
100 | 0 0 80 15 "No Source Available" | |
101 | Term::check_contents "Back in main" "Value returned is .* 13" |