]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib: make _linker_namespace use selected frame
authorGuinevere Larsen <guinevere@redhat.com>
Fri, 6 Jun 2025 19:23:37 +0000 (16:23 -0300)
committerGuinevere Larsen <guinevere@redhat.com>
Fri, 6 Jun 2025 20:45:49 +0000 (17:45 -0300)
When the convenience variable $_linker_namespace was introduced, I meant
for it to print the namespace of the frame that where the user was
stopped. However, due to confusing what "current_frame" and
"selected_frame" meant, it instead printed the namespace of the
lowermost frame.

This commit updates the code to follow my original intent. Since the
variable was never in a GDB release, updating the behavior should not
cause any disruption. It also adds a test to verify the functionality.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/solib.c
gdb/testsuite/gdb.base/dlmopen-ns-ids.exp

index 3e821ba418a40ffa565ddadaa0ad76f9936a6d0c..7721fd673ae3c7ad1543fff1a1d55dd406cf72e5 100644 (file)
@@ -1820,7 +1820,7 @@ default_find_solib_addr (solib &so)
 
 /* Implementation of the linker_namespace convenience variable.
    This returns the GDB internal identifier of the linker namespace,
-   for the current frame, as an integer.  If the inferior doesn't support
+   for the selected frame, as an integer.  If the inferior doesn't support
    linker namespaces, this always returns 0.  */
 
 static value *
@@ -1831,7 +1831,7 @@ linker_namespace_make_value (gdbarch *gdbarch, internalvar *var,
   int nsid = 0;
   if (ops->find_solib_ns != nullptr)
     {
-      CORE_ADDR curr_pc = get_frame_pc (get_current_frame ());
+      CORE_ADDR curr_pc = get_frame_pc (get_selected_frame ());
       for (const solib &so : current_program_space->solibs ())
        if (solib_contains_address_p (so, curr_pc))
          {
index 801022b769e3c7de93cc072ff647c7fc1f9459c8..94b4a6e50bcf8bb5289a4540844b643157afff76 100644 (file)
@@ -134,6 +134,12 @@ proc_with_prefix test_conv_vars {} {
            "Verify we're in namespace $dl"
     }
 
+    # Check that we display the namespace of the selected
+    # frame, not the lowermost one.
+    gdb_test "up" "\#1.*in main.*"
+    gdb_test "print \$_linker_namespace" ".* = 0" \
+       "print namespace of selected frame"
+
     gdb_continue_to_breakpoint "first dlclose"
     gdb_test "print \$_active_linker_namespaces" "4" "all SOs loaded"