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