Example #1
0
void
mi_cmd_interpreter_exec (char *command, char **argv, int argc)
{
    struct interp *interp_to_use;
    int i;
    char *mi_error_message = NULL;
    struct cleanup *old_chain;

    if (argc < 2)
        error (_("-interpreter-exec: "
                 "Usage: -interpreter-exec interp command"));

    interp_to_use = interp_lookup (argv[0]);
    if (interp_to_use == NULL)
        error (_("-interpreter-exec: could not find interpreter \"%s\""),
               argv[0]);

    if (!interp_exec_p (interp_to_use))
        error (_("-interpreter-exec: interpreter \"%s\" "
                 "does not support command execution"),
               argv[0]);

    /* Insert the MI out hooks, making sure to also call the
       interpreter's hooks if it has any.  */
    /* KRS: We shouldn't need this... Events should be installed and
       they should just ALWAYS fire something out down the MI
       channel.  */
    mi_insert_notify_hooks ();

    /* Now run the code.  */

    old_chain = make_cleanup (null_cleanup, 0);
    for (i = 1; i < argc; i++)
    {
        struct gdb_exception e = interp_exec (interp_to_use, argv[i]);

        if (e.reason < 0)
        {
            mi_error_message = xstrdup (e.message);
            make_cleanup (xfree, mi_error_message);
            break;
        }
    }

    mi_remove_notify_hooks ();

    if (mi_error_message != NULL)
        error ("%s", mi_error_message);
    do_cleanups (old_chain);
}
Example #2
0
void
mi_cmd_interpreter_exec (char *command, char **argv, int argc)
{
  struct interp *interp_to_use;
  int i;
  char *mi_error_message = NULL;
  struct cleanup *old_chain;

  if (argc < 2)
    error (_("-interpreter-exec: "
	     "Usage: -interpreter-exec interp command"));

  interp_to_use = interp_lookup (argv[0]);
  if (interp_to_use == NULL)
    error (_("-interpreter-exec: could not find interpreter \"%s\""),
	   argv[0]);

  /* Note that unlike the CLI version of this command, we don't
     actually set INTERP_TO_USE as the current interpreter, as we
     still want gdb_stdout, etc. to point at MI streams.  */

  /* Insert the MI out hooks, making sure to also call the
     interpreter's hooks if it has any.  */
  /* KRS: We shouldn't need this... Events should be installed and
     they should just ALWAYS fire something out down the MI
     channel.  */
  mi_insert_notify_hooks ();

  /* Now run the code.  */

  old_chain = make_cleanup (null_cleanup, 0);
  for (i = 1; i < argc; i++)
    {
      struct gdb_exception e = interp_exec (interp_to_use, argv[i]);

      if (e.reason < 0)
	{
	  mi_error_message = xstrdup (e.message);
	  make_cleanup (xfree, mi_error_message);
	  break;
	}
    }

  mi_remove_notify_hooks ();

  if (mi_error_message != NULL)
    error ("%s", mi_error_message);
  do_cleanups (old_chain);
}