Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1999-2020 Free Software Foundation, Inc. |
fb40c209 AC |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
fb40c209 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
fb40c209 AC |
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. | |
e22f8b7c | 12 | # |
fb40c209 | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
fb40c209 | 15 | |
fb40c209 AC |
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 | |
b30bf9ee | 28 | set MIFLAGS "-i=mi" |
fb40c209 AC |
29 | |
30 | gdb_exit | |
31 | if [mi_gdb_start] { | |
32 | continue | |
33 | } | |
34 | ||
298a9cf0 TT |
35 | standard_testfile basics.c |
36 | ||
9357e021 | 37 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
5b362f04 | 38 | untested "failed to compile" |
b60f0898 | 39 | return -1 |
fb40c209 AC |
40 | } |
41 | ||
42 | mi_delete_breakpoints | |
43 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
44 | mi_gdb_reinitialize_dir $srcdir/$subdir | |
45 | mi_gdb_load ${binfile} | |
46 | ||
47 | proc test_breakpoints_creation_and_listing {} { | |
fb40c209 | 48 | global srcfile |
fb40c209 | 49 | |
45f07fef | 50 | set line_callee4_head [gdb_get_line_number "callee4 ("] |
b40e7bf3 | 51 | set line_callee4_body [expr $line_callee4_head + 2] |
45f07fef | 52 | set line_callee3_head [gdb_get_line_number "callee3 ("] |
b40e7bf3 | 53 | set line_callee3_body [expr $line_callee3_head + 2] |
45f07fef MC |
54 | set line_callee2_head [gdb_get_line_number "callee2 ("] |
55 | set line_callee2_body [expr $line_callee2_head + 2] | |
56 | set line_main_head [gdb_get_line_number "main ("] | |
57 | set line_main_body [expr $line_main_head + 2] | |
58 | ||
fb40c209 AC |
59 | # Insert some breakpoints and list them |
60 | # Also, disable some so they do not interfere with other tests | |
61 | # Tests: | |
62 | # -break-insert | |
63 | # -break-list | |
64 | # -break-disable | |
65 | # -break-info | |
66 | ||
4b48d439 KS |
67 | set bps {} |
68 | lappend bps [mi_create_breakpoint "main" \ | |
69 | "break-insert operation" \ | |
70 | -number 1 -func main -file ".*basics.c" \ | |
71 | -line $line_main_body] | |
fb40c209 | 72 | |
4b48d439 KS |
73 | lappend bps [mi_create_breakpoint "basics.c:callee2" \ |
74 | "insert breakpoint at basics.c:callee2" \ | |
75 | -number 2 -func callee2 -file ".*basics.c" \ | |
76 | -line $line_callee2_body] | |
fb40c209 | 77 | |
4b48d439 KS |
78 | lappend bps [mi_create_breakpoint "basics.c:$line_callee3_head" \ |
79 | "insert breakpoint at basics.c:\$line_callee3_head" \ | |
80 | -number 3 -func callee3 -file ".*basics.c" \ | |
a9e40818 | 81 | -line $line_callee3_body] |
fb40c209 | 82 | |
4b48d439 KS |
83 | lappend bps [mi_create_breakpoint \ |
84 | "\"\\\"${srcfile}\\\":$line_callee4_head\"" \ | |
85 | "insert breakpoint at \"<fullfilename>\":\$line_callee4_head" \ | |
86 | -number 4 -func callee4 -file ".*basics.c" \ | |
a9e40818 | 87 | -line $line_callee4_body] |
fb40c209 AC |
88 | |
89 | mi_gdb_test "204-break-list" \ | |
4b48d439 KS |
90 | "204\\^done,[mi_make_breakpoint_table $bps]" \ |
91 | "list of breakpoints" | |
fb40c209 AC |
92 | |
93 | mi_gdb_test "205-break-disable 2 3 4" \ | |
94 | "205\\^done.*" \ | |
95 | "disabling of breakpoints" | |
96 | ||
4b48d439 | 97 | set bp2 [mi_make_breakpoint -number 2 -enabled n] |
fb40c209 | 98 | mi_gdb_test "206-break-info 2" \ |
4b48d439 KS |
99 | "206\\^done,[mi_make_breakpoint_table [list $bp2]]"\ |
100 | "list of breakpoints, 16 disabled" | |
fb40c209 AC |
101 | } |
102 | ||
103 | proc test_running_the_program {} { | |
45f07fef MC |
104 | set line_main_head [gdb_get_line_number "main ("] |
105 | set line_main_body [expr $line_main_head + 2] | |
106 | ||
fb40c209 AC |
107 | # Run the program without args, then specify srgs and rerun the program |
108 | # Tests: | |
109 | # -exec-run | |
110 | # -gdb-set | |
111 | ||
112 | # mi_gdb_test cannot be used for asynchronous commands because there are | |
113 | # two prompts involved and this can lead to a race condition. | |
114 | # The following is equivalent to a send_gdb "000-exec-run\n" | |
115 | mi_run_cmd | |
18ac113b AR |
116 | mi_expect_stop "breakpoint-hit" "main" "" ".*basics.c" "$line_main_body" \ |
117 | { "" "disp=\"keep\"" } "run to main" | |
fb40c209 AC |
118 | } |
119 | ||
120 | proc test_controlled_execution {} { | |
fb40c209 AC |
121 | global hex |
122 | ||
45f07fef MC |
123 | set line_callee4_head [gdb_get_line_number "callee4 ("] |
124 | set line_callee4_body [expr $line_callee4_head + 2] | |
125 | set line_callee3_head [gdb_get_line_number "callee3 ("] | |
471ba8c9 | 126 | set line_callee3_call [expr $line_callee3_head + 2] |
45f07fef MC |
127 | set line_callee3_close_brace [expr $line_callee3_head + 3] |
128 | set line_callee1_head [gdb_get_line_number "callee1 ("] | |
129 | set line_callee1_body [expr $line_callee1_head + 2] | |
130 | set line_main_head [gdb_get_line_number "main ("] | |
131 | set line_main_body [expr $line_main_head + 2] | |
132 | ||
fb40c209 AC |
133 | # Continue execution until a breakpoint is reached, step into calls, verifying |
134 | # if the arguments are correctly shown, continue to the end of a called | |
135 | # function, step over a call (next). | |
136 | # Tests: | |
137 | # -exec-continue | |
138 | # -exec-next | |
139 | # -exec-step | |
140 | # -exec-finish | |
141 | ||
45f07fef | 142 | mi_next_to "main" "" "basics.c" [expr $line_main_body + 1] "next at main" |
fb40c209 AC |
143 | |
144 | # FIXME: A string argument is not printed right; should be fixed and | |
145 | # we should look for the right thing here. | |
146 | # NOTE: The ``\\\\\"'' is for \". | |
dcf95b47 DJ |
147 | mi_step_to "callee1" \ |
148 | "\{name=\"intarg\",value=\"2\"\},\{name=\"strarg\",value=\"$hex \\\\\"A string argument\.\\\\\"\"\},\{name=\"fltarg\",value=\"3.5\"\}" \ | |
45f07fef | 149 | "basics.c" "$line_callee1_body" "step at main" |
fb40c209 AC |
150 | |
151 | # FIXME: A string argument is not printed right; should be fixed and | |
152 | # we should look for the right thing here. | |
fc5cfef4 | 153 | mi_execute_to "exec-step 3" "end-stepping-range" "callee4" "" \ |
45f07fef | 154 | "basics.c" $line_callee4_body "" "step to callee4" |
fb40c209 AC |
155 | |
156 | # FIXME: A string argument is not printed right; should be fixed and | |
157 | # we should look for the right thing here. | |
158 | # NOTE: The ``.'' is part of ``gdb-result-var="$1"'' | |
471ba8c9 DJ |
159 | mi_finish_to "callee3" ".*" "basics.c" \ |
160 | "($line_callee3_call|$line_callee3_close_brace)" ".1" "0" "exec-finish" | |
fb40c209 AC |
161 | } |
162 | ||
163 | proc test_controlling_breakpoints {} { | |
fb40c209 AC |
164 | # Enable, delete, set ignore counts in breakpoints |
165 | # (disable was already tested above) | |
166 | # Tests: | |
167 | # -break-delete | |
168 | # -break-enable | |
169 | # -break-after | |
170 | # -break-condition | |
171 | ||
172 | } | |
173 | ||
174 | proc test_program_termination {} { | |
fb40c209 AC |
175 | # Run to completion: normal and forced |
176 | # Tests: | |
177 | # -exec-abort | |
178 | # (normal termination of inferior) | |
179 | ||
bb378428 | 180 | mi_execute_to "exec-continue" "exited-normally" "" "" "" "" "" "continue to end" |
fb40c209 AC |
181 | } |
182 | ||
183 | test_breakpoints_creation_and_listing | |
184 | test_running_the_program | |
185 | test_controlled_execution | |
186 | test_controlling_breakpoints | |
187 | test_program_termination | |
188 | ||
189 | mi_gdb_exit | |
190 | return 0 |