This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


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

Re: [RFA] New ui_file streams for Insight


On Sun, 1 Apr 2001, Andrew Cagney wrote:

> I suspect it isn't yet wired up quite right.  Can this be done by
> hooking init_ui_hook and/or pre_init_ui_hook and thus eliminate the need
> for the #ifdefs and externs (1).

Its wired up the way tui is. Probably not the best model :^) Here's the
patch with ifdefs removed.

2001-04-01  Martin M. Hunt  <hunt@redhat.com>

        * main.c (captured_main): For GDBtk, don't use tui_fileopen().
        Handle all stream setup in gdbtk_init

2001-03-31  Martin M. Hunt  <hunt@redhat.com>

        * generic/gdbtk-hooks.c (gdbtk_fileopen): New function.
        Initialize ui_file stuff for gdbtk.
        (gdbtk_fputs): Don't print if gdbtk_disable_fputs. Send
        stdlog and stdtarg to their handler functions.

        * generic/gdbtk.c (Gdbtk_Init): Don't set gdb_stdlog
        and gdb_stdtarg to gdb_stdout,
        (gdbtk_init): Unset gdbtk_disable_fputs
        when ready to accept output from gdb. Remove references to
        fputs_unfiltered_hook.

        * generic/gdbtk.h: Declare new flag gdbtk_disable_fputs.

        * generic/gdbtk-cmds.c (gdb_restore_fputs): Instead of setting
        fputs_unfiltered_hook, set the new flag gdbtk_disable_fputs.

        * library/prefs.tcl (pref_set_defaults): Add defaults
        for log_fg and target_fg.

        * library/interface.tcl (gdbtk_tcl_fputs_error): Use
        err_tag.
        (gdbtk_tcl_fputs_log): New function. Write log messages
        to console.
        (gdbtk_tcl_fputs_target): New function. Write target
        IO to console.

        * library/console.ith (einsert): Add tag parameter.

        * library/console.itb (_build_win): Add new tags for log
        and target IO.
        (einsert): Add tag parameter.

Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.7
diff -u -p -r1.7 main.c
--- main.c	2001/03/06 08:21:10	1.7
+++ main.c	2001/04/02 02:50:39
@@ -35,7 +35,8 @@
 #include "gdb_string.h"
 #include "event-loop.h"
 #include "ui-out.h"
-#if defined (TUI) || defined (GDBTK)
+
+#if defined (TUI)
 /* FIXME: cagney/2000-01-31: This #include is to allow older code such
    as that found in the TUI to continue to build. */
 #include "tui/tui-file.h"
@@ -199,10 +200,7 @@ captured_main (void *data)
   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
   current_directory = gdb_dirbuf;

-#if defined (TUI) || defined (GDBTK)
-  /* Older code uses the tui_file and fputs_unfiltered_hook().  It
-     should be using a customized UI_FILE object and re-initializing
-     within its own _initialize function.  */
+#if defined (TUI)
   gdb_stdout = tui_fileopen (stdout);
   gdb_stderr = tui_fileopen (stderr);
   gdb_stdlog = gdb_stdout;	/* for moment */
Index: gdbtk/generic/gdbtk-cmds.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-cmds.c,v
retrieving revision 1.25
diff -u -p -r1.25 gdbtk-cmds.c
--- gdbtk-cmds.c	2001/03/13 23:31:14	1.25
+++ gdbtk-cmds.c	2001/04/02 02:50:40
@@ -452,12 +452,6 @@ Gdbtk_Init (interp)
   if (gdb_variable_init (interp) != TCL_OK)
     return TCL_ERROR;

-  /* Route GDB internal log messages and target output and through
-     stderr instead of stdout.  FIXME: Should have a separate streams
-     for handling these two types of output. */
-  gdb_stdtarg = gdb_stderr;
-  gdb_stdlog = gdb_stderr;
-
   /* Register/initialize any architecture specific data */
   setup_architecture_data ();
   register_gdbarch_swap (&old_regs, sizeof (old_regs), NULL);
