daily update
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-break.c
CommitLineData
fb40c209 1/* MI Command Set - breakpoint and watchpoint commands.
9b254dd1 2 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
ab91fdd5 3 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fb40c209
AC
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb40c209
AC
19
20#include "defs.h"
21#include "mi-cmds.h"
22#include "ui-out.h"
23#include "mi-out.h"
24#include "breakpoint.h"
25#include "gdb_string.h"
26#include "mi-getopt.h"
27#include "gdb-events.h"
5b7f31a4 28#include "gdb.h"
98deb0da 29#include "exceptions.h"
fb40c209 30
fb40c209
AC
31enum
32 {
33 FROM_TTY = 0
34 };
35
36/* Output a single breakpoint. */
37
38static void
39breakpoint_notify (int b)
40{
ce43223b 41 gdb_breakpoint_query (uiout, b, NULL);
fb40c209
AC
42}
43
44
45struct gdb_events breakpoint_hooks =
46{
47 breakpoint_notify,
48 breakpoint_notify,
49 breakpoint_notify,
50};
51
52
53enum bp_type
54 {
55 REG_BP,
56 HW_BP,
57 REGEXP_BP
58 };
59
afe8ab22
VP
60/* Implements the -break-insert command.
61 See the MI manual for the list of possible options. */
fb40c209
AC
62
63enum mi_cmd_result
64mi_cmd_break_insert (char *command, char **argv, int argc)
65{
66 char *address = NULL;
67 enum bp_type type = REG_BP;
68 int temp_p = 0;
69 int thread = -1;
70 int ignore_count = 0;
71 char *condition = NULL;
afe8ab22 72 int pending = 0;
98deb0da 73 struct gdb_exception e;
fb40c209
AC
74 struct gdb_events *old_hooks;
75 enum opt
76 {
77 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
afe8ab22 78 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT
fb40c209
AC
79 };
80 static struct mi_opt opts[] =
81 {
82 {"h", HARDWARE_OPT, 0},
83 {"t", TEMP_OPT, 0},
84 {"c", CONDITION_OPT, 1},
85 {"i", IGNORE_COUNT_OPT, 1},
86 {"p", THREAD_OPT, 1},
afe8ab22 87 {"f", PENDING_OPT, 0},
d5d6fca5 88 { 0, 0, 0 }
fb40c209
AC
89 };
90
91 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
92 to denote the end of the option list. */
93 int optind = 0;
94 char *optarg;
95 while (1)
96 {
97 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
98 if (opt < 0)
99 break;
100 switch ((enum opt) opt)
101 {
102 case TEMP_OPT:
103 temp_p = 1;
104 break;
105 case HARDWARE_OPT:
106 type = HW_BP;
107 break;
108#if 0
109 case REGEXP_OPT:
110 type = REGEXP_BP;
111 break;
112#endif
113 case CONDITION_OPT:
114 condition = optarg;
115 break;
116 case IGNORE_COUNT_OPT:
117 ignore_count = atol (optarg);
118 break;
119 case THREAD_OPT:
120 thread = atol (optarg);
121 break;
afe8ab22
VP
122 case PENDING_OPT:
123 pending = 1;
124 break;
fb40c209
AC
125 }
126 }
127
128 if (optind >= argc)
8a3fe4f8 129 error (_("mi_cmd_break_insert: Missing <location>"));
fb40c209 130 if (optind < argc - 1)
8a3fe4f8 131 error (_("mi_cmd_break_insert: Garbage following <location>"));
fb40c209
AC
132 address = argv[optind];
133
134 /* Now we have what we need, let's insert the breakpoint! */
2726dafc 135 old_hooks = deprecated_set_gdb_event_hooks (&breakpoint_hooks);
98deb0da
VP
136 /* Make sure we restore hooks even if exception is thrown. */
137 TRY_CATCH (e, RETURN_MASK_ALL)
fb40c209 138 {
98deb0da
VP
139 switch (type)
140 {
141 case REG_BP:
142 set_breakpoint (address, condition,
143 0 /*hardwareflag */ , temp_p,
144 thread, ignore_count,
145 pending);
146 break;
147 case HW_BP:
148 set_breakpoint (address, condition,
149 1 /*hardwareflag */ , temp_p,
150 thread, ignore_count,
151 pending);
152 break;
fb40c209 153#if 0
98deb0da
VP
154 case REGEXP_BP:
155 if (temp_p)
156 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
157 else
158 rbreak_command_wrapper (address, FROM_TTY);
159 return MI_CMD_DONE;
160 break;
fb40c209 161#endif
98deb0da
VP
162 default:
163 internal_error (__FILE__, __LINE__,
164 _("mi_cmd_break_insert: Bad switch."));
165 }
fb40c209 166 }
2726dafc 167 deprecated_set_gdb_event_hooks (old_hooks);
98deb0da
VP
168 if (e.reason < 0)
169 throw_exception (e);
fb40c209 170
98deb0da 171 return MI_CMD_DONE;
fb40c209
AC
172}
173
174enum wp_type
175{
176 REG_WP,
177 READ_WP,
178 ACCESS_WP
179};
180
181/* Insert a watchpoint. The type of watchpoint is specified by the
182 first argument:
183 -break-watch <expr> --> insert a regular wp.
184 -break-watch -r <expr> --> insert a read watchpoint.
185 -break-watch -a <expr> --> insert an access wp. */
186
187enum mi_cmd_result
188mi_cmd_break_watch (char *command, char **argv, int argc)
189{
190 char *expr = NULL;
191 enum wp_type type = REG_WP;
192 enum opt
193 {
194 READ_OPT, ACCESS_OPT
195 };
196 static struct mi_opt opts[] =
197 {
198 {"r", READ_OPT, 0},
199 {"a", ACCESS_OPT, 0},
d5d6fca5 200 { 0, 0, 0 }
fb40c209
AC
201 };
202
203 /* Parse arguments. */
204 int optind = 0;
205 char *optarg;
206 while (1)
207 {
208 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
209 if (opt < 0)
210 break;
211 switch ((enum opt) opt)
212 {
213 case READ_OPT:
214 type = READ_WP;
215 break;
216 case ACCESS_OPT:
217 type = ACCESS_WP;
218 break;
219 }
220 }
221 if (optind >= argc)
8a3fe4f8 222 error (_("mi_cmd_break_watch: Missing <expression>"));
fb40c209 223 if (optind < argc - 1)
8a3fe4f8 224 error (_("mi_cmd_break_watch: Garbage following <expression>"));
fb40c209
AC
225 expr = argv[optind];
226
227 /* Now we have what we need, let's insert the watchpoint! */
228 switch (type)
229 {
230 case REG_WP:
fb40c209 231 watch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
232 break;
233 case READ_WP:
fb40c209 234 rwatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
235 break;
236 case ACCESS_WP:
fb40c209 237 awatch_command_wrapper (expr, FROM_TTY);
fb40c209
AC
238 break;
239 default:
8a3fe4f8 240 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
fb40c209
AC
241 }
242 return MI_CMD_DONE;
243}
This page took 0.620776 seconds and 4 git commands to generate.