public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: Fix libc_has_debug_info when there's no libc
@ 2024-04-26  2:52 Thiago Jung Bauermann
  2024-04-26  5:09 ` Bernd Edlinger
  2024-04-26 16:37 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Thiago Jung Bauermann @ 2024-04-26  2:52 UTC (permalink / raw)
  To: gdb-patches; +Cc: Bernd Edlinger

Bernd reported a Tcl error when running gdb.base/relativedebug.exp with
a riscv-unknown-elf target with newlib (so there is no libc) because of
commit f5ef12c3f1af ("gdb/testsuite: Add libc_has_debug_info require
helper"):

Running /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp ...
FAIL: gdb.base/relativedebug.exp: info sharedlibrary libc.so
ERROR: tcl error sourcing /home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp.
ERROR: tcl error code TCL READ VARNAME
ERROR: can't read "libc_has_debug_info": no such variable
    while executing
"verbose "$me: returning $libc_has_debug_info" 2"
    (procedure "gdb_real__libc_has_debug_info" line 47)
    invoked from within
"gdb_real__libc_has_debug_info"
    ("uplevel" body line 1)
    invoked from within
"uplevel 2 [list $real_name {*}$args]"
    invoked from within
"gdb_do_cache_wrap $real_name {*}$args"
    (procedure "gdb_do_cache" line 48)
    invoked from within
"gdb_do_cache libc_has_debug_info"
    (procedure "libc_has_debug_info" line 1)
    invoked from within
"libc_has_debug_info"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 $fn"
    (procedure "require" line 11)
    invoked from within
"require {!target_info exists gdb,nosignals} libc_has_debug_info"
    (file "/home/ed/gnu/binutils-build-riscv64/gdb/testsuite/../../../binutils-gdb/gdb/testsuite/gdb.base/relativedebug.exp" line 16)

The problem is that when there's no libc.so in the inferior,
"info sharedlibrary libc.so" responds with an output that doesn't match
any of the patterns provided in libc_has_debug_info so gdb_test_multiple
matches an internal pattern for the GDB prompt and thus the
$libc_has_debug_info variable doesn't get set in the default pattern.

Fix by:

- always defining libc_has_debug_info and message with a default
  value,
- adding a pattern for the case where there's no libc.so in the
  inferior, and
- removing the default pattern, which doesn't serve a purpose anymore.

Also, remove a couple of verbose messages which aren't really useful
because they're redundant with the $message variable.
---
 gdb/testsuite/lib/gdb.exp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 1e26937c0dcf..35e4de9e3b9d 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3726,20 +3726,20 @@ gdb_caching_proc libc_has_debug_info {} {
     gdb_reinitialize_dir $srcdir/$subdir
     gdb_load "$obj"
     runto_main
+    set libc_has_debug_info 0
+    set message "unable to get information on libc.so"
     set test "info sharedlibrary libc.so"
     gdb_test_multiple $test $test {
 	-re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
 	    # Matched the "(*)" in the "Syms Read" columns which means:
 	    # "(*): Shared library is missing debugging information."
-	    verbose -log "$me: libc doesn't have debug info"
 	    set libc_has_debug_info 0
 	    set message "libc doesn't have debug info"
 	}
 	-re ".*Yes\[ \t\]+\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
-	    verbose -log "$me: libc has debug info"
 	    set libc_has_debug_info 1
 	}
-	default {
+	-re -wrap "No shared libraries matched." {
 	    set libc_has_debug_info 0
 	    set message "libc not found in the inferior"
 	}

base-commit: cd0dbe767775fdbfdc875a14f9080fdea0841c92

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-30  2:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26  2:52 [PATCH] gdb/testsuite: Fix libc_has_debug_info when there's no libc Thiago Jung Bauermann
2024-04-26  5:09 ` Bernd Edlinger
2024-04-26 16:37 ` Tom Tromey
2024-04-30  2:07   ` Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).