[binutils-gdb] gdb: change gdbarch_insn_is_{call, ret, jump} to return bool

Simon Marchi via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b3306c1448fbd5a02a7ba289b3be2b5d50bbd7bf

commit b3306c1448fbd5a02a7ba289b3be2b5d50bbd7bf
Author: Simon Marchi <[email protected]>
Date:   Fri Feb 27 15:05:26 2026 -0500

    gdb: change gdbarch_insn_is_{call,ret,jump} to return bool
    
    Change-Id: I5ff05978a1526d9aaeb6c4e46440009ca0d51116
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/amd64-tdep.c          | 66 +++++++++++++++++++++++------------------------
 gdb/arch-utils.c          | 15 ++++++-----
 gdb/arch-utils.h          |  6 ++---
 gdb/gdbarch-gen.c         |  6 ++---
 gdb/gdbarch-gen.h         | 18 ++++++-------
 gdb/gdbarch_components.py | 12 ++++-----
 gdb/i386-tdep.c           | 58 ++++++++++++++++++++---------------------
 gdb/z80-tdep.c            | 24 ++++++++---------
 8 files changed, 103 insertions(+), 102 deletions(-)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 60e38687e47..0d23abb3164 100755
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -1148,9 +1148,9 @@ static const unsigned char twobyte_has_modrm[256] = {
   /*	   0 1 2 3 4 5 6 7 8 9 a b c d e f	  */
 };
 
-static int amd64_syscall_p (const struct amd64_insn *insn, int *lengthp);
+static bool amd64_syscall_p (const struct amd64_insn *insn, int *lengthp);
 
