GDB (API)
|
00001 /* MI Command Set - catch commands. 00002 Copyright (C) 2012-2013 Free Software Foundation, Inc. 00003 00004 Contributed by Intel Corporation. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 #include "arch-utils.h" 00023 #include "breakpoint.h" 00024 #include "gdb.h" 00025 #include "libiberty.h" 00026 #include "ada-lang.h" 00027 #include "mi-cmds.h" 00028 #include "mi-getopt.h" 00029 #include "mi-cmd-break.h" 00030 00031 /* Handler for the -catch-assert command. */ 00032 00033 void 00034 mi_cmd_catch_assert (char *cmd, char *argv[], int argc) 00035 { 00036 struct gdbarch *gdbarch = get_current_arch(); 00037 char *condition = NULL; 00038 int enabled = 1; 00039 int temp = 0; 00040 00041 int oind = 0; 00042 char *oarg; 00043 00044 enum opt 00045 { 00046 OPT_CONDITION, OPT_DISABLED, OPT_TEMP, 00047 }; 00048 static const struct mi_opt opts[] = 00049 { 00050 { "c", OPT_CONDITION, 1}, 00051 { "d", OPT_DISABLED, 0 }, 00052 { "t", OPT_TEMP, 0 }, 00053 { 0, 0, 0 } 00054 }; 00055 00056 for (;;) 00057 { 00058 int opt = mi_getopt ("-catch-assert", argc, argv, opts, 00059 &oind, &oarg); 00060 00061 if (opt < 0) 00062 break; 00063 00064 switch ((enum opt) opt) 00065 { 00066 case OPT_CONDITION: 00067 condition = oarg; 00068 break; 00069 case OPT_DISABLED: 00070 enabled = 0; 00071 break; 00072 case OPT_TEMP: 00073 temp = 1; 00074 break; 00075 } 00076 } 00077 00078 /* This command does not accept any argument. Make sure the user 00079 did not provide any. */ 00080 if (oind != argc) 00081 error (_("Invalid argument: %s"), argv[oind]); 00082 00083 setup_breakpoint_reporting (); 00084 create_ada_exception_catchpoint (gdbarch, ada_catch_assert, 00085 NULL, condition, temp, enabled, 0); 00086 } 00087 00088 /* Handler for the -catch-exception command. */ 00089 00090 void 00091 mi_cmd_catch_exception (char *cmd, char *argv[], int argc) 00092 { 00093 struct gdbarch *gdbarch = get_current_arch(); 00094 char *condition = NULL; 00095 int enabled = 1; 00096 char *exception_name = NULL; 00097 int temp = 0; 00098 enum ada_exception_catchpoint_kind ex_kind = ada_catch_exception; 00099 00100 int oind = 0; 00101 char *oarg; 00102 00103 enum opt 00104 { 00105 OPT_CONDITION, OPT_DISABLED, OPT_EXCEPTION_NAME, OPT_TEMP, 00106 OPT_UNHANDLED, 00107 }; 00108 static const struct mi_opt opts[] = 00109 { 00110 { "c", OPT_CONDITION, 1}, 00111 { "d", OPT_DISABLED, 0 }, 00112 { "e", OPT_EXCEPTION_NAME, 1 }, 00113 { "t", OPT_TEMP, 0 }, 00114 { "u", OPT_UNHANDLED, 0}, 00115 { 0, 0, 0 } 00116 }; 00117 00118 for (;;) 00119 { 00120 int opt = mi_getopt ("-catch-exception", argc, argv, opts, 00121 &oind, &oarg); 00122 00123 if (opt < 0) 00124 break; 00125 00126 switch ((enum opt) opt) 00127 { 00128 case OPT_CONDITION: 00129 condition = oarg; 00130 break; 00131 case OPT_DISABLED: 00132 enabled = 0; 00133 break; 00134 case OPT_EXCEPTION_NAME: 00135 exception_name = oarg; 00136 break; 00137 case OPT_TEMP: 00138 temp = 1; 00139 break; 00140 case OPT_UNHANDLED: 00141 ex_kind = ada_catch_exception_unhandled; 00142 break; 00143 } 00144 } 00145 00146 /* This command does not accept any argument. Make sure the user 00147 did not provide any. */ 00148 if (oind != argc) 00149 error (_("Invalid argument: %s"), argv[oind]); 00150 00151 /* Specifying an exception name does not make sense when requesting 00152 an unhandled exception breakpoint. */ 00153 if (ex_kind == ada_catch_exception_unhandled && exception_name != NULL) 00154 error (_("\"-e\" and \"-u\" are mutually exclusive")); 00155 00156 setup_breakpoint_reporting (); 00157 create_ada_exception_catchpoint (gdbarch, ex_kind, 00158 exception_name, condition, 00159 temp, enabled, 0); 00160 } 00161 00162 /* Common path for the -catch-load and -catch-unload. */ 00163 00164 static void 00165 mi_catch_load_unload (int load, char *argv[], int argc) 00166 { 00167 struct cleanup *back_to; 00168 const char *actual_cmd = load ? "-catch-load" : "-catch-unload"; 00169 int temp = 0; 00170 int enabled = 1; 00171 int oind = 0; 00172 char *oarg; 00173 enum opt 00174 { 00175 OPT_TEMP, 00176 OPT_DISABLED, 00177 }; 00178 static const struct mi_opt opts[] = 00179 { 00180 { "t", OPT_TEMP, 0 }, 00181 { "d", OPT_DISABLED, 0 }, 00182 { 0, 0, 0 } 00183 }; 00184 00185 for (;;) 00186 { 00187 int opt = mi_getopt (actual_cmd, argc, argv, opts, 00188 &oind, &oarg); 00189 00190 if (opt < 0) 00191 break; 00192 00193 switch ((enum opt) opt) 00194 { 00195 case OPT_TEMP: 00196 temp = 1; 00197 break; 00198 case OPT_DISABLED: 00199 enabled = 0; 00200 break; 00201 } 00202 } 00203 00204 if (oind >= argc) 00205 error (_("-catch-load/unload: Missing <library name>")); 00206 if (oind < argc -1) 00207 error (_("-catch-load/unload: Garbage following the <library name>")); 00208 00209 back_to = setup_breakpoint_reporting (); 00210 00211 add_solib_catchpoint (argv[oind], load, temp, enabled); 00212 00213 do_cleanups (back_to); 00214 } 00215 00216 /* Handler for the -catch-load. */ 00217 00218 void 00219 mi_cmd_catch_load (char *cmd, char *argv[], int argc) 00220 { 00221 mi_catch_load_unload (1, argv, argc); 00222 } 00223 00224 00225 /* Handler for the -catch-unload. */ 00226 00227 void 00228 mi_cmd_catch_unload (char *cmd, char *argv[], int argc) 00229 { 00230 mi_catch_load_unload (0, argv, argc); 00231 } 00232