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 v4 08/11] [gdb] Make gdb_disassembly return number of insns
Date: Wed,  7 Oct 2026 11:40:54 +0200	[thread overview]
Message-ID: <20261007094057.1811886-9-tdevries@suse.de> (raw)
In-Reply-To: <20261007094057.1811886-1-tdevries@suse.de>

Currently the function gdb_disassembly returns void.

Make it return the number of disassembled instructions.
---
 gdb/disasm.c | 32 ++++++++++++++++++++++----------
 gdb/disasm.h | 10 +++++++---
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/gdb/disasm.c b/gdb/disasm.c
index 01361fe4323..ec922fbd323 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -524,7 +524,7 @@ dump_insns (struct gdbarch *gdbarch,
 
    N.B. This view is deprecated.  */
 
-static void
+static int
 do_mixed_source_and_assembly_deprecated
   (struct gdbarch *gdbarch, struct ui_out *uiout,
    struct symtab *symtab,
@@ -669,6 +669,8 @@ do_mixed_source_and_assembly_deprecated
       if (how_many >= 0 && num_displayed >= how_many)
 	break;
     }
+
+  return num_displayed;
 }
 
 /* The idea here is to present a source-O-centric view of a
@@ -676,7 +678,7 @@ do_mixed_source_and_assembly_deprecated
    in source order, with (possibly) out of order assembly
    immediately following.  */
 
-static void
+static int
 do_mixed_source_and_assembly (struct gdbarch *gdbarch,
 			      struct ui_out *uiout,
 			      struct symtab *main_symtab,
@@ -906,16 +908,18 @@ do_mixed_source_and_assembly (struct gdbarch *gdbarch,
       last_symtab = sal.symtab;
       last_line = sal.line;
     }
+
+  return num_displayed;
 }
 
-static void
+static int
 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
 		  CORE_ADDR low, CORE_ADDR high,
 		  int how_many, gdb_disassembly_flags flags)
 {
   ui_out_emit_list list_emitter (uiout, "asm_insns");
 
-  dump_insns (gdbarch, uiout, low, high, how_many, flags, NULL);
+  return dump_insns (gdbarch, uiout, low, high, how_many, flags, NULL);
 }
 
 /* Combine implicit and user disassembler options and return them
@@ -1141,13 +1145,16 @@ gdb_disassembler::print_insn (CORE_ADDR memaddr,
   return length;
 }
 
-void
+/* See disasm.h.  */
+
+int
 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
 		 gdb_disassembly_flags flags, int how_many,
 		 CORE_ADDR low, CORE_ADDR high)
 {
   struct symtab *symtab;
   int nlines = -1;
+  int num_displayed = 0;
 
   /* Assume symtab is valid for whole PC range.  */
   symtab = find_symtab_for_pc (low);
@@ -1157,17 +1164,22 @@ gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
 
   if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
       || nlines <= 0)
-    do_assembly_only (gdbarch, uiout, low, high, how_many, flags);
+    num_displayed
+      = do_assembly_only (gdbarch, uiout, low, high, how_many, flags);
 
   else if (flags & DISASSEMBLY_SOURCE)
-    do_mixed_source_and_assembly (gdbarch, uiout, symtab, low, high,
-				  how_many, flags);
+    num_displayed
+      = do_mixed_source_and_assembly (gdbarch, uiout, symtab, low, high,
+				      how_many, flags);
 
   else if (flags & DISASSEMBLY_SOURCE_DEPRECATED)
-    do_mixed_source_and_assembly_deprecated (gdbarch, uiout, symtab,
-					     low, high, how_many, flags);
+    num_displayed
+      = do_mixed_source_and_assembly_deprecated (gdbarch, uiout, symtab,
+						 low, high, how_many, flags);
 
   gdb_flush (gdb_stdout);
+
+  return num_displayed;
 }
 
 /* Print the instruction at address MEMADDR in debugged memory,
diff --git a/gdb/disasm.h b/gdb/disasm.h
index 57195564ca8..9109dbf0a79 100644
--- a/gdb/disasm.h
+++ b/gdb/disasm.h
@@ -323,9 +323,13 @@ struct disasm_insn
   unsigned int is_speculative:1;
 };
 
-extern void gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
-			     gdb_disassembly_flags flags, int how_many,
-			     CORE_ADDR low, CORE_ADDR high);
+/* Print at most HOW_MANY instructions of the instruction stream at
+   [LOW, HIGH) on UIOUT using FLAGS.  Return the number of the instructions
+   printed.  */
+
+extern int gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
+			    gdb_disassembly_flags flags, int how_many,
+			    CORE_ADDR low, CORE_ADDR high);
 
 /* Print the instruction at address MEMADDR in debugged memory,
    on STREAM.  Returns the length of the instruction, in bytes,
-- 
2.51.0


  parent reply	other threads:[~2026-10-07  9:42 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 ` [PATCH v4 03/11] [gdb/tui] Disassemble less often " Tom de Vries
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 ` Tom de Vries [this message]
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-9-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