]> Git Repo - binutils.git/blame - gdb/mi/mi-cmd-break.c
gdb: fix building with system readline
[binutils.git] / gdb / mi / mi-cmd-break.c
CommitLineData
fb40c209 1/* MI Command Set - breakpoint and watchpoint commands.
4c38e0a4 2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009, 2010
0fb0cc75 3 Free Software Foundation, Inc.
ab91fdd5 4 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
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
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
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
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
20
21#include "defs.h"
a6d9a66e 22#include "arch-utils.h"
fb40c209
AC
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"
5b7f31a4 29#include "gdb.h"
98deb0da 30#include "exceptions.h"
383f836e 31#include "observer.h"
fb40c209 32
fb40c209
AC
33enum
34 {
35 FROM_TTY = 0
36 };
37
383f836e
TT
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. */
fb40c209
AC
47
48static void
49breakpoint_notify (int b)
50{
383f836e
TT
51 if (mi_can_breakpoint_notify)
52 gdb_breakpoint_query (uiout, b, NULL);
fb40c209
AC
53}
54
fb40c209
AC
55enum bp_type
56 {
57 REG_BP,
58 HW_BP,
59 REGEXP_BP
60 };
61
afe8ab22
VP
62/* Implements the -break-insert command.
63 See the MI manual for the list of possible options. */
fb40c209 64
ce8f13f8 65void
fb40c209
AC
66mi_cmd_break_insert (char *command, char **argv, int argc)
67{
68 char *address = NULL;
69 enum bp_type type = REG_BP;
8cdf0e15 70 int hardware = 0;
fb40c209
AC
71 int temp_p = 0;
72 int thread = -1;
73 int ignore_count = 0;
74 char *condition = NULL;
afe8ab22 75 int pending = 0;
41447f92 76 int enabled = 1;
8cdf0e15 77 struct cleanup *back_to;
41447f92 78
98deb0da 79 struct gdb_exception e;
fb40c209
AC
80 struct gdb_events *old_hooks;
81 enum opt
82 {
8cdf0e15 83 HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
41447f92 84 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT
fb40c209
AC
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},
afe8ab22 93 {"f", PENDING_OPT, 0},
41447f92 94 {"d", DISABLE_OPT, 0},
d5d6fca5 95 { 0, 0, 0 }
fb40c209
AC
96 };
97
98 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
99 to denote the end of the option list. */
100 int optind = 0;
101 char *optarg;
102 while (1)
103 {
104 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
105 if (opt < 0)
106 break;
107 switch ((enum opt) opt)
108 {
109 case TEMP_OPT:
110 temp_p = 1;
111 break;
112 case HARDWARE_OPT:
8cdf0e15 113 hardware = 1;
fb40c209 114 break;
fb40c209
AC
115 case CONDITION_OPT:
116 condition = optarg;
117 break;
118 case IGNORE_COUNT_OPT:
119 ignore_count = atol (optarg);
120 break;
121 case THREAD_OPT:
122 thread = atol (optarg);
123 break;
afe8ab22
VP
124 case PENDING_OPT:
125 pending = 1;
126 break;
41447f92
VP
127 case DISABLE_OPT:
128 enabled = 0;
fb40c209
AC
129 }
130 }
131
132 if (optind >= argc)
8a3fe4f8 133 error (_("mi_cmd_break_insert: Missing <location>"));
fb40c209 134 if (optind < argc - 1)
8a3fe4f8 135 error (_("mi_cmd_break_insert: Garbage following <location>"));
fb40c209
AC
136 address = argv[optind];
137
138 /* Now we have what we need, let's insert the breakpoint! */
383f836e
TT
139 if (! mi_breakpoint_observers_installed)
140 {
141 observer_attach_breakpoint_created (breakpoint_notify);
142 observer_attach_breakpoint_modified (breakpoint_notify);
143 observer_attach_breakpoint_deleted (breakpoint_notify);
144 mi_breakpoint_observers_installed = 1;
145 }
146
8cdf0e15 147 back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
383f836e 148 mi_can_breakpoint_notify = 1;
8cdf0e15
VP
149 create_breakpoint (get_current_arch (), address, condition, thread,
150 0 /* condition and thread are valid. */,
151 temp_p, hardware, 0 /* traceflag */,
152 ignore_count,
153 pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
154 NULL, 0, enabled);
155 do_cleanups (back_to);
156
fb40c209
AC
157}
158
159enum wp_type
160{
161 REG_WP,
162 READ_WP,
163 ACCESS_WP
164};
165
166/* Insert a watchpoint. The type of watchpoint is specified by the
167 first argument:
168 -break-watch <expr> --> insert a regular wp.
169 -break-watch -r <expr> --> insert a read watchpoint.
170 -break-watch -a <expr> --> insert an access wp. */
171
ce8f13f8 172void
fb40c209
AC
173mi_cmd_break_watch (char *command, char **argv, int argc)
174{
175 char *expr = NULL;
176 enum wp_type type = REG_WP;
177 enum opt
178 {
179 READ_OPT, ACCESS_OPT
180 };
181 static struct mi_opt opts[] =
182 {
183 {"r", READ_OPT, 0},
184 {"a", ACCESS_OPT, 0},
d5d6fca5 185 { 0, 0, 0 }
fb40c209
AC
186 };
187
188 /* Parse arguments. */
189 int optind = 0;
190 char *optarg;
191 while (1)
192 {
193 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
194 if (opt < 0)
195 break;
196 switch ((enum opt) opt)
197 {
198 case READ_OPT:
199 type = READ_WP;
200 break;
201 case ACCESS_OPT:
202 type = ACCESS_WP;
203 break;
204 }
205 }
206 if (optind >= argc)
8a3fe4f8 207 error (_("mi_cmd_break_watch: Missing <expression>"));
fb40c209 208 if (optind < argc - 1)
8a3fe4f8 209 error (_("mi_cmd_break_watch: Garbage following <expression>"));
fb40c209
AC
210 expr = argv[optind];
211
212 /* Now we have what we need, let's insert the watchpoint! */
213 switch (type)
214 {
215 case REG_WP:
fb40c209 216 watch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
217 break;
218 case READ_WP:
fb40c209 219 rwatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
220 break;
221 case ACCESS_WP:
fb40c209 222 awatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
223 break;
224 default:
8a3fe4f8 225 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
fb40c209 226 }
fb40c209 227}
48cb2d85
VP
228
229/* The mi_read_next_line consults these variable to return successive
230 command lines. While it would be clearer to use a closure pointer,
231 it is not expected that any future code will use read_command_lines_1,
232 therefore no point of overengineering. */
233
234static char **mi_command_line_array;
235static int mi_command_line_array_cnt;
236static int mi_command_line_array_ptr;
237
238static char *
a58d7472 239mi_read_next_line (void)
48cb2d85
VP
240{
241 if (mi_command_line_array_ptr == mi_command_line_array_cnt)
242 return NULL;
243 else
244 return mi_command_line_array[mi_command_line_array_ptr++];
245}
246
247void
248mi_cmd_break_commands (char *command, char **argv, int argc)
249{
250 struct command_line *break_command;
251 char *endptr;
252 int bnum;
253 struct breakpoint *b;
254
255 if (argc < 1)
256 error ("USAGE: %s <BKPT> [<COMMAND> [<COMMAND>...]]", command);
257
258 bnum = strtol (argv[0], &endptr, 0);
259 if (endptr == argv[0])
260 error ("breakpoint number argument \"%s\" is not a number.",
261 argv[0]);
262 else if (*endptr != '\0')
263 error ("junk at the end of breakpoint number argument \"%s\".",
264 argv[0]);
265
266 b = get_breakpoint (bnum);
267 if (b == NULL)
268 error ("breakpoint %d not found.", bnum);
269
270 mi_command_line_array = argv;
271 mi_command_line_array_ptr = 1;
272 mi_command_line_array_cnt = argc;
273
5d4e2b76 274 break_command = read_command_lines_1 (mi_read_next_line, 1);
48cb2d85
VP
275 breakpoint_set_commands (b, break_command);
276}
277
This page took 1.758375 seconds and 4 git commands to generate.