public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/3] [gdb/tui] Fix left margin in disassembly window
Date: Tue, 11 Apr 2023 10:23:31 +0200	[thread overview]
Message-ID: <20230411082332.25052-2-tdevries@suse.de> (raw)
In-Reply-To: <20230411082332.25052-1-tdevries@suse.de>

With a hello world a.out, and maint set tui-left-margin-verbose on, we have
this disassembly window:
...
┌───────────────────────────────────────────────────────────┐
│___ 0x555555555149 <main>           endbr64                │
│___ 0x55555555514d <main+4>         push   %rbp            │
│___ 0x55555555514e <main+5>         mov    %rsp,%rbp       │
│B+> 0x555555555151 <main+8>         lea    0xeac(%rip),%rax│
│___ 0x555555555158 <main+15>        mov    %rax,%rdi       │
...
Note the space between "B+>" and 0x555555555151.  The space shows that a bit
of the left margin is not written, which is a problem because that location is
showing a character previously written, which happens to be a space, but also
may be something else, for instance a '[' as reported in PR tui/30325.

The problem is caused by confusion about the meaning of:
...
 #define TUI_EXECINFO_SIZE 4
...

There's the meaning of defining the size of this zero-terminated char array:
...
      char element[TUI_EXECINFO_SIZE];
...
which is used to print the "B+>" bit, which is 3 chars wide.

And there's the meaning of defining part of the size of the left margin:
...
  int left_margin () const
  { return 1 + TUI_EXECINFO_SIZE + extra_margin (); }
...
where it represents 4 chars.

The discrepancy between the two causes the space between "B+>" and
"0x555555555151".

Fix this by redefining TUI_EXECINFO_SIZE to 3, and using:
...
      char element[TUI_EXECINFO_SIZE + 1];
...
such that we have:
...
|B+>0x555555555151 <main+8>         lea    0xeac(%rip),%rax │
...

This changes the layout of the disassembly window back to what it was before
commit 9e820dec13e ("Use a curses pad for source and disassembly windows"),
the commit that introduced the PR30325 regression.

This also changes the source window from:
...
│___000005__{                                               |
...
to:
...
│___000005_{                                                |
...

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30325
---
 gdb/tui/tui-winsource.c | 7 ++++---
 gdb/tui/tui-winsource.h | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 6c69fb7a907..84f9d97c554 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -666,12 +666,13 @@ 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];
+      /* Add 1 for '\0'.  */
+      char element[TUI_EXECINFO_SIZE + 1];
       /* Initialize all but last element.  */
       char space = tui_left_margin_verbose ? '_' : ' ';
-      memset (element, space, TUI_EXECINFO_SIZE - 1);
+      memset (element, space, TUI_EXECINFO_SIZE);
       /* Initialize last element.  */
-      element[TUI_EXECINFO_SIZE - 1] = '\0';
+      element[TUI_EXECINFO_SIZE] = '\0';
 
       /* Now update the exec info content based upon the state
 	 of each line as indicated by the source content.  */
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 7370ae95d8b..a8ff94f5769 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -58,7 +58,7 @@ DEF_ENUM_FLAGS_TYPE (enum tui_bp_flag, tui_bp_flags);
 #define TUI_BP_HIT_POS      0
 #define TUI_BP_BREAK_POS    1
 #define TUI_EXEC_POS        2
-#define TUI_EXECINFO_SIZE   4
+#define TUI_EXECINFO_SIZE   3
 
 /* Elements in the Source/Disassembly Window.  */
 struct tui_source_element
-- 
2.35.3


  reply	other threads:[~2023-04-11  8:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11  8:23 [PATCH 1/3] [gdb/tui] Add maint set/show tui-left-margin-verbose Tom de Vries
2023-04-11  8:23 ` Tom de Vries [this message]
2023-04-12 20:43   ` [PATCH 2/3] [gdb/tui] Fix left margin in disassembly window Tom Tromey
2023-04-12 21:06   ` Andrew Burgess
2023-04-12 22:25     ` Tom de Vries
2023-04-13  9:12       ` Andrew Burgess
2023-04-13  9:25         ` Andrew Burgess
2023-04-13 15:05           ` Tom de Vries
2023-04-11  8:23 ` [PATCH 3/3] [gdb/tui] Revert workaround in tui_source_window::show_line_number Tom de Vries
2023-04-12 20:44   ` Tom Tromey
2023-04-11  8:47 ` [PATCH 1/3] [gdb/tui] Add maint set/show tui-left-margin-verbose Eli Zaretskii
2023-04-12 22:21   ` Tom de Vries
2023-04-12 20:42 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230411082332.25052-2-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).