2009-01-30 Julian Brown <julian@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-break.c
CommitLineData
fb40c209 1/* MI Command Set - breakpoint and watchpoint commands.
0fb0cc75
JB
2 Copyright (C) 2000, 2001, 2002, 2007, 2008, 2009
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"
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"
5b7f31a4 28#include "gdb.h"
98deb0da 29#include "exceptions.h"
383f836e 30#include "observer.h"
fb40c209 31
fb40c209
AC
32enum
33 {
34 FROM_TTY = 0
35 };
36
383f836e
TT
37/* True if MI breakpoint observers have been registered. */
38
39static int mi_breakpoint_observers_installed;
40
41/* Control whether breakpoint_notify may act. */
42
43static int mi_can_breakpoint_notify;
44
45/* Output a single breakpoint, when allowed. */
fb40c209
AC
46
47static void
48breakpoint_notify (int b)
49{
383f836e
TT
50 if (mi_can_breakpoint_notify)
51 gdb_breakpoint_query (uiout, b, NULL);
fb40c209
AC
52}
53
fb40c209
AC
54enum bp_type
55 {
56 REG_BP,
57 HW_BP,
58 REGEXP_BP
59 };
60
afe8ab22
VP
61/* Implements the -break-insert command.
62 See the MI manual for the list of possible options. */
fb40c209 63
ce8f13f8 64void
fb40c209
AC
65mi_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;
afe8ab22 73 int pending = 0;
98deb0da 74 struct gdb_exception e;
fb40c209
AC
75 struct gdb_events *old_hooks;
76 enum opt
77 {
78 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
afe8ab22 79 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT
fb40c209
AC
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},
afe8ab22 88 {"f", PENDING_OPT, 0},
d5d6fca5 89 { 0, 0, 0 }
fb40c209
AC
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;
afe8ab22
VP
123 case PENDING_OPT:
124 pending = 1;
125 break;
fb40c209
AC
126 }
127 }
128
129 if (optind >= argc)
8a3fe4f8 130 error (_("mi_cmd_break_insert: Missing <location>"));
fb40c209 131 if (optind < argc - 1)
8a3fe4f8 132 error (_("mi_cmd_break_insert: Garbage following <location>"));
fb40c209
AC
133 address = argv[optind];
134
135 /* Now we have what we need, let's insert the breakpoint! */
383f836e
TT
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;
98deb0da
VP
145 /* Make sure we restore hooks even if exception is thrown. */
146 TRY_CATCH (e, RETURN_MASK_ALL)
fb40c209 147 {
98deb0da
VP
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;
fb40c209 162#if 0
98deb0da
VP
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);
98deb0da 168 break;
fb40c209 169#endif
98deb0da
VP
170 default:
171 internal_error (__FILE__, __LINE__,
172 _("mi_cmd_break_insert: Bad switch."));
173 }
fb40c209 174 }
383f836e 175 mi_can_breakpoint_notify = 0;
98deb0da
VP
176 if (e.reason < 0)
177 throw_exception (e);
fb40c209
AC
178}
179
180enum 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
ce8f13f8 193void
fb40c209
AC
194mi_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},
d5d6fca5 206 { 0, 0, 0 }
fb40c209
AC
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)
8a3fe4f8 228 error (_("mi_cmd_break_watch: Missing <expression>"));
fb40c209 229 if (optind < argc - 1)
8a3fe4f8 230 error (_("mi_cmd_break_watch: Garbage following <expression>"));
fb40c209
AC
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:
fb40c209 237 watch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
238 break;
239 case READ_WP:
fb40c209 240 rwatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
241 break;
242 case ACCESS_WP:
fb40c209 243 awatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
244 break;
245 default:
8a3fe4f8 246 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
fb40c209 247 }
fb40c209 248}
This page took 0.67475 seconds and 4 git commands to generate.