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
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
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. */
}
}
+/* 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,
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");
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,
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 */
{$_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] {
# 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"
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"
"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