From 592dd36d94fd2ccbcf79007393d0830b49718881 Mon Sep 17 00:00:00 2001 From: kseitz Date: Tue, 18 Feb 2003 23:33:05 +0000 Subject: [PATCH] * generic/gdbtk-main.c (main): Change name of intepreter to "insight". * generic/gdbtk.h: Add ifdef wrappers. (gdbtk_init): Declare. (gdbtk_source_start_file): Declare. * generic/gdbtk.c (gdbtk_init): Export. Reomve init_ui_hook stuff. Do not add hooks here anymore (moved into interps). Do not muck with gdbk_stdout et al (moved into interps). (gdbtk_source_start_file): Code ripped out of gdbtk_init which deals with sourcing the main startup file. (gdbtk_init_1): Hack: New function. (argv0): Hack: New static global. (tk_init): Moved to gdbtk-interps.c. (gdbtk_resume): Likewise. (gdbtk_suspend): Likewise. (gdbtk_prompt_p): Likewise. (gdbtk_exec): Likewise. (gdbtk_command_loop): Likewise. (_initialize_gdbtk): Move interpreter stuff to gdbtk-interps.c. Hack: Add new init_ui_hook. * generic/gdbtk-interps.c: New file. --- gdb/gdbtk/ChangeLog | 24 ++++++ gdb/gdbtk/generic/gdbtk-interp.c | 178 +++++++++++++++++++++++++++++++++++++++ gdb/gdbtk/generic/gdbtk-main.c | 2 +- gdb/gdbtk/generic/gdbtk.c | 172 +++++++++---------------------------- gdb/gdbtk/generic/gdbtk.h | 12 ++- 5 files changed, 256 insertions(+), 132 deletions(-) create mode 100644 gdb/gdbtk/generic/gdbtk-interp.c diff --git a/gdb/gdbtk/ChangeLog b/gdb/gdbtk/ChangeLog index 4efc84f950..2511d2e5b0 100644 --- a/gdb/gdbtk/ChangeLog +++ b/gdb/gdbtk/ChangeLog @@ -1,3 +1,27 @@ +2003-02-18 Keith Seitz + + * generic/gdbtk-main.c (main): Change name of intepreter to "insight". + * generic/gdbtk.h: Add ifdef wrappers. + (gdbtk_init): Declare. + (gdbtk_source_start_file): Declare. + * generic/gdbtk.c (gdbtk_init): Export. + Reomve init_ui_hook stuff. + Do not add hooks here anymore (moved into interps). + Do not muck with gdbk_stdout et al (moved into interps). + (gdbtk_source_start_file): Code ripped out of gdbtk_init + which deals with sourcing the main startup file. + (gdbtk_init_1): Hack: New function. + (argv0): Hack: New static global. + (tk_init): Moved to gdbtk-interps.c. + (gdbtk_resume): Likewise. + (gdbtk_suspend): Likewise. + (gdbtk_prompt_p): Likewise. + (gdbtk_exec): Likewise. + (gdbtk_command_loop): Likewise. + (_initialize_gdbtk): Move interpreter stuff to gdbtk-interps.c. + Hack: Add new init_ui_hook. + * generic/gdbtk-interps.c: New file. + 2003-02-17 Christopher Faylor Revert below change. diff --git a/gdb/gdbtk/generic/gdbtk-interp.c b/gdb/gdbtk/generic/gdbtk-interp.c new file mode 100644 index 0000000000..6dc3750494 --- /dev/null +++ b/gdb/gdbtk/generic/gdbtk-interp.c @@ -0,0 +1,178 @@ +/* Insight Definitions for GDB, the GNU debugger. + Written by Keith Seitz + + Copyright 2003 Free Software Foundation, Inc. + + This file is part of Insight. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "defs.h" +#include "interps.h" +#include "ui-file.h" +#include "ui-out.h" +#include "cli-out.h" +#include "gdb_string.h" +#include "cli/cli-cmds.h" +#include "cli/cli-decode.h" + +#include "tcl.h" +#include "tk.h" +#include "gdbtk.h" + +static void gdbtk_command_loop (void); +static void hack_disable_interpreter_exec (char *, int); + +struct gdbtk_interp_data +{ + struct ui_file *_stdout; + struct ui_file *_stderr; + struct ui_file *_stdlog; + struct ui_file *_stdtarg; +}; + +static struct gdbtk_interp_data *gdbtk_data; + +/* See note in gdbtk_interpreter_init */ +static void +hack_disable_interpreter_exec (char *args, int from_tty) +{ + error ("interpreter-exec not available when running Insight"); +} + +static void * +gdbtk_interpreter_init (void) +{ + gdbtk_init (); + + /* Disable interpreter-exec. It causes us big trouble right now. */ + struct cmd_list_element *cmd = NULL; + struct cmd_list_element *alias = NULL; + struct cmd_list_element *prefix = NULL; + struct cmd_list_element *c; + + if (lookup_cmd_composition ("interpreter-exec", &alias, &prefix, &cmd)) + { + set_cmd_cfunc (cmd, hack_disable_interpreter_exec); + } + + return gdbtk_data; +} + +static int +gdbtk_interpreter_resume (void *data) +{ + static int started = 0; + struct gdbtk_interp_data *d = (struct gdbtk_interp_data *) data; + gdbtk_add_hooks (); + + gdb_stdout = d->_stdout; + gdb_stderr = d->_stderr; + gdb_stdlog = d->_stdlog; + gdb_stdtarg = d->_stdtarg; + + command_loop_hook = gdbtk_command_loop; + + /* 2003-02-11 keiths: We cannot actually source our main Tcl file in + our interpreter's init function because any errors that may + get generated will go to the wrong gdb_stderr. Instead of hacking + our interpreter init function to force gdb_stderr to our ui_file, + we defer sourcing the startup file until now, when gdb is ready + to let our interpreter run. */ + if (!started) + { + started = 1; + gdbtk_source_start_file (); + } + + return 1; +} + +static int +gdbtk_interpreter_suspend (void *data) +{ + return 1; +} + +static int +gdbtk_interpreter_display_prompt_p (void *data) +{ + return 1; +} + +static int +gdbtk_interpreter_exec (void *data, const char *command_str) +{ + return 1; +} + +/* This function is called instead of gdb's internal command loop. This is the + last chance to do anything before entering the main Tk event loop. + At the end of the command, we enter the main loop. */ + +static void +gdbtk_command_loop (void) +{ + extern FILE *instream; + + /* We no longer want to use stdin as the command input stream */ + instream = NULL; + + if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_preloop") != TCL_OK) + { + const char *msg; + + /* Force errorInfo to be set up propertly. */ + Tcl_AddErrorInfo (gdbtk_interp, ""); + + msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); +#ifdef _WIN32 + MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); +#else + fputs_unfiltered (msg, gdb_stderr); +#endif + } + +#ifdef _WIN32 + close_bfds (); +#endif + + Tk_MainLoop (); +} + +void +_initialize_gdbtk_interp (void) +{ + static const struct interp_procs procs = { + gdbtk_interpreter_init, /* init_proc */ + gdbtk_interpreter_resume, /* resume_proc */ + gdbtk_interpreter_suspend, /* suspend_proc */ + gdbtk_interpreter_exec, /* exec_proc */ + gdbtk_interpreter_display_prompt_p /* prompt_proc_p */ + }; + struct interp *gdbtk_interp; + + gdbtk_data = + (struct gdbtk_interp_data *) xmalloc (sizeof (struct gdbtk_interp_data)); + memset (gdbtk_data, 0, sizeof (struct gdbtk_interp_data)); + gdbtk_data->_stdout = gdbtk_fileopen (); + gdbtk_data->_stderr = gdbtk_fileopen (); + gdbtk_data->_stdlog = gdbtk_fileopen (); + gdbtk_data->_stdtarg = gdbtk_fileopen (); + gdbtk_interp = interp_new ("insight", gdbtk_data, cli_out_new (gdbtk_data->_stdout), + &procs); + interp_add (gdbtk_interp); +} diff --git a/gdb/gdbtk/generic/gdbtk-main.c b/gdb/gdbtk/generic/gdbtk-main.c index ec945a643e..32e54249d8 100644 --- a/gdb/gdbtk/generic/gdbtk-main.c +++ b/gdb/gdbtk/generic/gdbtk-main.c @@ -32,6 +32,6 @@ main (int argc, char **argv) args.argc = argc; args.argv = argv; args.use_windows = 1; - args.interpreter_p = "gdbtk"; + args.interpreter_p = "insight"; return gdb_main (&args); } diff --git a/gdb/gdbtk/generic/gdbtk.c b/gdb/gdbtk/generic/gdbtk.c index 3fb975b04f..1f4d1bbf22 100644 --- a/gdb/gdbtk/generic/gdbtk.c +++ b/gdb/gdbtk/generic/gdbtk.c @@ -29,10 +29,8 @@ #include "tracepoint.h" #include "demangle.h" #include "version.h" -#include "cli-out.h" #include "top.h" #include "annotate.h" -#include "interps.h" #if defined(_WIN32) || defined(__CYGWIN__) #define WIN32_LEAN_AND_MEAN @@ -84,7 +82,9 @@ char *external_editor_command = NULL; extern int Tktable_Init (Tcl_Interp * interp); -static void gdbtk_init (char *); +void gdbtk_init (void); + +static void gdbtk_init_1 (char *argv0); void gdbtk_interactive (void); @@ -119,6 +119,7 @@ static char *gdbtk_source_filename = NULL; int gdbtk_disable_fputs = 1; +static const char *argv0; #ifndef _WIN32 @@ -346,8 +347,8 @@ gdbtk_cleanup (PTR dummy) * the Tcl based library files. */ -static void -gdbtk_init (char *argv0) +void +gdbtk_init (void) { struct cleanup *old_chain; char *s; @@ -362,7 +363,6 @@ gdbtk_init (char *argv0) #ifndef _WIN32 if (getenv ("DISPLAY") == NULL) { - init_ui_hook = NULL; return; } #endif @@ -558,13 +558,6 @@ gdbtk_init (char *argv0) Tcl_StaticPackage (gdbtk_interp, "Insight", Gdbtk_Init, NULL); - /* This adds all the hooks that call up from the bowels of gdb - * back into Tcl-land... - */ - - gdbtk_add_hooks (); - - /* Add a back door to Tk from the gdb console... */ add_com ("tk", class_obscure, tk_command, @@ -585,24 +578,19 @@ gdbtk_init (char *argv0) external_editor_command = NULL; } - /* close old output and send new to GDBTK */ - ui_file_delete (gdb_stdout); - ui_file_delete (gdb_stderr); - gdb_stdout = gdbtk_fileopen (); - gdb_stderr = gdbtk_fileopen (); - gdb_stdlog = gdbtk_fileopen (); - gdb_stdtarg = gdbtk_fileopen (); - uiout = cli_out_new (gdb_stdout); - #ifdef __CYGWIN32__ (void) FreeConsole (); #endif - /* find the gdb tcl library and source main.tcl */ + discard_cleanups (old_chain); +} - { +void +gdbtk_source_start_file (void) +{ + /* find the gdb tcl library and source main.tcl */ #ifdef NO_TCLPRO_DEBUGGER - static char script[] = "\ + static char script[] = "\ proc gdbtk_find_main {} {\n\ global Paths GDBTK_LIBRARY\n\ rename gdbtk_find_main {}\n\ @@ -628,31 +616,29 @@ proc gdbtk_find_main {} {\n\ gdbtk_find_main"; #endif /* NO_TCLPRO_DEBUGGER */ - /* now enable gdbtk to parse the output from gdb */ - gdbtk_disable_fputs = 0; + /* now enable gdbtk to parse the output from gdb */ + gdbtk_disable_fputs = 0; - if (Tcl_GlobalEval (gdbtk_interp, (char *) script) != TCL_OK) - { - const char *msg; + if (Tcl_GlobalEval (gdbtk_interp, (char *) script) != TCL_OK) + { + const char *msg; - /* Force errorInfo to be set up propertly. */ - Tcl_AddErrorInfo (gdbtk_interp, ""); - msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); + /* Force errorInfo to be set up propertly. */ + Tcl_AddErrorInfo (gdbtk_interp, ""); + msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); #ifdef _WIN32 - /* On windows, display the error using a pop-up message box. - If GDB wasn't started from the DOS prompt, the user won't - get to see the failure reason. */ - MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); - throw_exception (RETURN_ERROR); + /* On windows, display the error using a pop-up message box. + If GDB wasn't started from the DOS prompt, the user won't + get to see the failure reason. */ + MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); + throw_exception (RETURN_ERROR); #else - /* FIXME: cagney/2002-04-17: Wonder what the lifetime of - ``msg'' is - does it need a cleanup? */ - error (msg); + /* FIXME: cagney/2002-04-17: Wonder what the lifetime of + ``msg'' is - does it need a cleanup? */ + error (msg); #endif - } - } - + } /* Now source in the filename provided by the --tclcommand option. This is mostly used for the gdbtk testsuite... */ @@ -665,8 +651,13 @@ gdbtk_find_main"; free (gdbtk_source_filename); free (script); } +} - discard_cleanups (old_chain); +static void +gdbtk_init_1 (char *arg0) +{ + argv0 = arg0; + init_ui_hook = NULL; } /* gdbtk_test is used in main.c to validate the -tclcommand option to @@ -683,96 +674,17 @@ gdbtk_test (char *filename) return 1; } -void * -tk_init (void) -{ - /* FIXME: Should return the interpreter's context. */ - return NULL; -} - -int -gdbtk_resume (void *data) -{ - return 1; -} - -int -gdbtk_suspend (void *data) -{ - return 1; -} - -int -gdbtk_prompt_p (void *data) -{ - return 0; -} - -int -gdbtk_exec (void *data, const char *command) -{ - internal_error (__FILE__, __LINE__, "tk_exec not implemented"); -} - -/* This function is called instead of gdb's internal command loop. This is the - last chance to do anything before entering the main Tk event loop. - At the end of the command, we enter the main loop. */ - -static void -gdbtk_command_loop (void *data) -{ - extern FILE *instream; - - /* We no longer want to use stdin as the command input stream */ - instream = NULL; - - if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_preloop") != TCL_OK) - { - const char *msg; - - /* Force errorInfo to be set up propertly. */ - Tcl_AddErrorInfo (gdbtk_interp, ""); - - msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); -#ifdef _WIN32 - MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); -#else - fputs_unfiltered (msg, gdb_stderr); -#endif - } - -#ifdef _WIN32 - close_bfds (); -#endif - - Tk_MainLoop (); -} - /* Come here during initialize_all_files () */ void _initialize_gdbtk () { - static const struct interp_procs tk_procs = - { - tk_init, - gdbtk_resume, - gdbtk_suspend, - gdbtk_exec, - gdbtk_prompt_p, - gdbtk_command_loop, - }; - - interp_add (interp_new ("gdbtk", NULL, NULL, &tk_procs)); - - /* FIXME: cagney/2003-02-12: This is wrong. The initialization - should be done via the init function. */ - if (use_windows) - { - /* Tell the rest of the world that Gdbtk is now set up. */ - init_ui_hook = gdbtk_init; - } -#ifdef __CYGWIN32__ + /* Current_interpreter not set yet, so we must check + if "interpreter_p" is set to "insight" to know if + insight is GOING to run. */ + if (strcmp (interpreter_p, "insight") == 0) + init_ui_hook = gdbtk_init_1; +#ifdef __CYGWIN__ else { DWORD ft = GetFileType (GetStdHandle (STD_INPUT_HANDLE)); diff --git a/gdb/gdbtk/generic/gdbtk.h b/gdb/gdbtk/generic/gdbtk.h index 471e6c5ded..8065478a9f 100644 --- a/gdb/gdbtk/generic/gdbtk.h +++ b/gdb/gdbtk/generic/gdbtk.h @@ -1,5 +1,5 @@ /* Tcl/Tk interface routines header file. - Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001 + Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2003 Free Software Foundation, Inc. Written by Stu Grossman of Cygnus Support. @@ -22,6 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifndef _GDBTK_H +#define _GDBTK_H + #ifdef _WIN32 #define GDBTK_PATH_SEP ";" #else @@ -176,3 +179,10 @@ extern void by the startup code to fill in the hooks needed by core gdb. */ extern void gdbtk_add_hooks (void); +/* Initialize Insight */ +extern void gdbtk_init (void); + +/* Start Insight. Insight must have already been initialized with a call + to gdbtk_init. */ +extern void gdbtk_source_start_file (void); +#endif /* !_GDBTK_H */ -- 2.11.0