daily update
[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 Free Software Foundation, Inc.
3 Contributed by Cygnus Solutions (a Red Hat company).
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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"
28 #include "gdb.h"
29
30 enum
31 {
32 FROM_TTY = 0
33 };
34
35 /* Output a single breakpoint. */
36
37 static void
38 breakpoint_notify (int b)
39 {
40 gdb_breakpoint_query (uiout, b, NULL);
41 }
42
43
44 struct gdb_events breakpoint_hooks =
45 {
46 breakpoint_notify,
47 breakpoint_notify,
48 breakpoint_notify,
49 };
50
51
52 enum bp_type
53 {
54 REG_BP,
55 HW_BP,
56 REGEXP_BP
57 };
58
59 /* Implements the -break-insert command.
60 See the MI manual for the list of possible options. */
61
62 enum mi_cmd_result
63 mi_cmd_break_insert (char *command, char **argv, int argc)
64 {
65 char *address = NULL;
66 enum bp_type type = REG_BP;
67 int temp_p = 0;
68 int thread = -1;
69 int ignore_count = 0;
70 char *condition = NULL;
71 int pending = 0;
72 enum gdb_rc rc;
73 struct gdb_events *old_hooks;
74 enum opt
75 {
76 HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT,
77 IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT
78 };
79 static struct mi_opt opts[] =
80 {
81 {"h", HARDWARE_OPT, 0},
82 {"t", TEMP_OPT, 0},
83 {"c", CONDITION_OPT, 1},
84 {"i", IGNORE_COUNT_OPT, 1},
85 {"p", THREAD_OPT, 1},
86 {"f", PENDING_OPT, 0},
87 { 0, 0, 0 }
88 };
89
90 /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
91 to denote the end of the option list. */
92 int optind = 0;
93 char *optarg;
94 while (1)
95 {
96 int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg);
97 if (opt < 0)
98 break;
99 switch ((enum opt) opt)
100 {
101 case TEMP_OPT:
102 temp_p = 1;
103 break;
104 case HARDWARE_OPT:
105 type = HW_BP;
106 break;
107 #if 0
108 case REGEXP_OPT:
109 type = REGEXP_BP;
110 break;
111 #endif
112 case CONDITION_OPT:
113 condition = optarg;
114 break;
115 case IGNORE_COUNT_OPT:
116 ignore_count = atol (optarg);
117 break;
118 case THREAD_OPT:
119 thread = atol (optarg);
120 break;
121 case PENDING_OPT:
122 pending = 1;
123 break;
124 }
125 }
126
127 if (optind >= argc)
128 error (_("mi_cmd_break_insert: Missing <location>"));
129 if (optind < argc - 1)
130 error (_("mi_cmd_break_insert: Garbage following <location>"));
131 address = argv[optind];
132
133 /* Now we have what we need, let's insert the breakpoint! */
134 old_hooks = deprecated_set_gdb_event_hooks (&breakpoint_hooks);
135 switch (type)
136 {
137 case REG_BP:
138 rc = gdb_breakpoint (address, condition,
139 0 /*hardwareflag */ , temp_p,
140 thread, ignore_count,
141 pending,
142 &mi_error_message);
143 break;
144 case HW_BP:
145 rc = gdb_breakpoint (address, condition,
146 1 /*hardwareflag */ , temp_p,
147 thread, ignore_count,
148 pending,
149 &mi_error_message);
150 break;
151 #if 0
152 case REGEXP_BP:
153 if (temp_p)
154 error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"));
155 else
156 rbreak_command_wrapper (address, FROM_TTY);
157 return MI_CMD_DONE;
158 break;
159 #endif
160 default:
161 internal_error (__FILE__, __LINE__,
162 _("mi_cmd_break_insert: Bad switch."));
163 }
164 deprecated_set_gdb_event_hooks (old_hooks);
165
166 if (rc == GDB_RC_FAIL)
167 return MI_CMD_ERROR;
168 else
169 return MI_CMD_DONE;
170 }
171
172 enum wp_type
173 {
174 REG_WP,
175 READ_WP,
176 ACCESS_WP
177 };
178
179 /* Insert a watchpoint. The type of watchpoint is specified by the
180 first argument:
181 -break-watch <expr> --> insert a regular wp.
182 -break-watch -r <expr> --> insert a read watchpoint.
183 -break-watch -a <expr> --> insert an access wp. */
184
185 enum mi_cmd_result
186 mi_cmd_break_watch (char *command, char **argv, int argc)
187 {
188 char *expr = NULL;
189 enum wp_type type = REG_WP;
190 enum opt
191 {
192 READ_OPT, ACCESS_OPT
193 };
194 static struct mi_opt opts[] =
195 {
196 {"r", READ_OPT, 0},
197 {"a", ACCESS_OPT, 0},
198 { 0, 0, 0 }
199 };
200
201 /* Parse arguments. */
202 int optind = 0;
203 char *optarg;
204 while (1)
205 {
206 int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg);
207 if (opt < 0)
208 break;
209 switch ((enum opt) opt)
210 {
211 case READ_OPT:
212 type = READ_WP;
213 break;
214 case ACCESS_OPT:
215 type = ACCESS_WP;
216 break;
217 }
218 }
219 if (optind >= argc)
220 error (_("mi_cmd_break_watch: Missing <expression>"));
221 if (optind < argc - 1)
222 error (_("mi_cmd_break_watch: Garbage following <expression>"));
223 expr = argv[optind];
224
225 /* Now we have what we need, let's insert the watchpoint! */
226 switch (type)
227 {
228 case REG_WP:
229 watch_command_wrapper (expr, FROM_TTY);
230 break;
231 case READ_WP:
232 rwatch_command_wrapper (expr, FROM_TTY);
233 break;
234 case ACCESS_WP:
235 awatch_command_wrapper (expr, FROM_TTY);
236 break;
237 default:
238 error (_("mi_cmd_break_watch: Unknown watchpoint type."));
239 }
240 return MI_CMD_DONE;
241 }
This page took 0.039319 seconds and 4 git commands to generate.