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
;
76 struct gdb_exception e
;
77 struct gdb_events
*old_hooks
;
80 HARDWARE_OPT
, TEMP_OPT
/*, REGEXP_OPT */ , CONDITION_OPT
,
81 IGNORE_COUNT_OPT
, THREAD_OPT
, PENDING_OPT
, DISABLE_OPT
83 static struct mi_opt opts
[] =
85 {"h", HARDWARE_OPT
, 0},
87 {"c", CONDITION_OPT
, 1},
88 {"i", IGNORE_COUNT_OPT
, 1},
90 {"f", PENDING_OPT
, 0},
91 {"d", DISABLE_OPT
, 0},
95 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
96 to denote the end of the option list. */
101 int opt
= mi_getopt ("mi_cmd_break_insert", argc
, argv
, opts
, &optind
, &optarg
);
104 switch ((enum opt
) opt
)
120 case IGNORE_COUNT_OPT
:
121 ignore_count
= atol (optarg
);
124 thread
= atol (optarg
);
135 error (_("mi_cmd_break_insert: Missing <location>"));
136 if (optind
< argc
- 1)
137 error (_("mi_cmd_break_insert: Garbage following <location>"));
138 address
= argv
[optind
];
140 /* Now we have what we need, let's insert the breakpoint! */
141 if (! mi_breakpoint_observers_installed
)
143 observer_attach_breakpoint_created (breakpoint_notify
);
144 observer_attach_breakpoint_modified (breakpoint_notify
);
145 observer_attach_breakpoint_deleted (breakpoint_notify
);
146 mi_breakpoint_observers_installed
= 1;
149 mi_can_breakpoint_notify
= 1;
150 /* Make sure we restore hooks even if exception is thrown. */
151 TRY_CATCH (e
, RETURN_MASK_ALL
)
156 set_breakpoint (address
, condition
,
157 0 /*hardwareflag */ , temp_p
,
158 thread
, ignore_count
,
162 set_breakpoint (address
, condition
,
163 1 /*hardwareflag */ , temp_p
,
164 thread
, ignore_count
,
170 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
172 rbreak_command_wrapper (address
, FROM_TTY
);
176 internal_error (__FILE__
, __LINE__
,
177 _("mi_cmd_break_insert: Bad switch."));
180 mi_can_breakpoint_notify
= 0;
192 /* Insert a watchpoint. The type of watchpoint is specified by the
194 -break-watch <expr> --> insert a regular wp.
195 -break-watch -r <expr> --> insert a read watchpoint.
196 -break-watch -a <expr> --> insert an access wp. */
199 mi_cmd_break_watch (char *command
, char **argv
, int argc
)
202 enum wp_type type
= REG_WP
;
207 static struct mi_opt opts
[] =
210 {"a", ACCESS_OPT
, 0},
214 /* Parse arguments. */
219 int opt
= mi_getopt ("mi_cmd_break_watch", argc
, argv
, opts
, &optind
, &optarg
);
222 switch ((enum opt
) opt
)
233 error (_("mi_cmd_break_watch: Missing <expression>"));
234 if (optind
< argc
- 1)
235 error (_("mi_cmd_break_watch: Garbage following <expression>"));
238 /* Now we have what we need, let's insert the watchpoint! */
242 watch_command_wrapper (expr
, FROM_TTY
);
245 rwatch_command_wrapper (expr
, FROM_TTY
);
248 awatch_command_wrapper (expr
, FROM_TTY
);
251 error (_("mi_cmd_break_watch: Unknown watchpoint type."));