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