]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/mi/mi-cmd-catch.c
fix "tkill" check
[thirdparty/binutils-gdb.git] / gdb / mi / mi-cmd-catch.c
CommitLineData
91985142 1/* MI Command Set - catch commands.
28e7fd62 2 Copyright (C) 2012-2013 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"
25#include "libiberty.h"
349774ef 26#include "ada-lang.h"
91985142
MG
27#include "mi-cmds.h"
28#include "mi-getopt.h"
29#include "mi-cmd-break.h"
30
349774ef
JB
31/* Handler for the -catch-assert command. */
32
33void
34mi_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 (gdbarch, ada_catch_assert,
85 NULL, condition, temp, enabled, 0);
86}
87
88/* Handler for the -catch-exception command. */
89
90void
91mi_cmd_catch_exception (char *cmd, char *argv[], int argc)
92{
93 struct gdbarch *gdbarch = get_current_arch();
94 char *condition = NULL;
95 int enabled = 1;
96 char *exception_name = NULL;
97 int temp = 0;
98 enum ada_exception_catchpoint_kind ex_kind = ada_catch_exception;
99
100 int oind = 0;
101 char *oarg;
102
103 enum opt
104 {
105 OPT_CONDITION, OPT_DISABLED, OPT_EXCEPTION_NAME, OPT_TEMP,
106 OPT_UNHANDLED,
107 };
108 static const struct mi_opt opts[] =
109 {
110 { "c", OPT_CONDITION, 1},
111 { "d", OPT_DISABLED, 0 },
112 { "e", OPT_EXCEPTION_NAME, 1 },
113 { "t", OPT_TEMP, 0 },
114 { "u", OPT_UNHANDLED, 0},
115 { 0, 0, 0 }
116 };
117
118 for (;;)
119 {
120 int opt = mi_getopt ("-catch-exception", argc, argv, opts,
121 &oind, &oarg);
122
123 if (opt < 0)
124 break;
125
126 switch ((enum opt) opt)
127 {
128 case OPT_CONDITION:
129 condition = oarg;
130 break;
131 case OPT_DISABLED:
132 enabled = 0;
133 break;
134 case OPT_EXCEPTION_NAME:
135 exception_name = oarg;
136 break;
137 case OPT_TEMP:
138 temp = 1;
139 break;
140 case OPT_UNHANDLED:
141 ex_kind = ada_catch_exception_unhandled;
142 break;
143 }
144 }
145
146 /* This command does not accept any argument. Make sure the user
147 did not provide any. */
148 if (oind != argc)
149 error (_("Invalid argument: %s"), argv[oind]);
150
151 /* Specifying an exception name does not make sense when requesting
152 an unhandled exception breakpoint. */
153 if (ex_kind == ada_catch_exception_unhandled && exception_name != NULL)
154 error (_("\"-e\" and \"-u\" are mutually exclusive"));
155
156 setup_breakpoint_reporting ();
157 create_ada_exception_catchpoint (gdbarch, ex_kind,
158 exception_name, condition,
159 temp, enabled, 0);
160}
91985142
MG
161
162/* Common path for the -catch-load and -catch-unload. */
163
164static void
165mi_catch_load_unload (int load, char *argv[], int argc)
166{
91985142
MG
167 struct cleanup *back_to;
168 const char *actual_cmd = load ? "-catch-load" : "-catch-unload";
169 int temp = 0;
170 int enabled = 1;
171 int oind = 0;
172 char *oarg;
173 enum opt
174 {
175 OPT_TEMP,
176 OPT_DISABLED,
177 };
178 static const struct mi_opt opts[] =
179 {
180 { "t", OPT_TEMP, 0 },
181 { "d", OPT_DISABLED, 0 },
182 { 0, 0, 0 }
183 };
184
185 for (;;)
186 {
187 int opt = mi_getopt (actual_cmd, argc, argv, opts,
188 &oind, &oarg);
189
190 if (opt < 0)
191 break;
192
193 switch ((enum opt) opt)
194 {
195 case OPT_TEMP:
196 temp = 1;
197 break;
198 case OPT_DISABLED:
199 enabled = 0;
200 break;
201 }
202 }
203
204 if (oind >= argc)
205 error (_("-catch-load/unload: Missing <library name>"));
206 if (oind < argc -1)
207 error (_("-catch-load/unload: Garbage following the <library name>"));
208
209 back_to = setup_breakpoint_reporting ();
210
211 add_solib_catchpoint (argv[oind], load, temp, enabled);
212
213 do_cleanups (back_to);
214}
215
216/* Handler for the -catch-load. */
217
218void
219mi_cmd_catch_load (char *cmd, char *argv[], int argc)
220{
221 mi_catch_load_unload (1, argv, argc);
222}
223
224
225/* Handler for the -catch-unload. */
226
227void
228mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
229{
230 mi_catch_load_unload (0, argv, argc);
231}
232