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