aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2025-08-12 18:47:01 +0200
committerTom de Vries <tdevries@suse.de>2025-08-12 18:47:01 +0200
commit96d90166e847db11a901d435583658663224d1bc (patch)
tree5d1b1851e942d6365bc50b750187f699d6ee6880
parent6f9909c4179983330a29b6fd246b39ab1b003934 (diff)
downloadbinutils-96d90166e847db11a901d435583658663224d1bc.zip
binutils-96d90166e847db11a901d435583658663224d1bc.tar.gz
binutils-96d90166e847db11a901d435583658663224d1bc.tar.bz2
[gdb/tui] Make tui_disassemble more efficient
Function tui_disassemble (with addr_size parameter) has two modes of operation: - addr_size != nullptr, and - addr_size == nullptr. I noticed that for the addr_size == nullptr case, more than necessary is done. Fix this by using continue and null_stream. While we're at it, eliminate the unnecessary variables new_size and orig_pc. Tested on x86_64-linux. Approved-By: Andrew Burgess <aburgess@redhat.com>
-rw-r--r--gdb/tui/tui-disasm.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 627f71c..07453b4 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -100,6 +100,9 @@ tui_disassemble (struct gdbarch *gdbarch,
{
bool term_out = disassembler_styling && gdb_stdout->can_emit_style_escape ();
string_file gdb_dis_out (term_out);
+ struct ui_file *stream = (addr_size == nullptr
+ ? (decltype (stream))&null_stream
+ : (decltype (stream))&gdb_dis_out);
/* Must start with an empty list. */
asm_lines.clear ();
@@ -108,11 +111,13 @@ tui_disassemble (struct gdbarch *gdbarch,
for (int i = 0; i < count; ++i)
{
tui_asm_line tal;
- CORE_ADDR orig_pc = pc;
+
+ /* Save the instruction address. */
+ tal.addr = pc;
try
{
- pc = pc + gdb_print_insn (gdbarch, pc, &gdb_dis_out, NULL);
+ pc += gdb_print_insn (gdbarch, pc, stream, NULL);
}
catch (const gdb_exception_error &except)
{
@@ -124,25 +129,24 @@ tui_disassemble (struct gdbarch *gdbarch,
return pc;
}
+ /* If that's all we need, continue. */
+ if (addr_size == nullptr)
+ {
+ asm_lines.push_back (std::move (tal));
+ continue;
+ }
+
/* Capture the disassembled instruction. */
tal.insn = gdb_dis_out.release ();
/* And capture the address the instruction is at. */
- tal.addr = orig_pc;
- print_address (gdbarch, orig_pc, &gdb_dis_out);
+ print_address (gdbarch, tal.addr, &gdb_dis_out);
tal.addr_string = gdb_dis_out.release ();
+ tal.addr_size = (term_out
+ ? len_without_escapes (tal.addr_string)
+ : tal.addr_string.size ());
- if (addr_size != nullptr)
- {
- size_t new_size;
-
- if (term_out)
- new_size = len_without_escapes (tal.addr_string);
- else
- new_size = tal.addr_string.size ();
- *addr_size = std::max (*addr_size, new_size);
- tal.addr_size = new_size;
- }
+ *addr_size = std::max (*addr_size, tal.addr_size);
asm_lines.push_back (std::move (tal));
}