1 /* MI Command Set - catch commands.
2 Copyright (C) 2012-2017 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"
27 #include "mi-getopt.h"
28 #include "mi-cmd-break.h"
30 /* Handler for the -catch-assert command. */
33 mi_cmd_catch_assert (const char *cmd, char *argv[], int argc)
35 struct gdbarch *gdbarch = get_current_arch();
36 char *condition = NULL;
45 OPT_CONDITION, OPT_DISABLED, OPT_TEMP,
47 static const struct mi_opt opts[] =
49 { "c", OPT_CONDITION, 1},
50 { "d", OPT_DISABLED, 0 },
57 int opt = mi_getopt ("-catch-assert", argc, argv, opts,
63 switch ((enum opt) opt)
77 /* This command does not accept any argument. Make sure the user
78 did not provide any. */
80 error (_("Invalid argument: %s"), argv[oind]);
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);
91 /* Handler for the -catch-exception command. */
94 mi_cmd_catch_exception (const char *cmd, char *argv[], int argc)
96 struct gdbarch *gdbarch = get_current_arch();
97 char *condition = NULL;
99 char *exception_name = NULL;
101 enum ada_exception_catchpoint_kind ex_kind = ada_catch_exception;
108 OPT_CONDITION, OPT_DISABLED, OPT_EXCEPTION_NAME, OPT_TEMP,
111 static const struct mi_opt opts[] =
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},
123 int opt = mi_getopt ("-catch-exception", argc, argv, opts,
129 switch ((enum opt) opt)
137 case OPT_EXCEPTION_NAME:
138 exception_name = oarg;
144 ex_kind = ada_catch_exception_unhandled;
149 /* This command does not accept any argument. Make sure the user
150 did not provide any. */
152 error (_("Invalid argument: %s"), argv[oind]);
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"));
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,
171 /* Common path for the -catch-load and -catch-unload. */
174 mi_catch_load_unload (int load, char *argv[], int argc)
176 const char *actual_cmd = load ? "-catch-load" : "-catch-unload";
186 static const struct mi_opt opts[] =
188 { "t", OPT_TEMP, 0 },
189 { "d", OPT_DISABLED, 0 },
195 int opt = mi_getopt (actual_cmd, argc, argv, opts,
201 switch ((enum opt) opt)
213 error (_("-catch-load/unload: Missing <library name>"));
215 error (_("-catch-load/unload: Garbage following the <library name>"));
217 scoped_restore restore_breakpoint_reporting = setup_breakpoint_reporting ();
218 add_solib_catchpoint (argv[oind], load, temp, enabled);
221 /* Handler for the -catch-load. */
224 mi_cmd_catch_load (const char *cmd, char *argv[], int argc)
226 mi_catch_load_unload (1, argv, argc);
230 /* Handler for the -catch-unload. */
233 mi_cmd_catch_unload (const char *cmd, char *argv[], int argc)
235 mi_catch_load_unload (0, argv, argc);