[binutils-gdb] gdb: change gdbarch_has_shared_address_space 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=dffaef4457657fd7e75662a6f7bf072092d03ed7

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

    gdb: change gdbarch_has_shared_address_space to return bool
    
    Change the target_is_uclinux global in m68k-linux-tdep.c to be an
    std::optional, for clarity.
    
    Change-Id: Ifb401865bac15dbb9803aeeb9f3d61ed965d6541
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/arch-utils.c          | 4 ++--
 gdb/arch-utils.h          | 2 +-
 gdb/gdbarch-gen.c         | 2 +-
 gdb/gdbarch-gen.h         | 4 ++--
 gdb/gdbarch_components.py | 2 +-
 gdb/linux-tdep.c          | 6 +++---
 gdb/linux-tdep.h          | 2 +-
 gdb/m68k-linux-tdep.c     | 8 ++++----
 gdb/progspace.c           | 5 +----
 9 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 6065315870c..886f9431fea 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -849,12 +849,12 @@ get_current_arch (void)
     return current_inferior ()->arch ();
 }
 
-int
+bool
 default_has_shared_address_space (struct gdbarch *gdbarch)
 {
   /* Simply say no.  In most unix-like targets each inferior/process
      has its own address space.  */
-  return 0;
+  return false;
 }
 
 int
diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h
index cc7d6fd8459..5ff262179f8 100644
--- a/gdb/arch-utils.h
+++ b/gdb/arch-utils.h
@@ -300,7 +300,7 @@ extern struct gdbarch *gdbarch_from_bfd (bfd *abfd);
    routines to determine the architecture to execute a command in.  */
 extern struct gdbarch *get_current_arch (void);
 
-extern int default_has_shared_address_space (struct gdbarch *);
+extern bool default_has_shared_address_space (struct gdbarch *);
 
 extern int default_fast_tracepoint_valid_at (struct gdbarch *gdbarch,
 					     CORE_ADDR addr, std::string *msg);
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index 3ba67a79fbf..332849c162e 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -4732,7 +4732,7 @@ set_gdbarch_has_global_breakpoints (struct gdbarch *gdbarch,
   gdbarch->has_global_breakpoints = has_global_breakpoints;
 }
 
-int
+bool
 gdbarch_has_shared_address_space (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 4949d92d69e..b4f73e308db 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1509,8 +1509,8 @@ extern void set_gdbarch_has_global_breakpoints (struct gdbarch *gdbarch, bool ha
 
 /* True if inferiors share an address space (e.g., uClinux). */
 
-typedef int (gdbarch_has_shared_address_space_ftype) (struct gdbarch *gdbarch);
-extern int gdbarch_has_shared_address_space (struct gdbarch *gdbarch);
+typedef bool (gdbarch_has_shared_address_space_ftype) (struct gdbarch *gdbarch);
+extern bool gdbarch_has_shared_address_space (struct gdbarch *gdbarch);
 extern void set_gdbarch_has_shared_address_space (struct gdbarch *gdbarch, gdbarch_has_shared_address_space_ftype *has_shared_address_space);
 
 /* True if a fast tracepoint can be set at an address. */
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index cb88a15872a..c719c272791 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2394,7 +2394,7 @@ Method(
     comment="""
 True if inferiors share an address space (e.g., uClinux).
 """,
-    type="int",
+    type="bool",
     name="has_shared_address_space",
     params=[],
     predefault="default_has_shared_address_space",
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 47007ca841c..5a2bd97df50 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -422,8 +422,8 @@ linux_get_siginfo_type (struct gdbarch *gdbarch)
 /* Return true if the target is running on uClinux instead of normal
    Linux kernel.  */
 
-int
-linux_is_uclinux (void)
+bool
+linux_is_uclinux ()
 {
   CORE_ADDR dummy;
 
@@ -431,7 +431,7 @@ linux_is_uclinux (void)
 	  && target_auxv_search (AT_PAGESZ, &dummy) == 0);
 }
 
-static int
+static bool
 linux_has_shared_address_space (struct gdbarch *gdbarch)
 {
   return linux_is_uclinux ();
diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h
index 73d4832069f..4f74d40075d 100644
--- a/gdb/linux-tdep.h
+++ b/gdb/linux-tdep.h
@@ -100,7 +100,7 @@ extern void linux_displaced_step_restore_all_in_ptid (inferior *parent_inf,
 extern void linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch,
 			    int num_disp_step_buffers);
 
-extern int linux_is_uclinux (void);
+extern bool linux_is_uclinux ();
 
 /* Fetch the AT_HWCAP entry from auxv data AUXV.  Use TARGET and GDBARCH to
    parse auxv entries.
diff --git a/gdb/m68k-linux-tdep.c b/gdb/m68k-linux-tdep.c
index 1d147eb482b..ceb15cb1a20 100644
--- a/gdb/m68k-linux-tdep.c
+++ b/gdb/m68k-linux-tdep.c
@@ -209,14 +209,14 @@ struct m68k_linux_sigtramp_info
 };
 
 /* Nonzero if running on uClinux.  */
-static int target_is_uclinux;
+static std::optional<bool> target_is_uclinux;
 
 static void
 m68k_linux_inferior_created (inferior *inf)
 {
   /* Record that we will need to re-evaluate whether we are running on a
      uClinux or normal GNU/Linux target (see m68k_linux_get_sigtramp_info).  */
-  target_is_uclinux = -1;
+  target_is_uclinux = std::nullopt;
 }
 
 static struct m68k_linux_sigtramp_info
@@ -229,7 +229,7 @@ m68k_linux_get_sigtramp_info (const frame_info_ptr &this_frame)
 
   /* Determine whether we are running on a uClinux or normal GNU/Linux
      target so we can use the correct sigcontext layouts.  */
-  if (target_is_uclinux == -1)
+  if (!target_is_uclinux.has_value ())
     target_is_uclinux = linux_is_uclinux ();
 
   sp = get_frame_register_unsigned (this_frame, M68K_SP_REGNUM);
@@ -240,7 +240,7 @@ m68k_linux_get_sigtramp_info (const frame_info_ptr &this_frame)
   if (m68k_linux_pc_in_sigtramp (this_frame) == 2)
     info.sc_reg_offset = m68k_linux_ucontext_reg_offset;
   else
-    info.sc_reg_offset = (target_is_uclinux
+    info.sc_reg_offset = (target_is_uclinux.value ()
 			  ? m68k_uclinux_sigcontext_reg_offset
 			  : m68k_linux_sigcontext_reg_offset);
   return info;
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 484fd085b1f..1407b058dfd 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -43,10 +43,7 @@ struct program_space *current_program_space;
 address_space_ref_ptr
 maybe_new_address_space ()
 {
-  int shared_aspace
-    = gdbarch_has_shared_address_space (current_inferior ()->arch ());
-
-  if (shared_aspace)
+  if (gdbarch_has_shared_address_space (current_inferior ()->arch ()))
     {
       /* Just return the first in the list.  */
       return program_spaces[0]->aspace;
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.