diff options
author | Guinevere Larsen <guinevere@redhat.com> | 2025-08-14 11:25:38 -0300 |
---|---|---|
committer | Guinevere Larsen <guinevere@redhat.com> | 2025-08-20 17:21:39 -0300 |
commit | 46373d8d659e049f0a4c73a2654911b4c4b8010c (patch) | |
tree | a116e066be7ea32fbea2b2435640cc6a9b47c49a /gdb | |
parent | bac0d9a350627a5e6ac0ff048e35bb93ee6c9867 (diff) | |
download | gdb-46373d8d659e049f0a4c73a2654911b4c4b8010c.zip gdb-46373d8d659e049f0a4c73a2654911b4c4b8010c.tar.gz gdb-46373d8d659e049f0a4c73a2654911b4c4b8010c.tar.bz2 |
gdb: rework _active_linker_namespaces variable
This commit reworks the _active_linker_namespaces convenience variable
following Simon's feedback here:
https://sourceware.org/pipermail/gdb-patches/2025-August/219938.html
This patch implements the renaming to _linker_namespace_count (following
the standard set by _inferior_thread_count) and makes the convenience
variable more resilient in the multi-inferior case by providing a new
function, solib_linker_namespace_count, which counts gets the count of
namespaces using the solib_ops of the provided program_space
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/NEWS | 6 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 8 | ||||
-rw-r--r-- | gdb/solib-svr4.c | 6 | ||||
-rw-r--r-- | gdb/solib.c | 32 | ||||
-rw-r--r-- | gdb/solib.h | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/default.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 14 |
7 files changed, 51 insertions, 21 deletions
@@ -40,11 +40,11 @@ namespace into which the library was loaded, if more than one namespace is active. -* New built-in convenience variables $_active_linker_namespaces and +* New built-in convenience variables $linker_namespace_count and $_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 linker namespaces, these always return - the integers 1 and 0 respectively. + In systems that don't support linker namespaces, or if the inferior hasn't + started yet, these always return the integer 0. * Add record full support for rv64gc architectures diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index d4a5a63..7718a9c 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -13104,11 +13104,11 @@ variable which may be @samp{truecolor} or @samp{24bit}. Other color spaces are determined by the "Co" termcap which in turn depends on the @env{TERM} environment variable. -@vindex $_active_linker_namespaces@r{, convenience variable} -@item $_active_linker_namespaces +@vindex $_linker_namespace_count@r{, convenience variable} +@item $_linker_namespace_count Number of active linker namespaces in the inferior (@pxref{Files}). In systems -with no support for linker namespaces, this variable will always be set to -@samp{1}. +with no support for linker namespaces or if the inferior hasn't started, this +variable will always be set to @samp{0}. @vindex $_linker_namespace@r{, convenience variable} @item $_linker_namespace diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index af08b75..f907571 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -435,12 +435,6 @@ svr4_maybe_add_namespace (svr4_info *info, CORE_ADDR lmid) info->namespace_id.push_back (lmid); info->active_namespaces.insert (i); - - /* Create or update the convenience variable "active_namespaces". - It only needs to be updated here, as this only changes when a - dlmopen or dlclose call happens. */ - set_internalvar_integer (lookup_internalvar ("_active_linker_namespaces"), - info->active_namespaces.size ()); } /* Return whether DEBUG_BASE is the default namespace of INFO. */ diff --git a/gdb/solib.c b/gdb/solib.c index 3ec2032..316ffd6 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1805,6 +1805,18 @@ remove_user_added_objfile (struct objfile *objfile) } } +/* See solib.h. */ + +int +solib_linker_namespace_count (program_space *pspace) +{ + if (const auto ops = pspace->solib_ops (); ops != nullptr + && ops->supports_namespaces ()) + return ops->num_active_namespaces (); + + return 0; +} + /* Implementation of the linker_namespace convenience variable. This returns the GDB internal identifier of the linker namespace, @@ -1840,6 +1852,23 @@ static const struct internalvar_funcs linker_namespace_funcs = nullptr, }; +static value * +linker_namespace_count_make_value (gdbarch *gdbarch, internalvar *var, + void *ignore) +{ + return value_from_longest + (builtin_type (gdbarch)->builtin_int, + solib_linker_namespace_count (current_program_space)); +} + +/* Implementation of `$_linker_namespace_count' variable. */ + +static const struct internalvar_funcs linker_namespace_count_funcs = +{ + linker_namespace_count_make_value, + nullptr, +}; + INIT_GDB_FILE (solib) { gdb::observers::free_objfile.attach (remove_user_added_objfile, "solib"); @@ -1854,7 +1883,8 @@ INIT_GDB_FILE (solib) for consistency. */ create_internalvar_type_lazy ("_linker_namespace", &linker_namespace_funcs, nullptr); - set_internalvar_integer (lookup_internalvar ("_active_linker_namespaces"), 1); + create_internalvar_type_lazy ("_linker_namespace_count", + &linker_namespace_count_funcs, nullptr); add_com ( "sharedlibrary", class_files, sharedlibrary_command, diff --git a/gdb/solib.h b/gdb/solib.h index b9465e1..f6d6de9 100644 --- a/gdb/solib.h +++ b/gdb/solib.h @@ -373,4 +373,8 @@ extern void update_solib_breakpoints (void); extern void handle_solib_event (void); +/* Calculate the number of linker namespaces active in PSPACE. */ + +extern int solib_linker_namespace_count (program_space *pspace); + #endif /* GDB_SOLIB_H */ diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp index d857165..b5e64c2 100644 --- a/gdb/testsuite/gdb.base/default.exp +++ b/gdb/testsuite/gdb.base/default.exp @@ -768,7 +768,7 @@ set show_conv_list \ {$_gdb_setting = <internal function _gdb_setting>} \ {$_shell_exitsignal = void} \ {$_shell_exitcode = 0} \ - {$_active_linker_namespaces = 1} \ + {$_linker_namespace_count = 0} \ {$_linker_namespace = <error: No registers.>}\ } if [allow_python_tests] { diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp index 4d3e8eb..e23edbf 100644 --- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp +++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp @@ -107,11 +107,13 @@ proc test_info_shared {} { # Run all tests related to the linkage namespaces convenience # variables, _active_namespaces and _current_namespaces. +# Also tests that the namespace ID is only printed at the correct +# times. proc_with_prefix test_conv_vars {} { clean_restart $::binfile - gdb_test "print \$_active_linker_namespaces" "1" \ - "1 namespace before starting inferior" + gdb_test "print \$_linker_namespace_count" "0" \ + "0 namespace before starting inferior" gdb_test "print \$_linker_namespace" "No registers." \ "No current namespace before starting inferior" @@ -119,7 +121,7 @@ proc_with_prefix test_conv_vars {} { return } - gdb_test "print \$_active_linker_namespaces" "1" \ + gdb_test "print \$_linker_namespace_count" "1" \ "Before activating namespaces" gdb_test "print \$_linker_namespace" ".* = 0" \ "Still in the default namespace" @@ -141,12 +143,12 @@ proc_with_prefix test_conv_vars {} { "print namespace of selected frame" gdb_continue_to_breakpoint "first dlclose" - gdb_test "print \$_active_linker_namespaces" "4" "all SOs loaded" + gdb_test "print \$_linker_namespace_count" "4" "all SOs loaded" gdb_test "next" ".*second dlclose.*" "close one SO" - gdb_test "print \$_active_linker_namespaces" "3" "one SOs unloaded" + gdb_test "print \$_linker_namespace_count" "3" "one SOs unloaded" gdb_test "next" ".*third dlclose.*" "close another SO" - gdb_test "print \$_active_linker_namespaces" "2" "two SOs unloaded" + gdb_test "print \$_linker_namespace_count" "2" "two SOs unloaded" # Restarting GDB so that we can test setting a breakpoint # using the convenience variable, while a proper bp syntax |