-static int
+static bool
 rex_prefix_p (gdb_byte pfx)
 {
   return REX_PREFIX_P (pfx);
@@ -1673,7 +1673,7 @@ amd64_displaced_step_copy_insn (struct gdbarch *gdbarch,
   return displaced_step_copy_insn_closure_up (dsc.release ());
 }
 
-static int
+static bool
 amd64_absolute_jmp_p (const struct amd64_insn *details)
 {
   const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
@@ -1682,35 +1682,35 @@ amd64_absolute_jmp_p (const struct amd64_insn *details)
     {
       /* jump near, absolute indirect (/4) */
       if ((insn[1] & 0x38) == 0x20)
-	return 1;
+	return true;
 
       /* jump far, absolute indirect (/5) */
       if ((insn[1] & 0x38) == 0x28)
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
-/* Return non-zero if the instruction DETAILS is a jump, zero otherwise.  */
+/* Return true if the instruction DETAILS is a jump, false otherwise.  */
 
-static int
+static bool
 amd64_jmp_p (const struct amd64_insn *details)
 {
   const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
 
   /* jump short, relative.  */
   if (insn[0] == 0xeb)
-    return 1;
+    return true;
 
   /* jump near, relative.  */
   if (insn[0] == 0xe9)
-    return 1;
+    return true;
 
   return amd64_absolute_jmp_p (details);
 }
 
-static int
+static bool
 amd64_absolute_call_p (const struct amd64_insn *details)
 {
   const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
@@ -1719,17 +1719,17 @@ amd64_absolute_call_p (const struct amd64_insn *details)
     {
       /* Call near, absolute indirect (/2) */
       if ((insn[1] & 0x38) == 0x10)
-	return 1;
+	return true;
 
       /* Call far, absolute indirect (/3) */
       if ((insn[1] & 0x38) == 0x18)
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
-static int
+static bool
 amd64_ret_p (const struct amd64_insn *details)
 {
   /* NOTE: gcc can emit "repz ; ret".  */
@@ -1742,32 +1742,32 @@ amd64_ret_p (const struct amd64_insn *details)
     case 0xca: /* ret far, pop N bytes */
     case 0xcb: /* ret far */
     case 0xcf: /* iret */
-      return 1;
+      return true;
 
     default:
-      return 0;
+      return false;
     }
 }
 
-static int
+static bool
 amd64_call_p (const struct amd64_insn *details)
 {
   const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
 
   if (amd64_absolute_call_p (details))
-    return 1;
+    return true;
 
   /* call near, relative */
   if (insn[0] == 0xe8)
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
-/* Return non-zero if INSN is a system call, and set *LENGTHP to its
-   length in bytes.  Otherwise, return zero.  */
+/* Return true if INSN is a system call, and set *LENGTHP to its
+   length in bytes.  Otherwise, return false.  */
 
-static int
+static bool
 amd64_syscall_p (const struct amd64_insn *details, int *lengthp)
 {
   const gdb_byte *insn = &details->raw_insn[details->opcode_offset];
@@ -1775,18 +1775,18 @@ amd64_syscall_p (const struct amd64_insn *details, int *lengthp)
   if (insn[0] == 0x0f && insn[1] == 0x05)
     {
       *lengthp = 2;
-      return 1;
+      return true;
     }
 
-  return 0;
+  return false;
 }
 
 /* Classify the instruction at ADDR using PRED.
    Throw an error if the memory can't be read.  */
 
-static int
+static bool
 amd64_classify_insn_at (struct gdbarch *gdbarch, CORE_ADDR addr,
-			int (*pred) (const struct amd64_insn *))
+			bool (*pred) (const struct amd64_insn *))
 {
   struct amd64_insn details;
 
@@ -1795,14 +1795,12 @@ amd64_classify_insn_at (struct gdbarch *gdbarch, CORE_ADDR addr,
   read_code (addr, buf.data (), buf.size ());
   amd64_get_insn_details (buf.data (), &details);
 
-  int classification = pred (&details);
-
-  return classification;
+  return pred (&details);
 }
 
 /* The gdbarch insn_is_call method.  */
 
-static int
+static bool
 amd64_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   return amd64_classify_insn_at (gdbarch, addr, amd64_call_p);
@@ -1810,7 +1808,7 @@ amd64_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 
 /* The gdbarch insn_is_ret method.  */
 
-static int
+static bool
 amd64_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   return amd64_classify_insn_at (gdbarch, addr, amd64_ret_p);
@@ -1818,7 +1816,7 @@ amd64_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 
 /* The gdbarch insn_is_jump method.  */
 
-static int
+static bool
 amd64_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   return amd64_classify_insn_at (gdbarch, addr, amd64_jmp_p);
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 3a0e3f35f2c..4fcd82f0111 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -903,19 +903,22 @@ default_return_in_first_hidden_param_p (struct gdbarch *gdbarch,
   return !(language_pass_by_reference (type).trivially_copyable);
 }
 
-int default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
+bool
+default_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  return 0;
+  return false;
 }
 
-int default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
+bool
+default_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  return 0;
+  return false;
 }
 
-int default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
+bool
+default_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
-  return 0;
+  return false;
 }
 
 /*  See arch-utils.h.  */
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index 66a5c897449..4d1c76a69bf 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -324,9 +324,9 @@ extern const char *default_auto_wide_charset (void);
 extern bool default_return_in_first_hidden_param_p (struct gdbarch *,
 						    struct type *);
 
-extern int default_insn_is_call (struct gdbarch *, CORE_ADDR);
-extern int default_insn_is_ret (struct gdbarch *, CORE_ADDR);
-extern int default_insn_is_jump (struct gdbarch *, CORE_ADDR);
+extern bool default_insn_is_call (struct gdbarch *, CORE_ADDR);
+extern bool default_insn_is_ret (struct gdbarch *, CORE_ADDR);
+extern bool default_insn_is_jump (struct gdbarch *, CORE_ADDR);
 
 /* Default implementation of gdbarch_program_breakpoint_here_p.  */
 extern bool default_program_breakpoint_here_p (struct gdbarch *gdbarch,
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index 52211c13802..2c6da958bdd 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -4899,7 +4899,7 @@ set_gdbarch_ravenscar_ops (struct gdbarch *gdbarch,
   gdbarch->ravenscar_ops = ravenscar_ops;
 }
 
-int
+bool
 gdbarch_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_assert (gdbarch != NULL);
@@ -4916,7 +4916,7 @@ set_gdbarch_insn_is_call (struct gdbarch *gdbarch,
   gdbarch->insn_is_call = insn_is_call;
 }
 
-int
+bool
 gdbarch_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_assert (gdbarch != NULL);
@@ -4933,7 +4933,7 @@ set_gdbarch_insn_is_ret (struct gdbarch *gdbarch,
   gdbarch->insn_is_ret = insn_is_ret;
 }
 
-int
+bool
 gdbarch_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 03b4ee0561c..db7cdb437fd 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1574,22 +1574,22 @@ extern void set_gdbarch_core_info_proc (struct gdbarch *gdbarch, gdbarch_core_in
 extern struct ravenscar_arch_ops * gdbarch_ravenscar_ops (struct gdbarch *gdbarch);
 extern void set_gdbarch_ravenscar_ops (struct gdbarch *gdbarch, struct ravenscar_arch_ops * ravenscar_ops);
 
-/* Return non-zero if the instruction at ADDR is a call; zero otherwise. */
+/* Return true if the instruction at ADDR is a call; false otherwise. */
 
-typedef int (gdbarch_insn_is_call_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
-extern int gdbarch_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr);
+typedef bool (gdbarch_insn_is_call_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
+extern bool gdbarch_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern void set_gdbarch_insn_is_call (struct gdbarch *gdbarch, gdbarch_insn_is_call_ftype *insn_is_call);
 
-/* Return non-zero if the instruction at ADDR is a return; zero otherwise. */
+/* Return true if the instruction at ADDR is a return; false otherwise. */
 
-typedef int (gdbarch_insn_is_ret_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
-extern int gdbarch_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr);
+typedef bool (gdbarch_insn_is_ret_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
+extern bool gdbarch_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern void set_gdbarch_insn_is_ret (struct gdbarch *gdbarch, gdbarch_insn_is_ret_ftype *insn_is_ret);
 
-/* Return non-zero if the instruction at ADDR is a jump; zero otherwise. */
+/* Return true if the instruction at ADDR is a jump; false otherwise. */
 
-typedef int (gdbarch_insn_is_jump_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
-extern int gdbarch_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr);
+typedef bool (gdbarch_insn_is_jump_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
+extern bool gdbarch_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern void set_gdbarch_insn_is_jump (struct gdbarch *gdbarch, gdbarch_insn_is_jump_ftype *insn_is_jump);
 
 /* Return true if there's a program/permanent breakpoint planted in
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 1b1e73bbe66..77c82c30044 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2507,9 +2507,9 @@ Ravenscar arch-dependent ops.
 
 Method(
     comment="""
-Return non-zero if the instruction at ADDR is a call; zero otherwise.
+Return true if the instruction at ADDR is a call; false otherwise.
 """,
-    type="int",
+    type="bool",
     name="insn_is_call",
     params=[("CORE_ADDR", "addr")],
     predefault="default_insn_is_call",
@@ -2518,9 +2518,9 @@ Return non-zero if the instruction at ADDR is a call; zero otherwise.
 
 Method(
     comment="""
-Return non-zero if the instruction at ADDR is a return; zero otherwise.
+Return true if the instruction at ADDR is a return; false otherwise.
 """,
-    type="int",
+    type="bool",
     name="insn_is_ret",
     params=[("CORE_ADDR", "addr")],
     predefault="default_insn_is_ret",
@@ -2529,9 +2529,9 @@ Return non-zero if the instruction at ADDR is a return; zero otherwise.
 
 Method(
     comment="""
-Return non-zero if the instruction at ADDR is a jump; zero otherwise.
+Return true if the instruction at ADDR is a jump; false otherwise.
 """,
-    type="int",
+    type="bool",
     name="insn_is_jump",
     params=[("CORE_ADDR", "addr")],
     predefault="default_insn_is_jump",
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index e52140a3c13..9cee112facd 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -556,65 +556,65 @@ i386_skip_prefixes (gdb_byte *insn, size_t max_len)
   return NULL;
 }
 
-static int
+static bool
 i386_absolute_jmp_p (const gdb_byte *insn)
 {
   /* jmp far (absolute address in operand).  */
   if (insn[0] == 0xea)
-    return 1;
+    return true;
 
   if (insn[0] == 0xff)
     {
       /* jump near, absolute indirect (/4).  */
       if ((insn[1] & 0x38) == 0x20)
-	return 1;
+	return true;
 
       /* jump far, absolute indirect (/5).  */
       if ((insn[1] & 0x38) == 0x28)
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
-/* Return non-zero if INSN is a jump, zero otherwise.  */
+/* Return true if INSN is a jump, false otherwise.  */
 
-static int
+static bool
 i386_jmp_p (const gdb_byte *insn)
 {
   /* jump short, relative.  */
   if (insn[0] == 0xeb)
-    return 1;
+    return true;
 
   /* jump near, relative.  */
   if (insn[0] == 0xe9)
-    return 1;
+    return true;
 
   return i386_absolute_jmp_p (insn);
 }
 
-static int
+static bool
 i386_absolute_call_p (const gdb_byte *insn)
 {
   /* call far, absolute.  */
   if (insn[0] == 0x9a)
-    return 1;
+    return true;
 
   if (insn[0] == 0xff)
     {
       /* Call near, absolute indirect (/2).  */
       if ((insn[1] & 0x38) == 0x10)
-	return 1;
+	return true;
 
       /* Call far, absolute indirect (/3).  */
       if ((insn[1] & 0x38) == 0x18)
-	return 1;
+	return true;
     }
 
-  return 0;
+  return false;
 }
 
-static int
+static bool
 i386_ret_p (const gdb_byte *insn)
 {
   switch (insn[0])
@@ -624,30 +624,30 @@ i386_ret_p (const gdb_byte *insn)
     case 0xca: /* ret far, pop N bytes.  */
     case 0xcb: /* ret far */
     case 0xcf: /* iret */
-      return 1;
+      return true;
 
     default:
-      return 0;
+      return false;
     }
 }
 
-static int
+static bool
 i386_call_p (const gdb_byte *insn)
 {
   if (i386_absolute_call_p (insn))
-    return 1;
+    return true;
 
   /* call near, relative.  */
   if (insn[0] == 0xe8)
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
-/* Return non-zero if INSN is a system call, and set *LENGTHP to its
-   length in bytes.  Otherwise, return zero.  */
+/* Return true if INSN is a system call, and set *LENGTHP to its
+   length in bytes.  Otherwise, return false.  */
 
-static int
+static bool
 i386_syscall_p (const gdb_byte *insn, int *lengthp)
 {
   /* Is it 'int $0x80'?  */
@@ -658,15 +658,15 @@ i386_syscall_p (const gdb_byte *insn, int *lengthp)
       || (insn[0] == 0x0f && insn[1] == 0x05))
     {
       *lengthp = 2;
-      return 1;
+      return true;
     }
 
-  return 0;
+  return false;
 }
 
 /* The gdbarch insn_is_call method.  */
 
-static int
+static bool
 i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[I386_MAX_INSN_LEN], *insn;
@@ -679,7 +679,7 @@ i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 
 /* The gdbarch insn_is_ret method.  */
 
-static int
+static bool
 i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[I386_MAX_INSN_LEN], *insn;
@@ -692,7 +692,7 @@ i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 
 /* The gdbarch insn_is_jump method.  */
 
-static int
+static bool
 i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[I386_MAX_INSN_LEN], *insn;
diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c
index b304b7764c2..f7e207d02ec 100644
--- a/gdb/z80-tdep.c
+++ b/gdb/z80-tdep.c
@@ -1000,8 +1000,8 @@ z80_overlay_update (struct obj_section *osect)
       }
 }
 
-/* Return non-zero if the instruction at ADDR is a call; zero otherwise.  */
-static int
+/* Return true if the instruction at ADDR is a call; false otherwise.  */
+static bool
 z80_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[8];
@@ -1015,13 +1015,13 @@ z80_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
       case insn_call_nn:
       case insn_call_cc_nn:
       case insn_rst_n:
-	return 1;
+	return true;
       }
-  return 0;
+  return false;
 }
 
-/* Return non-zero if the instruction at ADDR is a return; zero otherwise. */
-static int
+/* Return true if the instruction at ADDR is a return; false otherwise. */
+static bool
 z80_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[8];
@@ -1034,13 +1034,13 @@ z80_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
       {
       case insn_ret:
       case insn_ret_cc:
-	return 1;
+	return true;
       }
-  return 0;
+  return false;
 }
 
-/* Return non-zero if the instruction at ADDR is a jump; zero otherwise.  */
-static int
+/* Return true if the instruction at ADDR is a jump; false otherwise.  */
+static bool
 z80_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   gdb_byte buf[8];
@@ -1057,9 +1057,9 @@ z80_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
       case insn_jr_d:
       case insn_jr_cc_d:
       case insn_djnz_d:
-	return 1;
+	return true;
       }
-  return 0;
+  return false;
 }
 
 static const struct frame_unwind_legacy z80_frame_unwind (
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.