]>
Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - breakpoint and watchpoint commands. |
8926118c | 2 | Copyright 2000, 2001, 2002 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 | |
9 | the Free Software Foundation; either version 2 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, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "defs.h" | |
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" | |
29 | #include "gdb-events.h" | |
5b7f31a4 | 30 | #include "gdb.h" |
fb40c209 AC |
31 | |
32 | /* Convenience macro for allocting typesafe memory. */ | |
33 | ||
34 | #undef XMALLOC | |
35 | #define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE)) | |
36 | ||
37 | enum | |
38 | { | |
39 | FROM_TTY = 0 | |
40 | }; | |
41 | ||
42 | /* Output a single breakpoint. */ | |
43 | ||
44 | static void | |
45 | breakpoint_notify (int b) | |
46 | { | |
2b65245e | 47 | gdb_breakpoint_query (uiout, b); |
fb40c209 AC |
48 | } |
49 | ||
50 | ||
51 | struct gdb_events breakpoint_hooks = | |
52 | { | |
53 | breakpoint_notify, | |
54 | breakpoint_notify, | |
55 | breakpoint_notify, | |
56 | }; | |
57 | ||
58 | ||
59 | enum bp_type | |
60 | { | |
61 | REG_BP, | |
62 | HW_BP, | |
63 | REGEXP_BP | |
64 | }; | |
65 | ||
66 | /* Insert a breakpoint. The type of breakpoint is specified by the | |
67 | first argument: -break-insert <location> --> insert a regular | |
68 | breakpoint. -break-insert -t <location> --> insert a temporary | |
69 | breakpoint. -break-insert -h <location> --> insert an hardware | |
70 | breakpoint. -break-insert -t -h <location> --> insert a temporary | |
71 | hw bp. | |
72 | -break-insert -r <regexp> --> insert a bp at functions matching | |
73 | <regexp> */ | |
74 | ||
75 | enum mi_cmd_result | |
76 | mi_cmd_break_insert (char *command, char **argv, int argc) | |
77 | { | |
78 | char *address = NULL; | |
79 | enum bp_type type = REG_BP; | |
80 | int temp_p = 0; | |
81 | int thread = -1; | |
82 | int ignore_count = 0; | |
83 | char *condition = NULL; | |
84 | enum gdb_rc rc; | |
85 | struct gdb_events *old_hooks; | |
86 | enum opt | |
87 | { | |
88 | HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT, | |
89 | IGNORE_COUNT_OPT, THREAD_OPT | |
90 | }; | |
91 | static struct mi_opt opts[] = | |
92 | { | |
93 | {"h", HARDWARE_OPT, 0}, | |
94 | {"t", TEMP_OPT, 0}, | |
95 | {"c", CONDITION_OPT, 1}, | |
96 | {"i", IGNORE_COUNT_OPT, 1}, | |
97 | {"p", THREAD_OPT, 1}, | |
98 | 0 | |
99 | }; | |
100 | ||
101 | /* Parse arguments. It could be -r or -h or -t, <location> or ``--'' | |
102 | to denote the end of the option list. */ | |
103 | int optind = 0; | |
104 | char *optarg; | |
105 | while (1) | |
106 | { | |
107 | int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg); | |
108 | if (opt < 0) | |
109 | break; | |
110 | switch ((enum opt) opt) | |
111 | { | |
112 | case TEMP_OPT: | |
113 | temp_p = 1; | |
114 | break; | |
115 | case HARDWARE_OPT: | |
116 | type = HW_BP; | |
117 | break; | |
118 | #if 0 | |
119 | case REGEXP_OPT: | |
120 | type = REGEXP_BP; | |
121 | break; | |
122 | #endif | |
123 | case CONDITION_OPT: | |
124 | condition = optarg; | |
125 | break; | |
126 | case IGNORE_COUNT_OPT: | |
127 | ignore_count = atol (optarg); | |
128 | break; | |
129 | case THREAD_OPT: | |
130 | thread = atol (optarg); | |
131 | break; | |
132 | } | |
133 | } | |
134 | ||
135 | if (optind >= argc) | |
136 | error ("mi_cmd_break_insert: Missing <location>"); | |
137 | if (optind < argc - 1) | |
138 | error ("mi_cmd_break_insert: Garbage following <location>"); | |
139 | address = argv[optind]; | |
140 | ||
141 | /* Now we have what we need, let's insert the breakpoint! */ | |
142 | old_hooks = set_gdb_event_hooks (&breakpoint_hooks); | |
143 | switch (type) | |
144 | { | |
145 | case REG_BP: | |
146 | rc = gdb_breakpoint (address, condition, | |
147 | 0 /*hardwareflag */ , temp_p, | |
148 | thread, ignore_count); | |
149 | break; | |
150 | case HW_BP: | |
151 | rc = gdb_breakpoint (address, condition, | |
152 | 1 /*hardwareflag */ , temp_p, | |
153 | thread, ignore_count); | |
154 | break; | |
155 | #if 0 | |
156 | case REGEXP_BP: | |
157 | if (temp_p) | |
158 | error ("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint"); | |
159 | else | |
160 | rbreak_command_wrapper (address, FROM_TTY); | |
161 | return MI_CMD_DONE; | |
162 | break; | |
163 | #endif | |
164 | default: | |
8e65ff28 AC |
165 | internal_error (__FILE__, __LINE__, |
166 | "mi_cmd_break_insert: Bad switch."); | |
fb40c209 AC |
167 | } |
168 | set_gdb_event_hooks (old_hooks); | |
169 | ||
170 | if (rc == GDB_RC_FAIL) | |
171 | return MI_CMD_CAUGHT_ERROR; | |
172 | else | |
173 | return MI_CMD_DONE; | |
174 | } | |
175 | ||
176 | enum wp_type | |
177 | { | |
178 | REG_WP, | |
179 | READ_WP, | |
180 | ACCESS_WP | |
181 | }; | |
182 | ||
183 | /* Insert a watchpoint. The type of watchpoint is specified by the | |
184 | first argument: | |
185 | -break-watch <expr> --> insert a regular wp. | |
186 | -break-watch -r <expr> --> insert a read watchpoint. | |
187 | -break-watch -a <expr> --> insert an access wp. */ | |
188 | ||
189 | enum mi_cmd_result | |
190 | mi_cmd_break_watch (char *command, char **argv, int argc) | |
191 | { | |
192 | char *expr = NULL; | |
193 | enum wp_type type = REG_WP; | |
194 | enum opt | |
195 | { | |
196 | READ_OPT, ACCESS_OPT | |
197 | }; | |
198 | static struct mi_opt opts[] = | |
199 | { | |
200 | {"r", READ_OPT, 0}, | |
201 | {"a", ACCESS_OPT, 0}, | |
202 | 0 | |
203 | }; | |
204 | ||
205 | /* Parse arguments. */ | |
206 | int optind = 0; | |
207 | char *optarg; | |
208 | while (1) | |
209 | { | |
210 | int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg); | |
211 | if (opt < 0) | |
212 | break; | |
213 | switch ((enum opt) opt) | |
214 | { | |
215 | case READ_OPT: | |
216 | type = READ_WP; | |
217 | break; | |
218 | case ACCESS_OPT: | |
219 | type = ACCESS_WP; | |
220 | break; | |
221 | } | |
222 | } | |
223 | if (optind >= argc) | |
224 | error ("mi_cmd_break_watch: Missing <expression>"); | |
225 | if (optind < argc - 1) | |
226 | error ("mi_cmd_break_watch: Garbage following <expression>"); | |
227 | expr = argv[optind]; | |
228 | ||
229 | /* Now we have what we need, let's insert the watchpoint! */ | |
230 | switch (type) | |
231 | { | |
232 | case REG_WP: | |
fb40c209 | 233 | watch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
234 | break; |
235 | case READ_WP: | |
fb40c209 | 236 | rwatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
237 | break; |
238 | case ACCESS_WP: | |
fb40c209 | 239 | awatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
240 | break; |
241 | default: | |
242 | error ("mi_cmd_break_watch: Unknown watchpoint type."); | |
243 | } | |
244 | return MI_CMD_DONE; | |
245 | } |