1 /* MI Command Set - breakpoint and watchpoint commands.
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009
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
;
73 char *condition
= NULL
;
77 struct gdb_exception e
;
78 struct gdb_events
*old_hooks
;
81 HARDWARE_OPT
, TEMP_OPT
/*, REGEXP_OPT */ , CONDITION_OPT
,
82 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
, DISABLE_OPT
84 static struct mi_opt opts
[] =
86 {"h", HARDWARE_OPT
, 0},
88 {"c", CONDITION_OPT
, 1},
89 {"i", IGNORE_COUNT_OPT
, 1},
91 {"f", PENDING_OPT
, 0},
92 {"d", DISABLE_OPT
, 0},
96 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
97 to denote the end of the option list. */
102 int opt
= mi_getopt ("mi_cmd_break_insert", argc
, argv
, opts
, &optind
, &optarg
);
105 switch ((enum opt
) opt
)
121 case IGNORE_COUNT_OPT
:
122 ignore_count
= atol (optarg
);
125 thread
= atol (optarg
);
136 error (_("mi_cmd_break_insert: Missing <location>"));
137 if (optind
< argc
- 1)
138 error (_("mi_cmd_break_insert: Garbage following <location>"));
139 address
= argv
[optind
];
141 /* Now we have what we need, let's insert the breakpoint! */
142 if (! mi_breakpoint_observers_installed
)
144 observer_attach_breakpoint_created (breakpoint_notify
);
145 observer_attach_breakpoint_modified (breakpoint_notify
);
146 observer_attach_breakpoint_deleted (breakpoint_notify
);
147 mi_breakpoint_observers_installed
= 1;
150 mi_can_breakpoint_notify
= 1;
151 /* Make sure we restore hooks even if exception is thrown. */
152 TRY_CATCH (e
, RETURN_MASK_ALL
)
157 set_breakpoint (get_current_arch (), address
, condition
,
158 0 /*hardwareflag */ , temp_p
,
159 thread
, ignore_count
,
163 set_breakpoint (get_current_arch (), address
, condition
,
164 1 /*hardwareflag */ , temp_p
,
165 thread
, ignore_count
,
171 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
173 rbreak_command_wrapper (address
, FROM_TTY
);
177 internal_error (__FILE__
, __LINE__
,
178 _("mi_cmd_break_insert: Bad switch."));
181 mi_can_breakpoint_notify
= 0;
193 /* Insert a watchpoint. The type of watchpoint is specified by the
195 -break-watch <expr> --> insert a regular wp.
196 -break-watch -r <expr> --> insert a read watchpoint.
197 -break-watch -a <expr> --> insert an access wp. */
200 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
203 enum wp_type type
= REG_WP
;
208 static struct mi_opt opts
[] =
211 {"a", ACCESS_OPT
, 0},
215 /* Parse arguments. */
220 int opt
= mi_getopt ("mi_cmd_break_watch", argc
, argv
, opts
, &optind
, &optarg
);
223 switch ((enum opt
) opt
)
234 error (_("mi_cmd_break_watch: Missing <expression>"));
235 if (optind
< argc
- 1)
236 error (_("mi_cmd_break_watch: Garbage following <expression>"));
239 /* Now we have what we need, let's insert the watchpoint! */
243 watch_command_wrapper (expr
, FROM_TTY
);
246 rwatch_command_wrapper (expr
, FROM_TTY
);
249 awatch_command_wrapper (expr
, FROM_TTY
);
252 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
256 /* The mi_read_next_line consults these variable to return successive
257 command lines. While it would be clearer to use a closure pointer,
258 it is not expected that any future code will use read_command_lines_1,
259 therefore no point of overengineering. */
261 static char **mi_command_line_array
;
262 static int mi_command_line_array_cnt
;
263 static int mi_command_line_array_ptr
;
268 if (mi_command_line_array_ptr
== mi_command_line_array_cnt
)
271 return mi_command_line_array
[mi_command_line_array_ptr
++];
275 mi_cmd_break_commands (char *command
, char **argv
, int argc
)
277 struct command_line
*break_command
;
280 struct breakpoint
*b
;
283 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command
);
285 bnum
= strtol (argv
[0], &endptr
, 0);
286 if (endptr
== argv
[0])
287 error ("breakpoint number argument \"%s\" is not a number.",
289 else if (*endptr
!= '\0')
290 error ("junk at the end of breakpoint number argument \"%s\".",
293 b
= get_breakpoint (bnum
);
295 error ("breakpoint %d not found.", bnum
);
297 mi_command_line_array
= argv
;
298 mi_command_line_array_ptr
= 1;
299 mi_command_line_array_cnt
= argc
;
301 break_command
= read_command_lines_1 (mi_read_next_line
, 1);
302 breakpoint_set_commands (b
, break_command
);