1 /* MI Command Set - catch commands.
2 Copyright (C) 2012-2018 Free Software Foundation, Inc.
4 Contributed by Intel Corporation.
6 This file is part of GDB.
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.
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.
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/>. */
22 #include "arch-utils.h"
23 #include "breakpoint.h"
26 #include "mi-getopt.h"
27 #include "mi-cmd-break.h"
29 /* Handler for the -catch-assert command. */
32 mi_cmd_catch_assert (const char *cmd
, char *argv
[], int argc
)
34 struct gdbarch
*gdbarch
= get_current_arch();
35 std::string condition
;
44 OPT_CONDITION
, OPT_DISABLED
, OPT_TEMP
,
46 static const struct mi_opt opts
[] =
48 { "c", OPT_CONDITION
, 1},
49 { "d", OPT_DISABLED
, 0 },
56 int opt
= mi_getopt ("-catch-assert", argc
, argv
, opts
,
62 switch ((enum opt
) opt
)
65 condition
.assign (oarg
);
76 /* This command does not accept any argument. Make sure the user
77 did not provide any. */
79 error (_("Invalid argument: %s"), argv
[oind
]);
81 scoped_restore restore_breakpoint_reporting
= setup_breakpoint_reporting ();
82 create_ada_exception_catchpoint (gdbarch
, ada_catch_assert
,
83 NULL
, condition
, temp
, enabled
, 0);
86 /* Handler for the -catch-exception command. */
89 mi_cmd_catch_exception (const char *cmd
, char *argv
[], int argc
)
91 struct gdbarch
*gdbarch
= get_current_arch();
92 std::string condition
;
94 char *exception_name
= NULL
;
96 enum ada_exception_catchpoint_kind ex_kind
= ada_catch_exception
;
103 OPT_CONDITION
, OPT_DISABLED
, OPT_EXCEPTION_NAME
, OPT_TEMP
,
106 static const struct mi_opt opts
[] =
108 { "c", OPT_CONDITION
, 1},
109 { "d", OPT_DISABLED
, 0 },
110 { "e", OPT_EXCEPTION_NAME
, 1 },
111 { "t", OPT_TEMP
, 0 },
112 { "u", OPT_UNHANDLED
, 0},
118 int opt
= mi_getopt ("-catch-exception", argc
, argv
, opts
,
124 switch ((enum opt
) opt
)
127 condition
.assign (oarg
);
132 case OPT_EXCEPTION_NAME
:
133 exception_name
= oarg
;
139 ex_kind
= ada_catch_exception_unhandled
;
144 /* This command does not accept any argument. Make sure the user
145 did not provide any. */
147 error (_("Invalid argument: %s"), argv
[oind
]);
149 /* Specifying an exception name does not make sense when requesting
150 an unhandled exception breakpoint. */
151 if (ex_kind
== ada_catch_exception_unhandled
&& exception_name
!= NULL
)
152 error (_("\"-e\" and \"-u\" are mutually exclusive"));
154 scoped_restore restore_breakpoint_reporting
= setup_breakpoint_reporting ();
155 /* create_ada_exception_catchpoint needs EXCEPTION_NAME to be
156 xstrdup'ed, and will assume control of its lifetime. */
157 if (exception_name
!= NULL
)
158 exception_name
= xstrdup (exception_name
);
159 create_ada_exception_catchpoint (gdbarch
, ex_kind
,
161 condition
, temp
, enabled
, 0);
164 /* Handler for the -catch-handlers command. */
167 mi_cmd_catch_handlers (const char *cmd
, char *argv
[], int argc
)
169 struct gdbarch
*gdbarch
= get_current_arch ();
170 std::string condition
;
172 char *exception_name
= NULL
;
180 OPT_CONDITION
, OPT_DISABLED
, OPT_EXCEPTION_NAME
, OPT_TEMP
182 static const struct mi_opt opts
[] =
184 { "c", OPT_CONDITION
, 1},
185 { "d", OPT_DISABLED
, 0 },
186 { "e", OPT_EXCEPTION_NAME
, 1 },
187 { "t", OPT_TEMP
, 0 },
193 int opt
= mi_getopt ("-catch-handlers", argc
, argv
, opts
,
199 switch ((enum opt
) opt
)
202 condition
.assign (oarg
);
207 case OPT_EXCEPTION_NAME
:
208 exception_name
= oarg
;
216 /* This command does not accept any argument. Make sure the user
217 did not provide any. */
219 error (_("Invalid argument: %s"), argv
[oind
]);
221 scoped_restore restore_breakpoint_reporting
222 = setup_breakpoint_reporting ();
223 /* create_ada_exception_catchpoint needs EXCEPTION_NAME to be
224 xstrdup'ed, and will assume control of its lifetime. */
225 if (exception_name
!= NULL
)
226 exception_name
= xstrdup (exception_name
);
227 create_ada_exception_catchpoint (gdbarch
, ada_catch_handlers
,
229 condition
, temp
, enabled
, 0);
232 /* Common path for the -catch-load and -catch-unload. */
235 mi_catch_load_unload (int load
, char *argv
[], int argc
)
237 const char *actual_cmd
= load
? "-catch-load" : "-catch-unload";
247 static const struct mi_opt opts
[] =
249 { "t", OPT_TEMP
, 0 },
250 { "d", OPT_DISABLED
, 0 },
256 int opt
= mi_getopt (actual_cmd
, argc
, argv
, opts
,
262 switch ((enum opt
) opt
)
274 error (_("-catch-load/unload: Missing <library name>"));
276 error (_("-catch-load/unload: Garbage following the <library name>"));
278 scoped_restore restore_breakpoint_reporting
= setup_breakpoint_reporting ();
279 add_solib_catchpoint (argv
[oind
], load
, temp
, enabled
);
282 /* Handler for the -catch-load. */
285 mi_cmd_catch_load (const char *cmd
, char *argv
[], int argc
)
287 mi_catch_load_unload (1, argv
, argc
);
291 /* Handler for the -catch-unload. */
294 mi_cmd_catch_unload (const char *cmd
, char *argv
[], int argc
)
296 mi_catch_load_unload (0, argv
, argc
);