1 /* CLI Definitions for GDB, the GNU debugger.
3 Copyright 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "event-top.h"
28 #include "top.h" /* for "execute_command" */
29 #include "gdb_string.h"
31 struct ui_out *cli_uiout;
33 /* These are the ui_out and the interpreter for the console interpreter. */
35 /* Longjmp-safe wrapper for "execute_command" */
36 static int do_captured_execute_command (struct ui_out *uiout, void *data);
37 static enum gdb_rc safe_execute_command (struct ui_out *uiout, char *command,
39 struct captured_execute_command_args
45 /* These implement the cli out interpreter: */
48 cli_interpreter_init (void)
54 cli_interpreter_resume (void *data)
56 /*sync_execution = 1; */
57 gdb_setup_readline ();
62 cli_interpreter_suspend (void *data)
64 gdb_disable_readline ();
68 /* Don't display the prompt if we are set quiet. */
70 cli_interpreter_display_prompt_p (void *data)
72 if (interp_quiet_p (NULL))
79 cli_interpreter_exec (void *data, const char *command_str)
82 struct ui_file *old_stream;
84 /* FIXME: cagney/2003-02-01: Need to const char *propogate
85 safe_execute_command. */
86 char *str = strcpy (alloca (strlen (command_str) + 1), command_str);
88 /* gdb_stdout could change between the time cli_uiout was initialized
89 and now. Since we're probably using a different interpreter which has
90 a new ui_file for gdb_stdout, use that one instead of the default.
92 It is important that it gets reset everytime, since the user could
93 set gdb to use a different interpreter. */
94 old_stream = cli_out_set_stream (cli_uiout, gdb_stdout);
95 result = safe_execute_command (cli_uiout, str, 1);
96 cli_out_set_stream (cli_uiout, old_stream);
101 do_captured_execute_command (struct ui_out *uiout, void *data)
103 struct captured_execute_command_args *args =
104 (struct captured_execute_command_args *) data;
105 execute_command (args->command, args->from_tty);
110 safe_execute_command (struct ui_out *uiout, char *command, int from_tty)
112 struct captured_execute_command_args args;
113 args.command = command;
114 args.from_tty = from_tty;
115 return catch_exceptions (uiout, do_captured_execute_command, &args,
116 NULL, RETURN_MASK_ALL);
120 /* standard gdb initialization hook */
121 extern initialize_file_ftype _initialize_cli_interp; /* -Wmissing-prototypes */
124 _initialize_cli_interp (void)
126 static const struct interp_procs procs = {
127 cli_interpreter_init, /* init_proc */
128 cli_interpreter_resume, /* resume_proc */
129 cli_interpreter_suspend, /* suspend_proc */
130 cli_interpreter_exec, /* exec_proc */
131 cli_interpreter_display_prompt_p /* prompt_proc_p */
133 struct interp *cli_interp;
135 /* Create a default uiout builder for the CLI. */
136 cli_uiout = cli_out_new (gdb_stdout);
137 cli_interp = interp_new (INTERP_CONSOLE, NULL, cli_uiout, &procs);
139 interp_add (cli_interp);