1 /* MI Command Set - breakpoint and watchpoint commands.
2 Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "arch-utils.h"
25 #include "breakpoint.h"
26 #include "gdb_string.h"
27 #include "mi-getopt.h"
29 #include "exceptions.h"
38 /* True if MI breakpoint observers have been registered. */
40 static int mi_breakpoint_observers_installed
;
42 /* Control whether breakpoint_notify may act. */
44 static int mi_can_breakpoint_notify
;
46 /* Output a single breakpoint, when allowed. */
49 breakpoint_notify (struct breakpoint
*b
)
51 if (mi_can_breakpoint_notify
)
52 gdb_breakpoint_query (current_uiout
, b
->number
, NULL
);
62 /* Implements the -break-insert command.
63 See the MI manual for the list of possible options. */
66 mi_cmd_break_insert (char *command
, char **argv
, int argc
)
73 char *condition
= NULL
;
77 struct cleanup
*back_to
;
78 enum bptype type_wanted
;
79 struct breakpoint_ops
*ops
;
83 HARDWARE_OPT
, TEMP_OPT
, CONDITION_OPT
,
84 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
, DISABLE_OPT
,
87 static const struct mi_opt opts
[] =
89 {"h", HARDWARE_OPT
, 0},
91 {"c", CONDITION_OPT
, 1},
92 {"i", IGNORE_COUNT_OPT
, 1},
94 {"f", PENDING_OPT
, 0},
95 {"d", DISABLE_OPT
, 0},
96 {"a", TRACEPOINT_OPT
, 0},
100 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
101 to denote the end of the option list. */
107 int opt
= mi_getopt ("-break-insert", argc
, argv
,
111 switch ((enum opt
) opt
)
122 case IGNORE_COUNT_OPT
:
123 ignore_count
= atol (oarg
);
126 thread
= atol (oarg
);
141 error (_("-break-insert: Missing <location>"));
143 error (_("-break-insert: Garbage following <location>"));
144 address
= argv
[oind
];
146 /* Now we have what we need, let's insert the breakpoint! */
147 if (! mi_breakpoint_observers_installed
)
149 observer_attach_breakpoint_created (breakpoint_notify
);
150 mi_breakpoint_observers_installed
= 1;
153 back_to
= make_cleanup_restore_integer (&mi_can_breakpoint_notify
);
154 mi_can_breakpoint_notify
= 1;
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
));
166 ops
= tracepoint
? &tracepoint_breakpoint_ops
: &bkpt_breakpoint_ops
;
168 create_breakpoint (get_current_arch (), address
, condition
, thread
,
170 0 /* condition and thread are valid. */,
173 pending
? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
174 ops
, 0, enabled
, 0, 0);
175 do_cleanups (back_to
);
187 mi_cmd_break_passcount (char *command
, char **argv
, int argc
)
191 struct tracepoint
*t
;
194 error (_("Usage: tracepoint-number passcount"));
198 t
= get_tracepoint (n
);
203 observer_notify_tracepoint_modified (n
);
207 error (_("Could not find tracepoint %d"), n
);
211 /* Insert a watchpoint. The type of watchpoint is specified by the
213 -break-watch <expr> --> insert a regular wp.
214 -break-watch -r <expr> --> insert a read watchpoint.
215 -break-watch -a <expr> --> insert an access wp. */
218 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
221 enum wp_type type
= REG_WP
;
226 static const struct mi_opt opts
[] =
229 {"a", ACCESS_OPT
, 0},
233 /* Parse arguments. */
239 int opt
= mi_getopt ("-break-watch", argc
, argv
,
244 switch ((enum opt
) opt
)
255 error (_("-break-watch: Missing <expression>"));
257 error (_("-break-watch: Garbage following <expression>"));
260 /* Now we have what we need, let's insert the watchpoint! */
264 watch_command_wrapper (expr
, FROM_TTY
, 0);
267 rwatch_command_wrapper (expr
, FROM_TTY
, 0);
270 awatch_command_wrapper (expr
, FROM_TTY
, 0);
273 error (_("-break-watch: Unknown watchpoint type."));
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. */
282 static char **mi_command_line_array
;
283 static int mi_command_line_array_cnt
;
284 static int mi_command_line_array_ptr
;
287 mi_read_next_line (void)
289 if (mi_command_line_array_ptr
== mi_command_line_array_cnt
)
292 return mi_command_line_array
[mi_command_line_array_ptr
++];
296 mi_cmd_break_commands (char *command
, char **argv
, int argc
)
298 struct command_line
*break_command
;
301 struct breakpoint
*b
;
304 error (_("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]"), command
);
306 bnum
= strtol (argv
[0], &endptr
, 0);
307 if (endptr
== argv
[0])
308 error (_("breakpoint number argument \"%s\" is not a number."),
310 else if (*endptr
!= '\0')
311 error (_("junk at the end of breakpoint number argument \"%s\"."),
314 b
= get_breakpoint (bnum
);
316 error (_("breakpoint %d not found."), bnum
);
318 mi_command_line_array
= argv
;
319 mi_command_line_array_ptr
= 1;
320 mi_command_line_array_cnt
= argc
;
322 if (is_tracepoint (b
))
323 break_command
= read_command_lines_1 (mi_read_next_line
, 1,
324 check_tracepoint_command
, b
);
326 break_command
= read_command_lines_1 (mi_read_next_line
, 1, 0, 0);
328 breakpoint_set_commands (b
, break_command
);