xref: /dflybsd-src/contrib/gdb-7/gdb/mi/mi-cmd-catch.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
1*ef5ccd6cSJohn Marino /* MI Command Set - catch commands.
2*ef5ccd6cSJohn Marino    Copyright (C) 2012-2013 Free Software Foundation, Inc.
3*ef5ccd6cSJohn Marino 
4*ef5ccd6cSJohn Marino    Contributed by Intel Corporation.
5*ef5ccd6cSJohn Marino 
6*ef5ccd6cSJohn Marino    This file is part of GDB.
7*ef5ccd6cSJohn Marino 
8*ef5ccd6cSJohn Marino    This program is free software; you can redistribute it and/or modify
9*ef5ccd6cSJohn Marino    it under the terms of the GNU General Public License as published by
10*ef5ccd6cSJohn Marino    the Free Software Foundation; either version 3 of the License, or
11*ef5ccd6cSJohn Marino    (at your option) any later version.
12*ef5ccd6cSJohn Marino 
13*ef5ccd6cSJohn Marino    This program is distributed in the hope that it will be useful,
14*ef5ccd6cSJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
15*ef5ccd6cSJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*ef5ccd6cSJohn Marino    GNU General Public License for more details.
17*ef5ccd6cSJohn Marino 
18*ef5ccd6cSJohn Marino    You should have received a copy of the GNU General Public License
19*ef5ccd6cSJohn Marino    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20*ef5ccd6cSJohn Marino 
21*ef5ccd6cSJohn Marino #include "defs.h"
22*ef5ccd6cSJohn Marino #include "arch-utils.h"
23*ef5ccd6cSJohn Marino #include "breakpoint.h"
24*ef5ccd6cSJohn Marino #include "gdb.h"
25*ef5ccd6cSJohn Marino #include "libiberty.h"
26*ef5ccd6cSJohn Marino #include "mi-cmds.h"
27*ef5ccd6cSJohn Marino #include "mi-getopt.h"
28*ef5ccd6cSJohn Marino #include "mi-cmd-break.h"
29*ef5ccd6cSJohn Marino 
30*ef5ccd6cSJohn Marino 
31*ef5ccd6cSJohn Marino /* Common path for the -catch-load and -catch-unload.  */
32*ef5ccd6cSJohn Marino 
33*ef5ccd6cSJohn Marino static void
mi_catch_load_unload(int load,char * argv[],int argc)34*ef5ccd6cSJohn Marino mi_catch_load_unload (int load, char *argv[], int argc)
35*ef5ccd6cSJohn Marino {
36*ef5ccd6cSJohn Marino   struct cleanup *back_to;
37*ef5ccd6cSJohn Marino   const char *actual_cmd = load ? "-catch-load" : "-catch-unload";
38*ef5ccd6cSJohn Marino   int temp = 0;
39*ef5ccd6cSJohn Marino   int enabled = 1;
40*ef5ccd6cSJohn Marino   int oind = 0;
41*ef5ccd6cSJohn Marino   char *oarg;
42*ef5ccd6cSJohn Marino   enum opt
43*ef5ccd6cSJohn Marino     {
44*ef5ccd6cSJohn Marino       OPT_TEMP,
45*ef5ccd6cSJohn Marino       OPT_DISABLED,
46*ef5ccd6cSJohn Marino     };
47*ef5ccd6cSJohn Marino   static const struct mi_opt opts[] =
48*ef5ccd6cSJohn Marino     {
49*ef5ccd6cSJohn Marino       { "t", OPT_TEMP, 0 },
50*ef5ccd6cSJohn Marino       { "d", OPT_DISABLED, 0 },
51*ef5ccd6cSJohn Marino       { 0, 0, 0 }
52*ef5ccd6cSJohn Marino     };
53*ef5ccd6cSJohn Marino 
54*ef5ccd6cSJohn Marino   for (;;)
55*ef5ccd6cSJohn Marino     {
56*ef5ccd6cSJohn Marino       int opt = mi_getopt (actual_cmd, argc, argv, opts,
57*ef5ccd6cSJohn Marino                            &oind, &oarg);
58*ef5ccd6cSJohn Marino 
59*ef5ccd6cSJohn Marino       if (opt < 0)
60*ef5ccd6cSJohn Marino         break;
61*ef5ccd6cSJohn Marino 
62*ef5ccd6cSJohn Marino       switch ((enum opt) opt)
63*ef5ccd6cSJohn Marino         {
64*ef5ccd6cSJohn Marino         case OPT_TEMP:
65*ef5ccd6cSJohn Marino           temp = 1;
66*ef5ccd6cSJohn Marino           break;
67*ef5ccd6cSJohn Marino         case OPT_DISABLED:
68*ef5ccd6cSJohn Marino           enabled = 0;
69*ef5ccd6cSJohn Marino           break;
70*ef5ccd6cSJohn Marino         }
71*ef5ccd6cSJohn Marino     }
72*ef5ccd6cSJohn Marino 
73*ef5ccd6cSJohn Marino   if (oind >= argc)
74*ef5ccd6cSJohn Marino     error (_("-catch-load/unload: Missing <library name>"));
75*ef5ccd6cSJohn Marino   if (oind < argc -1)
76*ef5ccd6cSJohn Marino     error (_("-catch-load/unload: Garbage following the <library name>"));
77*ef5ccd6cSJohn Marino 
78*ef5ccd6cSJohn Marino   back_to = setup_breakpoint_reporting ();
79*ef5ccd6cSJohn Marino 
80*ef5ccd6cSJohn Marino   add_solib_catchpoint (argv[oind], load, temp, enabled);
81*ef5ccd6cSJohn Marino 
82*ef5ccd6cSJohn Marino   do_cleanups (back_to);
83*ef5ccd6cSJohn Marino }
84*ef5ccd6cSJohn Marino 
85*ef5ccd6cSJohn Marino /* Handler for the -catch-load.  */
86*ef5ccd6cSJohn Marino 
87*ef5ccd6cSJohn Marino void
mi_cmd_catch_load(char * cmd,char * argv[],int argc)88*ef5ccd6cSJohn Marino mi_cmd_catch_load (char *cmd, char *argv[], int argc)
89*ef5ccd6cSJohn Marino {
90*ef5ccd6cSJohn Marino   mi_catch_load_unload (1, argv, argc);
91*ef5ccd6cSJohn Marino }
92*ef5ccd6cSJohn Marino 
93*ef5ccd6cSJohn Marino 
94*ef5ccd6cSJohn Marino /* Handler for the -catch-unload.  */
95*ef5ccd6cSJohn Marino 
96*ef5ccd6cSJohn Marino void
mi_cmd_catch_unload(char * cmd,char * argv[],int argc)97*ef5ccd6cSJohn Marino mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
98*ef5ccd6cSJohn Marino {
99*ef5ccd6cSJohn Marino   mi_catch_load_unload (0, argv, argc);
100*ef5ccd6cSJohn Marino }
101*ef5ccd6cSJohn Marino 
102