Upgrade GDB from 7.0 and 7.2 on the vendor branch
[dragonfly.git] / contrib / gdb-7 / gdb / mi / mi-cmd-break.c
CommitLineData
5796c8dc 1/* MI Command Set - breakpoint and watchpoint commands.
cf7f2e2d 2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010
5796c8dc
SS
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 "arch-utils.h"
23#include "mi-cmds.h"
24#include "ui-out.h"
25#include "mi-out.h"
26#include "breakpoint.h"
27#include "gdb_string.h"
28#include "mi-getopt.h"
29#include "gdb.h"
30#include "exceptions.h"
31#include "observer.h"
32
33enum
34 {
35 FROM_TTY = 0
36 };
37
38/* True if MI breakpoint observers have been registered. */
39
40static int mi_breakpoint_observers_installed;
41
42/* Control whether breakpoint_notify may act. */
43
44static int mi_can_breakpoint_notify;
45
46/* Output a single breakpoint, when allowed. */
47
48static void
49breakpoint_notify (int b)
50{
51 if (mi_can_breakpoint_notify)
52 gdb_breakpoint_query (uiout, b, NULL);
53}
54
55enum bp_type
56 {
57 REG_BP,
58 HW_BP,
59 REGEXP_BP
60 };
61
62/* Implements the -break-insert command.
63 See the MI manual for the list of possible options. */
64
65void
66mi_cmd_break_insert (char *command, char **argv, int argc)
67{
68 char *address = NULL;
cf7f2e2d 69 int hardware = 0;
5796c8dc
SS
70 int temp_p = 0;
71 int thread = -1;
72 int ignore_count = 0;
73 char *condition = NULL;
74 int pending = 0;
75 int enabled = 1;
cf7f2e2d
JM
76 int tracepoint = 0;
77 struct cleanup *back_to;
78 enum bptype type_wanted;
5796c8dc 79
5796c8dc
SS
80 enum opt
81 {
cf7f2e2d
JM
82 HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
83 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT,
84 TRACEPOINT_OPT,
5796c8dc
SS
85 };
86 static struct mi_opt opts[] =
87 {
88 {"h", HARDWARE_OPT, 0},
89 {"t", TEMP_OPT, 0},
90 {"c", CONDITION_OPT, 1},
91 {"i", IGNORE_COUNT_OPT, 1},
92 {"p", THREAD_OPT, 1},
93 {"f", PENDING_OPT, 0},
94 {"d", DISABLE_OPT, 0},
cf7f2e2d 95 {"a", TRACEPOINT_OPT, 0},
5796c8dc
SS
96 { 0, 0, 0 }
97 };
98
99 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
100 to denote the end of the option list. */
101 int optind = 0;
102 char *optarg;
cf7f2e2d 103
5796c8dc
SS
104 while (1)
105 {
106 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
107 if (opt < 0)
108 break;
109 switch ((enum opt) opt)
110 {
111 case TEMP_OPT:
112 temp_p = 1;
113 break;
114 case HARDWARE_OPT:
cf7f2e2d 115 hardware = 1;
5796c8dc 116 break;
5796c8dc
SS
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;
cf7f2e2d
JM
131 break;
132 case TRACEPOINT_OPT:
133 tracepoint = 1;
134 break;
5796c8dc
SS
135 }
136 }
137
138 if (optind >= argc)
139 error (_("mi_cmd_break_insert: Missing <location>"));
140 if (optind < argc - 1)
141 error (_("mi_cmd_break_insert: Garbage following <location>"));
142 address = argv[optind];
143
144 /* Now we have what we need, let's insert the breakpoint! */
145 if (! mi_breakpoint_observers_installed)
146 {
147 observer_attach_breakpoint_created (breakpoint_notify);
148 observer_attach_breakpoint_modified (breakpoint_notify);
149 observer_attach_breakpoint_deleted (breakpoint_notify);
150 mi_breakpoint_observers_installed = 1;
151 }
152
cf7f2e2d 153 back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
5796c8dc 154 mi_can_breakpoint_notify = 1;
cf7f2e2d
JM
155
156 /* Note that to request a fast tracepoint, the client uses the
157 "hardware" flag, although there's nothing of hardware related to
158 fast tracepoints -- one can implement slow tracepoints with
159 hardware breakpoints, but fast tracepoints are always software.
160 "fast" is a misnomer, actually, "jump" would be more appropriate.
161 A simulator or an emulator could conceivably implement fast
162 regular non-jump based tracepoints. */
163 type_wanted = (tracepoint
164 ? (hardware ? bp_fast_tracepoint : bp_tracepoint)
165 : (hardware ? bp_hardware_breakpoint : bp_breakpoint));
166
167 create_breakpoint (get_current_arch (), address, condition, thread,
168 0 /* condition and thread are valid. */,
169 temp_p, type_wanted,
170 ignore_count,
171 pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
172 NULL, 0, enabled);
173 do_cleanups (back_to);
174
5796c8dc
SS
175}
176
177enum wp_type
178{
179 REG_WP,
180 READ_WP,
181 ACCESS_WP
182};
183
cf7f2e2d
JM
184void
185mi_cmd_break_passcount (char *command, char **argv, int argc)
186{
187 int n;
188 int p;
189 struct breakpoint *t;
190
191 if (argc != 2)
192 error (_("Usage: tracepoint-number passcount"));
193
194 n = atoi (argv[0]);
195 p = atoi (argv[1]);
196 t = get_tracepoint (n);
197
198 if (t)
199 {
200 t->pass_count = p;
201 observer_notify_tracepoint_modified (n);
202 }
203 else
204 {
205 error (_("Cound not find tracepoint %d"), n);
206 }
207}
208
5796c8dc
SS
209/* Insert a watchpoint. The type of watchpoint is specified by the
210 first argument:
211 -break-watch <expr> --> insert a regular wp.
212 -break-watch -r <expr> --> insert a read watchpoint.
213 -break-watch -a <expr> --> insert an access wp. */
214
215void
216mi_cmd_break_watch (char *command, char **argv, int argc)
217{
218 char *expr = NULL;
219 enum wp_type type = REG_WP;
220 enum opt
221 {
222 READ_OPT, ACCESS_OPT
223 };
224 static struct mi_opt opts[] =
225 {
226 {"r", READ_OPT, 0},
227 {"a", ACCESS_OPT, 0},
228 { 0, 0, 0 }
229 };
230
231 /* Parse arguments. */
232 int optind = 0;
233 char *optarg;
cf7f2e2d 234
5796c8dc
SS
235 while (1)
236 {
cf7f2e2d
JM
237 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv,
238 opts, &optind, &optarg);
239
5796c8dc
SS
240 if (opt < 0)
241 break;
242 switch ((enum opt) opt)
243 {
244 case READ_OPT:
245 type = READ_WP;
246 break;
247 case ACCESS_OPT:
248 type = ACCESS_WP;
249 break;
250 }
251 }
252 if (optind >= argc)
253 error (_("mi_cmd_break_watch: Missing <expression>"));
254 if (optind < argc - 1)
255 error (_("mi_cmd_break_watch: Garbage following <expression>"));
256 expr = argv[optind];
257
258 /* Now we have what we need, let's insert the watchpoint! */
259 switch (type)
260 {
261 case REG_WP:
262 watch_command_wrapper (expr, FROM_TTY);
263 break;
264 case READ_WP:
265 rwatch_command_wrapper (expr, FROM_TTY);
266 break;
267 case ACCESS_WP:
268 awatch_command_wrapper (expr, FROM_TTY);
269 break;
270 default:
271 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
272 }
273}
274
275/* The mi_read_next_line consults these variable to return successive
276 command lines. While it would be clearer to use a closure pointer,
277 it is not expected that any future code will use read_command_lines_1,
278 therefore no point of overengineering. */
279
280static char **mi_command_line_array;
281static int mi_command_line_array_cnt;
282static int mi_command_line_array_ptr;
283
284static char *
cf7f2e2d 285mi_read_next_line (void)
5796c8dc
SS
286{
287 if (mi_command_line_array_ptr == mi_command_line_array_cnt)
288 return NULL;
289 else
290 return mi_command_line_array[mi_command_line_array_ptr++];
291}
292
293void
294mi_cmd_break_commands (char *command, char **argv, int argc)
295{
296 struct command_line *break_command;
297 char *endptr;
298 int bnum;
299 struct breakpoint *b;
300
301 if (argc < 1)
302 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command);
303
304 bnum = strtol (argv[0], &endptr, 0);
305 if (endptr == argv[0])
306 error ("breakpoint number argument \"%s\" is not a number.",
307 argv[0]);
308 else if (*endptr != '\0')
309 error ("junk at the end of breakpoint number argument \"%s\".",
310 argv[0]);
311
312 b = get_breakpoint (bnum);
313 if (b == NULL)
314 error ("breakpoint %d not found.", bnum);
315
316 mi_command_line_array = argv;
317 mi_command_line_array_ptr = 1;
318 mi_command_line_array_cnt = argc;
319
cf7f2e2d
JM
320 if (is_tracepoint (b))
321 break_command = read_command_lines_1 (mi_read_next_line, 1,
322 check_tracepoint_command, b);
323 else
324 break_command = read_command_lines_1 (mi_read_next_line, 1, 0, 0);
325
5796c8dc
SS
326 breakpoint_set_commands (b, break_command);
327}
328