1 /* MI Command Set - breakpoint and watchpoint commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Solutions (a Red Hat company).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "arch-utils.h"
26 #include "breakpoint.h"
27 #include "gdb_string.h"
28 #include "mi-getopt.h"
30 #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 (int b)
51 if (mi_can_breakpoint_notify)
52 gdb_breakpoint_query (uiout, b, 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;
82 HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
83 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT,
86 static struct mi_opt opts[] =
88 {"h", HARDWARE_OPT, 0},
90 {"c", CONDITION_OPT, 1},
91 {"i", IGNORE_COUNT_OPT, 1},
93 {"f", PENDING_OPT, 0},
94 {"d", DISABLE_OPT, 0},
95 {"a", TRACEPOINT_OPT, 0},
99 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
100 to denote the end of the option list. */
106 int opt = mi_getopt ("-break-insert", argc, argv,
107 opts, &optind, &optarg);
110 switch ((enum opt) opt)
121 case IGNORE_COUNT_OPT:
122 ignore_count = atol (optarg);
125 thread = atol (optarg);
140 error (_("-break-insert: Missing <location>"));
141 if (optind < argc - 1)
142 error (_("-break-insert: Garbage following <location>"));
143 address = argv[optind];
145 /* Now we have what we need, let's insert the breakpoint! */
146 if (! mi_breakpoint_observers_installed)
148 observer_attach_breakpoint_created (breakpoint_notify);
149 observer_attach_breakpoint_modified (breakpoint_notify);
150 observer_attach_breakpoint_deleted (breakpoint_notify);
151 mi_breakpoint_observers_installed = 1;
154 back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
155 mi_can_breakpoint_notify = 1;
157 /* Note that to request a fast tracepoint, the client uses the
158 "hardware" flag, although there's nothing of hardware related to
159 fast tracepoints -- one can implement slow tracepoints with
160 hardware breakpoints, but fast tracepoints are always software.
161 "fast" is a misnomer, actually, "jump" would be more appropriate.
162 A simulator or an emulator could conceivably implement fast
163 regular non-jump based tracepoints. */
164 type_wanted = (tracepoint
165 ? (hardware ? bp_fast_tracepoint : bp_tracepoint)
166 : (hardware ? bp_hardware_breakpoint : bp_breakpoint));
168 create_breakpoint (get_current_arch (), address, condition, thread,
169 0 /* condition and thread are valid. */,
172 pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
173 NULL, 0, enabled, 0);
174 do_cleanups (back_to);
186 mi_cmd_break_passcount (char *command, char **argv, int argc)
190 struct breakpoint *t;
193 error (_("Usage: tracepoint-number passcount"));
197 t = get_tracepoint (n);
202 observer_notify_tracepoint_modified (n);
206 error (_("Cound not find tracepoint %d"), n);
210 /* Insert a watchpoint. The type of watchpoint is specified by the
212 -break-watch <expr> --> insert a regular wp.
213 -break-watch -r <expr> --> insert a read watchpoint.
214 -break-watch -a <expr> --> insert an access wp. */
217 mi_cmd_break_watch (char *command, char **argv, int argc)
220 enum wp_type type = REG_WP;
225 static struct mi_opt opts[] =
228 {"a", ACCESS_OPT, 0},
232 /* Parse arguments. */
238 int opt = mi_getopt ("-break-watch", argc, argv,
239 opts, &optind, &optarg);
243 switch ((enum opt) opt)
254 error (_("-break-watch: Missing <expression>"));
255 if (optind < argc - 1)
256 error (_("-break-watch: Garbage following <expression>"));
259 /* Now we have what we need, let's insert the watchpoint! */
263 watch_command_wrapper (expr, FROM_TTY, 0);
266 rwatch_command_wrapper (expr, FROM_TTY, 0);
269 awatch_command_wrapper (expr, FROM_TTY, 0);
272 error (_("-break-watch: Unknown watchpoint type."));
276 /* The mi_read_next_line consults these variable to return successive
277 command lines. While it would be clearer to use a closure pointer,
278 it is not expected that any future code will use read_command_lines_1,
279 therefore no point of overengineering. */
281 static char **mi_command_line_array;
282 static int mi_command_line_array_cnt;
283 static int mi_command_line_array_ptr;
286 mi_read_next_line (void)
288 if (mi_command_line_array_ptr == mi_command_line_array_cnt)
291 return mi_command_line_array[mi_command_line_array_ptr++];
295 mi_cmd_break_commands (char *command, char **argv, int argc)
297 struct command_line *break_command;
300 struct breakpoint *b;
303 error (_("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]"), command);
305 bnum = strtol (argv[0], &endptr, 0);
306 if (endptr == argv[0])
307 error (_("breakpoint number argument \"%s\" is not a number."),
309 else if (*endptr != '\0')
310 error (_("junk at the end of breakpoint number argument \"%s\"."),
313 b = get_breakpoint (bnum);
315 error (_("breakpoint %d not found."), bnum);
317 mi_command_line_array = argv;
318 mi_command_line_array_ptr = 1;
319 mi_command_line_array_cnt = argc;
321 if (is_tracepoint (b))
322 break_command = read_command_lines_1 (mi_read_next_line, 1,
323 check_tracepoint_command, b);
325 break_command = read_command_lines_1 (mi_read_next_line, 1, 0, 0);
327 breakpoint_set_commands (b, break_command);