aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2025-03-26 11:14:52 -0300
committerGuinevere Larsen <guinevere@redhat.com>2025-04-23 09:44:53 -0300
commitdbbb9cfd3708a5b09b449c6cbc4d74dfec13904d (patch)
tree8038a1039c96fb89019ff9f766422602916cb8ef /gdb/testsuite
parentb1cbe15966c1cd6228cae62db5b8a011cf08e014 (diff)
downloadbinutils-dbbb9cfd3708a5b09b449c6cbc4d74dfec13904d.zip
binutils-dbbb9cfd3708a5b09b449c6cbc4d74dfec13904d.tar.gz
binutils-dbbb9cfd3708a5b09b449c6cbc4d74dfec13904d.tar.bz2
GDB: Introduce "info linker-namespaces" command
Continuing to improve GDB's ability to debug linker namespaces, this commit adds the command "info linker- 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 linker-namespaces There are 2 linker namespaces loaded There are 3 libraries loaded in linker namespace [[0]] Displaying libraries for linker 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 linker namespace [[1]] Displaying libraries for linker 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 linker-namespaces 0 There are 3 libraries loaded in linker namespace [[0]] Displaying libraries for linker 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. Because some gcc and glibc defaults can change between systems, we are not guaranteed to always have libc and libm loaded in a namespace, so we can't guarantee the number of libraries, but the range of the result is 2, so we can still check for glaring issues. Reviewed-By: Eli Zaretskii <eliz@gnu.org> Approved-by: Kevin Buettner <kevinb@redhat.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/dlmopen-ns-ids.exp78
1 files changed, 78 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 1af57d1..8f52199 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -159,5 +159,83 @@ proc_with_prefix test_conv_vars {} {
gdb_continue_to_end "" continue 1
}
+# Run several tests relating to the command "info namespaces".
+proc test_info_linker_namespaces {} {
+ clean_restart $::binfile
+
+ if { ![runto_main] } {
+ return
+ }
+
+ with_test_prefix "info linker-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_all_libs false
+ gdb_test_multiple "info linker-namespaces \[\[0\]\]" "print namespace 0" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[0\\\]\\\]" {
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, and up to 2 more libraries.
+ set libs $expect_out(1,string)
+ set found_all_libs [expr $libs - 1 <= 2]
+ exp_continue
+ }
+ -re "^\r\n$::gdb_prompt $" {
+ 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_test_so false
+ set found_all_libs false
+ gdb_test_multiple "info linker-namespaces $ns" "print namespace $ns" -lbl {
+ -re "^\r\nThere are ($::decimal) libraries loaded in linker namespace \\\[\\\[$ns\\\]\\\]" {
+ set libs $expect_out(1,string)
+ # Some systems may add libc and libm to every loaded namespace,
+ # others may load only one or neither, because the SO doesn't
+ # actually use either library. The best we can do is check if
+ # we found the dynamic linker, the test SO, and maybe up to 2
+ # more libraries.
+ set found_all_libs [expr $libs - 2 <= 2]
+ 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_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 linker-namespaces" \
+ [multi_line "There are 4 linker namespaces loaded" \
+ "There are $::decimal libraries loaded in linker namespace ..0.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..1.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..2.." \
+ ".*" \
+ "There are $::decimal libraries loaded in linker namespace ..3.." \
+ ".*" ] "print namespaces with no argument"
+}
+
test_info_shared
test_conv_vars
+test_info_linker_namespaces