@@ -1855,8 +1849,8 @@ gdb_restore_fputs (clientData, interp, o
      int objc;
      Tcl_Obj *CONST objv[];
 {
-    fputs_unfiltered_hook = gdbtk_fputs;
-    return TCL_OK;
+  gdbtk_disable_fputs = 0;
+  return TCL_OK;
 }

 /* This implements the TCL command `gdb_regnames'.  Its syntax is:
Index: gdbtk/generic/gdbtk-hooks.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk-hooks.c,v
retrieving revision 1.8
diff -u -p -r1.8 gdbtk-hooks.c
--- gdbtk-hooks.c	2000/11/29 00:27:46	1.8
+++ gdbtk-hooks.c	2001/04/02 02:50:40
@@ -1,5 +1,6 @@
-/* Startup code for gdbtk.
-   Copyright 1994-1998, 2000 Free Software Foundation, Inc.
+/* Startup code for Insight.
+   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001
+   Free Software Foundation, Inc.

    Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.

@@ -193,11 +194,8 @@ gdbtk_restore_result_ptr (void *old_resu
   result_ptr = (gdbtk_result *) old_result_ptr;
 }

-
-
 /* This allows you to Tcl_Eval a tcl command which takes
    a command word, and then a single argument. */
-
 int
 gdbtk_two_elem_cmd (cmd_name, argv1)
      char *cmd_name;
@@ -221,6 +219,14 @@ gdbtk_two_elem_cmd (cmd_name, argv1)
   return result;
 }

+struct ui_file *
+gdbtk_fileopen (void)
+{
+  struct ui_file *file = ui_file_new ();
+  set_ui_file_fputs (file, gdbtk_fputs);
+  return file;
+}
+
 /* This handles all the output from gdb.  All the gdb printf_xxx functions
  * eventually end up here.  The output is either passed to the result_ptr
  * where it will go to the result of some gdbtk command, or passed to the
@@ -242,13 +248,18 @@ gdbtk_two_elem_cmd (cmd_name, argv1)
  */

 void
