GDB (API)
|
00001 /* Insight Definitions for GDB, the GNU debugger. 00002 Written by Keith Seitz <kseitz@sources.redhat.com> 00003 00004 Copyright (C) 2003, 2004, 2008, 2011, 2012 Free Software Foundation, Inc. 00005 00006 This file is part of Insight. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. */ 00022 00023 #include "defs.h" 00024 #include "interps.h" 00025 #include "ui-file.h" 00026 #include "ui-out.h" 00027 #include "cli-out.h" 00028 #include "gdb_string.h" 00029 #include "cli/cli-cmds.h" 00030 #include "cli/cli-decode.h" 00031 #include "exceptions.h" 00032 00033 #include "tcl.h" 00034 #include "tk.h" 00035 #include "gdbtk.h" 00036 00037 #ifdef __MINGW32__ 00038 # define WIN32_LEAN_AND_MEAN 00039 # include <windows.h> 00040 #endif 00041 00042 00043 static void gdbtk_command_loop (void *); 00044 static void hack_disable_interpreter_exec (char *, int); 00045 void _initialize_gdbtk_interp (void); 00046 00047 struct gdbtk_interp_data 00048 { 00049 struct ui_file *_stdout; 00050 struct ui_file *_stderr; 00051 struct ui_file *_stdlog; 00052 struct ui_file *_stdtarg; 00053 struct ui_file *_stdtargin; 00054 struct ui_out *uiout; 00055 }; 00056 00057 /* See note in gdbtk_interpreter_init */ 00058 static void 00059 hack_disable_interpreter_exec (char *args, int from_tty) 00060 { 00061 error ("interpreter-exec not available when running Insight"); 00062 } 00063 00064 static void * 00065 gdbtk_interpreter_init (struct interp *interp, int top_level) 00066 { 00067 /* Disable interpreter-exec. It causes us big trouble right now. */ 00068 struct cmd_list_element *cmd = NULL; 00069 struct cmd_list_element *alias = NULL; 00070 struct cmd_list_element *prefix = NULL; 00071 struct gdbtk_interp_data *data; 00072 00073 data = XZALLOC (struct gdbtk_interp_data); 00074 data->_stdout = gdbtk_fileopen (); 00075 data->_stderr = gdbtk_fileopen (); 00076 data->_stdlog = gdbtk_fileopen (); 00077 data->_stdtarg = gdbtk_fileopen (); 00078 data->_stdtargin = gdbtk_fileopenin (); 00079 data->uiout = cli_out_new (data->_stdout), 00080 00081 gdbtk_init (); 00082 00083 if (lookup_cmd_composition ("interpreter-exec", &alias, &prefix, &cmd)) 00084 { 00085 set_cmd_cfunc (cmd, hack_disable_interpreter_exec); 00086 } 00087 00088 return data; 00089 } 00090 00091 static int 00092 gdbtk_interpreter_resume (void *data) 00093 { 00094 static int started = 0; 00095 struct gdbtk_interp_data *d = (struct gdbtk_interp_data *) data; 00096 gdbtk_add_hooks (); 00097 00098 gdb_stdout = d->_stdout; 00099 gdb_stderr = d->_stderr; 00100 gdb_stdlog = d->_stdlog; 00101 gdb_stdtarg = d->_stdtarg; 00102 gdb_stdtargin = d->_stdtargin; 00103 00104 /* 2003-02-11 keiths: We cannot actually source our main Tcl file in 00105 our interpreter's init function because any errors that may 00106 get generated will go to the wrong gdb_stderr. Instead of hacking 00107 our interpreter init function to force gdb_stderr to our ui_file, 00108 we defer sourcing the startup file until now, when gdb is ready 00109 to let our interpreter run. */ 00110 if (!started) 00111 { 00112 started = 1; 00113 gdbtk_source_start_file (); 00114 } 00115 00116 return 1; 00117 } 00118 00119 static int 00120 gdbtk_interpreter_suspend (void *data) 00121 { 00122 return 1; 00123 } 00124 00125 static int 00126 gdbtk_interpreter_display_prompt_p (void *data) 00127 { 00128 return 1; 00129 } 00130 00131 static struct gdb_exception 00132 gdbtk_interpreter_exec (void *data, const char *command_str) 00133 { 00134 return exception_none; 00135 } 00136 00137 /* This function is called instead of gdb's internal command loop. This is the 00138 last chance to do anything before entering the main Tk event loop. 00139 At the end of the command, we enter the main loop. 00140 DATA is the interpreter cookie, currently unused. */ 00141 00142 static void 00143 gdbtk_command_loop (void *data) 00144 { 00145 extern FILE *instream; 00146 00147 /* We no longer want to use stdin as the command input stream */ 00148 instream = NULL; 00149 00150 if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_preloop") != TCL_OK) 00151 { 00152 const char *msg; 00153 00154 /* Force errorInfo to be set up propertly. */ 00155 Tcl_AddErrorInfo (gdbtk_interp, ""); 00156 00157 msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); 00158 #ifdef _WIN32 00159 MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); 00160 #else 00161 fputs_unfiltered (msg, gdb_stderr); 00162 #endif 00163 } 00164 00165 #ifdef _WIN32 00166 close_bfds (); 00167 #endif 00168 00169 Tk_MainLoop (); 00170 } 00171 00172 static struct ui_out * 00173 gdbtk_interpreter_ui_out (struct interp *interp) 00174 { 00175 struct gdbtk_interp_data *data = interp_data (interp); 00176 00177 return data->uiout; 00178 } 00179 00180 void 00181 _initialize_gdbtk_interp (void) 00182 { 00183 static const struct interp_procs procs = { 00184 gdbtk_interpreter_init, /* init_proc */ 00185 gdbtk_interpreter_resume, /* resume_proc */ 00186 gdbtk_interpreter_suspend, /* suspend_proc */ 00187 gdbtk_interpreter_exec, /* exec_proc */ 00188 gdbtk_interpreter_display_prompt_p, /* prompt_proc_p */ 00189 gdbtk_interpreter_ui_out, /* ui_out_proc */ 00190 NULL, /* set_logging_proc */ 00191 gdbtk_command_loop /* command_loop_proc */ 00192 }; 00193 interp_add (interp_new ("insight", &procs)); 00194 }