* infrun.c (normal_stop): Don't call
[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 struct gdb_exception e;
75 struct gdb_events *old_hooks;
76 enum opt
77 {
78 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
79 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT
80 };
81 static struct mi_opt opts[] =
82 {
83 {"h", HARDWARE_OPT, 0},
84 {"t", TEMP_OPT, 0},
85 {"c", CONDITION_OPT, 1},
86 {"i", IGNORE_COUNT_OPT, 1},
87 {"p", THREAD_OPT, 1},
88 {"f", PENDING_OPT, 0},
89 { 0, 0, 0 }
90 };
91
92 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
93 to denote the end of the option list. */
94 int optind = 0;
95 char *optarg;
96 while (1)
97 {
98 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
99 if (opt < 0)
100 break;
101 switch ((enum opt) opt)
102 {
103 case TEMP_OPT:
104 temp_p = 1;
105 break;
106 case HARDWARE_OPT:
107 type = HW_BP;
108 break;
109 #if 0
110 case REGEXP_OPT:
111 type = REGEXP_BP;
112 break;
113 #endif
114 case CONDITION_OPT:
115 condition = optarg;
116 break;
117 case IGNORE_COUNT_OPT:
118 ignore_count = atol (optarg);
119 break;
120 case THREAD_OPT:
121 thread = atol (optarg);
122 break;
123 case PENDING_OPT:
124 pending = 1;
125 break;
126 }
127 }
128
129 if (optind >= argc)
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];
134
135 /* Now we have what we need, let's insert the breakpoint! */
136 if (! mi_breakpoint_observers_installed)
137 {
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;
142 }
143
144 mi_can_breakpoint_notify = 1;
145 /* Make sure we restore hooks even if exception is thrown. */
146 TRY_CATCH (e, RETURN_MASK_ALL)
147 {
148 switch (type)
149 {
150 case REG_BP:
151 set_breakpoint (address, condition,
152 0 /*hardwareflag */ , temp_p,
153 thread, ignore_count,
154 pending);
155 break;
156 case HW_BP:
157 set_breakpoint (address, condition,
158 1 /*hardwareflag */ , temp_p,
159 thread, ignore_count,
160 pending);
161 break;
162 #if 0
163 case REGEXP_BP:
164 if (temp_p)
165 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
166 else
167 rbreak_command_wrapper (address, FROM_TTY);
168 break;
169 #endif
170 default:
171 internal_error (__FILE__, __LINE__,
172 _("mi_cmd_break_insert: Bad switch."));
173 }
174 }
175 mi_can_breakpoint_notify = 0;
176 if (e.reason < 0)
177 throw_exception (e);
178 }
179
180 enum wp_type
181 {
182 REG_WP,
183 READ_WP,
184 ACCESS_WP
185 };
186
187 /* Insert a watchpoint. The type of watchpoint is specified by the
188 first argument:
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. */
192
193 void
194 mi_cmd_break_watch (char *command, char **argv, int argc)
195 {
196 char *expr = NULL;
197 enum wp_type type = REG_WP;
198 enum opt
199 {
200 READ_OPT, ACCESS_OPT
201 };
202 static struct mi_opt opts[] =
203 {
204 {"r", READ_OPT, 0},
205 {"a", ACCESS_OPT, 0},
206 { 0, 0, 0 }
207 };
208
209 /* Parse arguments. */
210 int optind = 0;
211 char *optarg;
212 while (1)
213 {
214 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
215 if (opt < 0)
216 break;
217 switch ((enum opt) opt)
218 {
219 case READ_OPT:
220 type = READ_WP;
221 break;
222 case ACCESS_OPT:
223 type = ACCESS_WP;
224 break;
225 }
226 }
227 if (optind >= argc)
228 error (_("mi_cmd_break_watch: Missing <expression>"));
229 if (optind < argc - 1)
230 error (_("mi_cmd_break_watch: Garbage following <expression>"));
231 expr = argv[optind];
232
233 /* Now we have what we need, let's insert the watchpoint! */
234 switch (type)
235 {
236 case REG_WP:
237 watch_command_wrapper (expr, FROM_TTY);
238 break;
239 case READ_WP:
240 rwatch_command_wrapper (expr, FROM_TTY);
241 break;
242 case ACCESS_WP:
243 awatch_command_wrapper (expr, FROM_TTY);
244 break;
245 default:
246 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
247 }
248 }
This page took 0.034632 seconds and 4 git commands to generate.