static enum mi_cmd_result mi_cmd_execute (struct mi_parse *parse) { if (parse->cmd->argv_func != NULL || parse->cmd->args_func != NULL) { /* FIXME: We need to save the token because the command executed may be asynchronous and need to print the token again. In the future we can pass the token down to the func and get rid of the last_async_command */ /* The problem here is to keep the token around when we launch the target, and we want to interrupt it later on. The interrupt command will have its own token, but when the target stops, we must display the token corresponding to the last execution command given. So we have another string where we copy the token (previous_async_command), if this was indeed the token of an execution command, and when we stop we print that one. This is possible because the interrupt command, when over, will copy that token back into the default token string (last_async_command). */ if (target_executing) { if (!previous_async_command) previous_async_command = xstrdup (last_async_command); if (strcmp (parse->command, "exec-interrupt")) { fputs_unfiltered (parse->token, raw_stdout); fputs_unfiltered ("^error,msg=\"", raw_stdout); fputs_unfiltered ("Cannot execute command ", raw_stdout); fputstr_unfiltered (parse->command, '"', raw_stdout); fputs_unfiltered (" while target running", raw_stdout); fputs_unfiltered ("\"\n", raw_stdout); return MI_CMD_ERROR; } } last_async_command = xstrdup (parse->token); make_exec_cleanup (free_current_contents, &last_async_command); /* FIXME: DELETE THIS! */ if (parse->cmd->args_func != NULL) return parse->cmd->args_func (parse->args, 0 /*from_tty */ ); return parse->cmd->argv_func (parse->command, parse->argv, parse->argc); } else if (parse->cmd->cli.cmd != 0) { /* FIXME: DELETE THIS. */ /* The operation is still implemented by a cli command */ /* Must be a synchronous one */ mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p, parse->args); return MI_CMD_DONE; } else { /* FIXME: DELETE THIS. */ fputs_unfiltered (parse->token, raw_stdout); fputs_unfiltered ("^error,msg=\"", raw_stdout); fputs_unfiltered ("Undefined mi command: ", raw_stdout); fputstr_unfiltered (parse->command, '"', raw_stdout); fputs_unfiltered (" (missing implementation)", raw_stdout); fputs_unfiltered ("\"\n", raw_stdout); return MI_CMD_ERROR; } }
static int captured_mi_execute_command (struct ui_out *uiout, void *data) { struct captured_mi_execute_command_args *args = (struct captured_mi_execute_command_args *) data; struct mi_parse *context = args->command; switch (context->op) { case MI_COMMAND: /* A MI command was read from the input stream */ if (mi_debug_p) /* FIXME: gdb_???? */ fprintf_unfiltered (raw_stdout, " token=`%s' command=`%s' args=`%s'\n", context->token, context->command, context->args); /* FIXME: cagney/1999-09-25: Rather than this convoluted condition expression, each function should return an indication of what action is required and then switch on that. */ args->action = EXECUTE_COMMAND_DISPLAY_PROMPT; args->rc = mi_cmd_execute (context); if (!target_can_async_p () || !target_executing) { /* print the result if there were no errors Remember that on the way out of executing a command, you have to directly use the mi_interp's uiout, since the command could have reset the interpreter, in which case the current uiout will most likely crash in the mi_out_* routines. */ if (args->rc == MI_CMD_DONE) { fputs_unfiltered (context->token, raw_stdout); fputs_unfiltered ("^done", raw_stdout); mi_out_put (uiout, raw_stdout); mi_out_rewind (uiout); fputs_unfiltered ("\n", raw_stdout); } else if (args->rc == MI_CMD_ERROR) { if (mi_error_message) { fputs_unfiltered (context->token, raw_stdout); fputs_unfiltered ("^error,msg=\"", raw_stdout); fputstr_unfiltered (mi_error_message, '"', raw_stdout); xfree (mi_error_message); fputs_unfiltered ("\"\n", raw_stdout); } mi_out_rewind (uiout); } else if (args->rc == MI_CMD_CAUGHT_ERROR) { mi_out_rewind (uiout); args->action = EXECUTE_COMMAND_DISPLAY_ERROR; return 1; } else mi_out_rewind (uiout); } else if (sync_execution) { /* Don't print the prompt. We are executing the target in synchronous mode. */ args->action = EXECUTE_COMMAND_SUPRESS_PROMPT; return 1; } break; case CLI_COMMAND: /* A CLI command was read from the input stream */ /* This will be removed as soon as we have a complete set of mi commands */ /* echo the command on the console. */ fprintf_unfiltered (gdb_stdlog, "%s\n", context->command); mi_execute_cli_command (context->command, 0, NULL); /* If we changed interpreters, DON'T print out anything. */ if (current_interp_named_p (INTERP_MI) || current_interp_named_p (INTERP_MI1) || current_interp_named_p (INTERP_MI2) || current_interp_named_p (INTERP_MI3)) { /* print the result */ /* FIXME: Check for errors here. */ fputs_unfiltered (context->token, raw_stdout); fputs_unfiltered ("^done", raw_stdout); mi_out_put (uiout, raw_stdout); mi_out_rewind (uiout); fputs_unfiltered ("\n", raw_stdout); args->action = EXECUTE_COMMAND_DISPLAY_PROMPT; args->rc = MI_CMD_DONE; } break; } return 1; }