]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib: Change type of convenience variable _current_linker_namespace
authorGuinevere Larsen <guinevere@redhat.com>
Thu, 15 May 2025 13:45:57 +0000 (10:45 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Thu, 5 Jun 2025 11:53:43 +0000 (08:53 -0300)
Based on IRC feedback since commit 6a0da68c036a85a46415aa0dada2421eee7c2269

    gdb: add convenience variables around linker namespace debugging

This commit changes the type of the _current_linker_namespace variable
to be a simple integer. This makes it easier to use for expressions,
like breakpoint conditions or printing from a specific namespace once
that is supported, at the cost of making namespace IDs slightly less
consistent.

This is based on PR solib/32960, where no negative feedback was given
for the suggestion.

The commit also changes the usage of "linkage namespaces" to "linker
namespaces" in the NEWS file, to reduce chance of confusion from an end
user.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32960
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/solib.c
gdb/testsuite/gdb.base/dlmopen-ns-ids.exp

index ec71d899994a2acfed5d3202e5455c9797e151c5..507e53359ce47209a6e4beb972163e3abc59bbaf 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
   a -h or --help option, which prints each options and a brief
   description.
 
-* On systems that support linkage namespaces, the output of the command
+* On systems that support linker namespaces, the output of the command
   "info sharedlibraries" may add one more column, NS, which identifies the
   namespace into which the library was loaded, if more than one namespace
   is active.
 
 * New built-in convenience variables $_active_linker_namespaces and
-  $_current_linker_namespace.  These show the number of active linkage
+  $_current_linker_namespace.  These show the number of active linker
   namespaces, and the namespace to which the current location belongs to.
-  In systems that don't support linkage namespaces, these always return 1
-  and [[0]] respectively.
+  In systems that don't support linker namespaces, these always return
+  the integers 1 and 0 respectively.
 
 * Add record full support for rv64gc architectures
 
index 267647108dda829b885d1ea29fb8c6dffa7ba950..9aad9e7bc702e0f4359087145ac9df6784156a1f 100644 (file)
@@ -13112,9 +13112,9 @@ support for linkage namespaces, this variable will always be set to @samp{1}.
 @vindex $_current_linker_namespace@r{, convenience variable}
 @item $_current_linker_namespace
 The namespace which contains the current location in the inferior.  This
-returns GDB's internal identifier for namespaces, which is @samp{[[@var{n}]]}
-where @var{n} is a zero-based namespace number.  In systems with no support
-for linkage namespaces, this variable will always be set to @samp{[[0]]}.
+returns @value{GDBN}'s internal numbering for the namespace.  In systems with no
+support for linker namespaces, this variable will always be set to
+@samp{0}.
 
 @end table
 
index 21cb90a126a6794fd4c7e01ea42c66b5805c6dc4..afc1dcc02baf9a4593ddffeda8ab114465153227 100644 (file)
@@ -1820,24 +1820,22 @@ default_find_solib_addr (solib &so)
 
 /* Implementation of the current_linker_namespace convenience variable.
    This returns the GDB internal identifier of the linker namespace,
-   for the current frame, in the form '[[<number>]]'.  If the inferior
-   doesn't support linker namespaces, this always returns [[0]].  */
+   for the current frame, as an integer.  If the inferior doesn't support
+   linker namespaces, this always returns 0.  */
 
 static value *
 current_linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
                                     void *ignore)
 {
   const solib_ops *ops = gdbarch_so_ops (gdbarch);
-  const language_defn *lang = language_def (get_frame_language
-                                             (get_current_frame ()));
-  std::string nsid = "[[0]]";
+  int nsid = 0;
   if (ops->find_solib_ns != nullptr)
     {
       CORE_ADDR curr_pc = get_frame_pc (get_current_frame ());
       for (const solib &so : current_program_space->solibs ())
        if (solib_contains_address_p (so, curr_pc))
          {
-           nsid = string_printf ("[[%d]]", ops->find_solib_ns (so));
+           nsid = ops->find_solib_ns (so);
            break;
          }
     }
@@ -1845,7 +1843,7 @@ current_linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
 
   /* 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 lang->value_string (gdbarch, nsid.c_str (), nsid.length ());
+  return value_from_longest (builtin_type (gdbarch)->builtin_int, nsid);
 }
 
 /* Implementation of `$_current_linker_namespace' variable.  */
index 8f521992bd1ede2e31fa49ca9060974a990cb152..cae1be75b770dc00fe0aaaf9ccbe5fb828a8f1fc 100644 (file)
@@ -121,7 +121,7 @@ proc_with_prefix test_conv_vars {} {
 
     gdb_test "print \$_active_linker_namespaces" "1" \
        "Before activating namespaces"
-    gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[0\\\]\\\]\"" \
+    gdb_test "print \$_current_linker_namespace" ".* = 0" \
        "Still in the default namespace"
 
     gdb_breakpoint "inc" allow-pending
@@ -130,7 +130,7 @@ proc_with_prefix test_conv_vars {} {
     foreach_with_prefix dl {3 2 1} {
        gdb_continue_to_breakpoint "inc"
 
-       gdb_test "print \$_current_linker_namespace" ".*\"\\\[\\\[$dl\\\]\\\]\"" \
+       gdb_test "print \$_current_linker_namespace" ".* = $dl" \
            "Verify we're in namespace $dl"
     }
 
@@ -154,7 +154,7 @@ proc_with_prefix test_conv_vars {} {
     # breakpoints and pending breakpoints at the same time with
     # gdb_breakpoint.
     gdb_test "next" ".*assert.*" "load the first SO"
-    gdb_breakpoint "inc if \$_streq(\$_current_linker_namespace, \"\[\[2\]\]\")"
+    gdb_breakpoint "inc if \$_current_linker_namespace == 2"
     gdb_continue_to_breakpoint "inc"
     gdb_continue_to_end "" continue 1
 }