1 /* MI Command Set - breakpoint and watchpoint commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010
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
)
69 enum bp_type type
= REG_BP
;
74 char *condition
= NULL
;
77 struct cleanup
*back_to
;
79 struct gdb_exception e
;
80 struct gdb_events
*old_hooks
;
83 HARDWARE_OPT
, TEMP_OPT
, CONDITION_OPT
,
84 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},
98 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
99 to denote the end of the option list. */
104 int opt
= mi_getopt ("mi_cmd_break_insert", argc
, argv
, opts
, &optind
, &optarg
);
107 switch ((enum opt
) opt
)
118 case IGNORE_COUNT_OPT
:
119 ignore_count
= atol (optarg
);
122 thread
= atol (optarg
);
133 error (_("mi_cmd_break_insert: Missing <location>"));
134 if (optind
< argc
- 1)
135 error (_("mi_cmd_break_insert: Garbage following <location>"));
136 address
= argv
[optind
];
138 /* Now we have what we need, let's insert the breakpoint! */
139 if (! mi_breakpoint_observers_installed
)
141 observer_attach_breakpoint_created (breakpoint_notify
);
142 observer_attach_breakpoint_modified (breakpoint_notify
);
143 observer_attach_breakpoint_deleted (breakpoint_notify
);
144 mi_breakpoint_observers_installed
= 1;
147 back_to
= make_cleanup_restore_integer (&mi_can_breakpoint_notify
);
148 mi_can_breakpoint_notify
= 1;
149 create_breakpoint (get_current_arch (), address
, condition
, thread
,
150 0 /* condition and thread are valid. */,
151 temp_p
, hardware
, 0 /* traceflag */,
153 pending
? AUTO_BOOLEAN_TRUE
: AUTO_BOOLEAN_FALSE
,
155 do_cleanups (back_to
);
166 /* Insert a watchpoint. The type of watchpoint is specified by the
168 -break-watch <expr> --> insert a regular wp.
169 -break-watch -r <expr> --> insert a read watchpoint.
170 -break-watch -a <expr> --> insert an access wp. */
173 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
176 enum wp_type type
= REG_WP
;
181 static struct mi_opt opts
[] =
184 {"a", ACCESS_OPT
, 0},
188 /* Parse arguments. */
193 int opt
= mi_getopt ("mi_cmd_break_watch", argc
, argv
, opts
, &optind
, &optarg
);
196 switch ((enum opt
) opt
)
207 error (_("mi_cmd_break_watch: Missing <expression>"));
208 if (optind
< argc
- 1)
209 error (_("mi_cmd_break_watch: Garbage following <expression>"));
212 /* Now we have what we need, let's insert the watchpoint! */
216 watch_command_wrapper (expr
, FROM_TTY
);
219 rwatch_command_wrapper (expr
, FROM_TTY
);
222 awatch_command_wrapper (expr
, FROM_TTY
);
225 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
229 /* The mi_read_next_line consults these variable to return successive
230 command lines. While it would be clearer to use a closure pointer,
231 it is not expected that any future code will use read_command_lines_1,
232 therefore no point of overengineering. */
234 static char **mi_command_line_array
;
235 static int mi_command_line_array_cnt
;
236 static int mi_command_line_array_ptr
;
239 mi_read_next_line (void)
241 if (mi_command_line_array_ptr
== mi_command_line_array_cnt
)
244 return mi_command_line_array
[mi_command_line_array_ptr
++];
248 mi_cmd_break_commands (char *command
, char **argv
, int argc
)
250 struct command_line
*break_command
;
253 struct breakpoint
*b
;
256 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command
);
258 bnum
= strtol (argv
[0], &endptr
, 0);
259 if (endptr
== argv
[0])
260 error ("breakpoint number argument \"%s\" is not a number.",
262 else if (*endptr
!= '\0')
263 error ("junk at the end of breakpoint number argument \"%s\".",
266 b
= get_breakpoint (bnum
);
268 error ("breakpoint %d not found.", bnum
);
270 mi_command_line_array
= argv
;
271 mi_command_line_array_ptr
= 1;
272 mi_command_line_array_cnt
= argc
;
274 if (breakpoint_is_tracepoint (b
))
275 break_command
= read_command_lines_1 (mi_read_next_line
, 1,
276 check_tracepoint_command
, b
);
278 break_command
= read_command_lines_1 (mi_read_next_line
, 1, 0, 0);
280 breakpoint_set_commands (b
, break_command
);