Commit | Line | Data |
---|---|---|
91985142 | 1 | /* MI Command Set - catch commands. |
618f726f | 2 | Copyright (C) 2012-2016 Free Software Foundation, Inc. |
91985142 MG |
3 | |
4 | Contributed by Intel Corporation. | |
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 | |
10 | the Free Software Foundation; either version 3 of the License, or | |
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 | |
19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | #include "defs.h" | |
22 | #include "arch-utils.h" | |
23 | #include "breakpoint.h" | |
24 | #include "gdb.h" | |
349774ef | 25 | #include "ada-lang.h" |
91985142 MG |
26 | #include "mi-cmds.h" |
27 | #include "mi-getopt.h" | |
28 | #include "mi-cmd-break.h" | |
29 | ||
349774ef JB |
30 | /* Handler for the -catch-assert command. */ |
31 | ||
32 | void | |
33 | mi_cmd_catch_assert (char *cmd, char *argv[], int argc) | |
34 | { | |
35 | struct gdbarch *gdbarch = get_current_arch(); | |
36 | char *condition = NULL; | |
37 | int enabled = 1; | |
38 | int temp = 0; | |
39 | ||
40 | int oind = 0; | |
41 | char *oarg; | |
42 | ||
43 | enum opt | |
44 | { | |
45 | OPT_CONDITION, OPT_DISABLED, OPT_TEMP, | |
46 | }; | |
47 | static const struct mi_opt opts[] = | |
48 | { | |
49 | { "c", OPT_CONDITION, 1}, | |
50 | { "d", OPT_DISABLED, 0 }, | |
51 | { "t", OPT_TEMP, 0 }, | |
52 | { 0, 0, 0 } | |
53 | }; | |
54 | ||
55 | for (;;) | |
56 | { | |
57 | int opt = mi_getopt ("-catch-assert", argc, argv, opts, | |
58 | &oind, &oarg); | |
59 | ||
60 | if (opt < 0) | |
61 | break; | |
62 | ||
63 | switch ((enum opt) opt) | |
64 | { | |
65 | case OPT_CONDITION: | |
66 | condition = oarg; | |
67 | break; | |
68 | case OPT_DISABLED: | |
69 | enabled = 0; | |
70 | break; | |
71 | case OPT_TEMP: | |
72 | temp = 1; | |
73 | break; | |
74 | } | |
75 | } | |
76 | ||
77 | /* This command does not accept any argument. Make sure the user | |
78 | did not provide any. */ | |
79 | if (oind != argc) | |
80 | error (_("Invalid argument: %s"), argv[oind]); | |
81 | ||
82 | setup_breakpoint_reporting (); | |
2df4d1d5 JB |
83 | /* create_ada_exception_catchpoint needs CONDITION to be xstrdup'ed, |
84 | and will assume control of its lifetime. */ | |
85 | if (condition != NULL) | |
86 | condition = xstrdup (condition); | |
349774ef JB |
87 | create_ada_exception_catchpoint (gdbarch, ada_catch_assert, |
88 | NULL, condition, temp, enabled, 0); | |
89 | } | |
90 | ||
91 | /* Handler for the -catch-exception command. */ | |
92 | ||
93 | void | |
94 | mi_cmd_catch_exception (char *cmd, char *argv[], int argc) | |
95 | { | |
96 | struct gdbarch *gdbarch = get_current_arch(); | |
97 | char *condition = NULL; | |
98 | int enabled = 1; | |
99 | char *exception_name = NULL; | |
100 | int temp = 0; | |
101 | enum ada_exception_catchpoint_kind ex_kind = ada_catch_exception; | |
102 | ||
103 | int oind = 0; | |
104 | char *oarg; | |
105 | ||
106 | enum opt | |
107 | { | |
108 | OPT_CONDITION, OPT_DISABLED, OPT_EXCEPTION_NAME, OPT_TEMP, | |
109 | OPT_UNHANDLED, | |
110 | }; | |
111 | static const struct mi_opt opts[] = | |
112 | { | |
113 | { "c", OPT_CONDITION, 1}, | |
114 | { "d", OPT_DISABLED, 0 }, | |
115 | { "e", OPT_EXCEPTION_NAME, 1 }, | |
116 | { "t", OPT_TEMP, 0 }, | |
117 | { "u", OPT_UNHANDLED, 0}, | |
118 | { 0, 0, 0 } | |
119 | }; | |
120 | ||
121 | for (;;) | |
122 | { | |
123 | int opt = mi_getopt ("-catch-exception", argc, argv, opts, | |
124 | &oind, &oarg); | |
125 | ||
126 | if (opt < 0) | |
127 | break; | |
128 | ||
129 | switch ((enum opt) opt) | |
130 | { | |
131 | case OPT_CONDITION: | |
132 | condition = oarg; | |
133 | break; | |
134 | case OPT_DISABLED: | |
135 | enabled = 0; | |
136 | break; | |
137 | case OPT_EXCEPTION_NAME: | |
138 | exception_name = oarg; | |
139 | break; | |
140 | case OPT_TEMP: | |
141 | temp = 1; | |
142 | break; | |
143 | case OPT_UNHANDLED: | |
144 | ex_kind = ada_catch_exception_unhandled; | |
145 | break; | |
146 | } | |
147 | } | |
148 | ||
149 | /* This command does not accept any argument. Make sure the user | |
150 | did not provide any. */ | |
151 | if (oind != argc) | |
152 | error (_("Invalid argument: %s"), argv[oind]); | |
153 | ||
154 | /* Specifying an exception name does not make sense when requesting | |
155 | an unhandled exception breakpoint. */ | |
156 | if (ex_kind == ada_catch_exception_unhandled && exception_name != NULL) | |
157 | error (_("\"-e\" and \"-u\" are mutually exclusive")); | |
158 | ||
159 | setup_breakpoint_reporting (); | |
2df4d1d5 JB |
160 | /* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION |
161 | to be xstrdup'ed, and will assume control of their lifetime. */ | |
162 | if (exception_name != NULL) | |
163 | exception_name = xstrdup (exception_name); | |
164 | if (condition != NULL) | |
165 | condition = xstrdup (condition); | |
349774ef JB |
166 | create_ada_exception_catchpoint (gdbarch, ex_kind, |
167 | exception_name, condition, | |
168 | temp, enabled, 0); | |
169 | } | |
91985142 MG |
170 | |
171 | /* Common path for the -catch-load and -catch-unload. */ | |
172 | ||
173 | static void | |
174 | mi_catch_load_unload (int load, char *argv[], int argc) | |
175 | { | |
91985142 MG |
176 | struct cleanup *back_to; |
177 | const char *actual_cmd = load ? "-catch-load" : "-catch-unload"; | |
178 | int temp = 0; | |
179 | int enabled = 1; | |
180 | int oind = 0; | |
181 | char *oarg; | |
182 | enum opt | |
183 | { | |
184 | OPT_TEMP, | |
185 | OPT_DISABLED, | |
186 | }; | |
187 | static const struct mi_opt opts[] = | |
188 | { | |
189 | { "t", OPT_TEMP, 0 }, | |
190 | { "d", OPT_DISABLED, 0 }, | |
191 | { 0, 0, 0 } | |
192 | }; | |
193 | ||
194 | for (;;) | |
195 | { | |
196 | int opt = mi_getopt (actual_cmd, argc, argv, opts, | |
197 | &oind, &oarg); | |
198 | ||
199 | if (opt < 0) | |
200 | break; | |
201 | ||
202 | switch ((enum opt) opt) | |
203 | { | |
204 | case OPT_TEMP: | |
205 | temp = 1; | |
206 | break; | |
207 | case OPT_DISABLED: | |
208 | enabled = 0; | |
209 | break; | |
210 | } | |
211 | } | |
212 | ||
213 | if (oind >= argc) | |
214 | error (_("-catch-load/unload: Missing <library name>")); | |
215 | if (oind < argc -1) | |
216 | error (_("-catch-load/unload: Garbage following the <library name>")); | |
217 | ||
218 | back_to = setup_breakpoint_reporting (); | |
219 | ||
220 | add_solib_catchpoint (argv[oind], load, temp, enabled); | |
221 | ||
222 | do_cleanups (back_to); | |
223 | } | |
224 | ||
225 | /* Handler for the -catch-load. */ | |
226 | ||
227 | void | |
228 | mi_cmd_catch_load (char *cmd, char *argv[], int argc) | |
229 | { | |
230 | mi_catch_load_unload (1, argv, argc); | |
231 | } | |
232 | ||
233 | ||
234 | /* Handler for the -catch-unload. */ | |
235 | ||
236 | void | |
237 | mi_cmd_catch_unload (char *cmd, char *argv[], int argc) | |
238 | { | |
239 | mi_catch_load_unload (0, argv, argc); | |
240 | } | |
241 |