-gdbtk_fputs (ptr, stream)
-     const char *ptr;
-     struct ui_file *stream;
+gdbtk_fputs (const char *ptr, struct ui_file *stream)
 {
+  if (gdbtk_disable_fputs)
+    return;
+
   in_fputs = 1;

-  if (result_ptr != NULL)
+  if (stream == gdb_stdlog)
+    gdbtk_two_elem_cmd ("gdbtk_tcl_fputs_log", (char *) ptr);
+  else if (stream == gdb_stdtarg)
+    gdbtk_two_elem_cmd ("gdbtk_tcl_fputs_target", (char *) ptr);
+  else if (result_ptr != NULL)
     {
       if (result_ptr->flags & GDBTK_TO_RESULT)
 	{
Index: gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.8
diff -u -p -r1.8 gdbtk.c
--- gdbtk.c	2000/11/29 00:27:46	1.8
+++ gdbtk.c	2001/04/02 02:50:40
@@ -1,5 +1,6 @@
-/* Startup code for gdbtk.
-   Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Startup code for Insight
+   Copyright 1994, 1995, 1996, 1997, 1998, 2001
+   Free Software Foundation, Inc.

    Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.

@@ -32,7 +33,6 @@
 #include "tracepoint.h"
 #include "demangle.h"
 #include "version.h"
-#include "tui/tui-file.h"

 #ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN
@@ -125,6 +125,8 @@ int running_now;
    interpreter when it goes idle at startup. Used with the testsuite. */
 static char *gdbtk_source_filename = NULL;

+int gdbtk_disable_fputs = 1;
+

 #ifndef _WIN32

@@ -348,6 +350,7 @@ gdbtk_cleanup (dummy)
   Tcl_Finalize ();
 }

+
 /* Initialize gdbtk.  This involves creating a Tcl interpreter,
  * defining all the Tcl commands that the GUI will use, pointing
  * all the gdb "hooks" to the correct functions,
@@ -362,6 +365,7 @@ gdbtk_init (argv0)
   struct cleanup *old_chain;
   int found_main;
   char *s;
+
   Tcl_Obj *auto_path_elem, *auto_path_name;

   /* If there is no DISPLAY environment variable, Tk_Init below will fail,
@@ -375,6 +379,14 @@ gdbtk_init (argv0)

   old_chain = make_cleanup (cleanup_init, 0);

+  /* 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 ();
+
   /* First init tcl and tk. */
   Tcl_FindExecutable (argv0);
   gdbtk_interp = Tcl_CreateInterp ();
@@ -472,6 +484,7 @@ gdbtk_init (argv0)

   gdbtk_add_hooks ();

+
   /* Add a back door to Tk from the gdb console... */

   add_com ("tk", class_obscure, tk_command,
@@ -486,6 +499,7 @@ gdbtk_init (argv0)
   Tcl_SetVar (gdbtk_interp, "external_editor_command",
 	      external_editor_command, 0);

+
   /* find the gdb tcl library and source main.tcl */

   {
@@ -515,27 +529,18 @@ proc gdbtk_find_main {} {\n\
 }\n\
 gdbtk_find_main";
 #endif /* NO_TCLPRO_DEBUGGER */
-
-    /* fputs_unfiltered_hook = NULL; *//* Force errors to stdout/stderr */
-
-    fputs_unfiltered_hook = gdbtk_fputs;

-    /* FIXME: set gdb_stdtarg for now until gdbtk is changed to use
-       struct ui_out. */
-
-    gdb_stdtarg = gdb_stdout;
-
+    /* now enable gdbtk to parse the output from gdb */
+    gdbtk_disable_fputs = 0;
+
     if (Tcl_GlobalEval (gdbtk_interp, (char *) script) != TCL_OK)
       {
 	char *msg;

 	/* Force errorInfo to be set up propertly.  */
 	Tcl_AddErrorInfo (gdbtk_interp, "");
-
 	msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY);

-	fputs_unfiltered_hook = NULL;	/* Force errors to stdout/stderr */
-
 #ifdef _WIN32
 	MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL);
 #else
@@ -543,10 +548,10 @@ gdbtk_find_main";
 #endif

 	error ("");
-
       }
   }

+
   /* Now source in the filename provided by the --tclcommand option.
      This is mostly used for the gdbtk testsuite... */

@@ -558,7 +563,6 @@ gdbtk_find_main";
       free (gdbtk_source_filename);
       free (script);
     }
-

   discard_cleanups (old_chain);
 }
