Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - breakpoint and watchpoint commands. |
0b302171 | 2 | Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc. |
ab91fdd5 | 3 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
fb40c209 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb40c209 AC |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
fb40c209 AC |
22 | #include "mi-cmds.h" |
23 | #include "ui-out.h" | |
24 | #include "mi-out.h" | |
25 | #include "breakpoint.h" | |
26 | #include "gdb_string.h" | |
27 | #include "mi-getopt.h" | |
5b7f31a4 | 28 | #include "gdb.h" |
98deb0da | 29 | #include "exceptions.h" |
383f836e | 30 | #include "observer.h" |
8d3788bd | 31 | #include "mi-main.h" |
fb40c209 | 32 | |
fb40c209 AC |
33 | enum |
34 | { | |
35 | FROM_TTY = 0 | |
36 | }; | |
37 | ||
383f836e TT |
38 | /* True if MI breakpoint observers have been registered. */ |
39 | ||
40 | static int mi_breakpoint_observers_installed; | |
41 | ||
42 | /* Control whether breakpoint_notify may act. */ | |
43 | ||
44 | static int mi_can_breakpoint_notify; | |
45 | ||
2b03b41d | 46 | /* Output a single breakpoint, when allowed. */ |
fb40c209 AC |
47 | |
48 | static void | |
8d3788bd | 49 | breakpoint_notify (struct breakpoint *b) |
fb40c209 | 50 | { |
383f836e | 51 | if (mi_can_breakpoint_notify) |
79a45e25 | 52 | gdb_breakpoint_query (current_uiout, b->number, NULL); |
fb40c209 AC |
53 | } |
54 | ||
fb40c209 AC |
55 | enum bp_type |
56 | { | |
57 | REG_BP, | |
58 | HW_BP, | |
59 | REGEXP_BP | |
60 | }; | |
61 | ||
afe8ab22 VP |
62 | /* Implements the -break-insert command. |
63 | See the MI manual for the list of possible options. */ | |
fb40c209 | 64 | |
ce8f13f8 | 65 | void |
fb40c209 AC |
66 | mi_cmd_break_insert (char *command, char **argv, int argc) |
67 | { | |
68 | char *address = NULL; | |
8cdf0e15 | 69 | int hardware = 0; |
fb40c209 AC |
70 | int temp_p = 0; |
71 | int thread = -1; | |
72 | int ignore_count = 0; | |
73 | char *condition = NULL; | |
afe8ab22 | 74 | int pending = 0; |
41447f92 | 75 | int enabled = 1; |
6534d786 | 76 | int tracepoint = 0; |
8cdf0e15 | 77 | struct cleanup *back_to; |
0fb4aa4b | 78 | enum bptype type_wanted; |
19ca11c5 | 79 | struct breakpoint_ops *ops; |
41447f92 | 80 | |
fb40c209 AC |
81 | enum opt |
82 | { | |
8cdf0e15 | 83 | HARDWARE_OPT, TEMP_OPT, CONDITION_OPT, |
6534d786 VP |
84 | IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT, |
85 | TRACEPOINT_OPT, | |
fb40c209 | 86 | }; |
91174723 | 87 | static const struct mi_opt opts[] = |
fb40c209 AC |
88 | { |
89 | {"h", HARDWARE_OPT, 0}, | |
90 | {"t", TEMP_OPT, 0}, | |
91 | {"c", CONDITION_OPT, 1}, | |
92 | {"i", IGNORE_COUNT_OPT, 1}, | |
93 | {"p", THREAD_OPT, 1}, | |
afe8ab22 | 94 | {"f", PENDING_OPT, 0}, |
41447f92 | 95 | {"d", DISABLE_OPT, 0}, |
6534d786 | 96 | {"a", TRACEPOINT_OPT, 0}, |
d5d6fca5 | 97 | { 0, 0, 0 } |
fb40c209 AC |
98 | }; |
99 | ||
100 | /* Parse arguments. It could be -r or -h or -t, <location> or ``--'' | |
101 | to denote the end of the option list. */ | |
f8c000a2 AS |
102 | int oind = 0; |
103 | char *oarg; | |
102040f0 | 104 | |
fb40c209 AC |
105 | while (1) |
106 | { | |
1b05df00 | 107 | int opt = mi_getopt ("-break-insert", argc, argv, |
f8c000a2 | 108 | opts, &oind, &oarg); |
fb40c209 AC |
109 | if (opt < 0) |
110 | break; | |
111 | switch ((enum opt) opt) | |
112 | { | |
113 | case TEMP_OPT: | |
114 | temp_p = 1; | |
115 | break; | |
116 | case HARDWARE_OPT: | |
8cdf0e15 | 117 | hardware = 1; |
fb40c209 | 118 | break; |
fb40c209 | 119 | case CONDITION_OPT: |
f8c000a2 | 120 | condition = oarg; |
fb40c209 AC |
121 | break; |
122 | case IGNORE_COUNT_OPT: | |
f8c000a2 | 123 | ignore_count = atol (oarg); |
fb40c209 AC |
124 | break; |
125 | case THREAD_OPT: | |
f8c000a2 | 126 | thread = atol (oarg); |
fb40c209 | 127 | break; |
afe8ab22 VP |
128 | case PENDING_OPT: |
129 | pending = 1; | |
130 | break; | |
41447f92 VP |
131 | case DISABLE_OPT: |
132 | enabled = 0; | |
6534d786 VP |
133 | break; |
134 | case TRACEPOINT_OPT: | |
135 | tracepoint = 1; | |
136 | break; | |
fb40c209 AC |
137 | } |
138 | } | |
139 | ||
f8c000a2 | 140 | if (oind >= argc) |
1b05df00 | 141 | error (_("-break-insert: Missing <location>")); |
f8c000a2 | 142 | if (oind < argc - 1) |
1b05df00 | 143 | error (_("-break-insert: Garbage following <location>")); |
f8c000a2 | 144 | address = argv[oind]; |
fb40c209 | 145 | |
2b03b41d | 146 | /* Now we have what we need, let's insert the breakpoint! */ |
383f836e TT |
147 | if (! mi_breakpoint_observers_installed) |
148 | { | |
149 | observer_attach_breakpoint_created (breakpoint_notify); | |
383f836e TT |
150 | mi_breakpoint_observers_installed = 1; |
151 | } | |
152 | ||
8cdf0e15 | 153 | back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify); |
383f836e | 154 | mi_can_breakpoint_notify = 1; |
0fb4aa4b PA |
155 | |
156 | /* Note that to request a fast tracepoint, the client uses the | |
157 | "hardware" flag, although there's nothing of hardware related to | |
158 | fast tracepoints -- one can implement slow tracepoints with | |
159 | hardware breakpoints, but fast tracepoints are always software. | |
160 | "fast" is a misnomer, actually, "jump" would be more appropriate. | |
161 | A simulator or an emulator could conceivably implement fast | |
162 | regular non-jump based tracepoints. */ | |
163 | type_wanted = (tracepoint | |
164 | ? (hardware ? bp_fast_tracepoint : bp_tracepoint) | |
165 | : (hardware ? bp_hardware_breakpoint : bp_breakpoint)); | |
19ca11c5 | 166 | ops = tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; |
0fb4aa4b | 167 | |
8cdf0e15 | 168 | create_breakpoint (get_current_arch (), address, condition, thread, |
e7e0cddf | 169 | NULL, |
8cdf0e15 | 170 | 0 /* condition and thread are valid. */, |
0fb4aa4b | 171 | temp_p, type_wanted, |
8cdf0e15 VP |
172 | ignore_count, |
173 | pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
19ca11c5 | 174 | ops, 0, enabled, 0, 0); |
8cdf0e15 VP |
175 | do_cleanups (back_to); |
176 | ||
fb40c209 AC |
177 | } |
178 | ||
179 | enum wp_type | |
180 | { | |
181 | REG_WP, | |
182 | READ_WP, | |
183 | ACCESS_WP | |
184 | }; | |
185 | ||
9b4c786c VP |
186 | void |
187 | mi_cmd_break_passcount (char *command, char **argv, int argc) | |
188 | { | |
189 | int n; | |
190 | int p; | |
d9b3f62e | 191 | struct tracepoint *t; |
9b4c786c VP |
192 | |
193 | if (argc != 2) | |
194 | error (_("Usage: tracepoint-number passcount")); | |
195 | ||
196 | n = atoi (argv[0]); | |
197 | p = atoi (argv[1]); | |
198 | t = get_tracepoint (n); | |
199 | ||
200 | if (t) | |
201 | { | |
202 | t->pass_count = p; | |
203 | observer_notify_tracepoint_modified (n); | |
204 | } | |
205 | else | |
206 | { | |
401a70b8 | 207 | error (_("Could not find tracepoint %d"), n); |
9b4c786c VP |
208 | } |
209 | } | |
210 | ||
fb40c209 AC |
211 | /* Insert a watchpoint. The type of watchpoint is specified by the |
212 | first argument: | |
213 | -break-watch <expr> --> insert a regular wp. | |
214 | -break-watch -r <expr> --> insert a read watchpoint. | |
2b03b41d | 215 | -break-watch -a <expr> --> insert an access wp. */ |
fb40c209 | 216 | |
ce8f13f8 | 217 | void |
fb40c209 AC |
218 | mi_cmd_break_watch (char *command, char **argv, int argc) |
219 | { | |
220 | char *expr = NULL; | |
221 | enum wp_type type = REG_WP; | |
222 | enum opt | |
223 | { | |
224 | READ_OPT, ACCESS_OPT | |
225 | }; | |
91174723 | 226 | static const struct mi_opt opts[] = |
fb40c209 AC |
227 | { |
228 | {"r", READ_OPT, 0}, | |
229 | {"a", ACCESS_OPT, 0}, | |
d5d6fca5 | 230 | { 0, 0, 0 } |
fb40c209 AC |
231 | }; |
232 | ||
233 | /* Parse arguments. */ | |
f8c000a2 AS |
234 | int oind = 0; |
235 | char *oarg; | |
102040f0 | 236 | |
fb40c209 AC |
237 | while (1) |
238 | { | |
1b05df00 | 239 | int opt = mi_getopt ("-break-watch", argc, argv, |
f8c000a2 | 240 | opts, &oind, &oarg); |
102040f0 | 241 | |
fb40c209 AC |
242 | if (opt < 0) |
243 | break; | |
244 | switch ((enum opt) opt) | |
245 | { | |
246 | case READ_OPT: | |
247 | type = READ_WP; | |
248 | break; | |
249 | case ACCESS_OPT: | |
250 | type = ACCESS_WP; | |
251 | break; | |
252 | } | |
253 | } | |
f8c000a2 | 254 | if (oind >= argc) |
1b05df00 | 255 | error (_("-break-watch: Missing <expression>")); |
f8c000a2 | 256 | if (oind < argc - 1) |
1b05df00 | 257 | error (_("-break-watch: Garbage following <expression>")); |
f8c000a2 | 258 | expr = argv[oind]; |
fb40c209 | 259 | |
2b03b41d | 260 | /* Now we have what we need, let's insert the watchpoint! */ |
fb40c209 AC |
261 | switch (type) |
262 | { | |
263 | case REG_WP: | |
84f4c1fe | 264 | watch_command_wrapper (expr, FROM_TTY, 0); |
fb40c209 AC |
265 | break; |
266 | case READ_WP: | |
84f4c1fe | 267 | rwatch_command_wrapper (expr, FROM_TTY, 0); |
fb40c209 AC |
268 | break; |
269 | case ACCESS_WP: | |
84f4c1fe | 270 | awatch_command_wrapper (expr, FROM_TTY, 0); |
fb40c209 AC |
271 | break; |
272 | default: | |
1b05df00 | 273 | error (_("-break-watch: Unknown watchpoint type.")); |
fb40c209 | 274 | } |
fb40c209 | 275 | } |
48cb2d85 VP |
276 | |
277 | /* The mi_read_next_line consults these variable to return successive | |
278 | command lines. While it would be clearer to use a closure pointer, | |
279 | it is not expected that any future code will use read_command_lines_1, | |
280 | therefore no point of overengineering. */ | |
281 | ||
282 | static char **mi_command_line_array; | |
283 | static int mi_command_line_array_cnt; | |
284 | static int mi_command_line_array_ptr; | |
285 | ||
286 | static char * | |
a58d7472 | 287 | mi_read_next_line (void) |
48cb2d85 VP |
288 | { |
289 | if (mi_command_line_array_ptr == mi_command_line_array_cnt) | |
290 | return NULL; | |
291 | else | |
292 | return mi_command_line_array[mi_command_line_array_ptr++]; | |
293 | } | |
294 | ||
295 | void | |
296 | mi_cmd_break_commands (char *command, char **argv, int argc) | |
297 | { | |
298 | struct command_line *break_command; | |
299 | char *endptr; | |
300 | int bnum; | |
301 | struct breakpoint *b; | |
302 | ||
303 | if (argc < 1) | |
9b20d036 | 304 | error (_("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]"), command); |
48cb2d85 VP |
305 | |
306 | bnum = strtol (argv[0], &endptr, 0); | |
307 | if (endptr == argv[0]) | |
9b20d036 | 308 | error (_("breakpoint number argument \"%s\" is not a number."), |
48cb2d85 VP |
309 | argv[0]); |
310 | else if (*endptr != '\0') | |
9b20d036 | 311 | error (_("junk at the end of breakpoint number argument \"%s\"."), |
48cb2d85 VP |
312 | argv[0]); |
313 | ||
314 | b = get_breakpoint (bnum); | |
315 | if (b == NULL) | |
9b20d036 | 316 | error (_("breakpoint %d not found."), bnum); |
48cb2d85 VP |
317 | |
318 | mi_command_line_array = argv; | |
319 | mi_command_line_array_ptr = 1; | |
320 | mi_command_line_array_cnt = argc; | |
321 | ||
d77f58be | 322 | if (is_tracepoint (b)) |
a7bdde9e VP |
323 | break_command = read_command_lines_1 (mi_read_next_line, 1, |
324 | check_tracepoint_command, b); | |
325 | else | |
326 | break_command = read_command_lines_1 (mi_read_next_line, 1, 0, 0); | |
327 | ||
48cb2d85 VP |
328 | breakpoint_set_commands (b, break_command); |
329 | } | |
330 |