Implement creating tracepoints with -break-insert.
[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, 2010
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
33 enum
34 {
35 FROM_TTY = 0
36 };
37
38 /* True if MI breakpoint observers have been registered. */
39
40 static int mi_breakpoint_observers_installed;
41
42 /* Control whether breakpoint_notify may act. */
43
44 static int mi_can_breakpoint_notify;
45
46 /* Output a single breakpoint, when allowed. */
47
48 static void
49 breakpoint_notify (int b)
50 {
51 if (mi_can_breakpoint_notify)
52 gdb_breakpoint_query (uiout, b, NULL);
53 }
54
55 enum 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
65 void
66 mi_cmd_break_insert (char *command, char **argv, int argc)
67 {
68 char *address = NULL;
69 enum bp_type type = REG_BP;
70 int hardware = 0;
71 int temp_p = 0;
72 int thread = -1;
73 int ignore_count = 0;
74 char *condition = NULL;
75 int pending = 0;
76 int enabled = 1;
77 int tracepoint = 0;
78 struct cleanup *back_to;
79
80 struct gdb_exception e;
81 struct gdb_events *old_hooks;
82 enum opt
83 {
84 HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
85 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT,
86 TRACEPOINT_OPT,
87 };
88 static struct mi_opt opts[] =
89 {
90 {"h", HARDWARE_OPT, 0},
91 {"t", TEMP_OPT, 0},
92 {"c", CONDITION_OPT, 1},
93 {"i", IGNORE_COUNT_OPT, 1},
94 {"p", THREAD_OPT, 1},
95 {"f", PENDING_OPT, 0},
96 {"d", DISABLE_OPT, 0},
97 {"a", TRACEPOINT_OPT, 0},
98 { 0, 0, 0 }
99 };
100
101 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
102 to denote the end of the option list. */
103 int optind = 0;
104 char *optarg;
105 while (1)
106 {
107 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
108 if (opt < 0)
109 break;
110 switch ((enum opt) opt)
111 {
112 case TEMP_OPT:
113 temp_p = 1;
114 break;
115 case HARDWARE_OPT:
116 hardware = 1;
117 break;
118 case CONDITION_OPT:
119 condition = optarg;
120 break;
121 case IGNORE_COUNT_OPT:
122 ignore_count = atol (optarg);
123 break;
124 case THREAD_OPT:
125 thread = atol (optarg);
126 break;
127 case PENDING_OPT:
128 pending = 1;
129 break;
130 case DISABLE_OPT:
131 enabled = 0;
132 break;
133 case TRACEPOINT_OPT:
134 tracepoint = 1;
135 break;
136 }
137 }
138
139 if (optind >= argc)
140 error (_("mi_cmd_break_insert: Missing <location>"));
141 if (optind < argc - 1)
142 error (_("mi_cmd_break_insert: Garbage following <location>"));
143 address = argv[optind];
144
145 /* Now we have what we need, let's insert the breakpoint! */
146 if (! mi_breakpoint_observers_installed)
147 {
148 observer_attach_breakpoint_created (breakpoint_notify);
149 observer_attach_breakpoint_modified (breakpoint_notify);
150 observer_attach_breakpoint_deleted (breakpoint_notify);
151 mi_breakpoint_observers_installed = 1;
152 }
153
154 back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
155 mi_can_breakpoint_notify = 1;
156 create_breakpoint (get_current_arch (), address, condition, thread,
157 0 /* condition and thread are valid. */,
158 temp_p, hardware, tracepoint,
159 ignore_count,
160 pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
161 NULL, 0, enabled);
162 do_cleanups (back_to);
163
164 }
165
166 enum wp_type
167 {
168 REG_WP,
169 READ_WP,
170 ACCESS_WP
171 };
172
173 /* Insert a watchpoint. The type of watchpoint is specified by the
174 first argument:
175 -break-watch <expr> --> insert a regular wp.
176 -break-watch -r <expr> --> insert a read watchpoint.
177 -break-watch -a <expr> --> insert an access wp. */
178
179 void
180 mi_cmd_break_watch (char *command, char **argv, int argc)
181 {
182 char *expr = NULL;
183 enum wp_type type = REG_WP;
184 enum opt
185 {
186 READ_OPT, ACCESS_OPT
187 };
188 static struct mi_opt opts[] =
189 {
190 {"r", READ_OPT, 0},
191 {"a", ACCESS_OPT, 0},
192 { 0, 0, 0 }
193 };
194
195 /* Parse arguments. */
196 int optind = 0;
197 char *optarg;
198 while (1)
199 {
200 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
201 if (opt < 0)
202 break;
203 switch ((enum opt) opt)
204 {
205 case READ_OPT:
206 type = READ_WP;
207 break;
208 case ACCESS_OPT:
209 type = ACCESS_WP;
210 break;
211 }
212 }
213 if (optind >= argc)
214 error (_("mi_cmd_break_watch: Missing <expression>"));
215 if (optind < argc - 1)
216 error (_("mi_cmd_break_watch: Garbage following <expression>"));
217 expr = argv[optind];
218
219 /* Now we have what we need, let's insert the watchpoint! */
220 switch (type)
221 {
222 case REG_WP:
223 watch_command_wrapper (expr, FROM_TTY);
224 break;
225 case READ_WP:
226 rwatch_command_wrapper (expr, FROM_TTY);
227 break;
228 case ACCESS_WP:
229 awatch_command_wrapper (expr, FROM_TTY);
230 break;
231 default:
232 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
233 }
234 }
235
236 /* The mi_read_next_line consults these variable to return successive
237 command lines. While it would be clearer to use a closure pointer,
238 it is not expected that any future code will use read_command_lines_1,
239 therefore no point of overengineering. */
240
241 static char **mi_command_line_array;
242 static int mi_command_line_array_cnt;
243 static int mi_command_line_array_ptr;
244
245 static char *
246 mi_read_next_line (void)
247 {
248 if (mi_command_line_array_ptr == mi_command_line_array_cnt)
249 return NULL;
250 else
251 return mi_command_line_array[mi_command_line_array_ptr++];
252 }
253
254 void
255 mi_cmd_break_commands (char *command, char **argv, int argc)
256 {
257 struct command_line *break_command;
258 char *endptr;
259 int bnum;
260 struct breakpoint *b;
261
262 if (argc < 1)
263 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command);
264
265 bnum = strtol (argv[0], &endptr, 0);
266 if (endptr == argv[0])
267 error ("breakpoint number argument \"%s\" is not a number.",
268 argv[0]);
269 else if (*endptr != '\0')
270 error ("junk at the end of breakpoint number argument \"%s\".",
271 argv[0]);
272
273 b = get_breakpoint (bnum);
274 if (b == NULL)
275 error ("breakpoint %d not found.", bnum);
276
277 mi_command_line_array = argv;
278 mi_command_line_array_ptr = 1;
279 mi_command_line_array_cnt = argc;
280
281 if (breakpoint_is_tracepoint (b))
282 break_command = read_command_lines_1 (mi_read_next_line, 1,
283 check_tracepoint_command, b);
284 else
285 break_command = read_command_lines_1 (mi_read_next_line, 1, 0, 0);
286
287 breakpoint_set_commands (b, break_command);
288 }
289
This page took 0.051488 seconds and 5 git commands to generate.