Index: gdbtk/generic/gdbtk.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.h,v
retrieving revision 1.4
diff -u -p -r1.4 gdbtk.h
--- gdbtk.h	2000/07/02 20:07:07	1.4
+++ gdbtk.h	2001/04/02 02:50:40
@@ -1,5 +1,6 @@
 /* Tcl/Tk interface routines header file.
-   Copyright 1994-1998, 2000 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1996, 1997, 1998, 2000, 2001
+   Free Software Foundation, Inc.

    Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.

@@ -160,6 +161,8 @@ extern int gdbtk_two_elem_cmd (char *, c
 extern int call_wrapper (ClientData, Tcl_Interp *, int, Tcl_Obj * CONST[]);
 extern int target_is_native (struct target_ops *t);
 extern void gdbtk_fputs (const char *, struct ui_file *);
+extern struct ui_file *gdbtk_fileopen (void);
+extern int gdbtk_disable_fputs;

 #ifdef _WIN32
 extern void close_bfds ();
Index: gdbtk/library/console.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/console.itb,v
retrieving revision 1.7
diff -u -p -r1.7 console.itb
--- console.itb	2000/12/08 20:17:03	1.7
+++ console.itb	2001/04/02 02:50:40
@@ -1,5 +1,5 @@
-# Console window for GDBtk
-# Copyright 1998, 1999 Cygnus Solutions
+# Console window for Insight
+# Copyright 1998, 1999, 2001 Cygnus Solutions
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License (GPL) as published by
@@ -60,6 +60,8 @@ body Console::_build_win {} {

   $_twin tag configure prompt_tag -foreground [pref get gdb/console/prompt_fg]
   $_twin tag configure err_tag -foreground [pref get gdb/console/error_fg]
+  $_twin tag configure log_tag -foreground [pref get gdb/console/log_fg]
+  $_twin tag configure target_tag -foreground [pref get gdb/console/target_fg]
   $_twin configure -font [pref get gdb/console/font]

   #
@@ -232,12 +234,12 @@ body Console::insert {line} {
 #-------------------------------------------------------------------
 #  METHOD:  einsert - insert error text in the text widget
 # ------------------------------------------------------------------
-body Console::einsert {line} {
+body Console::einsert {line tag} {
   debug $line
   if {$_needNL} {
     $_twin insert end "\n"
   }
-  $_twin insert end $line err_tag
+  $_twin insert end $line $tag
   $_twin see insert
   set _needNL 0
 }
Index: gdbtk/library/console.ith
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/console.ith,v
retrieving revision 1.2
diff -u -p -r1.2 console.ith
--- console.ith	2000/12/04 19:29:01	1.2
+++ console.ith	2001/04/02 02:50:40
@@ -29,7 +29,7 @@ class Console {
     method idle {}
     method busy {}
     method insert {line}
-    method einsert {line}
+    method einsert {line tag}
     method invoke {}
     method _insertion {args}
     method get_text {}
Index: gdbtk/library/interface.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/interface.tcl,v
retrieving revision 1.14
diff -u -p -r1.14 interface.tcl
--- interface.tcl	2001/02/08 19:26:31	1.14
+++ interface.tcl	2001/04/02 02:50:41
@@ -389,15 +389,31 @@ proc echo {args} {
 }

 # ------------------------------------------------------------------
-# PROC: gdbtk_tcl_fputs_error -
+# PROC: gdbtk_tcl_fputs_error - write an error message
 # ------------------------------------------------------------------
 proc gdbtk_tcl_fputs_error {message} {
-  global gdbtk_state
-  # Restore the fputs hook, in case anyone forgot to put it back...
-  gdb_restore_fputs
+  if {$::gdbtk_state(console) != ""} {
+    $::gdbtk_state(console) einsert $message err_tag
+    update
+  }
+}

-  if {$gdbtk_state(console) != ""} {
-    $gdbtk_state(console) einsert $message
+# ------------------------------------------------------------------
+# PROC: gdbtk_tcl_fputs_log - write a log message
+# ------------------------------------------------------------------
+proc gdbtk_tcl_fputs_log {message} {
+  if {$::gdbtk_state(console) != ""} {
+    $::gdbtk_state(console) einsert $message log_tag
+    update
+  }
+}
+
+# ------------------------------------------------------------------
+# PROC: gdbtk_tcl_fputs_target - write target output
+# ------------------------------------------------------------------
+proc gdbtk_tcl_fputs_target {message} {
+  if {$::gdbtk_state(console) != ""} {
+    $::gdbtk_state(console) einsert $message target_tag
     update
   }
 }
@@ -987,7 +1003,7 @@ necessary,\nmodify the port setting with

     if {![catch {pref get gdb/load/$gdb_target_name-after_attaching} aa] && $aa != ""} {
       if {[catch {gdb_cmd $aa} err]} {
-	catch {[ManagedWin::find Console] einsert $err}
+	catch {[ManagedWin::find Console] einsert $err err_tag}
       }
     }
     set gdb_target_changed 0
Index: gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.7
diff -u -p -r1.7 prefs.tcl
--- prefs.tcl	2001/03/15 18:31:38	1.7
+++ prefs.tcl	2001/04/02 02:50:41
@@ -287,6 +287,8 @@ proc pref_set_defaults {} {
   pref define gdb/console/wrap            0
   pref define gdb/console/prompt_fg       DarkGreen
   pref define gdb/console/error_fg        red
+  pref define gdb/console/log_fg          green
+  pref define gdb/console/target_fg       blue
   pref define gdb/console/font            src-font

   # Source window defaults


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