Commit | Line | Data |
---|---|---|
4a8f6654 AC |
1 | /* CLI Definitions for GDB, the GNU debugger. |
2 | ||
4c38e0a4 JB |
3 | Copyright (c) 2002, 2003, 2007, 2008, 2009, 2010 |
4 | Free Software Foundation, Inc. | |
4a8f6654 AC |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
4a8f6654 AC |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
4a8f6654 AC |
20 | |
21 | #include "defs.h" | |
22 | #include "interps.h" | |
23 | #include "wrapper.h" | |
24 | #include "event-top.h" | |
25 | #include "ui-out.h" | |
26 | #include "cli-out.h" | |
27 | #include "top.h" /* for "execute_command" */ | |
28 | #include "gdb_string.h" | |
60250e8b | 29 | #include "exceptions.h" |
4a8f6654 AC |
30 | |
31 | struct ui_out *cli_uiout; | |
32 | ||
4791eb66 | 33 | /* These are the ui_out and the interpreter for the console interpreter. */ |
4a8f6654 | 34 | |
4791eb66 | 35 | /* Longjmp-safe wrapper for "execute_command". */ |
71fff37b AC |
36 | static struct gdb_exception safe_execute_command (struct ui_out *uiout, |
37 | char *command, int from_tty); | |
4a8f6654 AC |
38 | struct captured_execute_command_args |
39 | { | |
40 | char *command; | |
41 | int from_tty; | |
42 | }; | |
43 | ||
44 | /* These implement the cli out interpreter: */ | |
45 | ||
46 | static void * | |
683f2885 | 47 | cli_interpreter_init (int top_level) |
4a8f6654 AC |
48 | { |
49 | return NULL; | |
50 | } | |
51 | ||
52 | static int | |
53 | cli_interpreter_resume (void *data) | |
54 | { | |
38caaeec DJ |
55 | struct ui_file *stream; |
56 | ||
4a8f6654 | 57 | /*sync_execution = 1; */ |
38caaeec DJ |
58 | |
59 | /* gdb_setup_readline will change gdb_stdout. If the CLI was previously | |
60 | writing to gdb_stdout, then set it to the new gdb_stdout afterwards. */ | |
61 | ||
62 | stream = cli_out_set_stream (cli_uiout, gdb_stdout); | |
63 | if (stream != gdb_stdout) | |
64 | { | |
65 | cli_out_set_stream (cli_uiout, stream); | |
66 | stream = NULL; | |
67 | } | |
68 | ||
4a8f6654 | 69 | gdb_setup_readline (); |
38caaeec DJ |
70 | |
71 | if (stream != NULL) | |
72 | cli_out_set_stream (cli_uiout, gdb_stdout); | |
73 | ||
4a8f6654 AC |
74 | return 1; |
75 | } | |
76 | ||
77 | static int | |
78 | cli_interpreter_suspend (void *data) | |
79 | { | |
80 | gdb_disable_readline (); | |
81 | return 1; | |
82 | } | |
83 | ||
84 | /* Don't display the prompt if we are set quiet. */ | |
85 | static int | |
86 | cli_interpreter_display_prompt_p (void *data) | |
87 | { | |
88 | if (interp_quiet_p (NULL)) | |
89 | return 0; | |
90 | else | |
91 | return 1; | |
92 | } | |
93 | ||
71fff37b | 94 | static struct gdb_exception |
4a8f6654 AC |
95 | cli_interpreter_exec (void *data, const char *command_str) |
96 | { | |
4a8f6654 | 97 | struct ui_file *old_stream; |
71fff37b | 98 | struct gdb_exception result; |
4a8f6654 AC |
99 | |
100 | /* FIXME: cagney/2003-02-01: Need to const char *propogate | |
101 | safe_execute_command. */ | |
102 | char *str = strcpy (alloca (strlen (command_str) + 1), command_str); | |
103 | ||
104 | /* gdb_stdout could change between the time cli_uiout was initialized | |
105 | and now. Since we're probably using a different interpreter which has | |
106 | a new ui_file for gdb_stdout, use that one instead of the default. | |
107 | ||
108 | It is important that it gets reset everytime, since the user could | |
4791eb66 | 109 | set gdb to use a different interpreter. */ |
4a8f6654 AC |
110 | old_stream = cli_out_set_stream (cli_uiout, gdb_stdout); |
111 | result = safe_execute_command (cli_uiout, str, 1); | |
112 | cli_out_set_stream (cli_uiout, old_stream); | |
113 | return result; | |
114 | } | |
115 | ||
c1043fc2 | 116 | static void |
4a8f6654 AC |
117 | do_captured_execute_command (struct ui_out *uiout, void *data) |
118 | { | |
119 | struct captured_execute_command_args *args = | |
120 | (struct captured_execute_command_args *) data; | |
cdb27c12 | 121 | |
4a8f6654 | 122 | execute_command (args->command, args->from_tty); |
4a8f6654 AC |
123 | } |
124 | ||
71fff37b | 125 | static struct gdb_exception |
4a8f6654 AC |
126 | safe_execute_command (struct ui_out *uiout, char *command, int from_tty) |
127 | { | |
71fff37b | 128 | struct gdb_exception e; |
4a8f6654 | 129 | struct captured_execute_command_args args; |
cdb27c12 | 130 | |
4a8f6654 AC |
131 | args.command = command; |
132 | args.from_tty = from_tty; | |
8a076db9 AC |
133 | e = catch_exception (uiout, do_captured_execute_command, &args, |
134 | RETURN_MASK_ALL); | |
135 | /* FIXME: cagney/2005-01-13: This shouldn't be needed. Instead the | |
136 | caller should print the exception. */ | |
9cbc821d | 137 | exception_print (gdb_stderr, e); |
8a076db9 | 138 | return e; |
4a8f6654 AC |
139 | } |
140 | ||
141 | ||
4791eb66 | 142 | /* Standard gdb initialization hook. */ |
b9362cc7 AC |
143 | extern initialize_file_ftype _initialize_cli_interp; /* -Wmissing-prototypes */ |
144 | ||
4a8f6654 AC |
145 | void |
146 | _initialize_cli_interp (void) | |
147 | { | |
148 | static const struct interp_procs procs = { | |
149 | cli_interpreter_init, /* init_proc */ | |
150 | cli_interpreter_resume, /* resume_proc */ | |
151 | cli_interpreter_suspend, /* suspend_proc */ | |
152 | cli_interpreter_exec, /* exec_proc */ | |
153 | cli_interpreter_display_prompt_p /* prompt_proc_p */ | |
154 | }; | |
155 | struct interp *cli_interp; | |
156 | ||
4791eb66 | 157 | /* Create a default uiout builder for the CLI. */ |
4a8f6654 AC |
158 | cli_uiout = cli_out_new (gdb_stdout); |
159 | cli_interp = interp_new (INTERP_CONSOLE, NULL, cli_uiout, &procs); | |
160 | ||
161 | interp_add (cli_interp); | |
162 | } |