Include frame information for *stopped due to CLI commands.
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-break.c
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).
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21 #include "defs.h"
22 #include "mi-cmds.h"
23 #include "ui-out.h"
24 #include "mi-out.h"
25 #include "breakpoint.h"
26 #include "gdb_string.h"
27 #include "mi-getopt.h"
28 #include "gdb.h"
29 #include "exceptions.h"
30 #include "observer.h"
31
32 enum
33 {
34 FROM_TTY = 0
35 };
36
37 /* True if MI breakpoint observers have been registered. */
38
39 static int mi_breakpoint_observers_installed;
40
41 /* Control whether breakpoint_notify may act. */
42
43 static int mi_can_breakpoint_notify;
44
45 /* Output a single breakpoint, when allowed. */
46
47 static void
48 breakpoint_notify (int b)
49 {
50 if (mi_can_breakpoint_notify)
51 gdb_breakpoint_query (uiout, b, NULL);
52 }
53
54 enum bp_type
55 {
56 REG_BP,
57 HW_BP,
58 REGEXP_BP
59 };
60
61 /* Implements the -break-insert command.
62 See the MI manual for the list of possible options. */
63
64 void
65 mi_cmd_break_insert (char *command, char **argv, int argc)
66 {
67 char *address = NULL;
68 enum bp_type type = REG_BP;
69 int temp_p = 0;
70 int thread = -1;
71 int ignore_count = 0;
72 char *condition = NULL;
73 int pending = 0;
74 int enabled = 1;
75
76 struct gdb_exception e;
77 struct gdb_events *old_hooks;
78 enum opt
79 {
80 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
81 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT
82 };
83 static struct mi_opt opts[] =
84 {
85 {"h", HARDWARE_OPT, 0},
86 {"t", TEMP_OPT, 0},
87 {"c", CONDITION_OPT, 1},
88 {"i", IGNORE_COUNT_OPT, 1},
89 {"p", THREAD_OPT, 1},
90 {"f", PENDING_OPT, 0},
91 {"d", DISABLE_OPT, 0},
92 { 0, 0, 0 }
93 };
94
95 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
96 to denote the end of the option list. */
97 int optind = 0;
98 char *optarg;
99 while (1)
100 {
101 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
102 if (opt < 0)
103 break;
104 switch ((enum opt) opt)
105 {
106 case TEMP_OPT:
107 temp_p = 1;
108 break;
109 case HARDWARE_OPT:
110 type = HW_BP;
111 break;
112 #if 0
113 case REGEXP_OPT:
114 type = REGEXP_BP;
115 break;
116 #endif
117 case CONDITION_OPT:
118 condition = optarg;
119 break;
120 case IGNORE_COUNT_OPT:
121 ignore_count = atol (optarg);
122 break;
123 case THREAD_OPT:
124 thread = atol (optarg);
125 break;
126 case PENDING_OPT:
127 pending = 1;
128 break;
129 case DISABLE_OPT:
130 enabled = 0;
131 }
132 }
133
134 if (optind >= argc)
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];
139
140 /* Now we have what we need, let's insert the breakpoint! */
141 if (! mi_breakpoint_observers_installed)
142 {
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;
147 }
148
149 mi_can_breakpoint_notify = 1;
150 /* Make sure we restore hooks even if exception is thrown. */
151 TRY_CATCH (e, RETURN_MASK_ALL)
152 {
153 switch (type)
154 {
155 case REG_BP:
156 set_breakpoint (address, condition,
157 0 /*hardwareflag */ , temp_p,
158 thread, ignore_count,
159 pending, enabled);
160 break;
161 case HW_BP:
162 set_breakpoint (address, condition,
163 1 /*hardwareflag */ , temp_p,
164 thread, ignore_count,
165 pending, enabled);
166 break;
167 #if 0
168 case REGEXP_BP:
169 if (temp_p)
170 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
171 else
172 rbreak_command_wrapper (address, FROM_TTY);
173 break;
174 #endif
175 default:
176 internal_error (__FILE__, __LINE__,
177 _("mi_cmd_break_insert: Bad switch."));
178 }
179 }
180 mi_can_breakpoint_notify = 0;
181 if (e.reason < 0)
182 throw_exception (e);
183 }
184
185 enum wp_type
186 {
187 REG_WP,
188 READ_WP,
189 ACCESS_WP
190 };
191
192 /* Insert a watchpoint. The type of watchpoint is specified by the
193 first argument:
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. */
197
198 void
199 mi_cmd_break_watch (char *command, char **argv, int argc)
200 {
201 char *expr = NULL;
202 enum wp_type type = REG_WP;
203 enum opt
204 {
205 READ_OPT, ACCESS_OPT
206 };
207 static struct mi_opt opts[] =
208 {
209 {"r", READ_OPT, 0},
210 {"a", ACCESS_OPT, 0},
211 { 0, 0, 0 }
212 };
213
214 /* Parse arguments. */
215 int optind = 0;
216 char *optarg;
217 while (1)
218 {
219 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
220 if (opt < 0)
221 break;
222 switch ((enum opt) opt)
223 {
224 case READ_OPT:
225 type = READ_WP;
226 break;
227 case ACCESS_OPT:
228 type = ACCESS_WP;
229 break;
230 }
231 }
232 if (optind >= argc)
233 error (_("mi_cmd_break_watch: Missing <expression>"));
234 if (optind < argc - 1)
235 error (_("mi_cmd_break_watch: Garbage following <expression>"));
236 expr = argv[optind];
237
238 /* Now we have what we need, let's insert the watchpoint! */
239 switch (type)
240 {
241 case REG_WP:
242 watch_command_wrapper (expr, FROM_TTY);
243 break;
244 case READ_WP:
245 rwatch_command_wrapper (expr, FROM_TTY);
246 break;
247 case ACCESS_WP:
248 awatch_command_wrapper (expr, FROM_TTY);
249 break;
250 default:
251 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
252 }
253 }
This page took 0.03421 seconds and 4 git commands to generate.