enum command_control_type execute_control_command (struct command_line *cmd) { /* Make sure we use the console uiout. It's possible that we are executing breakpoint commands while running the MI interpreter. */ interp *console = interp_lookup (current_ui, INTERP_CONSOLE); scoped_restore save_uiout = make_scoped_restore (¤t_uiout, interp_ui_out (console)); return execute_control_command_1 (cmd); }
static void if_command (const char *arg, int from_tty) { control_level = 1; command_line_up command = get_command_line (if_control, arg); if (command == NULL) return; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); execute_control_command_untraced (command.get ()); }
void execute_user_command (struct cmd_list_element *c, const char *args) { struct ui *ui = current_ui; struct command_line *cmdlines; enum command_control_type ret; extern unsigned int max_user_call_depth; cmdlines = c->user_commands; if (cmdlines == 0) /* Null command */ return; scoped_user_args_level push_user_args (args); if (user_args_stack.size () > max_user_call_depth) error (_("Max user call depth exceeded -- command aborted.")); /* Set the instream to 0, indicating execution of a user-defined function. */ scoped_restore restore_instream = make_scoped_restore (&ui->instream, nullptr); scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); scoped_restore save_nesting = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); 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; } }
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 (¤t_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; }
static ps_err_e ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr, gdb_byte *buf, size_t len, int write) { scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); int ret; CORE_ADDR core_addr = ps_addr_to_core_addr (addr); inferior_ptid = ph->thread->ptid; if (write) ret = target_write_memory (core_addr, buf, len); else ret = target_read_memory (core_addr, buf, len); return (ret == 0 ? PS_OK : PS_ERR); }
void thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid) { process_info *parent_proc = get_thread_process (parent_thr); struct thread_db *thread_db = parent_proc->priv->thread_db; /* If the thread layer isn't initialized, return. It may just be that the program uses clone, but does not use libthread_db. */ if (thread_db == NULL || !thread_db->all_symbols_looked_up) return; /* find_one_thread calls into libthread_db which accesses memory via the current thread. Temporarily switch to a thread we know is stopped. */ scoped_restore restore_current_thread = make_scoped_restore (¤t_thread, parent_thr); if (!find_one_thread (child_ptid)) warning ("Cannot find thread after clone.\n"); }
static enum command_control_type execute_control_command_1 (struct command_line *cmd) { struct command_line *current; struct value *val; struct value *val_mark; int loop; enum command_control_type ret; /* Start by assuming failure, if a problem is detected, the code below will simply "break" out of the switch. */ ret = invalid_control; switch (cmd->control_type) { case simple_control: { /* A simple command, execute it and return. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); execute_command (new_line.c_str (), 0); ret = cmd->control_type; break; } case continue_control: print_command_trace ("loop_continue"); /* Return for "continue", and "break" so we can either continue the loop at the top, or break out. */ ret = cmd->control_type; break; case break_control: print_command_trace ("loop_break"); /* Return for "continue", and "break" so we can either continue the loop at the top, or break out. */ ret = cmd->control_type; break; case while_control: { int len = strlen (cmd->line) + 7; char *buffer = (char *) alloca (len); xsnprintf (buffer, len, "while %s", cmd->line); print_command_trace (buffer); /* Parse the loop control expression for the while statement. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); expression_up expr = parse_expression (new_line.c_str ()); ret = simple_control; loop = 1; /* Keep iterating so long as the expression is true. */ while (loop == 1) { int cond_result; QUIT; /* Evaluate the expression. */ val_mark = value_mark (); val = evaluate_expression (expr.get ()); cond_result = value_true (val); value_free_to_mark (val_mark); /* If the value is false, then break out of the loop. */ if (!cond_result) break; /* Execute the body of the while statement. */ current = *cmd->body_list; while (current) { scoped_restore save_nesting = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); ret = execute_control_command_1 (current); /* If we got an error, or a "break" command, then stop looping. */ if (ret == invalid_control || ret == break_control) { loop = 0; break; } /* If we got a "continue" command, then restart the loop at this point. */ if (ret == continue_control) break; /* Get the next statement. */ current = current->next; } } /* Reset RET so that we don't recurse the break all the way down. */ if (ret == break_control) ret = simple_control; break; } case if_control: { int len = strlen (cmd->line) + 4; char *buffer = (char *) alloca (len); xsnprintf (buffer, len, "if %s", cmd->line); print_command_trace (buffer); /* Parse the conditional for the if statement. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); expression_up expr = parse_expression (new_line.c_str ()); current = NULL; ret = simple_control; /* Evaluate the conditional. */ val_mark = value_mark (); val = evaluate_expression (expr.get ()); /* Choose which arm to take commands from based on the value of the conditional expression. */ if (value_true (val)) current = *cmd->body_list; else if (cmd->body_count == 2) current = *(cmd->body_list + 1); value_free_to_mark (val_mark); /* Execute commands in the given arm. */ while (current) { scoped_restore save_nesting = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); ret = execute_control_command_1 (current); /* If we got an error, get out. */ if (ret != simple_control) break; /* Get the next statement in the body. */ current = current->next; } break; } case commands_control: { /* Breakpoint commands list, record the commands in the breakpoint's command list and return. */ std::string new_line = insert_user_defined_cmd_args (cmd->line); ret = commands_from_control_command (new_line.c_str (), cmd); break; } case compile_control: eval_compile_command (cmd, NULL, cmd->control_u.compile.scope, cmd->control_u.compile.scope_data); ret = simple_control; break; case python_control: case guile_control: { eval_ext_lang_from_control_command (cmd); ret = simple_control; break; } default: warning (_("Invalid control type in canned commands structure.")); break; } return ret; }