Make gdb_stdout&co be per UI

We need to have these send output to the proper UI.

However, this patch still make them look like globals.  Kind of like
__thread variables, if you will.  Changing everything throughout to
write something like current_ui->gdb_stdout instead would be massive
overkill, IMNSHO.

This leaves gdb_stdtargin/stdtarg/stdtargerr global, but maybe that was a
mistake, I'm not sure -- IIRC, MI formats target I/O differently, so
if we have a separate MI channel, then I guess target output should go
there instead of to gdb's stdout.  OTOH, maybe GDB should send that
instead to "set inferior-tty", instead of multiplexing it over MI.  We
can always fix those later when it gets clearer where they should go.

gdb/ChangeLog:
2016-06-21  Pedro Alves  <palves@redhat.com>

	* main.c (gdb_stdout, gdb_stderr, gdb_stdlog, gdb_stdin): Delete
	globals.
	(gen_ret_current_ui_field_ptr): New macro.  Use it to generate
	wrappers for gdb_stdout, gdb_stderr, gdb_stdlog and gdb_stdin.
	* top.h (struct ui) <m_gdb_stdout, m_gdb_stdin, m_gdb_stderr,
	m_gdb_stdlog>: New fields.
	(current_ui_gdb_stdout_ptr, current_ui_gdb_stdin_ptr)
	(current_ui_gdb_stderr_ptr, current_ui_gdb_stdlog_ptr): Declare.
	(gdb_stdout, gdb_stdin, gdb_stderr, gdb_stdlog): Reimplement as
	macros.
This commit is contained in:
Pedro Alves 2016-06-21 01:11:44 +01:00
parent a74e1786ac
commit 79aa2fe86f
5 changed files with 59 additions and 9 deletions

View File

@ -1,3 +1,16 @@
2016-06-21 Pedro Alves <palves@redhat.com>
* main.c (gdb_stdout, gdb_stderr, gdb_stdlog, gdb_stdin): Delete
globals.
(gen_ret_current_ui_field_ptr): New macro. Use it to generate
wrappers for gdb_stdout, gdb_stderr, gdb_stdlog and gdb_stdin.
* top.h (struct ui) <m_gdb_stdout, m_gdb_stdin, m_gdb_stderr,
m_gdb_stdlog>: New fields.
(current_ui_gdb_stdout_ptr, current_ui_gdb_stdin_ptr)
(current_ui_gdb_stderr_ptr, current_ui_gdb_stdlog_ptr): Declare.
(gdb_stdout, gdb_stdin, gdb_stderr, gdb_stdlog): Reimplement as
macros.
2016-06-21 Pedro Alves <palves@redhat.com> 2016-06-21 Pedro Alves <palves@redhat.com>
* event-top.c: Update readline-related comments. * event-top.c: Update readline-related comments.

View File

@ -68,10 +68,6 @@ static int gdb_datadir_provided = 0;
the possibly relocated path to python's lib directory. */ the possibly relocated path to python's lib directory. */
char *python_libdir = 0; char *python_libdir = 0;
struct ui_file *gdb_stdout;
struct ui_file *gdb_stderr;
struct ui_file *gdb_stdlog;
struct ui_file *gdb_stdin;
/* Target IO streams. */ /* Target IO streams. */
struct ui_file *gdb_stdtargin; struct ui_file *gdb_stdtargin;
struct ui_file *gdb_stdtarg; struct ui_file *gdb_stdtarg;

View File

@ -86,6 +86,21 @@ extern void initialize_all_files (void);
#define DEFAULT_PROMPT "(gdb) " #define DEFAULT_PROMPT "(gdb) "
#endif #endif
/* Generate a function that exports a pointer to a field of the
current UI. */
#define gen_ret_current_ui_field_ptr(type, name) \
type * \
current_ui_## name ## _ptr (void) \
{ \
return &current_ui->m_ ## name; \
}
gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdout)
gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdin)
gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stderr)
gen_ret_current_ui_field_ptr (struct ui_file *, gdb_stdlog)
/* Initialization file name for gdb. This is host-dependent. */ /* Initialization file name for gdb. This is host-dependent. */
const char gdbinit[] = GDBINIT; const char gdbinit[] = GDBINIT;

View File

@ -49,6 +49,23 @@ struct ui
/* The function to invoke when a complete line of input is ready for /* The function to invoke when a complete line of input is ready for
processing. */ processing. */
void (*input_handler) (char *); void (*input_handler) (char *);
/* The fields below that start with "m_" are "private". They're
meant to be accessed through wrapper macros that make them look
like globals. */
/* The ui_file streams. */
/* Normal results */
struct ui_file *m_gdb_stdout;
/* Input stream */
struct ui_file *m_gdb_stdin;
/* Serious error notifications */
struct ui_file *m_gdb_stderr;
/* Log/debug/trace messages that should bypass normal stdout/stderr
filtering. For moment, always call this stream using
*_unfiltered. In the very near future that restriction shall be
removed - either call shall be unfiltered. (cagney 1999-06-13). */
struct ui_file *m_gdb_stdlog;
}; };
extern struct ui *current_ui; extern struct ui *current_ui;

View File

@ -159,18 +159,27 @@ extern void reinitialize_more_filter (void);
extern int pagination_enabled; extern int pagination_enabled;
/* Global ui_file streams. These are all defined in main.c. */ extern struct ui_file **current_ui_gdb_stdout_ptr (void);
extern struct ui_file **current_ui_gdb_stdin_ptr (void);
extern struct ui_file **current_ui_gdb_stderr_ptr (void);
extern struct ui_file **current_ui_gdb_stdlog_ptr (void);
/* The current top level's ui_file streams. */
/* Normal results */ /* Normal results */
extern struct ui_file *gdb_stdout; #define gdb_stdout (*current_ui_gdb_stdout_ptr ())
/* Input stream */ /* Input stream */
extern struct ui_file *gdb_stdin; #define gdb_stdin (*current_ui_gdb_stdin_ptr ())
/* Serious error notifications */ /* Serious error notifications */
extern struct ui_file *gdb_stderr; #define gdb_stderr (*current_ui_gdb_stderr_ptr ())
/* Log/debug/trace messages that should bypass normal stdout/stderr /* Log/debug/trace messages that should bypass normal stdout/stderr
filtering. For moment, always call this stream using filtering. For moment, always call this stream using
*_unfiltered. In the very near future that restriction shall be *_unfiltered. In the very near future that restriction shall be
removed - either call shall be unfiltered. (cagney 1999-06-13). */ removed - either call shall be unfiltered. (cagney 1999-06-13). */
extern struct ui_file *gdb_stdlog; #define gdb_stdlog (*current_ui_gdb_stdlog_ptr ())
/* Truly global ui_file streams. These are all defined in main.c. */
/* Target output that should bypass normal stdout/stderr filtering. /* Target output that should bypass normal stdout/stderr filtering.
For moment, always call this stream using *_unfiltered. In the For moment, always call this stream using *_unfiltered. In the
very near future that restriction shall be removed - either call very near future that restriction shall be removed - either call