Example #1
0
File: python.c Project: ILyoan/gdb
static void
python_command (char *arg, int from_tty)
{
  struct cleanup *cleanup;

  cleanup = ensure_python_env (get_current_arch (), current_language);

  make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  while (arg && *arg && isspace (*arg))
    ++arg;
  if (arg && *arg)
    {
      if (PyRun_SimpleString (arg))
	error (_("Error while executing Python code."));
    }
  else
    {
      struct command_line *l = get_command_line (python_control, "");

      make_cleanup_free_command_lines (&l);
      execute_control_command_untraced (l);
    }

  do_cleanups (cleanup);
}
Example #2
0
static void
guile_command (char *arg, int from_tty)
{
  struct cleanup *cleanup;

  cleanup = make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  arg = skip_spaces (arg);

  if (arg && *arg)
    {
      char *msg = gdbscm_safe_eval_string (arg, 1);

      if (msg != NULL)
	{
	  make_cleanup (xfree, msg);
	  error ("%s", msg);
	}
    }
  else
    {
      struct command_line *l = get_command_line (guile_control, "");

      make_cleanup_free_command_lines (&l);
      execute_control_command_untraced (l);
    }

  do_cleanups (cleanup);
}
Example #3
0
static void
guile_repl_command (char *arg, int from_tty)
{
  struct cleanup *cleanup;

  cleanup = make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  arg = skip_spaces (arg);

  /* This explicitly rejects any arguments for now.
     "It is easier to relax a restriction than impose one after the fact."
     We would *like* to be able to pass arguments to the interactive shell
     but that's not what python-interactive does.  Until there is time to
     sort it out, we forbid arguments.  */

  if (arg && *arg)
    error (_("guile-repl currently does not take any arguments."));
  else
    {
      dont_repeat ();
      gdbscm_enter_repl ();
    }

  do_cleanups (cleanup);
}
Example #4
0
void
mi_cmd_var_assign (char *command, char **argv, int argc)
{
  struct ui_out *uiout = current_uiout;
  struct varobj *var;
  char *expression, *val;
  struct cleanup *cleanup;

  if (argc != 2)
    error (_("-var-assign: Usage: NAME EXPRESSION."));

  /* Get varobj handle, if a valid var obj name was specified.  */
  var = varobj_get_handle (argv[0]);

  if (!varobj_editable_p (var))
    error (_("-var-assign: Variable object is not editable"));

  expression = xstrdup (argv[1]);

  /* MI command '-var-assign' may write memory, so suppress memory
     changed notification if it does.  */
  cleanup
    = make_cleanup_restore_integer (&mi_suppress_notification.memory);
  mi_suppress_notification.memory = 1;

  if (!varobj_set_value (var, expression))
    error (_("-var-assign: Could not assign "
	     "expression to variable object"));

  val = varobj_get_value (var);
  ui_out_field_string (uiout, "value", val);
  xfree (val);

  do_cleanups (cleanup);
}
Example #5
0
static SCM
gdbscm_execute_gdb_command (SCM command_scm, SCM rest)
{
  int from_tty_arg_pos = -1, to_string_arg_pos = -1;
  int from_tty = 0, to_string = 0;
  volatile struct gdb_exception except;
  const SCM keywords[] = { from_tty_keyword, to_string_keyword, SCM_BOOL_F };
  char *command;
  char *result = NULL;
  struct cleanup *cleanups;

  gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#tt",
			      command_scm, &command, rest,
			      &from_tty_arg_pos, &from_tty,
			      &to_string_arg_pos, &to_string);

  /* Note: The contents of "command" may get modified while it is
     executed.  */
  cleanups = make_cleanup (xfree, command);

  TRY_CATCH (except, RETURN_MASK_ALL)
    {
      struct cleanup *inner_cleanups;

      inner_cleanups = make_cleanup_restore_integer (&interpreter_async);
      interpreter_async = 0;

      prevent_dont_repeat ();
      if (to_string)
	result = execute_command_to_string (command, from_tty);
      else
	{
	  execute_command (command, from_tty);
	  result = NULL;
	}

      /* Do any commands attached to breakpoint we stopped at.  */
      bpstat_do_actions ();

      do_cleanups (inner_cleanups);
    }
  do_cleanups (cleanups);
  GDBSCM_HANDLE_GDB_EXCEPTION (except);

  if (result)
    {
      SCM r = gdbscm_scm_from_c_string (result);
      xfree (result);
      return r;
    }
  return SCM_UNSPECIFIED;
}
Example #6
0
struct cleanup *
setup_breakpoint_reporting (void)
{
  struct cleanup *rev_flag;

  if (! mi_breakpoint_observers_installed)
    {
      observer_attach_breakpoint_created (breakpoint_notify);
      mi_breakpoint_observers_installed = 1;
    }

  rev_flag = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
  mi_can_breakpoint_notify = 1;

  return rev_flag;
}
Example #7
0
void
execute_user_command (struct cmd_list_element *c, char *args)
{
  struct command_line *cmdlines;
  struct cleanup *old_chain;
  enum command_control_type ret;
  static int user_call_depth = 0;
  extern int max_user_call_depth;

  cmdlines = c->user_commands;
  if (cmdlines == 0)
    /* Null command */
    return;

  old_chain = setup_user_args (args);

  if (++user_call_depth > max_user_call_depth)
    error (_("Max user call depth exceeded -- command aborted."));

  make_cleanup (do_restore_user_call_depth, &user_call_depth);

  /* Set the instream to 0, indicating execution of a
     user-defined function.  */
  make_cleanup (do_restore_instream_cleanup, instream);
  instream = (FILE *) 0;

  /* Also set the global in_user_command, so that NULL instream is
     not confused with Insight.  */
  in_user_command = 1;

  make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  command_nest_depth++;
  while (cmdlines)
    {
      ret = execute_control_command (cmdlines);
      if (ret != simple_control && ret != break_control)
	{
	  warning (_("Error executing canned sequence of commands."));
	  break;
	}
      cmdlines = cmdlines->next;
    }
  command_nest_depth--;
  do_cleanups (old_chain);
}
static SCM
ioscm_with_output_to_port_worker (SCM port, SCM thunk, enum oport oport,
				  const char *func_name)
{
  struct ui_file *port_file;
  struct cleanup *cleanups;
  SCM result;

  SCM_ASSERT_TYPE (gdbscm_is_true (scm_output_port_p (port)), port,
		   SCM_ARG1, func_name, _("output port"));
  SCM_ASSERT_TYPE (gdbscm_is_true (scm_thunk_p (thunk)), thunk,
		   SCM_ARG2, func_name, _("thunk"));

  cleanups = set_batch_flag_and_make_cleanup_restore_page_info ();

  make_cleanup_restore_integer (&current_ui->async);
  current_ui->async = 0;

  port_file = ioscm_file_port_new (port);

  make_cleanup_ui_file_delete (port_file);

  scoped_restore save_file = make_scoped_restore (oport == GDB_STDERR
						  ? &gdb_stderr : &gdb_stdout);

  if (oport == GDB_STDERR)
    gdb_stderr = port_file;
  else
    {
      if (ui_out_redirect (current_uiout, port_file) < 0)
	warning (_("Current output protocol does not support redirection"));
      else
	make_cleanup_ui_out_redirect_pop (current_uiout);

      gdb_stdout = port_file;
    }

  result = gdbscm_safe_call_0 (thunk, NULL);

  do_cleanups (cleanups);

  if (gdbscm_is_exception (result))
    gdbscm_throw (result);

  return result;
}
Example #9
0
void
if_command (char *arg, int from_tty)
{
  struct command_line *command = NULL;
  struct cleanup *old_chain;

  control_level = 1;
  command = get_command_line (if_control, arg);

  if (command == NULL)
    return;

  old_chain = make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  execute_control_command_untraced (command);
  free_command_lines (&command);

  do_cleanups (old_chain);
}
Example #10
0
static void
python_interactive_command (char *arg, int from_tty)
{
  struct cleanup *cleanup;
  int err;

  cleanup = make_cleanup_restore_integer (&interpreter_async);
  interpreter_async = 0;

  arg = skip_spaces (arg);

  ensure_python_env (get_current_arch (), current_language);

  if (arg && *arg)
    {
      int len = strlen (arg);
      char *script = xmalloc (len + 2);

      strcpy (script, arg);
      script[len] = '\n';
      script[len + 1] = '\0';
      err = eval_python_command (script);
      xfree (script);
    }
  else
    {
      err = PyRun_InteractiveLoop (instream, "<stdin>");
      dont_repeat ();
    }

  if (err)
    {
      gdbpy_print_stack ();
      error (_("Error while executing Python code."));
    }

  do_cleanups (cleanup);
}
Example #11
0
void
mi_cmd_break_insert (char *command, char **argv, int argc)
{
  char *address = NULL;
  int hardware = 0;
  int temp_p = 0;
  int thread = -1;
  int ignore_count = 0;
  char *condition = NULL;
  int pending = 0;
  int enabled = 1;
  int tracepoint = 0;
  struct cleanup *back_to;
  enum bptype type_wanted;

  enum opt
    {
      HARDWARE_OPT, TEMP_OPT, CONDITION_OPT,
      IGNORE_COUNT_OPT, THREAD_OPT, PENDING_OPT, DISABLE_OPT,
      TRACEPOINT_OPT,
    };
  static const struct mi_opt opts[] =
  {
    {"h", HARDWARE_OPT, 0},
    {"t", TEMP_OPT, 0},
    {"c", CONDITION_OPT, 1},
    {"i", IGNORE_COUNT_OPT, 1},
    {"p", THREAD_OPT, 1},
    {"f", PENDING_OPT, 0},
    {"d", DISABLE_OPT, 0},
    {"a", TRACEPOINT_OPT, 0},
    { 0, 0, 0 }
  };

  /* Parse arguments. It could be -r or -h or -t, <location> or ``--''
     to denote the end of the option list. */
  int oind = 0;
  char *oarg;

  while (1)
    {
      int opt = mi_getopt ("-break-insert", argc, argv,
			   opts, &oind, &oarg);
      if (opt < 0)
	break;
      switch ((enum opt) opt)
	{
	case TEMP_OPT:
	  temp_p = 1;
	  break;
	case HARDWARE_OPT:
	  hardware = 1;
	  break;
	case CONDITION_OPT:
	  condition = oarg;
	  break;
	case IGNORE_COUNT_OPT:
	  ignore_count = atol (oarg);
	  break;
	case THREAD_OPT:
	  thread = atol (oarg);
	  break;
	case PENDING_OPT:
	  pending = 1;
	  break;
	case DISABLE_OPT:
	  enabled = 0;
	  break;
	case TRACEPOINT_OPT:
	  tracepoint = 1;
	  break;
	}
    }

  if (oind >= argc)
    error (_("-break-insert: Missing <location>"));
  if (oind < argc - 1)
    error (_("-break-insert: Garbage following <location>"));
  address = argv[oind];

  /* Now we have what we need, let's insert the breakpoint!  */
  if (! mi_breakpoint_observers_installed)
    {
      observer_attach_breakpoint_created (breakpoint_notify);
      mi_breakpoint_observers_installed = 1;
    }

  back_to = make_cleanup_restore_integer (&mi_can_breakpoint_notify);
  mi_can_breakpoint_notify = 1;

  /* Note that to request a fast tracepoint, the client uses the
     "hardware" flag, although there's nothing of hardware related to
     fast tracepoints -- one can implement slow tracepoints with
     hardware breakpoints, but fast tracepoints are always software.
     "fast" is a misnomer, actually, "jump" would be more appropriate.
     A simulator or an emulator could conceivably implement fast
     regular non-jump based tracepoints.  */
  type_wanted = (tracepoint
		 ? (hardware ? bp_fast_tracepoint : bp_tracepoint)
		 : (hardware ? bp_hardware_breakpoint : bp_breakpoint));

  create_breakpoint (get_current_arch (), address, condition, thread,
		     NULL,
		     0 /* condition and thread are valid.  */,
		     temp_p, type_wanted,
		     ignore_count,
		     pending ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE,
		     &bkpt_breakpoint_ops, 0, enabled, 0, 0);
  do_cleanups (back_to);

}