This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add interpreter support


Hi,

This patch should "fix" things. It isn't perfect, but at least insight
won't crash anymore. (The "-nw" option won't work anymore, either. You
now need to use "-i=console" instead.)

There's one or two hacks in it (init_ui_hook is still used), but those
will go away when there's a resolution on the gdb side of how to best
handle passing argv[0] around.

Please let me know if there are any more problems.
Keith

ChangeLog
2003-02-18  Keith Seitz  <keiths@redhat.com>

        * 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.



Index: generic/gdbtk.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.h,v
retrieving revision 1.6
diff -u -p -r1.6 gdbtk.h
--- generic/gdbtk.h	10 May 2001 18:04:24 -0000	1.6
+++ generic/gdbtk.h	18 Feb 2003 23:28:27 -0000
@@ -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 <grossman@cygnus.com> 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 */
Index: generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.35
diff -u -p -r1.35 gdbtk.c
--- generic/gdbtk.c	17 Feb 2003 18:49:11 -0000	1.35
+++ generic/gdbtk.c	18 Feb 2003 23:28:27 -0000
@@ -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 = NUL
 
 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;
-
-	/* Force errorInfo to be set up propertly.  */
-	Tcl_AddErrorInfo (gdbtk_interp, "");
-	msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY);
+  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);
 
 #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));
Index: generic/gdbtk-main.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-main.c,v
retrieving revision 1.2
diff -u -p -r1.2 gdbtk-main.c
--- generic/gdbtk-main.c	15 Feb 2003 07:12:05 -0000	1.2
+++ generic/gdbtk-main.c	18 Feb 2003 23:28:27 -0000
@@ -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);
 }
Index: generic/gdbtk-interp.c
===================================================================
RCS file: generic/gdbtk-interp.c
diff -N generic/gdbtk-interp.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ generic/gdbtk-interp.c	18 Feb 2003 23:28:27 -0000
@@ -0,0 +1,178 @@
+/* Insight Definitions for GDB, the GNU debugger.
+   Written by Keith Seitz <kseitz@uglyboxes.com>
+
+   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);
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]