GDB (API)
|
00001 /* CLI Definitions for GDB, the GNU debugger. 00002 00003 Copyright (C) 2002-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "interps.h" 00022 #include "event-top.h" 00023 #include "ui-out.h" 00024 #include "cli-out.h" 00025 #include "top.h" /* for "execute_command" */ 00026 #include "gdb_string.h" 00027 #include "exceptions.h" 00028 00029 struct ui_out *cli_uiout; 00030 00031 /* These are the ui_out and the interpreter for the console 00032 interpreter. */ 00033 00034 /* Longjmp-safe wrapper for "execute_command". */ 00035 static struct gdb_exception safe_execute_command (struct ui_out *uiout, 00036 char *command, 00037 int from_tty); 00038 /* These implement the cli out interpreter: */ 00039 00040 static void * 00041 cli_interpreter_init (struct interp *self, int top_level) 00042 { 00043 return NULL; 00044 } 00045 00046 static int 00047 cli_interpreter_resume (void *data) 00048 { 00049 struct ui_file *stream; 00050 00051 /*sync_execution = 1; */ 00052 00053 /* gdb_setup_readline will change gdb_stdout. If the CLI was 00054 previously writing to gdb_stdout, then set it to the new 00055 gdb_stdout afterwards. */ 00056 00057 stream = cli_out_set_stream (cli_uiout, gdb_stdout); 00058 if (stream != gdb_stdout) 00059 { 00060 cli_out_set_stream (cli_uiout, stream); 00061 stream = NULL; 00062 } 00063 00064 gdb_setup_readline (); 00065 00066 if (stream != NULL) 00067 cli_out_set_stream (cli_uiout, gdb_stdout); 00068 00069 return 1; 00070 } 00071 00072 static int 00073 cli_interpreter_suspend (void *data) 00074 { 00075 gdb_disable_readline (); 00076 return 1; 00077 } 00078 00079 /* Don't display the prompt if we are set quiet. */ 00080 static int 00081 cli_interpreter_display_prompt_p (void *data) 00082 { 00083 if (interp_quiet_p (NULL)) 00084 return 0; 00085 else 00086 return 1; 00087 } 00088 00089 static struct gdb_exception 00090 cli_interpreter_exec (void *data, const char *command_str) 00091 { 00092 struct ui_file *old_stream; 00093 struct gdb_exception result; 00094 00095 /* FIXME: cagney/2003-02-01: Need to const char *propogate 00096 safe_execute_command. */ 00097 char *str = strcpy (alloca (strlen (command_str) + 1), command_str); 00098 00099 /* gdb_stdout could change between the time cli_uiout was 00100 initialized and now. Since we're probably using a different 00101 interpreter which has a new ui_file for gdb_stdout, use that one 00102 instead of the default. 00103 00104 It is important that it gets reset everytime, since the user 00105 could set gdb to use a different interpreter. */ 00106 old_stream = cli_out_set_stream (cli_uiout, gdb_stdout); 00107 result = safe_execute_command (cli_uiout, str, 1); 00108 cli_out_set_stream (cli_uiout, old_stream); 00109 return result; 00110 } 00111 00112 static struct gdb_exception 00113 safe_execute_command (struct ui_out *command_uiout, char *command, int from_tty) 00114 { 00115 volatile struct gdb_exception e; 00116 struct ui_out *saved_uiout; 00117 00118 /* Save and override the global ``struct ui_out'' builder. */ 00119 saved_uiout = current_uiout; 00120 current_uiout = command_uiout; 00121 00122 TRY_CATCH (e, RETURN_MASK_ALL) 00123 { 00124 execute_command (command, from_tty); 00125 } 00126 00127 /* Restore the global builder. */ 00128 current_uiout = saved_uiout; 00129 00130 /* FIXME: cagney/2005-01-13: This shouldn't be needed. Instead the 00131 caller should print the exception. */ 00132 exception_print (gdb_stderr, e); 00133 return e; 00134 } 00135 00136 static struct ui_out * 00137 cli_ui_out (struct interp *self) 00138 { 00139 return cli_uiout; 00140 } 00141 00142 /* Standard gdb initialization hook. */ 00143 extern initialize_file_ftype _initialize_cli_interp; /* -Wmissing-prototypes */ 00144 00145 void 00146 _initialize_cli_interp (void) 00147 { 00148 static const struct interp_procs procs = { 00149 cli_interpreter_init, /* init_proc */ 00150 cli_interpreter_resume, /* resume_proc */ 00151 cli_interpreter_suspend, /* suspend_proc */ 00152 cli_interpreter_exec, /* exec_proc */ 00153 cli_interpreter_display_prompt_p, /* prompt_proc_p */ 00154 cli_ui_out, /* ui_out_proc */ 00155 NULL, /* set_logging_proc */ 00156 cli_command_loop /* command_loop_proc */ 00157 }; 00158 struct interp *cli_interp; 00159 00160 /* Create a default uiout builder for the CLI. */ 00161 cli_uiout = cli_out_new (gdb_stdout); 00162 cli_interp = interp_new (INTERP_CONSOLE, &procs); 00163 00164 interp_add (cli_interp); 00165 }