From patchwork Tue Apr 11 08:23:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 67621 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 A8C1B3857719 for ; Tue, 11 Apr 2023 08:23:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8C1B3857719 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681201428; bh=5GHJXDQLWxpXX2RJlz1n1Mn1d9/jp9luRzk7IPf1HH4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vt0jfKRP+bexieD5KIFb3/mf5MqpPxgV514x4RvsJKM18TJHhkqezJ2pslwrRswhn PD96t0uo8CUPfhArQM0+JtCTmk7t6wOoFD5c0OB04cwu+X761bv3MagRQdNrgdZ4gp BonV5mkMoCrTf9Z0QVBpbP6/75mnM3nmNlL/0doE= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id D7A853858D28 for ; Tue, 11 Apr 2023 08:23:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7A853858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1A9A81FE00; Tue, 11 Apr 2023 08:23:24 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EC99413638; Tue, 11 Apr 2023 08:23:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id m5yAN/sYNWRpBAAAMHmgww (envelope-from ); Tue, 11 Apr 2023 08:23:23 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] [gdb/tui] Add maint set/show tui-left-margin-verbose Date: Tue, 11 Apr 2023 10:23:30 +0200 Message-Id: <20230411082332.25052-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The TUI has two types of windows derived from tui_source_window_base: - tui_source_window (the source window), and - tui_disasm_window (the disassembly window). The two windows share a common concept: the left margin. With a hello world a.out, we can see the source window: ... ┌─/home/vries/hello.c───────────────────────────────────────┐ │ 5 { │ │B+> 6 printf ("hello\n"); │ │ 7 return 0; │ │ 8 } │ │ 9 │ │ ... where the left margin is the part holding "B+>" and the line number, and the disassembly window: ... ┌───────────────────────────────────────────────────────────┐ │ 0x555555555149
endbr64 │ │ 0x55555555514d push %rbp │ │ 0x55555555514e mov %rsp,%rbp │ │B+> 0x555555555151 lea 0xeac(%rip),%rax│ │ 0x555555555158 mov %rax,%rdi │ ... where the left margin is just the bit holding "B+>". Because the left margin contains some spaces, it's not clear where it starts and ends, making it harder to observe problems related to it. Add a new maintenance command "maint set tui-left-margin-verbose", that when set to on replaces the spaces in the left margin with either '_' or '0', giving us this for the source window: ... ┌─/home/vries/hello.c───────────────────────────────────────┐ │___000005__{ │ │B+>000006__ printf ("hello\n"); │ │___000007__ return 0; │ │___000008__} │ ... and this for the disassembly window: ... ┌───────────────────────────────────────────────────────────┐ │___ 0x555555555149
endbr64 │ │___ 0x55555555514d push %rbp │ │___ 0x55555555514e mov %rsp,%rbp │ │B+> 0x555555555151 lea 0xeac(%rip),%rax│ │___ 0x555555555158 mov %rax,%rdi │ ... Note the space between "B+>" and 0x555555555151. The space shows that a bit of the left margin is not written, a problem reported as PR tui/30325. Specifically, PR tui/30325 is about the fact that the '[' character from the string "[ No Assembly Available ]" ends up in that same spot: ... │B+>[0x555555555151 lea 0xeac(%rip),%rax│ ... which only happens for certain window widths. The new command allows us to spot the problem with any window width. Likewise, when we revert the fix from commit 1b6d4bb2232 ("Redraw both spaces between line numbers and source code"), we have: ... ┌─/home/vries/hello.c───────────────────────────────────────┐ │___000005_ { │ │B+>000006_ printf ("hello\n"); │ │___000007_ return 0; │ │___000008_ } │ ... showing a similar problem at the space between '_' and '{'. Tested on x86_64-linux. Reviewed-By: Eli Zaretskii --- gdb/doc/gdb.texinfo | 8 ++++++++ gdb/tui/tui-source.c | 5 ++++- gdb/tui/tui-win.c | 16 ++++++++++++++++ gdb/tui/tui-win.h | 3 +++ gdb/tui/tui-winsource.c | 7 ++++++- 5 files changed, 37 insertions(+), 2 deletions(-) base-commit: 44019209faf3db952a6a04aaeeaa779a8ff7e661 diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 2d5358a792b..bb96ddb2d52 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41242,6 +41242,14 @@ has been resized. This setting is intended for use by the test suite, where it would otherwise be difficult to determine when a resize and refresh has been completed. +@kindex maint set tui-left-margin-verbose +@kindex maint show tui-left-margin-verbose +@item maint set tui-left-margin-verbose +@item maint show tui-left-margin-verbose +Control whether the left margin of the TUI source and disassembly windows +uses @samp{_} and @samp{0} at locations where otherwise there would be a +space. The default is @code{off}, which means spaces are used. + @kindex maint set per-command @kindex maint show per-command @item maint set per-command diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 73d44417533..aa3e58407c4 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -234,6 +234,9 @@ tui_source_window::show_line_number (int offset) const char text[20]; /* To completely overwrite the previous border when the source window height is increased, both spaces after the line number have to be redrawn. */ - xsnprintf (text, sizeof (text), "%*d ", m_digits - 1, lineno); + char space = tui_left_margin_verbose ? '_' : ' '; + xsnprintf (text, sizeof (text), + tui_left_margin_verbose ? "%0*d%c%c" : "%*d%c%c", m_digits - 1, + lineno, space, space); waddstr (handle.get (), text); } diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 008189eb99b..3b17cb8dd29 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -1111,6 +1111,10 @@ tui_window_command (const char *args, int from_tty) help_list (tui_window_cmds, "tui window ", all_commands, gdb_stdout); } +/* See tui-win.h. */ + +bool tui_left_margin_verbose = false; + /* Function to initialize gdb commands, for tui window manipulation. */ @@ -1284,6 +1288,18 @@ position indicator is styled."), &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("tui-left-margin-verbose", class_maintenance, + &tui_left_margin_verbose, _("\ +Set whether the left margin should use '_' and '0' instead of spaces."), + _("\ +Show whether the left margin should use '_' and '0' instead of spaces."), + _("\ +When enabled, the left margin will use '_' and '0' instead of spaces."), + nullptr, + nullptr, + &maintenance_set_cmdlist, + &maintenance_show_cmdlist); + tui_border_style.changed.attach (tui_rehighlight_all, "tui-win"); tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win"); } diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h index 4b33f1f2b54..3d35f1dfb7f 100644 --- a/gdb/tui/tui-win.h +++ b/gdb/tui/tui-win.h @@ -55,4 +55,7 @@ extern bool compact_source; current position indicator. */ extern bool style_tui_current_position; +/* Whether to replace the spaces in the left margin with '_' and '0'. */ +extern bool tui_left_margin_verbose; + #endif /* TUI_TUI_WIN_H */ diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 52a0f7af00f..6c69fb7a907 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -666,7 +666,12 @@ tui_source_window_base::update_exec_info (bool refresh_p) for (int i = 0; i < m_content.size (); i++) { struct tui_source_element *src_element = &m_content[i]; - char element[TUI_EXECINFO_SIZE] = " "; + char element[TUI_EXECINFO_SIZE]; + /* Initialize all but last element. */ + char space = tui_left_margin_verbose ? '_' : ' '; + memset (element, space, TUI_EXECINFO_SIZE - 1); + /* Initialize last element. */ + element[TUI_EXECINFO_SIZE - 1] = '\0'; /* Now update the exec info content based upon the state of each line as indicated by the source content. */