[v7,1/5] gdb: Create helper function for the current namespace

Message ID 20260601192251.60958-2-guinevere@redhat.com
State New
Headers
Series Introduce syntax for linker-namespace specific symbols |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Guinevere Larsen June 1, 2026, 7:22 p.m. UTC
  More code is needing to access the linker namespace of the selected
frame, so it makes sense to create a helper function that calculates the
current namespace, and make the internalvar use that helper instead.

This commit introduces this helper function.
---
 gdb/solib.c | 26 +++++++++++++++++---------
 gdb/solib.h |  4 ++++
 2 files changed, 21 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/solib.c b/gdb/solib.c
index d92d0dd9a3d..dbb69ef7678 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1793,15 +1793,10 @@  solib_linker_namespace_count (program_space *pspace)
   return 0;
 }
 
-/* Implementation of the linker_namespace convenience variable.
-
-   This returns the GDB internal identifier of the linker namespace,
-   for the selected frame, as an integer.  If the inferior doesn't support
-   linker namespaces, this always returns 0.  */
+/* See solib.h.  */
 
-static value *
-linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
-				     void *ignore)
+int
+get_current_linker_namespace ()
 {
   int nsid = 0;
   CORE_ADDR curr_pc = get_frame_pc (get_selected_frame ());
@@ -1815,9 +1810,22 @@  linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
 	break;
       }
 
+  return nsid;
+}
+
+/* Implementation of the linker_namespace convenience variable.
+   This returns the GDB internal identifier of the linker namespace,
+   for the selected frame, as an integer.  If the inferior doesn't support
+   linker namespaces, this always returns 0.  */
+
+static value *
+linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
+				     void *ignore)
+{
   /* If the PC is not in an SO, or the solib_ops doesn't support
      linker namespaces, the inferior is in the default namespace.  */
-  return value_from_longest (builtin_type (gdbarch)->builtin_int, nsid);
+  return value_from_longest (builtin_type (gdbarch)->builtin_int,
+			     get_current_linker_namespace ());
 }
 
 /* Implementation of `$_linker_namespace' variable.  */
diff --git a/gdb/solib.h b/gdb/solib.h
index 9e6c3f7346e..e52eef53df8 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -412,4 +412,8 @@  extern void handle_solib_event (void);
 
 extern int solib_linker_namespace_count (program_space *pspace);
 
+/* Calculate the linker namespace for the currently selected frame.  */
+
+int get_current_linker_namespace ();
+
 #endif /* GDB_SOLIB_H */