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
;
82 HARDWARE_OPT
, TEMP_OPT
, CONDITION_OPT
,
83 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
, DISABLE_OPT
,
86 static const 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
,
110 switch ((enum opt
) opt
)
121 case IGNORE_COUNT_OPT
:
122 ignore_count
= atol (oarg
);
125 thread
= atol (oarg
);
140 error (_("-break-insert: Missing <location>"));
142 error (_("-break-insert: Garbage following <location>"));
143 address
= argv
[oind
];
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 mi_breakpoint_observers_installed
= 1;
152 back_to
= make_cleanup_restore_integer (&mi_can_breakpoint_notify
);
153 mi_can_breakpoint_notify
= 1;
155 /* Note that to request a fast tracepoint, the client uses the
156 "hardware" flag, although there's nothing of hardware related to
157 fast tracepoints -- one can implement slow tracepoints with
158 hardware breakpoints, but fast tracepoints are always software.
159 "fast" is a misnomer, actually, "jump" would be more appropriate.
160 A simulator or an emulator could conceivably implement fast
161 regular non-jump based tracepoints. */
162 type_wanted
= (tracepoint
163 ? (hardware
? bp_fast_tracepoint
: bp_tracepoint
)
164 : (hardware
? bp_hardware_breakpoint
: bp_breakpoint
));
166 create_breakpoint (get_current_arch (), address
, condition
, thread
,
167 0 /* condition and thread are valid. */,
170 pending
? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
171 &bkpt_breakpoint_ops
, 0, enabled
, 0, 0);
172 do_cleanups (back_to
);
184 mi_cmd_break_passcount (char *command
, char **argv
, int argc
)
188 struct tracepoint
*t
;
191 error (_("Usage: tracepoint-number passcount"));
195 t
= get_tracepoint (n
);
200 observer_notify_tracepoint_modified (n
);
204 error (_("Could not find tracepoint %d"), n
);
208 /* Insert a watchpoint. The type of watchpoint is specified by the
210 -break-watch <expr> --> insert a regular wp.
211 -break-watch -r <expr> --> insert a read watchpoint.
212 -break-watch -a <expr> --> insert an access wp. */
215 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
218 enum wp_type type
= REG_WP
;
223 static const struct mi_opt opts
[] =
226 {"a", ACCESS_OPT
, 0},
230 /* Parse arguments. */
236 int opt
= mi_getopt ("-break-watch", argc
, argv
,
241 switch ((enum opt
) opt
)
252 error (_("-break-watch: Missing <expression>"));
254 error (_("-break-watch: Garbage following <expression>"));
257 /* Now we have what we need, let's insert the watchpoint! */
261 watch_command_wrapper (expr
, FROM_TTY
, 0);
264 rwatch_command_wrapper (expr
, FROM_TTY
, 0);
267 awatch_command_wrapper (expr
, FROM_TTY
, 0);
270 error (_("-break-watch: Unknown watchpoint type."));
274 /* The mi_read_next_line consults these variable to return successive
275 command lines. While it would be clearer to use a closure pointer,
276 it is not expected that any future code will use read_command_lines_1,
277 therefore no point of overengineering. */
279 static char **mi_command_line_array
;
280 static int mi_command_line_array_cnt
;
281 static int mi_command_line_array_ptr
;
284 mi_read_next_line (void)
286 if (mi_command_line_array_ptr
== mi_command_line_array_cnt
)
289 return mi_command_line_array
[mi_command_line_array_ptr
++];
293 mi_cmd_break_commands (char *command
, char **argv
, int argc
)
295 struct command_line
*break_command
;
298 struct breakpoint
*b
;
301 error (_("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]"), command
);
303 bnum
= strtol (argv
[0], &endptr
, 0);
304 if (endptr
== argv
[0])
305 error (_("breakpoint number argument \"%s\" is not a number."),
307 else if (*endptr
!= '\0')
308 error (_("junk at the end of breakpoint number argument \"%s\"."),
311 b
= get_breakpoint (bnum
);
313 error (_("breakpoint %d not found."), bnum
);
315 mi_command_line_array
= argv
;
316 mi_command_line_array_ptr
= 1;
317 mi_command_line_array_cnt
= argc
;
319 if (is_tracepoint (b
))
320 break_command
= read_command_lines_1 (mi_read_next_line
, 1,
321 check_tracepoint_command
, b
);
323 break_command
= read_command_lines_1 (mi_read_next_line
, 1, 0, 0);
325 breakpoint_set_commands (b
, break_command
);