From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v4 03/11] [gdb/tui] Disassemble less often in tui_find_disassembly_address
Date: Wed, 7 Oct 2026 11:40:49 +0200 [thread overview]
Message-ID: <20261007094057.1811886-4-tdevries@suse.de> (raw)
In-Reply-To: <20261007094057.1811886-1-tdevries@suse.de>
In tui_find_disassembly_address we have the following code:
...
CORE_ADDR new_low = pc;
do
{
/* The previous value of NEW_LOW so we know if the new value is
different or not. */
CORE_ADDR prev_low = new_low;
/* Find an address from which we can start disassembling. */
new_low = tui_find_backward_disassembly_start_address (new_low);
/* Disassemble forward. */
next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines);
if (asm_lines.empty ())
break;
last_addr = asm_lines.back ().addr;
if (new_low == prev_low)
break;
...
Say we enter this code with some pc, and have pc == prev_low == new_low before
the call to tui_find_backward_disassembly_start_address.
If tui_find_backward_disassembly_start_address also returns pc, there's no
point in trying to disassemble starting from pc.
Fix this by moving this check to just after
tui_find_backward_disassembly_start_address:
...
new_low = tui_find_backward_disassembly_start_address (new_low);
if (new_low == prev_low)
break;
...
At the point of the break, asm_lines either is:
- empty because it hasn't been set yet, or
- the result of disassembling starting at prev_low, which also happens to be
new_low.
While I think that's fine, I think it's clearer if we don't carry over
asm_lines from a previous iteration, and do asm_lines.clear () at the start of
the loop.
---
gdb/tui/tui-disasm.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 18439580ffb..a6cf12ba9c2 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -237,12 +237,16 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
CORE_ADDR new_low = pc;
do
{
+ asm_lines.clear ();
+
/* The previous value of NEW_LOW so we know if the new value is
different or not. */
CORE_ADDR prev_low = new_low;
/* Find an address from which we can start disassembling. */
new_low = tui_find_backward_disassembly_start_address (new_low);
+ if (new_low == prev_low)
+ break;
/* Disassemble forward. */
next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines);
@@ -250,9 +254,6 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
break;
last_addr = asm_lines.back ().addr;
- if (new_low == prev_low)
- break;
-
/* If disassembling from the current value of NEW_LOW reached PC
(or went past it) then this would do as a starting point if we
can't find anything better, so remember it. */
--
2.51.0
next prev parent reply other threads:[~2026-10-07 9:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 9:40 [PATCH v4 00/11] [gdb/tui] Some section hole handling fixes Tom de Vries
2026-10-07 9:40 ` [PATCH v4 01/11] [gdb/tui] Use early exit in tui_find_disassembly_address Tom de Vries
2026-10-07 9:40 ` [PATCH v4 02/11] [gdb/tui] Make low_prev loop-local " Tom de Vries
2026-10-07 9:40 ` Tom de Vries [this message]
2026-10-07 9:40 ` [PATCH v4 04/11] [gdb/tui] Fix buglet " Tom de Vries
2026-10-07 9:40 ` [PATCH v4 05/11] [gdb] Factor out update_section_map Tom de Vries
2026-10-07 9:40 ` [PATCH v4 06/11] [gdb] Add section_addrmap Tom de Vries
2026-10-07 9:40 ` [PATCH v4 07/11] [gdb] Extend addrmap::find with low/high results Tom de Vries
2026-10-07 9:40 ` [PATCH v4 08/11] [gdb] Make gdb_disassembly return number of insns Tom de Vries
2026-10-07 9:40 ` [PATCH v4 09/11] [gdb] Handle sections when disassembling Tom de Vries
2026-10-07 9:40 ` [PATCH v4 10/11] [gdb] Don't stop disassembly at section hole Tom de Vries
2026-10-07 9:40 ` [PATCH v4 11/11] [RFC, gdb/tui] Don't scroll into non-code sections Tom de Vries
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=20261007094057.1811886-4-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