Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.tui / tui-missing-src.exp
1 # Copyright 2020-2022 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 # 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
28 tuiterm_env
29
30 standard_testfile
31
32 set mainfile [standard_output_file main.c]
33 set f2file [standard_output_file f2.c]
34 set srcfiles [list $mainfile $f2file]
35
36 # Step 1: Write the main.c file into the output directory.
37 # This file will be removed after compilation.
38 set fd [open "$mainfile" w]
39 puts $fd {
40 extern int f2(int);
41 int
42 main ()
43 {
44 int a = 4;
45 a = f2(a);
46 return a - a;
47 }
48 }
49 close $fd
50
51 # Step 2: Write the f2.c file into the output directory.
52 set fd [open "$f2file" w]
53 puts $fd {
54 int
55 f2 (int x)
56 {
57 x <<= 1;
58 return x+5;
59 }
60 }
61 close $fd
62
63 # Step 3: Compile the source files.
64 if { [gdb_compile "${srcfiles}" "${binfile}" \
65 executable {debug additional_flags=-O0}] != "" } {
66 untested "failed to compile"
67 return -1
68 }
69
70 # Step 4: Remove the main.c file.
71 file delete $mainfile
72
73 # Step 5: Load the executable into GDB.
74 # There shall be no source content.
75 Term::clean_restart 24 80 $testfile
76 if {![Term::enter_tui]} {
77 unsupported "TUI not supported"
78 return
79 }
80 # There must exist a source layout with the size 80x15 and
81 # there should be nothing in it.
82 Term::check_box_contents "check source box is empty" \
83 0 0 80 15 "No Source Available"
84
85 # Step 6: Go to main and after one next, enter f2().
86 Term::command "set pagination off"
87 Term::command "start"
88 Term::command "next"
89 Term::command "step"
90 Term::check_contents "checking if inside f2 ()" "f2 \\(x=4\\)"
91 Term::check_box_contents "f2.c must be displayed in source window" \
92 0 0 80 15 "return x\\+5"
93
94 # Step 7: Back in main
95 Term::command "finish"
96 Term::check_box_contents "check source box is empty after return" \
97 0 0 80 15 "No Source Available"
98 Term::check_contents "Back in main" "Value returned is .* 13"
This page took 0.032711 seconds and 4 git commands to generate.