gdb/mi/mi-cmd-catch.c - gdb

Functions defined

Source code

  1. /* MI Command Set - catch commands.
  2.    Copyright (C) 2012-2015 Free Software Foundation, Inc.

  3.    Contributed by Intel Corporation.

  4.    This file is part of GDB.

  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 3 of the License, or
  8.    (at your option) any later version.

  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.

  13.    You should have received a copy of the GNU General Public License
  14.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  15. #include "defs.h"
  16. #include "arch-utils.h"
  17. #include "breakpoint.h"
  18. #include "gdb.h"
  19. #include "ada-lang.h"
  20. #include "mi-cmds.h"
  21. #include "mi-getopt.h"
  22. #include "mi-cmd-break.h"

  23. /* Handler for the -catch-assert command.  */

  24. void
  25. mi_cmd_catch_assert (char *cmd, char *argv[], int argc)
  26. {
  27.   struct gdbarch *gdbarch = get_current_arch();
  28.   char *condition = NULL;
  29.   int enabled = 1;
  30.   int temp = 0;

  31.   int oind = 0;
  32.   char *oarg;

  33.   enum opt
  34.     {
  35.       OPT_CONDITION, OPT_DISABLED, OPT_TEMP,
  36.     };
  37.   static const struct mi_opt opts[] =
  38.     {
  39.       { "c", OPT_CONDITION, 1},
  40.       { "d", OPT_DISABLED, 0 },
  41.       { "t", OPT_TEMP, 0 },
  42.       { 0, 0, 0 }
  43.     };

  44.   for (;;)
  45.     {
  46.       int opt = mi_getopt ("-catch-assert", argc, argv, opts,
  47.                            &oind, &oarg);

  48.       if (opt < 0)
  49.         break;

  50.       switch ((enum opt) opt)
  51.         {
  52.         case OPT_CONDITION:
  53.           condition = oarg;
  54.           break;
  55.         case OPT_DISABLED:
  56.           enabled = 0;
  57.           break;
  58.         case OPT_TEMP:
  59.           temp = 1;
  60.           break;
  61.         }
  62.     }

  63.   /* This command does not accept any argument.  Make sure the user
  64.      did not provide any.  */
  65.   if (oind != argc)
  66.     error (_("Invalid argument: %s"), argv[oind]);

  67.   setup_breakpoint_reporting ();
  68.   /* create_ada_exception_catchpoint needs CONDITION to be xstrdup'ed,
  69.      and will assume control of its lifetime.  */
  70.   if (condition != NULL)
  71.     condition = xstrdup (condition);
  72.   create_ada_exception_catchpoint (gdbarch, ada_catch_assert,
  73.                                    NULL, condition, temp, enabled, 0);
  74. }

  75. /* Handler for the -catch-exception command.  */

  76. void
  77. mi_cmd_catch_exception (char *cmd, char *argv[], int argc)
  78. {
  79.   struct gdbarch *gdbarch = get_current_arch();
  80.   char *condition = NULL;
  81.   int enabled = 1;
  82.   char *exception_name = NULL;
  83.   int temp = 0;
  84.   enum ada_exception_catchpoint_kind ex_kind = ada_catch_exception;

  85.   int oind = 0;
  86.   char *oarg;

  87.   enum opt
  88.     {
  89.       OPT_CONDITION, OPT_DISABLED, OPT_EXCEPTION_NAME, OPT_TEMP,
  90.       OPT_UNHANDLED,
  91.     };
  92.   static const struct mi_opt opts[] =
  93.     {
  94.       { "c", OPT_CONDITION, 1},
  95.       { "d", OPT_DISABLED, 0 },
  96.       { "e", OPT_EXCEPTION_NAME, 1 },
  97.       { "t", OPT_TEMP, 0 },
  98.       { "u", OPT_UNHANDLED, 0},
  99.       { 0, 0, 0 }
  100.     };

  101.   for (;;)
  102.     {
  103.       int opt = mi_getopt ("-catch-exception", argc, argv, opts,
  104.                            &oind, &oarg);

  105.       if (opt < 0)
  106.         break;

  107.       switch ((enum opt) opt)
  108.         {
  109.         case OPT_CONDITION:
  110.           condition = oarg;
  111.           break;
  112.         case OPT_DISABLED:
  113.           enabled = 0;
  114.           break;
  115.         case OPT_EXCEPTION_NAME:
  116.           exception_name = oarg;
  117.           break;
  118.         case OPT_TEMP:
  119.           temp = 1;
  120.           break;
  121.         case OPT_UNHANDLED:
  122.           ex_kind = ada_catch_exception_unhandled;
  123.           break;
  124.         }
  125.     }

  126.   /* This command does not accept any argument.  Make sure the user
  127.      did not provide any.  */
  128.   if (oind != argc)
  129.     error (_("Invalid argument: %s"), argv[oind]);

  130.   /* Specifying an exception name does not make sense when requesting
  131.      an unhandled exception breakpoint.  */
  132.   if (ex_kind == ada_catch_exception_unhandled && exception_name != NULL)
  133.     error (_("\"-e\" and \"-u\" are mutually exclusive"));

  134.   setup_breakpoint_reporting ();
  135.   /* create_ada_exception_catchpoint needs EXCEPTION_NAME and CONDITION
  136.      to be xstrdup'ed, and will assume control of their lifetime.  */
  137.   if (exception_name != NULL)
  138.     exception_name = xstrdup (exception_name);
  139.   if (condition != NULL)
  140.     condition = xstrdup (condition);
  141.   create_ada_exception_catchpoint (gdbarch, ex_kind,
  142.                                    exception_name, condition,
  143.                                    temp, enabled, 0);
  144. }

  145. /* Common path for the -catch-load and -catch-unload.  */

  146. static void
  147. mi_catch_load_unload (int load, char *argv[], int argc)
  148. {
  149.   struct cleanup *back_to;
  150.   const char *actual_cmd = load ? "-catch-load" : "-catch-unload";
  151.   int temp = 0;
  152.   int enabled = 1;
  153.   int oind = 0;
  154.   char *oarg;
  155.   enum opt
  156.     {
  157.       OPT_TEMP,
  158.       OPT_DISABLED,
  159.     };
  160.   static const struct mi_opt opts[] =
  161.     {
  162.       { "t", OPT_TEMP, 0 },
  163.       { "d", OPT_DISABLED, 0 },
  164.       { 0, 0, 0 }
  165.     };

  166.   for (;;)
  167.     {
  168.       int opt = mi_getopt (actual_cmd, argc, argv, opts,
  169.                            &oind, &oarg);

  170.       if (opt < 0)
  171.         break;

  172.       switch ((enum opt) opt)
  173.         {
  174.         case OPT_TEMP:
  175.           temp = 1;
  176.           break;
  177.         case OPT_DISABLED:
  178.           enabled = 0;
  179.           break;
  180.         }
  181.     }

  182.   if (oind >= argc)
  183.     error (_("-catch-load/unload: Missing <library name>"));
  184.   if (oind < argc -1)
  185.     error (_("-catch-load/unload: Garbage following the <library name>"));

  186.   back_to = setup_breakpoint_reporting ();

  187.   add_solib_catchpoint (argv[oind], load, temp, enabled);

  188.   do_cleanups (back_to);
  189. }

  190. /* Handler for the -catch-load.  */

  191. void
  192. mi_cmd_catch_load (char *cmd, char *argv[], int argc)
  193. {
  194.   mi_catch_load_unload (1, argv, argc);
  195. }


  196. /* Handler for the -catch-unload.  */

  197. void
  198. mi_cmd_catch_unload (char *cmd, char *argv[], int argc)
  199. {
  200.   mi_catch_load_unload (0, argv, argc);
  201. }