From patchwork Mon Mar 21 15:21:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 11437 Received: (qmail 123061 invoked by alias); 21 Mar 2016 15:27:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 123032 invoked by uid 89); 21 Mar 2016 15:27:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=died, Simply 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; Mon, 21 Mar 2016 15:27:47 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 91958627D0 for ; Mon, 21 Mar 2016 15:21:39 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2LFLGPp019569 for ; Mon, 21 Mar 2016 11:21:39 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 23/25] Handle UI terminal closed Date: Mon, 21 Mar 2016 15:21:13 +0000 Message-Id: <1458573675-15478-24-git-send-email-palves@redhat.com> In-Reply-To: <1458573675-15478-1-git-send-email-palves@redhat.com> References: <1458573675-15478-1-git-send-email-palves@redhat.com> Without this, GDB exits if a secondary UIs terminal/input stream is closed: $ ./gdb -ex "new-ui mi /dev/pts/6" New UI allocated <<< close /dev/pts/6 (gdb) Error detected on fd 9 $ We want that for the main UI, but not secondary UIs. --- gdb/event-top.c | 25 ++++++++++++++++++------- gdb/top.c | 31 +++++++++++++++++++++++++++++++ gdb/top.h | 1 + 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 69f6be7..39b9633 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -420,19 +420,30 @@ stdin_event_handler (int error, gdb_client_data client_data) { struct ui *ui = (struct ui *) client_data; - /* Switch to the UI whose input descriptor woke up the event - loop. */ - current_ui = ui; - if (error) { - printf_unfiltered (_("error detected on stdin\n")); + /* Switch to the main UI, so diagnostics always go there. */ + current_ui = main_ui; + delete_file_handler (ui->input_fd); - /* If stdin died, we may as well kill gdb. */ - quit_command ((char *) 0, stdin == ui->instream); + if (main_ui == ui) + { + /* If stdin died, we may as well kill gdb. */ + printf_unfiltered (_("error detected on stdin\n")); + quit_command ((char *) 0, stdin == ui->instream); + } + else + { + /* Simply delete the UI. */ + delete_ui (ui); + } } else { + /* Switch to the UI whose input descriptor woke up the event + loop. */ + current_ui = ui; + do { call_stdin_event_handler_again_p = 0; diff --git a/gdb/top.c b/gdb/top.c index 12064bc..7d6d7cb 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -282,6 +282,37 @@ new_ui (FILE *instream, FILE *outstream, FILE *errstream) return ui; } +static void +free_ui (struct ui *ui) +{ + ui_file_delete (ui->m_gdb_stdin); + ui_file_delete (ui->m_gdb_stdout); + ui_file_delete (ui->m_gdb_stderr); + + xfree (ui); +} + +void +delete_ui (struct ui *todel) +{ + struct ui *ui, *uiprev; + + uiprev = NULL; + + for (ui = ui_list; ui != NULL; uiprev = ui, ui = ui->next) + if (ui == todel) + break; + + gdb_assert (ui != NULL); + + if (uiprev != NULL) + uiprev->next = ui->next; + else + ui_list = ui->next; + + free_ui (ui); +} + /* Handler for SIGHUP. */ #ifdef SIGHUP diff --git a/gdb/top.h b/gdb/top.h index df76204..bac5a33 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -161,6 +161,7 @@ extern void switch_thru_all_uis_next (struct switch_thru_all_uis *state); for (UI = ui_list; UI; UI = UI->next) \ extern struct ui *new_ui (FILE *instream, FILE *outstream, FILE *errstream); +extern void delete_ui (struct ui *todel); extern void restore_ui_cleanup (void *data);