From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113114 invoked by alias); 6 May 2016 12:40:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 113047 invoked by uid 89); 6 May 2016 12:40:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=gui, Hx-languages-length:4322 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 06 May 2016 12:40:22 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C10223B731 for ; Fri, 6 May 2016 12:35:16 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u46CZ5I8017259 for ; Fri, 6 May 2016 08:35:16 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v3 11/34] Make out and error streams be per UI Date: Fri, 06 May 2016 12:40:00 -0000 Message-Id: <1462538104-19109-12-git-send-email-palves@redhat.com> In-Reply-To: <1462538104-19109-1-git-send-email-palves@redhat.com> References: <1462538104-19109-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-05/txt/msg00111.txt.bz2 stderr_fileopen () references stderr directly, which doesn't work when we have a separate UI with its own stderr-like stream. So this also adds a "errstream" to "struct ui", and plumbs stderr_fileopen to take a stream parameter. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * event-top.c (gdb_setup_readline): Pass the UI's outstream and errstream to stdout_fileopen and stderr_fileopen. * exceptions.c: Include top.h. (print_flush): Open the current UI's outstream file descriptor, instead of hardcoding file descriptor 1. * main.c (captured_main): Save the main UI's out and error streams. Adjust stderr_fileopen call. * top.h (struct ui) : New fields. * ui-file.c (stderr_fileopen): Add stream parameter. Use it instead of stderr. * ui-file.h (stderr_fileopen): Add stream parameter and update comment. --- gdb/event-top.c | 4 ++-- gdb/exceptions.c | 4 +++- gdb/main.c | 6 +++++- gdb/top.h | 4 ++++ gdb/ui-file.c | 4 ++-- gdb/ui-file.h | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 1d36b81..08eb89d 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -1237,8 +1237,8 @@ gdb_setup_readline (void) mess it up here. The sync stuff should really go away over time. */ if (!batch_silent) - gdb_stdout = stdio_fileopen (stdout); - gdb_stderr = stderr_fileopen (); + gdb_stdout = stdio_fileopen (ui->outstream); + gdb_stderr = stderr_fileopen (ui->errstream); gdb_stdlog = gdb_stderr; /* for moment */ gdb_stdtarg = gdb_stderr; /* for moment */ gdb_stdtargerr = gdb_stderr; /* for moment */ diff --git a/gdb/exceptions.c b/gdb/exceptions.c index 0e60050..9a10f66 100644 --- a/gdb/exceptions.c +++ b/gdb/exceptions.c @@ -26,10 +26,12 @@ #include "ui-out.h" #include "serial.h" #include "gdbthread.h" +#include "top.h" static void print_flush (void) { + struct ui *ui = current_ui; struct serial *gdb_stdout_serial; struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); @@ -56,7 +58,7 @@ print_flush (void) gdb_flush (gdb_stderr); /* 3. The system-level buffer. */ - gdb_stdout_serial = serial_fdopen (1); + gdb_stdout_serial = serial_fdopen (fileno (ui->outstream)); if (gdb_stdout_serial) { serial_drain_output (gdb_stdout_serial); diff --git a/gdb/main.c b/gdb/main.c index d862759..58e510e 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -507,7 +507,11 @@ captured_main (void *data) ndir = 0; saved_command_line = (char *) xstrdup (""); + ui->instream = stdin; + ui->outstream = stdout; + ui->errstream = stderr; + ui->input_fd = fileno (stdin); #ifdef __MINGW32__ @@ -517,7 +521,7 @@ captured_main (void *data) #endif gdb_stdout = stdio_fileopen (stdout); - gdb_stderr = stderr_fileopen (); + gdb_stderr = stderr_fileopen (stderr); gdb_stdlog = gdb_stderr; /* for moment */ gdb_stdtarg = gdb_stderr; /* for moment */ diff --git a/gdb/top.h b/gdb/top.h index c50c0c9..31c4a8e 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -73,6 +73,10 @@ struct ui Set to NULL if we are executing a user-defined command or interacting via a GUI. */ FILE *instream; + /* Standard output stream. */ + FILE *outstream; + /* Standard error stream. */ + FILE *errstream; /* The file descriptor for the input stream, so that we can register it with the event loop. */ diff --git a/gdb/ui-file.c b/gdb/ui-file.c index 4260710..a977f89 100644 --- a/gdb/ui-file.c +++ b/gdb/ui-file.c @@ -681,9 +681,9 @@ stderr_file_fputs (const char *linebuffer, struct ui_file *file) #endif struct ui_file * -stderr_fileopen (void) +stderr_fileopen (FILE *stream) { - struct ui_file *ui_file = stdio_fileopen (stderr); + struct ui_file *ui_file = stdio_fileopen (stream); #ifdef __MINGW32__ /* There is no real line-buffering on Windows, see diff --git a/gdb/ui-file.h b/gdb/ui-file.h index a6ec135..f6df572 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -135,8 +135,8 @@ extern struct ui_file *mem_fileopen (void); /* Open/create a STDIO based UI_FILE using the already open FILE. */ extern struct ui_file *stdio_fileopen (FILE *file); -/* Create a ui_file from stderr. */ -extern struct ui_file *stderr_fileopen (void); +/* Likewise, for stderr-like streams. */ +extern struct ui_file *stderr_fileopen (FILE *file); /* Open NAME returning an STDIO based UI_FILE. */ -- 2.5.5