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/>. */
25 #include "breakpoint.h"
26 #include "gdb_string.h"
27 #include "mi-getopt.h"
29 #include "exceptions.h"
37 /* True if MI breakpoint observers have been registered. */
39 static int mi_breakpoint_observers_installed
;
41 /* Control whether breakpoint_notify may act. */
43 static int mi_can_breakpoint_notify
;
45 /* Output a single breakpoint, when allowed. */
48 breakpoint_notify (int b
)
50 if (mi_can_breakpoint_notify
)
51 gdb_breakpoint_query (uiout
, b
, NULL
);
61 /* Implements the -break-insert command.
62 See the MI manual for the list of possible options. */
65 mi_cmd_break_insert (char *command
, char **argv
, int argc
)
68 enum bp_type type
= REG_BP
;
72 char *condition
= NULL
;
74 struct gdb_exception e
;
75 struct gdb_events
*old_hooks
;
78 HARDWARE_OPT
, TEMP_OPT
/*, REGEXP_OPT */ , CONDITION_OPT
,
79 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
81 static struct mi_opt opts
[] =
83 {"h", HARDWARE_OPT
, 0},
85 {"c", CONDITION_OPT
, 1},
86 {"i", IGNORE_COUNT_OPT
, 1},
88 {"f", PENDING_OPT
, 0},
92 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
93 to denote the end of the option list. */
98 int opt
= mi_getopt ("mi_cmd_break_insert", argc
, argv
, opts
, &optind
, &optarg
);
101 switch ((enum opt
) opt
)
117 case IGNORE_COUNT_OPT
:
118 ignore_count
= atol (optarg
);
121 thread
= atol (optarg
);
130 error (_("mi_cmd_break_insert: Missing <location>"));
131 if (optind
< argc
- 1)
132 error (_("mi_cmd_break_insert: Garbage following <location>"));
133 address
= argv
[optind
];
135 /* Now we have what we need, let's insert the breakpoint! */
136 if (! mi_breakpoint_observers_installed
)
138 observer_attach_breakpoint_created (breakpoint_notify
);
139 observer_attach_breakpoint_modified (breakpoint_notify
);
140 observer_attach_breakpoint_deleted (breakpoint_notify
);
141 mi_breakpoint_observers_installed
= 1;
144 mi_can_breakpoint_notify
= 1;
145 /* Make sure we restore hooks even if exception is thrown. */
146 TRY_CATCH (e
, RETURN_MASK_ALL
)
151 set_breakpoint (address
, condition
,
152 0 /*hardwareflag */ , temp_p
,
153 thread
, ignore_count
,
157 set_breakpoint (address
, condition
,
158 1 /*hardwareflag */ , temp_p
,
159 thread
, ignore_count
,
165 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
167 rbreak_command_wrapper (address
, FROM_TTY
);
171 internal_error (__FILE__
, __LINE__
,
172 _("mi_cmd_break_insert: Bad switch."));
175 mi_can_breakpoint_notify
= 0;
187 /* Insert a watchpoint. The type of watchpoint is specified by the
189 -break-watch <expr> --> insert a regular wp.
190 -break-watch -r <expr> --> insert a read watchpoint.
191 -break-watch -a <expr> --> insert an access wp. */
194 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
197 enum wp_type type
= REG_WP
;
202 static struct mi_opt opts
[] =
205 {"a", ACCESS_OPT
, 0},
209 /* Parse arguments. */
214 int opt
= mi_getopt ("mi_cmd_break_watch", argc
, argv
, opts
, &optind
, &optarg
);
217 switch ((enum opt
) opt
)
228 error (_("mi_cmd_break_watch: Missing <expression>"));
229 if (optind
< argc
- 1)
230 error (_("mi_cmd_break_watch: Garbage following <expression>"));
233 /* Now we have what we need, let's insert the watchpoint! */
237 watch_command_wrapper (expr
, FROM_TTY
);
240 rwatch_command_wrapper (expr
, FROM_TTY
);
243 awatch_command_wrapper (expr
, FROM_TTY
);
246 error (_("mi_cmd_break_watch: Unknown watchpoint type."));