Remove cleanups from mi_cmd_break_insert_1
[deliverable/binutils-gdb.git] / gdb / mi / mi-cmd-catch.c
1 /* MI Command Set - catch commands.
2 Copyright (C) 2012-2017 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 "ada-lang.h"
26 #include "mi-cmds.h"
27 #include "mi-getopt.h"
28 #include "mi-cmd-break.h"
29
30 /* Handler for the -catch-assert command. */
31
32 void
33 mi_cmd_catch_assert (const 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 scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
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);
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 (const 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 scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
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);
166 create_ada_exception_catchpoint (gdbarch, ex_kind,
167 exception_name, condition,
168 temp, enabled, 0);
169 }
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 {
176 const char *actual_cmd = load ? "-catch-load" : "-catch-unload";
177 int temp = 0;
178 int enabled = 1;
179 int oind = 0;
180 char *oarg;
181 enum opt
182 {
183 OPT_TEMP,
184 OPT_DISABLED,
185 };
186 static const struct mi_opt opts[] =
187 {
188 { "t", OPT_TEMP, 0 },
189 { "d", OPT_DISABLED, 0 },
190 { 0, 0, 0 }
191 };
192
193 for (;;)
194 {
195 int opt = mi_getopt (actual_cmd, argc, argv, opts,
196 &oind, &oarg);
197
198 if (opt < 0)
199 break;
200
201 switch ((enum opt) opt)
202 {
203 case OPT_TEMP:
204 temp = 1;
205 break;
206 case OPT_DISABLED:
207 enabled = 0;
208 break;
209 }
210 }
211
212 if (oind >= argc)
213 error (_("-catch-load/unload: Missing <library name>"));
214 if (oind < argc -1)
215 error (_("-catch-load/unload: Garbage following the <library name>"));
216
217 scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
218 add_solib_catchpoint (argv[oind], load, temp, enabled);
219 }
220
221 /* Handler for the -catch-load. */
222
223 void
224 mi_cmd_catch_load (const char *cmd, char *argv[], int argc)
225 {
226 mi_catch_load_unload (1, argv, argc);
227 }
228
229
230 /* Handler for the -catch-unload. */
231
232 void
233 mi_cmd_catch_unload (const char *cmd, char *argv[], int argc)
234 {
235 mi_catch_load_unload (0, argv, argc);
236 }
237
This page took 0.059346 seconds and 4 git commands to generate.