From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fernando Nasser To: "Martin M. Hunt" Cc: gdb@sources.redhat.com, insight@sources.redhat.com Subject: Re: [RFA] New ui_file streams for Insight Date: Sat, 31 Mar 2001 07:15:00 -0000 Message-id: <3AC5F395.180D4568@redhat.com> References: X-SW-Source: 2001-03/msg00335.html "Martin M. Hunt" wrote: > > Here are my first set of changes to add support for multiple streams to > Insight. Instead of using the tui code and copying gdb_stdlog and > gdb_stdtarg to gdb_stdout, it creates unique ui_files for each. Currently > Insight will simple write stderr, stdlog, and stdtarg to the console > window (if it is open). stderr messages appear in red, stdlog in green, > and stdtarg in blue. > Thank you very much for doing this. I am approving the gdbtk subdirectory part (assuming you have tested it on at least one native and one remote target) but I guess we have to wait for the main.c maintainer approval as well. We have the code for a separate target output (Tom wrote a Unix xterm and I added a Win32 console afterwards). I will check it in after your patch (Tom's xterm is already in, but it works only for natives at the moment). Regards, Fernando > In main.c, I moved the creation of the gdbtk ui_files until after the > arguments are parsed. I don't see that this would cause problems, > although I don't see why any of the ui_files are created before the > command line is processed. > > 2001-03-30 Martin M. Hunt > > * main.c (captured_main): For GDBtk, don't use tui_fileopen(). > Instead, wait until ars are processed, then if use_windows > is set, replace the gdb_stdout and gdb_stderr with gdbtk > ui_files. > > 2001-03-31 Martin M. Hunt > > * 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/03/31 08:09:18 > @@ -35,10 +35,11 @@ > #include "gdb_string.h" > #include "event-loop.h" > #include "ui-out.h" > -#if defined (TUI) || defined (GDBTK) > -/* FIXME: cagney/2000-01-31: This #include is to allow older code such > - as that found in the TUI to continue to build. */ > + > +#if defined (TUI) > #include "tui/tui-file.h" > +#elif defined (GDBTK) > +extern struct ui_file *gdbtk_fileopen (); > #endif > > /* If nonzero, display time usage both at startup and for each command. */ > @@ -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 */ > @@ -493,6 +491,17 @@ extern int gdbtk_test (char *); > /* Should this be moved to tui-top.c:_initialize_tui()? */ > if (tui_version) > init_ui_hook = tuiInit; > +#elif defined(GDBTK) > + if (use_windows) > + { > + /* 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 (); > + } > #endif > > /* Initialize all files. Give the interpreter a chance to take > 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/03/31 08:09:19 > @@ -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/03/31 08:09:19 > @@ -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 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/03/31 08:09:19 > @@ -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 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 > > @@ -486,6 +488,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 +518,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 +537,10 @@ gdbtk_find_main"; > #endif > > error (""); > - > } > } > > + > /* Now source in the filename provided by the --tclcommand option. > This is mostly used for the gdbtk testsuite... */ > > @@ -559,8 +553,8 @@ gdbtk_find_main"; > free (script); > } > > - > discard_cleanups (old_chain); > + > } > > /* gdbtk_test is used in main.c to validate the -tclcommand option to > 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/03/31 08:09:20 > @@ -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 of Cygnus Support. > > @@ -160,6 +161,7 @@ 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 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/03/31 08:09:20 > @@ -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/03/31 08:09:20 > @@ -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/03/31 08:09:20 > @@ -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/03/31 08:09:20 > @@ -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 -- Fernando Nasser Red Hat Canada Ltd. E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9