* [PATCH 1/3] gdb: add convenience variables around linker namespace debugging
2025-04-07 14:54 [PATCH 0/3] Add some linker namespaces conveniences Guinevere Larsen
@ 2025-04-07 14:54 ` Guinevere Larsen
2025-04-07 15:39 ` Eli Zaretskii
2025-04-07 14:54 ` [PATCH 2/3] gdb: factor out printing a table of solibs for info sharedlibrary Guinevere Larsen
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-07 14:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen
This commit adds 2 simple built-in convenience variables to help users
debug an inferior with multiple linker namespaces. The first is
$_active_namespaces, which just counts how many namespaces have SOs
loaded onto them. The second is $_current_namespace, and it tracks which
namespace does the current location in the inferior belongs to.
This commit also introduces a test ensuring that we track namespaces
correctly, and that a user can use the $_current_namespace variable to
set a conditional breakpoint, while linespec changes aren't finalized to
make it more convenient.
---
gdb/NEWS | 5 ++
gdb/doc/gdb.texinfo | 12 +++++
gdb/solib-svr4.c | 6 +++
gdb/solib.c | 42 +++++++++++++++
gdb/testsuite/gdb.base/default.exp | 2 +
gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c | 6 +++
gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 55 ++++++++++++++++++++
7 files changed, 128 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 99ec392d4c4..4bf380cbadd 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -40,6 +40,11 @@
namespace into which the library was loaded, if more than one namespace
is active.
+* New built-in convenience variables $_active_namespaces and
+ $_current_namespace. These show the number of active linkage namespaces,
+ and which one the current location belongs to. In systems that don't
+ support linkage namespaces, these always return 1 and [[0]] respectively.
+
* New commands
maintenance check psymtabs
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 4e4509a4649..f0ebf4b7dcf 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -13046,6 +13046,18 @@ 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.
+@item $_active_namespaces
+@vindex $_active_namespaces@r{, convenience variable}
+Number of active linkage namespaces in the inferior. In systems with no
+support for linkage namespaces, this variable will always be set to @samp{1}.
+
+@item $_current_namespace
+@vindex $_current_namespace@r{, convenience variable}
+Which namespace contains the current location in the inferior. This returns
+GDB's internal identifier for namespaces, which is @samp{[[]]} with an
+integer in the middle. In systems with no support for linkage namespaces,
+this variable will always be set to @samp{[[0]]}
+
@end table
@node Convenience Funs
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2f839bd7b0b..60b61e7e07d 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -451,6 +451,12 @@ 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_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 3ddd4f919c6..52fd6410429 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1715,6 +1715,41 @@ default_find_solib_addr (solib &so)
return {};
}
+/* Implementation of the current_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]]. */
+
+static value *
+current_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]]";
+ 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));
+ break;
+ }
+ }
+
+
+ /* 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 ());
+}
+
+static const struct internalvar_funcs current_namespace_funcs =
+{
+ current_namespace_make_value,
+ nullptr,
+};
+
void _initialize_solib ();
void
@@ -1727,6 +1762,13 @@ _initialize_solib ()
},
"solib");
+ /* Convenience variables for debugging linker namespaces. These are
+ set here, even if the solib_ops doesn't support them,
+ for consistency. */
+ create_internalvar_type_lazy ("_current_namespace",
+ ¤t_namespace_funcs, nullptr);
+ set_internalvar_integer (lookup_internalvar ("_active_namespaces"), 1);
+
add_com (
"sharedlibrary", class_files, sharedlibrary_command,
_ ("Load shared object library symbols for files matching REGEXP."));
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 93a6733c9ad..8e42b23d038 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -699,6 +699,8 @@ set show_conv_list \
{$_gdb_minor = 1} \
{$_shell_exitsignal = void} \
{$_shell_exitcode = 0} \
+ {$_active_namespaces = 1} \
+ {$_current_namespace = <error: No registers.>}\
}
if [allow_python_tests] {
append show_conv_list \
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
index 3bcd8196483..c7c038a08d1 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
@@ -41,6 +41,12 @@ main (void)
handle[2] = dlmopen (LM_ID_NEWLM, DSO_NAME, RTLD_LAZY | RTLD_LOCAL);
assert (handle[2] != NULL);
+ for (dl = 2; dl >= 0; dl--)
+ {
+ fun = dlsym (handle[dl], "inc");
+ fun (dl);
+ }
+
dlclose (handle[0]); /* TAG: first dlclose */
dlclose (handle[1]); /* TAG: second dlclose */
dlclose (handle[2]); /* TAG: third dlclose */
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 03b7a527af5..51d461d05a3 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -103,4 +103,59 @@ proc test_info_shared {} {
"after unloading everything"
}
+# Run all tests related to the linkage namespaces convenience
+# variables, _active_namespaces and _current_namespaces.
+proc_with_prefix test_conv_vars {} {
+ clean_restart $::binfile
+
+ gdb_test "print \$_active_namespaces" "1" \
+ "1 namespace before starting inferior"
+ gdb_test "print \$_current_namespace" "No registers." \
+ "No current namespace before starting inferior"
+
+ if { ![runto_main] } {
+ return
+ }
+
+ gdb_test "print \$_active_namespaces" "1" \
+ "Before activating namespaces"
+ gdb_test "print \$_current_namespace" ".*\"\\\[\\\[0\\\]\\\]\"" \
+ "Still in the default namespace"
+
+ gdb_breakpoint "inc" allow-pending
+ gdb_breakpoint [gdb_get_line_number "TAG: first dlclose"]
+
+ foreach_with_prefix dl {3 2 1} {
+ gdb_continue_to_breakpoint "inc"
+
+ gdb_test "print \$_current_namespace" ".*\"\\\[\\\[$dl\\\]\\\]\"" \
+ "Verify we're in namespace $dl"
+ }
+
+ gdb_continue_to_breakpoint "first dlclose"
+ gdb_test "print \$_active_namespaces" "4" "all SOs loaded"
+
+ gdb_test "next" ".*second dlclose.*" "close one SO"
+ gdb_test "print \$_active_namespaces" "3" "one SOs unloaded"
+ gdb_test "next" ".*third dlclose.*" "close another SO"
+ gdb_test "print \$_active_namespaces" "2" "two SOs unloaded"
+
+ # Restarting GDB so that we can test setting a breakpoint
+ # using the convenience variable, while a proper bp syntax
+ # isn't implemented for namespaces
+ clean_restart $::binfile
+ if {![runto_main]} {
+ return
+ }
+
+ # We need to load one SO because you can't have confitional
+ # 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_namespace, \"\[\[2\]\]\")"
+ gdb_continue_to_breakpoint "inc"
+ gdb_continue_to_end "" continue 1
+}
+
test_info_shared
+test_conv_vars
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] gdb: add convenience variables around linker namespace debugging
2025-04-07 14:54 ` [PATCH 1/3] gdb: add convenience variables around linker namespace debugging Guinevere Larsen
@ 2025-04-07 15:39 ` Eli Zaretskii
2025-04-07 17:10 ` Guinevere Larsen
0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2025-04-07 15:39 UTC (permalink / raw)
To: Guinevere Larsen; +Cc: gdb-patches
> From: Guinevere Larsen <guinevere@redhat.com>
> Cc: Guinevere Larsen <guinevere@redhat.com>
> Date: Mon, 7 Apr 2025 11:54:41 -0300
>
> This commit adds 2 simple built-in convenience variables to help users
> debug an inferior with multiple linker namespaces. The first is
> $_active_namespaces, which just counts how many namespaces have SOs
> loaded onto them. The second is $_current_namespace, and it tracks which
> namespace does the current location in the inferior belongs to.
>
> This commit also introduces a test ensuring that we track namespaces
> correctly, and that a user can use the $_current_namespace variable to
> set a conditional breakpoint, while linespec changes aren't finalized to
> make it more convenient.
> ---
> gdb/NEWS | 5 ++
> gdb/doc/gdb.texinfo | 12 +++++
> gdb/solib-svr4.c | 6 +++
> gdb/solib.c | 42 +++++++++++++++
> gdb/testsuite/gdb.base/default.exp | 2 +
> gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c | 6 +++
> gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 55 ++++++++++++++++++++
> 7 files changed, 128 insertions(+)
Thanks.
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -40,6 +40,11 @@
> namespace into which the library was loaded, if more than one namespace
> is active.
>
> +* New built-in convenience variables $_active_namespaces and
> + $_current_namespace. These show the number of active linkage namespaces,
> + and which one the current location belongs to. In systems that don't
^^
Two spaces there, please.
Also, I find the following minor rewording easier to grasp:
These show the number of active linkage namespaces, and the
namespace to which the current location belongs.
> +@item $_active_namespaces
> +@vindex $_active_namespaces@r{, convenience variable}
Please always put the indexing commands _before_ the @item which they
index, so that the corresponding command in the Info reader moves the
cursor to the @item and not after it.
> +@item $_current_namespace
> +@vindex $_current_namespace@r{, convenience variable}
Likewise.
> +Which namespace contains the current location in the inferior.
"The namespace which contains the current location in the inferior."
> This returns
> +GDB's internal identifier for namespaces, which is @samp{[[]]} with an
> +integer in the middle.
It is better to show than to describe:
This returns @value{GDBN}'s internal identifier for namespaces,
which is @samp{[[@var{n}]]}, where @var{n} is a zero-based namespace
number.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] gdb: add convenience variables around linker namespace debugging
2025-04-07 15:39 ` Eli Zaretskii
@ 2025-04-07 17:10 ` Guinevere Larsen
0 siblings, 0 replies; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-07 17:10 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 4/7/25 12:39 PM, Eli Zaretskii wrote:
>> From: Guinevere Larsen <guinevere@redhat.com>
>> Cc: Guinevere Larsen <guinevere@redhat.com>
>> Date: Mon, 7 Apr 2025 11:54:41 -0300
>>
>> This commit adds 2 simple built-in convenience variables to help users
>> debug an inferior with multiple linker namespaces. The first is
>> $_active_namespaces, which just counts how many namespaces have SOs
>> loaded onto them. The second is $_current_namespace, and it tracks which
>> namespace does the current location in the inferior belongs to.
>>
>> This commit also introduces a test ensuring that we track namespaces
>> correctly, and that a user can use the $_current_namespace variable to
>> set a conditional breakpoint, while linespec changes aren't finalized to
>> make it more convenient.
>> ---
>> gdb/NEWS | 5 ++
>> gdb/doc/gdb.texinfo | 12 +++++
>> gdb/solib-svr4.c | 6 +++
>> gdb/solib.c | 42 +++++++++++++++
>> gdb/testsuite/gdb.base/default.exp | 2 +
>> gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c | 6 +++
>> gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 55 ++++++++++++++++++++
>> 7 files changed, 128 insertions(+)
> Thanks.
>
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -40,6 +40,11 @@
>> namespace into which the library was loaded, if more than one namespace
>> is active.
>>
>> +* New built-in convenience variables $_active_namespaces and
>> + $_current_namespace. These show the number of active linkage namespaces,
>> + and which one the current location belongs to. In systems that don't
> ^^
> Two spaces there, please.
>
> Also, I find the following minor rewording easier to grasp:
>
> These show the number of active linkage namespaces, and the
> namespace to which the current location belongs.
>
>> +@item $_active_namespaces
>> +@vindex $_active_namespaces@r{, convenience variable}
> Please always put the indexing commands _before_ the @item which they
> index, so that the corresponding command in the Info reader moves the
> cursor to the @item and not after it.
>
>> +@item $_current_namespace
>> +@vindex $_current_namespace@r{, convenience variable}
> Likewise.
>
>> +Which namespace contains the current location in the inferior.
> "The namespace which contains the current location in the inferior."
>
>> This returns
>> +GDB's internal identifier for namespaces, which is @samp{[[]]} with an
>> +integer in the middle.
> It is better to show than to describe:
>
> This returns @value{GDBN}'s internal identifier for namespaces,
> which is @samp{[[@var{n}]]}, where @var{n} is a zero-based namespace
> number.
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
>
Thanks for the review, I applied all the fixes and your tag
--
Cheers,
Guinevere Larsen
She/Her/Hers
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] gdb: factor out printing a table of solibs for info sharedlibrary
2025-04-07 14:54 [PATCH 0/3] Add some linker namespaces conveniences Guinevere Larsen
2025-04-07 14:54 ` [PATCH 1/3] gdb: add convenience variables around linker namespace debugging Guinevere Larsen
@ 2025-04-07 14:54 ` Guinevere Larsen
2025-04-07 14:54 ` [PATCH 3/3] GDB: Introduce "info namespaces" command Guinevere Larsen
2025-04-07 18:08 ` [PATCH 0/3] Add some linker namespaces conveniences Kevin Buettner
3 siblings, 0 replies; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-07 14:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen
The next patch will add a new command that will print libraries in a
manner very similar to the existing "info sharedlibrary" command. To
make that patch simpler to review, this commit does the bulk of
refactoring work, since it ends up being a non-trivial diff to review.
No functional changes are expected after this commit.
---
gdb/solib.c | 137 ++++++++++++++++++++++++++++------------------------
1 file changed, 74 insertions(+), 63 deletions(-)
diff --git a/gdb/solib.c b/gdb/solib.c
index 52fd6410429..c232d1338b2 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1010,84 +1010,61 @@ solib_add (const char *pattern, int from_tty, int readsyms)
}
}
-/* Implement the "info sharedlibrary" command. Walk through the
- shared library list and print information about each attached
- library matching PATTERN. If PATTERN is elided, print them
- all. */
+/* Helper function for "info sharedlibrary" and "info namespace".
+ This receives a list of solibs to be printed, and prints a table
+ with all the relevant data. If PRINT_NAMESPACE is true, figure out
+ the solib_ops of the current gdbarch, to calculate the namespace
+ that contains an solib.
+ Returns true if one or more solibs are missing debug information,
+ false otherwise. */
static void
-info_sharedlibrary_command (const char *pattern, int from_tty)
+print_solib_list_table (std::vector<const solib *> solib_list,
+ bool print_namespace)
{
- bool so_missing_debug_info = false;
- int addr_width;
- int nr_libs;
gdbarch *gdbarch = current_inferior ()->arch ();
- struct ui_out *uiout = current_uiout;
-
- if (pattern)
- {
- char *re_err = re_comp (pattern);
-
- if (re_err)
- error (_ ("Invalid regexp: %s"), re_err);
- }
-
/* "0x", a little whitespace, and two hex digits per byte of pointers. */
- addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4);
-
- update_solib_list (from_tty);
-
- /* ui_out_emit_table table_emitter needs to know the number of rows,
- so we need to make two passes over the libs. */
+ int addr_width = 4 + (gdbarch_ptr_bit (gdbarch) / 4);
+ const solib_ops *ops = gdbarch_so_ops (gdbarch);
+ struct ui_out *uiout = current_uiout;
+ bool so_missing_debug_info = false;
- nr_libs = 0;
- for (const solib &so : current_program_space->solibs ())
- {
- if (!so.so_name.empty ())
- {
- if (pattern && !re_exec (so.so_name.c_str ()))
- continue;
- ++nr_libs;
- }
- }
+ /* There are 3 conditions for this command to print solib namespaces,
+ first PRINT_NAMESPACE has to be true, second the solib_ops has to
+ support multiple namespaces, and third there must be more than one
+ active namespace. Fold all these into the PRINT_NAMESPACE condition. */
+ print_namespace = print_namespace && ops->num_active_namespaces != nullptr
+ && ops->num_active_namespaces () > 1;
- /* How many columns the table should have. If the inferior has
- more than one namespace active, we need a column to show that. */
int num_cols = 4;
- const solib_ops *ops = gdbarch_so_ops (gdbarch);
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces () > 1)
+ if (print_namespace)
num_cols++;
{
- ui_out_emit_table table_emitter (uiout, num_cols, nr_libs,
+ ui_out_emit_table table_emitter (uiout, num_cols, solib_list.size (),
"SharedLibraryTable");
/* The "- 1" is because ui_out adds one space between columns. */
uiout->table_header (addr_width - 1, ui_left, "from", "From");
uiout->table_header (addr_width - 1, ui_left, "to", "To");
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces () > 1)
+ if (print_namespace)
uiout->table_header (5, ui_left, "namespace", "NS");
uiout->table_header (12 - 1, ui_left, "syms-read", "Syms Read");
uiout->table_header (0, ui_noalign, "name", "Shared Object Library");
uiout->table_body ();
- for (const solib &so : current_program_space->solibs ())
+ for (const solib *so : solib_list)
{
- if (so.so_name.empty ())
- continue;
-
- if (pattern && !re_exec (so.so_name.c_str ()))
+ if (so->so_name.empty ())
continue;
ui_out_emit_tuple tuple_emitter (uiout, "lib");
- if (so.addr_high != 0)
+ if (so->addr_high != 0)
{
- uiout->field_core_addr ("from", gdbarch, so.addr_low);
- uiout->field_core_addr ("to", gdbarch, so.addr_high);
+ uiout->field_core_addr ("from", gdbarch, so->addr_low);
+ uiout->field_core_addr ("to", gdbarch, so->addr_high);
}
else
{
@@ -1095,12 +1072,11 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
uiout->field_skip ("to");
}
- if (ops->num_active_namespaces != nullptr
- && ops->num_active_namespaces ()> 1)
+ if (print_namespace)
{
try
{
- uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (so));
+ uiout->field_fmt ("namespace", "[[%d]]", ops->find_solib_ns (*so));
}
catch (const gdb_exception_error &er)
{
@@ -1109,33 +1085,68 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
}
if (!top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ()
- && so.symbols_loaded && !objfile_has_symbols (so.objfile))
+ && so->symbols_loaded && !objfile_has_symbols (so->objfile))
{
so_missing_debug_info = true;
uiout->field_string ("syms-read", "Yes (*)");
}
else
- uiout->field_string ("syms-read", so.symbols_loaded ? "Yes" : "No");
+ uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No");
- uiout->field_string ("name", so.so_name, file_name_style.style ());
+ uiout->field_string ("name", so->so_name, file_name_style.style ());
uiout->text ("\n");
}
}
- if (nr_libs == 0)
+ if (so_missing_debug_info)
+ uiout->message (_ ("(*): Shared library is missing "
+ "debugging information.\n"));
+}
+
+/* Implement the "info sharedlibrary" command. Walk through the
+ shared library list and print information about each attached
+ library matching PATTERN. If PATTERN is elided, print them
+ all. */
+
+static void
+info_sharedlibrary_command (const char *pattern, int from_tty)
+{
+ struct ui_out *uiout = current_uiout;
+
+ if (pattern)
+ {
+ char *re_err = re_comp (pattern);
+
+ if (re_err)
+ error (_ ("Invalid regexp: %s"), re_err);
+ }
+
+ update_solib_list (from_tty);
+
+ /* ui_out_emit_table table_emitter needs to know the number of rows,
+ so we need to make two passes over the libs. */
+
+ std::vector<const solib *> print_libs;
+ for (const solib &so : current_program_space->solibs ())
+ {
+ if (!so.so_name.empty ())
+ {
+ if (pattern && !re_exec (so.so_name.c_str ()))
+ continue;
+ print_libs.push_back (&so);
+ }
+ }
+
+ print_solib_list_table (print_libs, true);
+
+ if (print_libs.size () == 0)
{
if (pattern)
uiout->message (_ ("No shared libraries matched.\n"));
else
uiout->message (_ ("No shared libraries loaded at this time.\n"));
}
- else
- {
- if (so_missing_debug_info)
- uiout->message (_ ("(*): Shared library is missing "
- "debugging information.\n"));
- }
}
/* See solib.h. */
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH 3/3] GDB: Introduce "info namespaces" command
2025-04-07 14:54 [PATCH 0/3] Add some linker namespaces conveniences Guinevere Larsen
2025-04-07 14:54 ` [PATCH 1/3] gdb: add convenience variables around linker namespace debugging Guinevere Larsen
2025-04-07 14:54 ` [PATCH 2/3] gdb: factor out printing a table of solibs for info sharedlibrary Guinevere Larsen
@ 2025-04-07 14:54 ` Guinevere Larsen
2025-04-07 15:45 ` Eli Zaretskii
2025-04-07 18:08 ` [PATCH 0/3] Add some linker namespaces conveniences Kevin Buettner
3 siblings, 1 reply; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-07 14:54 UTC (permalink / raw)
To: gdb-patches; +Cc: Guinevere Larsen
Continuing to improve GDB's ability to debug linker namespaces, this
commit adds the command "info namespaces". The command is similar to
"info sharedlibrary" but focused on improved readability when the
inferior has multiple linker namespaces active. This command can
be used in 2 different ways, with or without an argument.
When called without argument, the command will print the number of
namespaces, and for each active namespace, it's identifier, how many
libraries are loaded in it, and all the libraries (in a similar table to
what "info sharedlibrary" shows). As an example, this is what GDB's
output could look like:
(gdb) info namespaces
There are 2 namespaces loaded
There are 3 libraries loaded in namespace [[0]]
Displaying libraries for namespace [[0]]:
From To Syms Read Shared Object Library
0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
(*): Shared library is missing debugging information.
There are 4 libraries loaded in namespace [[1]]
Displaying libraries for namespace [[1]]:
From To Syms Read Shared Object Library
0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7fb9000 0x00007ffff7fbe000 Yes gdb.base/dlmopen-ns-ids/dlmopen-lib.so
0x00007ffff7bc4000 0x00007ffff7caa000 Yes (*) /lib64/libm.so.6
0x00007ffff79d1000 0x00007ffff7bc4000 Yes (*) /lib64/libc.so.6
(*): Shared library is missing debugging information.
When called with an argument, the argument must be a namespace
identifier (either with or without the square brackets decorators). In
this situation, the command will truncate the output to only show the
relevant information for the requested namespace. For example:
(gdb) info namespaces 0
There are 3 libraries loaded in namespace [[0]]
Displaying libraries for namespace [[0]]:
From To Syms Read Shared Object Library
0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
(*): Shared library is missing debugging information.
The test gdb.base/dlmopen-ns-id.exp has been extended to test this new
command.
---
gdb/NEWS | 5 ++
gdb/doc/gdb.texinfo | 15 ++++
gdb/solib-svr4.c | 49 ++++++++++++
gdb/solib.c | 91 ++++++++++++++++++++++
gdb/solist.h | 4 +
gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 93 +++++++++++++++++++++++
6 files changed, 257 insertions(+)
diff --git a/gdb/NEWS b/gdb/NEWS
index 4bf380cbadd..758c7e1e543 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -59,6 +59,11 @@ show riscv numeric-register-names
(e.g 'x1') or their abi names (e.g. 'ra').
Defaults to 'off', matching the old behaviour (abi names).
+info namespaces
+info namespaces [[N]]
+ Print information about the given namespace (identified as N), or about
+ all the namespaces if no argument is given.
+
* Changed commands
info sharedlibrary
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index f0ebf4b7dcf..aaa1431fff5 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -22223,6 +22223,21 @@ command for this. This command exists for historical reasons. It is
less useful than setting a catchpoint, because it does not allow for
conditions or commands as a catchpoint does.
+@table @code
+@item info namespaces
+@item info namespaces @code{[[N]]}
+
+With no argument, print the number of linker namespaces which are
+currently active - that is, namespaces that have libraries loaded
+on them. Then, it prints the number of libraries loaded into each
+namespace, and all the libraries loaded into them, in the same way
+as @code{info sharedlibrary}.
+
+If an argument is provided, only prints the library count and table
+for the provided namespace. The surrounding square brackets are
+optional.
+@end table
+
@table @code
@item set stop-on-solib-events
@kindex set stop-on-solib-events
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 60b61e7e07d..76823afde26 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3558,6 +3558,54 @@ svr4_num_active_namespaces ()
return info->active_namespaces.size ();
}
+/* See solib_ops::get_solibs_in_ns in solist.h. */
+static std::vector<const solib *>
+svr4_get_solibs_in_ns (int nsid)
+{
+ std::vector<const solib*> ns_solibs;
+ svr4_info *info = get_svr4_info (current_program_space);
+
+ /* If the namespace ID is inactive, there will be no active
+ libraries, so we can have an early exit, as a treat. */
+ if (info->active_namespaces.count (nsid) != 1)
+ return ns_solibs;
+
+ /* Since we only have the names of solibs in a given namespace,
+ we'll need to walk through the solib list of the inferior and
+ find which solib objects correspond to which svr4_so. We create
+ an unordered map with the names and lm_info to check things
+ faster, and to be able to remove SOs from the map, to avoid
+ returning the dynamic linker multiple times. */
+ CORE_ADDR debug_base = info->namespace_id[nsid];
+ std::unordered_map<std::string, const lm_info_svr4 *> namespace_solibs;
+ for (svr4_so &so : info->solib_lists[debug_base])
+ {
+ namespace_solibs[so.name]
+ = gdb::checked_static_cast<const lm_info_svr4 *>
+ (so.lm_info.get ());
+ }
+ for (const solib &so: current_program_space->solibs ())
+ {
+ auto *lm_inferior
+ = gdb::checked_static_cast<const lm_info_svr4 *> (so.lm_info.get ());
+
+ /* This is inspired by the svr4_same, by finding the svr4_so object
+ in the map, and then double checking if the lm_info is considered
+ the same. */
+ if (namespace_solibs.count (so.so_original_name) > 0
+ && namespace_solibs[so.so_original_name]->l_addr_inferior
+ == lm_inferior->l_addr_inferior)
+ {
+ ns_solibs.push_back (&so);
+ /* Remove the SO from the map, so that we don't end up
+ printing the dynamic linker multiple times. */
+ namespace_solibs.erase (so.so_original_name);
+ }
+ }
+
+ return ns_solibs;
+}
+
const struct solib_ops svr4_so_ops =
{
svr4_relocate_section_addresses,
@@ -3575,6 +3623,7 @@ const struct solib_ops svr4_so_ops =
svr4_find_solib_addr,
svr4_find_solib_ns,
svr4_num_active_namespaces,
+ svr4_get_solibs_in_ns,
};
void _initialize_svr4_solib ();
diff --git a/gdb/solib.c b/gdb/solib.c
index c232d1338b2..d946d3795ac 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1149,6 +1149,94 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
}
}
+/* Implement the "info namespaces" command. If the current
+ gdbarch's solib_ops object does not support multiple namespaces,
+ this command would just look like "info sharedlibrary", so point
+ the user to that command instead.
+ If solib_ops does support multiple namespaces, this command
+ will group the libraries by linker namespace, or only print the
+ libraries in the supplied namespace. */
+static void
+info_linker_namespace_command (const char *pattern, int from_tty)
+{
+ const solib_ops *ops = gdbarch_so_ops (current_inferior ()->arch ());
+ /* This command only really makes sense for inferiors that support
+ linker namespaces, so we can leave early. */
+ if (ops->num_active_namespaces == nullptr)
+ error (_("Current inferior does not support linker namespaces." \
+ "Use \"info sharedlibrary\" instead"));
+
+ struct ui_out *uiout = current_uiout;
+ std::vector<std::pair<int, std::vector<const solib *>>> all_solibs_to_print;
+
+ if (pattern != nullptr)
+ while (*pattern == ' ')
+ pattern++;
+
+ if (pattern == nullptr || pattern[0] == '\0')
+ {
+ uiout->message (_ ("There are %d namespaces loaded\n"),
+ ops->num_active_namespaces ());
+
+ int printed = 0;
+ for (int i = 0; printed < ops->num_active_namespaces (); i++)
+ {
+ std::vector<const solib *> solibs_to_print
+ = ops->get_solibs_in_ns (i);
+ if (solibs_to_print.size () > 0)
+ {
+ all_solibs_to_print.push_back (std::make_pair
+ (i, solibs_to_print));
+ printed++;
+ }
+ }
+ }
+ else
+ {
+ int ns;
+ /* Check if the pattern includes the optional [[ and ]] decorators.
+ To match multiple occurrences, '+' needs to be escaped, and every
+ escape sequence must be doubled to survive the compiler pass. */
+ re_comp ("^\\[\\[[0-9]\\+\\]\\]$");
+ if (re_exec (pattern))
+ ns = strtol (pattern+2, nullptr, 10);
+ else
+ {
+ char * end = nullptr;
+ ns = strtol (pattern, &end, 10);
+ if (end[0] != '\0')
+ error (_ ("Invalid namespace identifier: %s"), pattern);
+ }
+
+ all_solibs_to_print.push_back
+ (std::make_pair (ns, ops->get_solibs_in_ns (ns)));
+ }
+
+ bool ns_separator = false;
+
+ for (auto &solibs_pair : all_solibs_to_print)
+ {
+ if (ns_separator)
+ uiout->message ("\n\n");
+ else
+ ns_separator = true;
+ int ns = solibs_pair.first;
+ std::vector<const solib *> solibs_to_print = solibs_pair.second;
+ if (solibs_to_print.size () == 0)
+ {
+ uiout->message (_("Namespace [[%d]] is not active.\n"), ns);
+ /* If we got here, a specific namespace was requested, so there
+ will only be one vector. We can leave early. */
+ break;
+ }
+ uiout->message (_ ("There are %ld libraries loaded in namespace [[%d]]\n"),
+ solibs_to_print.size (), ns);
+ uiout->message (_ ("Displaying libraries for namespace [[%d]]:\n"), ns);
+
+ print_solib_list_table (solibs_to_print, false);
+ }
+}
+
/* See solib.h. */
bool
@@ -1790,6 +1878,9 @@ _initialize_solib ()
add_com ("nosharedlibrary", class_files, no_shared_libraries_command,
_ ("Unload all shared object library symbols."));
+ add_info ("namespaces", info_linker_namespace_command,
+ _ ("Get information about linker namespaces in the inferior."));
+
add_setshow_boolean_cmd ("auto-solib-add", class_support, &auto_solib_add,
_ ("\
Set autoloading of shared library symbols."),
diff --git a/gdb/solist.h b/gdb/solist.h
index 03d2392b19d..5f029054399 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -194,6 +194,10 @@ struct solib_ops
/* Returns the number of active namespaces in the inferior. */
int (*num_active_namespaces) ();
+
+ /* Returns all solibs for a given namespace. If the namespace is not
+ active, returns an empty vector. */
+ std::vector<const solib *> (*get_solibs_in_ns) (int ns);
};
/* A unique pointer to a so_list. */
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 51d461d05a3..095433896ac 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -157,5 +157,98 @@ proc_with_prefix test_conv_vars {} {
gdb_continue_to_end "" continue 1
}
+# Run several tests relating to the command "info namespaces".
+proc test_info_namespaces {} {
+ clean_restart $::binfile
+
+ if { ![runto_main] } {
+ return
+ }
+
+ with_test_prefix "info namespaces" {
+ gdb_breakpoint [gdb_get_line_number "TAG: first dlclose"]
+ gdb_continue_to_breakpoint "TAG: first dlclose"
+ }
+
+ # First, test printing a single namespace, and ensure all of
+ # them are correct, using both syntaxes.
+ set found_libm false
+ set found_libc false
+ set found_all_libs false
+ gdb_test_multiple "info namespaces \[\[0\]\]" "print namespace 0" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in namespace \\\[\\\[0\\\]\\\]" {
+ set libs $expect_out(1,string)
+ set found_all_libs [expr $libs == 3]
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+libm\.so\[^\r\n\]*(?=\r\n)" {
+ set found_libm true
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+libc\.so\[^\r\n\]*(?=\r\n)" {
+ set found_libc true
+ exp_continue
+ }
+ -re "^\r\n$::gdb_prompt $" {
+ gdb_assert $found_libm "libm was reported"
+ gdb_assert $found_libc "libc was reported"
+ gdb_assert $found_all_libs "the correct number of libraries was reported"
+ }
+ -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
+ exp_continue
+ }
+ }
+ foreach_with_prefix ns {1 2 3} {
+ set found_libm false
+ set found_libc false
+ set found_test_so false
+ set found_all_libs false
+ gdb_test_multiple "info namespaces $ns" "print namespace $ns" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in namespace \\\[\\\[$ns\\\]\\\]" {
+ set libs $expect_out(1,string)
+ set found_all_libs [expr $libs == 4]
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+libm\.so\[^\r\n\]*(?=\r\n)" {
+ set found_libm true
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+libc\.so\[^\r\n\]*(?=\r\n)" {
+ set found_libc true
+ exp_continue
+ }
+ -re "^\r\n\[^\r\n\]+${::binfile_lib}\[^\r\n\]*(?=\r\n)" {
+ set found_test_so true
+ exp_continue
+ }
+ -re "^\r\n$::gdb_prompt $" {
+ gdb_assert $found_libm "libm was reported"
+ gdb_assert $found_libc "libc was reported"
+ gdb_assert $found_test_so "this testfle's SO was reported"
+ gdb_assert $found_all_libs "the correct number of libraries was reported"
+ }
+ -re "(^\r\n)?\[^\r\n\]+(?=\r\n)" {
+ exp_continue
+ }
+ }
+ }
+
+ # These patterns are simpler, and purposefully glob multiple lines.
+ # The point is to ensure that we find and display all the namespaces,
+ # without worrying about the libraries printed, since that was tested
+ # above.
+ gdb_test "info namespaces" \
+ [multi_line "There are 4 namespaces loaded" \
+ "There are 3 libraries loaded in namespace ..0.." \
+ ".*" \
+ "There are 4 libraries loaded in namespace ..1.." \
+ ".*" \
+ "There are 4 libraries loaded in namespace ..2.." \
+ ".*" \
+ "There are 4 libraries loaded in namespace ..3.." \
+ ".*" ] "print namespaces with no argument"
+}
+
test_info_shared
test_conv_vars
+test_info_namespaces
--
2.49.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/3] GDB: Introduce "info namespaces" command
2025-04-07 14:54 ` [PATCH 3/3] GDB: Introduce "info namespaces" command Guinevere Larsen
@ 2025-04-07 15:45 ` Eli Zaretskii
2025-04-07 17:04 ` Guinevere Larsen
0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2025-04-07 15:45 UTC (permalink / raw)
To: Guinevere Larsen; +Cc: gdb-patches
> From: Guinevere Larsen <guinevere@redhat.com>
> Cc: Guinevere Larsen <guinevere@redhat.com>
> Date: Mon, 7 Apr 2025 11:54:43 -0300
>
> Continuing to improve GDB's ability to debug linker namespaces, this
> commit adds the command "info namespaces". The command is similar to
> "info sharedlibrary" but focused on improved readability when the
> inferior has multiple linker namespaces active. This command can
> be used in 2 different ways, with or without an argument.
>
> When called without argument, the command will print the number of
> namespaces, and for each active namespace, it's identifier, how many
> libraries are loaded in it, and all the libraries (in a similar table to
> what "info sharedlibrary" shows). As an example, this is what GDB's
> output could look like:
>
> (gdb) info namespaces
> There are 2 namespaces loaded
> There are 3 libraries loaded in namespace [[0]]
> Displaying libraries for namespace [[0]]:
> From To Syms Read Shared Object Library
> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
> 0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
> 0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
> (*): Shared library is missing debugging information.
>
> There are 4 libraries loaded in namespace [[1]]
> Displaying libraries for namespace [[1]]:
> From To Syms Read Shared Object Library
> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
> 0x00007ffff7fb9000 0x00007ffff7fbe000 Yes gdb.base/dlmopen-ns-ids/dlmopen-lib.so
> 0x00007ffff7bc4000 0x00007ffff7caa000 Yes (*) /lib64/libm.so.6
> 0x00007ffff79d1000 0x00007ffff7bc4000 Yes (*) /lib64/libc.so.6
> (*): Shared library is missing debugging information.
>
> When called with an argument, the argument must be a namespace
> identifier (either with or without the square brackets decorators). In
> this situation, the command will truncate the output to only show the
> relevant information for the requested namespace. For example:
>
> (gdb) info namespaces 0
> There are 3 libraries loaded in namespace [[0]]
> Displaying libraries for namespace [[0]]:
> From To Syms Read Shared Object Library
> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
> 0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
> 0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
> (*): Shared library is missing debugging information.
>
> The test gdb.base/dlmopen-ns-id.exp has been extended to test this new
> command.
> ---
> gdb/NEWS | 5 ++
> gdb/doc/gdb.texinfo | 15 ++++
> gdb/solib-svr4.c | 49 ++++++++++++
> gdb/solib.c | 91 ++++++++++++++++++++++
> gdb/solist.h | 4 +
> gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 93 +++++++++++++++++++++++
> 6 files changed, 257 insertions(+)
Thanks.
> +info namespaces
> +info namespaces [[N]]
> + Print information about the given namespace (identified as N), or about
> + all the namespaces if no argument is given.
This part is okay.
> +@table @code
> +@item info namespaces
No @kindex?
> +@item info namespaces @code{[[N]]}
N is a meta-syntactic variable, so please use @var{n} for it.
> +With no argument, print the number of linker namespaces which are
> +currently active - that is, namespaces that have libraries loaded
^
Please use either "--" or "---" to produce an em-dash or en-dash.
> +on them. Then, it prints the number of libraries loaded into each
^^^^^^^
"into them", right?
> +If an argument is provided, only prints the library count and table
> +for the provided namespace.K The surrounding square brackets are
"If an argument @code{[[@var{n}]]} is provided, only prints the
library count and the libraries for the specified namespace @var{n}."
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/3] GDB: Introduce "info namespaces" command
2025-04-07 15:45 ` Eli Zaretskii
@ 2025-04-07 17:04 ` Guinevere Larsen
0 siblings, 0 replies; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-07 17:04 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 4/7/25 12:45 PM, Eli Zaretskii wrote:
>> From: Guinevere Larsen <guinevere@redhat.com>
>> Cc: Guinevere Larsen <guinevere@redhat.com>
>> Date: Mon, 7 Apr 2025 11:54:43 -0300
>>
>> Continuing to improve GDB's ability to debug linker namespaces, this
>> commit adds the command "info namespaces". The command is similar to
>> "info sharedlibrary" but focused on improved readability when the
>> inferior has multiple linker namespaces active. This command can
>> be used in 2 different ways, with or without an argument.
>>
>> When called without argument, the command will print the number of
>> namespaces, and for each active namespace, it's identifier, how many
>> libraries are loaded in it, and all the libraries (in a similar table to
>> what "info sharedlibrary" shows). As an example, this is what GDB's
>> output could look like:
>>
>> (gdb) info namespaces
>> There are 2 namespaces loaded
>> There are 3 libraries loaded in namespace [[0]]
>> Displaying libraries for namespace [[0]]:
>> From To Syms Read Shared Object Library
>> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
>> 0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
>> 0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
>> (*): Shared library is missing debugging information.
>>
>> There are 4 libraries loaded in namespace [[1]]
>> Displaying libraries for namespace [[1]]:
>> From To Syms Read Shared Object Library
>> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
>> 0x00007ffff7fb9000 0x00007ffff7fbe000 Yes gdb.base/dlmopen-ns-ids/dlmopen-lib.so
>> 0x00007ffff7bc4000 0x00007ffff7caa000 Yes (*) /lib64/libm.so.6
>> 0x00007ffff79d1000 0x00007ffff7bc4000 Yes (*) /lib64/libc.so.6
>> (*): Shared library is missing debugging information.
>>
>> When called with an argument, the argument must be a namespace
>> identifier (either with or without the square brackets decorators). In
>> this situation, the command will truncate the output to only show the
>> relevant information for the requested namespace. For example:
>>
>> (gdb) info namespaces 0
>> There are 3 libraries loaded in namespace [[0]]
>> Displaying libraries for namespace [[0]]:
>> From To Syms Read Shared Object Library
>> 0x00007ffff7fc6000 0x00007ffff7fff000 Yes /lib64/ld-linux-x86-64.so.2
>> 0x00007ffff7ebc000 0x00007ffff7fa2000 Yes (*) /lib64/libm.so.6
>> 0x00007ffff7cc9000 0x00007ffff7ebc000 Yes (*) /lib64/libc.so.6
>> (*): Shared library is missing debugging information.
>>
>> The test gdb.base/dlmopen-ns-id.exp has been extended to test this new
>> command.
>> ---
>> gdb/NEWS | 5 ++
>> gdb/doc/gdb.texinfo | 15 ++++
>> gdb/solib-svr4.c | 49 ++++++++++++
>> gdb/solib.c | 91 ++++++++++++++++++++++
>> gdb/solist.h | 4 +
>> gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 93 +++++++++++++++++++++++
>> 6 files changed, 257 insertions(+)
> Thanks.
>
>> +info namespaces
>> +info namespaces [[N]]
>> + Print information about the given namespace (identified as N), or about
>> + all the namespaces if no argument is given.
> This part is okay.
>
>> +@table @code
>> +@item info namespaces
> No @kindex?
Thanks for the quick review!
I didn't use @kindex because I didn't know what it was used for, and
didn't accidentally put my command into an unrelated list somehow.
I fixed this and everything else pointed out in this review!
--
Cheers,
Guinevere Larsen
She/Her/Hers
>
>> +@item info namespaces @code{[[N]]}
> N is a meta-syntactic variable, so please use @var{n} for it.
>
>> +With no argument, print the number of linker namespaces which are
>> +currently active - that is, namespaces that have libraries loaded
> ^
> Please use either "--" or "---" to produce an em-dash or en-dash.
>
>> +on them. Then, it prints the number of libraries loaded into each
> ^^^^^^^
> "into them", right?
>
>> +If an argument is provided, only prints the library count and table
>> +for the provided namespace.K The surrounding square brackets are
> "If an argument @code{[[@var{n}]]} is provided, only prints the
> library count and the libraries for the specified namespace @var{n}."
>
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/3] Add some linker namespaces conveniences
2025-04-07 14:54 [PATCH 0/3] Add some linker namespaces conveniences Guinevere Larsen
` (2 preceding siblings ...)
2025-04-07 14:54 ` [PATCH 3/3] GDB: Introduce "info namespaces" command Guinevere Larsen
@ 2025-04-07 18:08 ` Kevin Buettner
2025-04-09 20:20 ` Guinevere Larsen
3 siblings, 1 reply; 10+ messages in thread
From: Kevin Buettner @ 2025-04-07 18:08 UTC (permalink / raw)
To: Guinevere Larsen; +Cc: gdb-patches
On Mon, 7 Apr 2025 11:54:40 -0300
Guinevere Larsen <guinevere@redhat.com> wrote:
> This series is a second step in improving the User Experience of
> debugging inferiors with multiple namespaces. It adds 2 things to make
> it more convenient for users to understand what the inferior is doing.
>
> The first patch adds convenience variables, specifically _active_namespaces
> and _current_namespaces. These can be used to track where in the execution
> of an inferior the user is, and could be used in breakpoint conditions
> to stop at a specific namespace.
>
> The third patch adds a new command, "info namespaces", to help the user
> check what solibs are loaded, and where. To make the patch more
> readable, the second patch is a minor refactor of the command "info
> sharedlibrary".
I'm wondering if we want "namespaces" to mean "linker namespaces". I
can imagine someone adding a command to iterate over the
DW_TAG_namespace entries in the available DWARF info and then print
things regarding those entries. That too could be a good (possibly
better) candidate for a GDB "info namespaces" command.
What I'm suggesting here is that we might want to add a qualifier to
the command and related names, i.e. that the new command be named
"info linker-namespaces" instead of just "info namespaces". Likewise,
add qualifiers for _active_namespaces and _current_namespaces.
Kevin
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 0/3] Add some linker namespaces conveniences
2025-04-07 18:08 ` [PATCH 0/3] Add some linker namespaces conveniences Kevin Buettner
@ 2025-04-09 20:20 ` Guinevere Larsen
0 siblings, 0 replies; 10+ messages in thread
From: Guinevere Larsen @ 2025-04-09 20:20 UTC (permalink / raw)
To: Kevin Buettner; +Cc: gdb-patches
On 4/7/25 3:08 PM, Kevin Buettner wrote:
> On Mon, 7 Apr 2025 11:54:40 -0300
> Guinevere Larsen <guinevere@redhat.com> wrote:
>
>> This series is a second step in improving the User Experience of
>> debugging inferiors with multiple namespaces. It adds 2 things to make
>> it more convenient for users to understand what the inferior is doing.
>>
>> The first patch adds convenience variables, specifically _active_namespaces
>> and _current_namespaces. These can be used to track where in the execution
>> of an inferior the user is, and could be used in breakpoint conditions
>> to stop at a specific namespace.
>>
>> The third patch adds a new command, "info namespaces", to help the user
>> check what solibs are loaded, and where. To make the patch more
>> readable, the second patch is a minor refactor of the command "info
>> sharedlibrary".
> I'm wondering if we want "namespaces" to mean "linker namespaces". I
> can imagine someone adding a command to iterate over the
> DW_TAG_namespace entries in the available DWARF info and then print
> things regarding those entries. That too could be a good (possibly
> better) candidate for a GDB "info namespaces" command.
>
> What I'm suggesting here is that we might want to add a qualifier to
> the command and related names, i.e. that the new command be named
> "info linker-namespaces" instead of just "info namespaces". Likewise,
> add qualifiers for _active_namespaces and _current_namespaces.
This makes sense. I'm working on this change locally and will send a v2
shortly.
>
> Kevin
>
--
Cheers,
Guinevere Larsen
She/Her/Hers
^ permalink raw reply [flat|nested] 10+ messages in thread