Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/7] [gdb/tui] Fix underflow in tui_find_backward_disassembly_start_address
Date: Wed,  9 Sep 2026 11:48:44 +0200	[thread overview]
Message-ID: <20260909094849.2745086-3-tdevries@suse.de> (raw)
In-Reply-To: <20260909094849.2745086-1-tdevries@suse.de>

In the tui-disasm.c selftests, we do:
...
      SELF_CHECK (tui_find_disassembly_address (gdbarch, 0, -1) == 0);
...

This causes tui_find_backward_disassembly_start_address to be called with
addr == 0, causing underflow in:
...
  bound_minimal_symbol msym
    = lookup_minimal_symbol_by_pc_section (addr - 1, nullptr,
                                           lookup_msym_prefer::TEXT,
                                           &msym_prev);
...

Fix this by handling addr == 0 in tui_find_backward_disassembly_start_address.
---
 gdb/tui/tui-disasm.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 923d4373e8f..7dcb59e6264 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -161,6 +161,12 @@ tui_disassemble (struct gdbarch *gdbarch,
 static CORE_ADDR
 tui_find_backward_disassembly_start_address (CORE_ADDR addr)
 {
+  if (addr == 0)
+    {
+      /* We cannot go backwards from zero.  */
+      return addr;
+    }
+
   bound_minimal_symbol msym_prev;
   bound_minimal_symbol msym
     = lookup_minimal_symbol_by_pc_section (addr - 1, nullptr,
-- 
2.51.0


  parent reply	other threads:[~2026-09-09  9:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  9:48 [PATCH v2 0/7] [gdb/tui] Some section hole handling fixes Tom de Vries
2026-09-09  9:48 ` [PATCH v2 1/7] [gdb/tui] Improve tui_disassemble comment Tom de Vries
2026-09-09  9:48 ` Tom de Vries [this message]
2026-09-11 18:12   ` [PATCH v2 2/7] [gdb/tui] Fix underflow in tui_find_backward_disassembly_start_address Tom Tromey
2026-09-11 18:14     ` Tom Tromey
2026-09-09  9:48 ` [PATCH v2 3/7] [gdb/tui] Improve section handling " Tom de Vries
2026-09-11 18:26   ` Tom Tromey
2026-09-14  7:31     ` Tom de Vries
2026-09-09  9:48 ` [PATCH v2 4/7] [gdb] replace bsearch with std::lower_bound in find_pc_section Tom de Vries
2026-09-11 18:19   ` Tom Tromey
2026-09-14  7:34     ` Tom de Vries
2026-09-09  9:48 ` [PATCH v2 5/7] [gdb] Add prev/next params to find_pc_section Tom de Vries
2026-09-11 18:40   ` Tom Tromey
2026-09-09  9:48 ` [PATCH v2 6/7] [gdb/tui] Handle section holes when forward disassembling Tom de Vries
2026-09-11 18:39   ` Tom Tromey
2026-09-09  9:48 ` [PATCH v2 7/7] [gdb/tui] Handle section holes when backward disassembling Tom de Vries
2026-09-11 18:48   ` Tom Tromey
2026-09-11 18:52 ` [PATCH v2 0/7] [gdb/tui] Some section hole handling fixes 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=20260909094849.2745086-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /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