Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - breakpoint and watchpoint commands. |
6aba47ca | 2 | Copyright (C) 2000, 2001, 2002, 2007 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" |
fb40c209 | 29 | |
fb40c209 AC |
30 | enum |
31 | { | |
32 | FROM_TTY = 0 | |
33 | }; | |
34 | ||
35 | /* Output a single breakpoint. */ | |
36 | ||
37 | static void | |
38 | breakpoint_notify (int b) | |
39 | { | |
ce43223b | 40 | gdb_breakpoint_query (uiout, b, NULL); |
fb40c209 AC |
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 | /* Insert a breakpoint. The type of breakpoint is specified by the | |
60 | first argument: -break-insert <location> --> insert a regular | |
61 | breakpoint. -break-insert -t <location> --> insert a temporary | |
62 | breakpoint. -break-insert -h <location> --> insert an hardware | |
63 | breakpoint. -break-insert -t -h <location> --> insert a temporary | |
64 | hw bp. | |
65 | -break-insert -r <regexp> --> insert a bp at functions matching | |
66 | <regexp> */ | |
67 | ||
68 | enum mi_cmd_result | |
69 | mi_cmd_break_insert (char *command, char **argv, int argc) | |
70 | { | |
71 | char *address = NULL; | |
72 | enum bp_type type = REG_BP; | |
73 | int temp_p = 0; | |
74 | int thread = -1; | |
75 | int ignore_count = 0; | |
76 | char *condition = NULL; | |
77 | enum gdb_rc rc; | |
78 | struct gdb_events *old_hooks; | |
79 | enum opt | |
80 | { | |
81 | HARDWARE_OPT, TEMP_OPT /*, REGEXP_OPT */ , CONDITION_OPT, | |
82 | IGNORE_COUNT_OPT, THREAD_OPT | |
83 | }; | |
84 | static struct mi_opt opts[] = | |
85 | { | |
86 | {"h", HARDWARE_OPT, 0}, | |
87 | {"t", TEMP_OPT, 0}, | |
88 | {"c", CONDITION_OPT, 1}, | |
89 | {"i", IGNORE_COUNT_OPT, 1}, | |
90 | {"p", THREAD_OPT, 1}, | |
d5d6fca5 | 91 | { 0, 0, 0 } |
fb40c209 AC |
92 | }; |
93 | ||
94 | /* Parse arguments. It could be -r or -h or -t, <location> or ``--'' | |
95 | to denote the end of the option list. */ | |
96 | int optind = 0; | |
97 | char *optarg; | |
98 | while (1) | |
99 | { | |
100 | int opt = mi_getopt ("mi_cmd_break_insert", argc, argv, opts, &optind, &optarg); | |
101 | if (opt < 0) | |
102 | break; | |
103 | switch ((enum opt) opt) | |
104 | { | |
105 | case TEMP_OPT: | |
106 | temp_p = 1; | |
107 | break; | |
108 | case HARDWARE_OPT: | |
109 | type = HW_BP; | |
110 | break; | |
111 | #if 0 | |
112 | case REGEXP_OPT: | |
113 | type = REGEXP_BP; | |
114 | break; | |
115 | #endif | |
116 | case CONDITION_OPT: | |
117 | condition = optarg; | |
118 | break; | |
119 | case IGNORE_COUNT_OPT: | |
120 | ignore_count = atol (optarg); | |
121 | break; | |
122 | case THREAD_OPT: | |
123 | thread = atol (optarg); | |
124 | break; | |
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); |
fb40c209 AC |
136 | switch (type) |
137 | { | |
138 | case REG_BP: | |
139 | rc = gdb_breakpoint (address, condition, | |
140 | 0 /*hardwareflag */ , temp_p, | |
ce43223b AC |
141 | thread, ignore_count, |
142 | &mi_error_message); | |
fb40c209 AC |
143 | break; |
144 | case HW_BP: | |
145 | rc = gdb_breakpoint (address, condition, | |
146 | 1 /*hardwareflag */ , temp_p, | |
ce43223b AC |
147 | thread, ignore_count, |
148 | &mi_error_message); | |
fb40c209 AC |
149 | break; |
150 | #if 0 | |
151 | case REGEXP_BP: | |
152 | if (temp_p) | |
8a3fe4f8 | 153 | error (_("mi_cmd_break_insert: Unsupported tempoary regexp breakpoint")); |
fb40c209 AC |
154 | else |
155 | rbreak_command_wrapper (address, FROM_TTY); | |
156 | return MI_CMD_DONE; | |
157 | break; | |
158 | #endif | |
159 | default: | |
8e65ff28 | 160 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 161 | _("mi_cmd_break_insert: Bad switch.")); |
fb40c209 | 162 | } |
2726dafc | 163 | deprecated_set_gdb_event_hooks (old_hooks); |
fb40c209 AC |
164 | |
165 | if (rc == GDB_RC_FAIL) | |
ce43223b | 166 | return MI_CMD_ERROR; |
fb40c209 AC |
167 | else |
168 | return MI_CMD_DONE; | |
169 | } | |
170 | ||
171 | enum wp_type | |
172 | { | |
173 | REG_WP, | |
174 | READ_WP, | |
175 | ACCESS_WP | |
176 | }; | |
177 | ||
178 | /* Insert a watchpoint. The type of watchpoint is specified by the | |
179 | first argument: | |
180 | -break-watch <expr> --> insert a regular wp. | |
181 | -break-watch -r <expr> --> insert a read watchpoint. | |
182 | -break-watch -a <expr> --> insert an access wp. */ | |
183 | ||
184 | enum mi_cmd_result | |
185 | mi_cmd_break_watch (char *command, char **argv, int argc) | |
186 | { | |
187 | char *expr = NULL; | |
188 | enum wp_type type = REG_WP; | |
189 | enum opt | |
190 | { | |
191 | READ_OPT, ACCESS_OPT | |
192 | }; | |
193 | static struct mi_opt opts[] = | |
194 | { | |
195 | {"r", READ_OPT, 0}, | |
196 | {"a", ACCESS_OPT, 0}, | |
d5d6fca5 | 197 | { 0, 0, 0 } |
fb40c209 AC |
198 | }; |
199 | ||
200 | /* Parse arguments. */ | |
201 | int optind = 0; | |
202 | char *optarg; | |
203 | while (1) | |
204 | { | |
205 | int opt = mi_getopt ("mi_cmd_break_watch", argc, argv, opts, &optind, &optarg); | |
206 | if (opt < 0) | |
207 | break; | |
208 | switch ((enum opt) opt) | |
209 | { | |
210 | case READ_OPT: | |
211 | type = READ_WP; | |
212 | break; | |
213 | case ACCESS_OPT: | |
214 | type = ACCESS_WP; | |
215 | break; | |
216 | } | |
217 | } | |
218 | if (optind >= argc) | |
8a3fe4f8 | 219 | error (_("mi_cmd_break_watch: Missing <expression>")); |
fb40c209 | 220 | if (optind < argc - 1) |
8a3fe4f8 | 221 | error (_("mi_cmd_break_watch: Garbage following <expression>")); |
fb40c209 AC |
222 | expr = argv[optind]; |
223 | ||
224 | /* Now we have what we need, let's insert the watchpoint! */ | |
225 | switch (type) | |
226 | { | |
227 | case REG_WP: | |
fb40c209 | 228 | watch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
229 | break; |
230 | case READ_WP: | |
fb40c209 | 231 | rwatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
232 | break; |
233 | case ACCESS_WP: | |
fb40c209 | 234 | awatch_command_wrapper (expr, FROM_TTY); |
fb40c209 AC |
235 | break; |
236 | default: | |
8a3fe4f8 | 237 | error (_("mi_cmd_break_watch: Unknown watchpoint type.")); |
fb40c209 AC |
238 | } |
239 | return MI_CMD_DONE; | |
240 | } |