]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.mi/mi-simplerun.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.mi / mi-simplerun.exp
1 # Copyright 1999-2024 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 #
17 # Test essential Machine interface (MI) operations
18 #
19 # Verify that, using the MI, we can run a simple program and perform basic
20 # debugging activities like: insert breakpoints, run the program,
21 # step, next, continue until it ends and, last but not least, quit.
22 #
23 # The goal is not to test gdb functionality, which is done by other tests,
24 # but to verify the correct output response to MI operations.
25 #
26
27 load_lib mi-support.exp
28 set MIFLAGS "-i=mi"
29
30 standard_testfile basics.c
31
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 untested "failed to compile"
34 return -1
35 }
36
37 if {[mi_clean_restart $binfile]} {
38 return
39 }
40
41 proc test_breakpoints_creation_and_listing {} {
42 global srcfile
43
44 set line_callee4_head [gdb_get_line_number "callee4 ("]
45 set line_callee4_body [expr $line_callee4_head + 2]
46 set line_callee3_head [gdb_get_line_number "callee3 ("]
47 set line_callee3_body [expr $line_callee3_head + 2]
48 set line_callee2_head [gdb_get_line_number "callee2 ("]
49 set line_callee2_body [expr $line_callee2_head + 2]
50 set line_main_head [gdb_get_line_number "main ("]
51 set line_main_body [expr $line_main_head + 2]
52
53 # Insert some breakpoints and list them
54 # Also, disable some so they do not interfere with other tests
55 # Tests:
56 # -break-insert
57 # -break-list
58 # -break-disable
59 # -break-info
60
61 set bps {}
62 lappend bps [mi_create_breakpoint "--qualified main" \
63 "break-insert operation" \
64 -number 1 -func main -file ".*basics.c" \
65 -line $line_main_body]
66
67 lappend bps [mi_create_breakpoint "basics.c:callee2" \
68 "insert breakpoint at basics.c:callee2" \
69 -number 2 -func callee2 -file ".*basics.c" \
70 -line $line_callee2_body]
71
72 lappend bps [mi_create_breakpoint "basics.c:$line_callee3_head" \
73 "insert breakpoint at basics.c:\$line_callee3_head" \
74 -number 3 -func callee3 -file ".*basics.c" \
75 -line $line_callee3_body]
76
77 lappend bps [mi_create_breakpoint \
78 "\"\\\"${srcfile}\\\":$line_callee4_head\"" \
79 "insert breakpoint at \"<fullfilename>\":\$line_callee4_head" \
80 -number 4 -func callee4 -file ".*basics.c" \
81 -line $line_callee4_body]
82
83 mi_gdb_test "204-break-list" \
84 "204\\^done,[mi_make_breakpoint_table $bps]" \
85 "list of breakpoints"
86
87 mi_gdb_test "205-break-disable 2 3 4" \
88 "205\\^done.*" \
89 "disabling of breakpoints"
90
91 set bp2 [mi_make_breakpoint -number 2 -enabled n]
92 mi_gdb_test "206-break-info 2" \
93 "206\\^done,[mi_make_breakpoint_table [list $bp2]]"\
94 "list of breakpoints, 16 disabled"
95 }
96
97 proc test_running_the_program {} {
98 set line_main_head [gdb_get_line_number "main ("]
99 set line_main_body [expr $line_main_head + 2]
100
101 # Run the program without args, then specify srgs and rerun the program
102 # Tests:
103 # -exec-run
104 # -gdb-set
105
106 # mi_gdb_test cannot be used for asynchronous commands because there are
107 # two prompts involved and this can lead to a race condition.
108 # The following is equivalent to a send_gdb "000-exec-run\n"
109 mi_run_cmd
110 mi_expect_stop "breakpoint-hit" "main" "" ".*basics.c" "$line_main_body" \
111 { "" "disp=\"keep\"" } "run to main"
112 }
113
114 proc test_controlled_execution {} {
115 global hex
116
117 set line_callee4_head [gdb_get_line_number "callee4 ("]
118 set line_callee4_body [expr $line_callee4_head + 2]
119 set line_callee3_head [gdb_get_line_number "callee3 ("]
120 set line_callee3_call [expr $line_callee3_head + 2]
121 set line_callee3_close_brace [expr $line_callee3_head + 3]
122 set line_callee1_head [gdb_get_line_number "callee1 ("]
123 set line_callee1_body [expr $line_callee1_head + 2]
124 set line_main_head [gdb_get_line_number "main ("]
125 set line_main_body [expr $line_main_head + 2]
126
127 # Continue execution until a breakpoint is reached, step into calls, verifying
128 # if the arguments are correctly shown, continue to the end of a called
129 # function, step over a call (next).
130 # Tests:
131 # -exec-continue
132 # -exec-next
133 # -exec-step
134 # -exec-finish
135
136 mi_next_to "main" "" "basics.c" [expr $line_main_body + 1] "next at main"
137
138 # FIXME: A string argument is not printed right; should be fixed and
139 # we should look for the right thing here.
140 # NOTE: The ``\\\\\"'' is for \".
141 mi_step_to "callee1" \
142 "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}" \
143 "basics.c" "$line_callee1_body" "step at main"
144
145 # FIXME: A string argument is not printed right; should be fixed and
146 # we should look for the right thing here.
147 mi_execute_to "exec-step 3" "end-stepping-range" "callee4" "" \
148 "basics.c" $line_callee4_body "" "step to callee4"
149
150 # FIXME: A string argument is not printed right; should be fixed and
151 # we should look for the right thing here.
152 # NOTE: The ``.'' is part of ``gdb-result-var="$1"''
153 mi_finish_to "callee3" ".*" "basics.c" \
154 "($line_callee3_call|$line_callee3_close_brace)" ".1" "0" "exec-finish"
155 }
156
157 proc test_controlling_breakpoints {} {
158 # Enable, delete, set ignore counts in breakpoints
159 # (disable was already tested above)
160 # Tests:
161 # -break-delete
162 # -break-enable
163 # -break-after
164 # -break-condition
165
166 }
167
168 proc test_program_termination {} {
169 # Run to completion: normal and forced
170 # Tests:
171 # -exec-abort
172 # (normal termination of inferior)
173
174 mi_execute_to "exec-continue" "exited-normally" "" "" "" "" "" "continue to end"
175 }
176
177 test_breakpoints_creation_and_listing
178 test_running_the_program
179 test_controlled_execution
180 test_controlling_breakpoints
181 test_program_termination
182
183 mi_gdb_exit