Commit | Line | Data |
---|---|---|
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 |
32 | enum |
33 | { | |
34 | FROM_TTY = 0 | |
35 | }; | |
36 | ||
383f836e TT |
37 | /* True if MI breakpoint observers have been registered. */ |
38 | ||
39 | static int mi_breakpoint_observers_installed; | |
40 | ||
41 | /* Control whether breakpoint_notify may act. */ | |
42 | ||
43 | static int mi_can_breakpoint_notify; | |
44 | ||
45 | /* Output a single breakpoint, when allowed. */ | |
fb40c209 AC |
46 | |
47 | static void | |
48 | breakpoint_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 |
54 | enum 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 | 64 | void |
fb40c209 AC |
65 | mi_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; |
41447f92 VP |
74 | int enabled = 1; |
75 | ||
98deb0da | 76 | struct gdb_exception e; |
fb40c209 AC |
77 | struct gdb_events *old_hooks; |
78 | enum opt | |
79 | { | |
80 | HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT, | |
41447f92 | 81 | IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT |
fb40c209 AC |
82 | }; |
83 | static struct mi_opt opts[] = | |
84 | { | |
85 | {"h", HARDWARE_OPT, 0}, | |
86 | {"t", TEMP_OPT, 0}, | |
87 | {"c", CONDITION_OPT, 1}, | |
88 | {"i", IGNORE_COUNT_OPT, 1}, | |
89 | {"p", THREAD_OPT, 1}, | |
afe8ab22 | 90 | {"f", PENDING_OPT, 0}, |
41447f92 | 91 | {"d", DISABLE_OPT, 0}, |
d5d6fca5 | 92 | { 0, 0, 0 } |
fb40c209 AC |
93 | }; |
94 | ||
95 | /* Parse arguments. It could be -r or -h or -t, <location> or ``--'' | |
96 | to denote the end of the option list. */ | |
97 | int optind = 0; | |
98 | char *optarg; | |
99 | while (1) | |
100 | { | |
101 | int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg); | |
102 | if (opt < 0) | |
103 | break; | |
104 | switch ((enum opt) opt) | |
105 | { | |
106 | case TEMP_OPT: | |
107 | temp_p = 1; | |
108 | break; | |
109 | case HARDWARE_OPT: | |
110 | type = HW_BP; | |
111 | break; | |
112 | #if 0 | |
113 | case REGEXP_OPT: | |
114 | type = REGEXP_BP; | |
115 | break; | |
116 | #endif | |
117 | case CONDITION_OPT: | |
118 | condition = optarg; | |
119 | break; | |
120 | case IGNORE_COUNT_OPT: | |
121 | ignore_count = atol (optarg); | |
122 | break; | |
123 | case THREAD_OPT: | |
124 | thread = atol (optarg); | |
125 | break; | |
afe8ab22 VP |
126 | case PENDING_OPT: |
127 | pending = 1; | |
128 | break; | |
41447f92 VP |
129 | case DISABLE_OPT: |
130 | enabled = 0; | |
fb40c209 AC |
131 | } |
132 | } | |
133 | ||
134 | if (optind >= argc) | |
8a3fe4f8 | 135 | error (_("mi_cmd_break_insert: Missing <location>")); |
fb40c209 | 136 | if (optind < argc - 1) |
8a3fe4f8 | 137 | error (_("mi_cmd_break_insert: Garbage following <location>")); |
fb40c209 AC |
138 | address = argv[optind]; |
139 | ||
140 | /* Now we have what we need, let's insert the breakpoint! */ | |
383f836e TT |
141 | if (! mi_breakpoint_observers_installed) |
142 | { | |
143 | observer_attach_breakpoint_created (breakpoint_notify); | |
144 | observer_attach_breakpoint_modified (breakpoint_notify); | |
145 | observer_attach_breakpoint_deleted (breakpoint_notify); | |
146 | mi_breakpoint_observers_installed = 1; | |
147 | } | |
148 | ||
149 | mi_can_breakpoint_notify = 1; | |
98deb0da VP |
150 | /* Make sure we restore hooks even if exception is thrown. */ |
151 | TRY_CATCH (e, RETURN_MASK_ALL) | |
fb40c209 | 152 | { |
98deb0da VP |
153 | switch (type) |
154 | { | |
155 | case REG_BP: | |
156 | set_breakpoint (address, condition, | |
157 | 0 /*hardwareflag */ , temp_p, | |
158 | thread, ignore_count, | |
41447f92 | 159 | pending, enabled); |
98deb0da VP |
160 | break; |
161 | case HW_BP: | |
162 | set_breakpoint (address, condition, | |
163 | 1 /*hardwareflag */ , temp_p, | |
164 | thread, ignore_count, | |
41447f92 | 165 | pending, enabled); |
98deb0da | 166 | break; |
fb40c209 | 167 | #if 0 |
98deb0da VP |
168 | case REGEXP_BP: |
169 | if (temp_p) | |
170 | error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint")); | |
171 | else | |
172 | rbreak_command_wrapper (address, FROM_TTY); | |
98deb0da | 173 | break; |
fb40c209 | 174 | #endif |
98deb0da VP |
175 | default: |
176 | internal_error (__FILE__, __LINE__, | |
177 | _("mi_cmd_break_insert: Bad switch.")); | |
178 | } | |
fb40c209 | 179 | } |
383f836e | 180 | mi_can_breakpoint_notify = 0; |
98deb0da VP |
181 | if (e.reason < 0) |
182 | throw_exception (e); | |
fb40c209 AC |
183 | } |
184 | ||
185 | enum wp_type | |
186 | { | |
187 | REG_WP, | |
188 | READ_WP, | |
189 | ACCESS_WP | |
190 | }; | |
191 | ||
192 | /* Insert a watchpoint. The type of watchpoint is specified by the | |
193 | first argument: | |
194 | -break-watch <expr> --> insert a regular wp. | |
195 | -break-watch -r <expr> --> insert a read watchpoint. | |
196 | -break-watch -a <expr> --> insert an access wp. */ | |
197 | ||
ce8f13f8 | 198 | void |
fb40c209 AC |
199 | mi_cmd_break_watch (char *command, char **argv, int argc) |
200 | { | |
201 | char *expr = NULL; | |
202 | enum wp_type type = REG_WP; | |
203 | enum opt | |
204 | { | |
205 | READ_OPT, ACCESS_OPT | |
206 | }; | |
207 | static struct mi_opt opts[] = | |
208 | { | |
209 | {"r", READ_OPT, 0}, | |
210 | {"a", ACCESS_OPT, 0}, | |
d5d6fca5 | 211 | { 0, 0, 0 } |
fb40c209 AC |
212 | }; |
213 | ||
214 | /* Parse arguments. */ | |
215 | int optind = 0; | |
216 | char *optarg; | |
217 | while (1) | |
218 | { | |
219 | int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg); | |
220 | if (opt < 0) | |
221 | break; | |
222 | switch ((enum opt) opt) | |
223 | { | |
224 | case READ_OPT: | |
225 | type = READ_WP; | |
226 | break; | |
227 | case ACCESS_OPT: | |
228 | type = ACCESS_WP; | |
229 | break; | |
230 | } | |
231 | } | |
232 | if (optind >= argc) | |
8a3fe4f8 | 233 | error (_("mi_cmd_break_watch: Missing <expression>")); |
fb40c209 | 234 | if (optind < argc - 1) |
8a3fe4f8 | 235 | error (_("mi_cmd_break_watch: Garbage following <expression>")); |
fb40c209 AC |
236 | expr = argv[optind]; |
237 | ||
238 | /* Now we have what we need, let's insert the watchpoint! */ | |
239 | switch (type) | |
240 | { | |
241 | case REG_WP: | |
fb40c209 | 242 | watch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
243 | break; |
244 | case READ_WP: | |
fb40c209 | 245 | rwatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
246 | break; |
247 | case ACCESS_WP: | |
fb40c209 | 248 | awatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
249 | break; |
250 | default: | |
8a3fe4f8 | 251 | error (_("mi_cmd_break_watch: Unknown watchpoint type.")); |
fb40c209 | 252 | } |
fb40c209 | 253 | } |