From: Guinevere Larsen Date: Fri, 6 Jun 2025 19:23:37 +0000 (-0300) Subject: gdb/solib: make _linker_namespace use selected frame X-Git-Tag: binutils-2_45~384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=925908e4995f7ab56349b30b29096e211cce42b0;p=thirdparty%2Fbinutils-gdb.git gdb/solib: make _linker_namespace use selected frame 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 --- diff --git a/gdb/solib.c b/gdb/solib.c index 3e821ba418a..7721fd673ae 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -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)) { diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp index 801022b769e..94b4a6e50bc 100644 --- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp +++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp @@ -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"