From patchwork Fri Jan 6 10:25:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 62786 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44FDD38493C8 for ; Fri, 6 Jan 2023 10:27:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44FDD38493C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673000852; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=O1h296SSMFFla1DwinhK0oeFwsJWCxUY0vaPF2zK4+TFarT/cgIAJ9JNquMp0DH5o PBXcG2q4k0CvEKcHmV89vUbjWKISzJuAyvcFJSrntVLqlxxyEF/i7ogx2cETVJeeGU 2+9cDL4w+nXSRCBSAA/D3gjkC+T2v5IJVP+jhtpk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BB4E538582B7 for ; Fri, 6 Jan 2023 10:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BB4E538582B7 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-621-nYPW5uItO7-CmZdm_d9ixA-1; Fri, 06 Jan 2023 05:26:11 -0500 X-MC-Unique: nYPW5uItO7-CmZdm_d9ixA-1 Received: by mail-ed1-f71.google.com with SMTP id m3-20020a056402430300b0047b94307bbeso961344edc.3 for ; Fri, 06 Jan 2023 02:26:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UPAOAdFHm+AXrmVqmMPZUmUvSH3YbNaw976fSd1EBnA=; b=XdS3EOMW8zrgbJPNTllg+vGSmMfk0mCLkb0vEFQVV+ECd+yZ1SfU7gY2VgkqK8M5nO e1RWlMrJqrI11DMrMfmStPELLpVxeCB0v31JOFSkOCKYo75yvXmjfrkWH1APXWqhIOqH 5gbhfrzO+gc4Cj7elpw2rXGsn8dWdv373oi14rOH/2bNXgOySBw9skNZzi5vfChi/AWX diHCe97fsQVWP+dlPNA79lq4a7Sue8SD1A3WVPZtPQDmkOHOxYLxE+Ft/Oqx02qEmBmb pjT/rZhWF3rzH45n3141z6wp4QMmU2DTB8N4aiC8F7A6BVgWTSGrhF8D+7lf0cRHC8de JX9w== X-Gm-Message-State: AFqh2kpTVChEXbzm61AqNa+HDHfmKVgPJ1btuCRL6G6fF3yXtEpjNo6k HfKjP/pbBaPfJkDu8sN9Qmu6m90U8N62FYR9iRxC5JYkAOnh6Y2cwjuGJinboEESl/QnhgDFCpp CdeJ3EW8jjyfhOGn1HxgihuKvrcgaXGKsa9D+OfV22rtPCfx8Hk/5lTfjcV1lAkS0IQS95H2ZIw == X-Received: by 2002:a17:906:8d03:b0:83f:743e:86d with SMTP id rv3-20020a1709068d0300b0083f743e086dmr6238328ejc.14.1673000770598; Fri, 06 Jan 2023 02:26:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXsKBEc4b+5xv7+oHWn764WlnXtPe2hxhckdvUfLTI2PFXwHLk5Pf5BuWvzPIyG2XC269GnLgw== X-Received: by 2002:a17:906:8d03:b0:83f:743e:86d with SMTP id rv3-20020a1709068d0300b0083f743e086dmr6238312ejc.14.1673000770321; Fri, 06 Jan 2023 02:26:10 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id k17-20020a1709063e1100b0084ca5f2b935sm267372eji.172.2023.01.06.02.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 02:26:09 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 09/15] gdb/tui: disable tui mode when an assert triggers Date: Fri, 6 Jan 2023 10:25:36 +0000 Message-Id: <212ca24d63f8068c2a3d5f2051435b2b26d4d3ee.1673000632.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" When an assert triggers in tui mode the output is not great, the internal backtrace that is generated is printed directly to the file descriptor for gdb_stderr, and, as a result, does not currently format itself correctly - the output uses only '\n' at the end of each line, and so, when the terminal is in raw mode, the cursor does not return to the start of each line after the '\n'. This is mostly fixable, we could update bt-utils.c to use '\r\n' instead of just '\n', and this would fix most of the problems. The one we can't easily fix is if/when GDB is built to use execinfo instead of libbacktrace, in this case we use backtrace_symbols_fd to print the symbols, and this function only uses '\n' as the line terminator. Fixing this would require switching to backtrace_symbols, but that API uses malloc, which is something we're trying to avoid (this code is called when GDB hits an error, so ideally we don't want to rely on malloc). However, the execinfo code is only used when libbacktrace is not available (or the user specifically disables libbacktrace) so maybe we can ignore that problem... ... but there is another problem. When the backtrace is printed in raw mode, it is possible that the backtrace fills the screen. With the terminal in raw mode we don't have the ability to scroll back, which means we loose some of the backtrace, which isn't ideal. In this commit I propose that we should disable tui mode whenever we handle a fatal signal, or when we hit the internal error code path (e.g. when an assert triggers). With this done then we don't need to update the bt-utils.c code, and the execinfo version of the code (using backtrace_symbols_fd) works just fine. We also get the ability to scroll back to view the error message and all of the backtrace, assuming the users terminal supports scrolling back. The only downside I see with this change is if the tui_disable call itself causes an error for some reason, or, if we handle a single at a time when it is not safe to call tui_disable, in these cases the extra tui_disable call might cause GDB to loose the original error. However, I think (just from personal experience) that the above two issues are pretty rare and the benefits from this change far out weighs the possible drawbacks. --- gdb/event-top.c | 8 ++++++++ gdb/utils.c | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 4a46e1b9346..14984707df1 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -48,6 +48,10 @@ #include "readline/readline.h" #include "readline/history.h" +#ifdef TUI +#include "tui/tui.h" +#endif + /* readline defines this. */ #undef savestring @@ -940,6 +944,10 @@ unblock_signal (int sig) static void ATTRIBUTE_NORETURN handle_fatal_signal (int sig) { +#ifdef TUI + tui_disable (); +#endif + #ifdef GDB_PRINT_INTERNAL_BACKTRACE const auto sig_write = [] (const char *msg) -> void { diff --git a/gdb/utils.c b/gdb/utils.c index 734c5bf7f70..95adbe58e4a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -29,7 +29,8 @@ #endif /* HAVE_SYS_RESOURCE_H */ #ifdef TUI -#include "tui/tui.h" /* For tui_get_command_dimension. */ +/* For tui_get_command_dimension and tui_disable. */ +#include "tui/tui.h" #endif #ifdef __GO32__ @@ -354,6 +355,10 @@ internal_vproblem (struct internal_problem *problem, } } +#ifdef TUI + tui_disable (); +#endif + /* Create a string containing the full error/warning message. Need to call query with this full string, as otherwize the reason (error/warning) and question become separated. Format using a