diff mbox series

[1/2] gdb/testsuite: Add libc_has_debug_info require helper

Message ID 20240420213307.976401-2-thiago.bauermann@linaro.org
State Superseded
Headers show
Series Add testcase for libc memory operations | expand

Commit Message

Thiago Jung Bauermann April 20, 2024, 9:33 p.m. UTC
Factor the test for libc debug info out of gdb.base/relativedebug.exp to
a new procedure.

Also, change the "info sharedlibrary" test to explicitly detect when
libc has debug info.
---
 gdb/testsuite/gdb.base/relativedebug.exp | 13 +-----
 gdb/testsuite/lib/gdb.exp                | 54 ++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 12 deletions(-)

Comments

Kevin Buettner April 21, 2024, 8:44 p.m. UTC | #1
On Sat, 20 Apr 2024 18:33:06 -0300
Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:

> Factor the test for libc debug info out of gdb.base/relativedebug.exp to
> a new procedure.
> 
> Also, change the "info sharedlibrary" test to explicitly detect when
> libc has debug info.

LGTM.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Kevin Buettner April 21, 2024, 9:02 p.m. UTC | #2
On Sun, 21 Apr 2024 13:44:06 -0700
Kevin Buettner <kevinb@redhat.com> wrote:

> On Sat, 20 Apr 2024 18:33:06 -0300
> Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:
> 
> > Factor the test for libc debug info out of gdb.base/relativedebug.exp to
> > a new procedure.
> > 
> > Also, change the "info sharedlibrary" test to explicitly detect when
> > libc has debug info.  
> 
> LGTM.
> 
> Approved-by: Kevin Buettner <kevinb@redhat.com>

Just found a problem...  While attempting to test part 2 using clang:

make check RUNTESTFLAGS="CC_FOR_TARGET=clang" TESTS="gdb.base/memops-watchpoint.exp"

Then, in the log file:

get_compiler_info: clang-17-0-6
Executing on host: clang  /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c   -fdiagnostics-color=never -Wno-unknown-warning-option -w -g -g  -lm  -o /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.x    (timeout = 300)
builtin_spawn -ignore SIGHUP clang /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c -fdiagnostics-color=never -Wno-unknown-warning-option -w -g -g -lm -o /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.x
/mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c:3:6: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    3 |             printf ("Hello, world!\n");
      |             ^
/mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c:3:6: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
1 error generated.
compiler exited with status 1
UNSUPPORTED: gdb.base/memops-watchpoint.exp: require failed: libc_has_debug_info (failed to compile test program)

My testing shows that things will work if you add the suggested #include to
the "set src" text.

Kevin
Thiago Jung Bauermann April 22, 2024, 12:05 a.m. UTC | #3
Hello Kevin,

Thank you for your review! Sorry for sending v2 without addressing your
comments. I only saw your emails after I sent the series.

Kevin Buettner <kevinb@redhat.com> writes:

> On Sun, 21 Apr 2024 13:44:06 -0700
> Kevin Buettner <kevinb@redhat.com> wrote:
>
>> On Sat, 20 Apr 2024 18:33:06 -0300
>> Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:
>>
>> > Factor the test for libc debug info out of gdb.base/relativedebug.exp to
>> > a new procedure.
>> >
>> > Also, change the "info sharedlibrary" test to explicitly detect when
>> > libc has debug info.
>>
>> LGTM.
>>
>> Approved-by: Kevin Buettner <kevinb@redhat.com>
>
> Just found a problem...  While attempting to test part 2 using clang:
>
> make check RUNTESTFLAGS="CC_FOR_TARGET=clang" TESTS="gdb.base/memops-watchpoint.exp"
>
> Then, in the log file:
>
> get_compiler_info: clang-17-0-6
> Executing on host: clang  /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c   -fdiagnostics-color=never -Wno-unknown-warning-option -w -g -g  -lm  -o /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.x    (timeout = 300)
> builtin_spawn -ignore SIGHUP clang /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c -fdiagnostics-color=never -Wno-unknown-warning-option -w -g -g -lm -o /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.x
> /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c:3:6: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
>     3 |             printf ("Hello, world!\n");
>       |             ^
> /mesquite2/sourceware-git/f39-review/bld/gdb/testsuite/temp/164548/libc_has_debug_info.c:3:6: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
> 1 error generated.
> compiler exited with status 1
> UNSUPPORTED: gdb.base/memops-watchpoint.exp: require failed: libc_has_debug_info (failed to compile test program)
>
> My testing shows that things will work if you add the suggested #include to
> the "set src" text.

Ah, of course. GCC doesn't complain about it because of the -w option:

       -w  Inhibit all warning messages.

and in GCC this is a warning not an error.

I'll fix it in the next version.

--
Thiago
diff mbox series

Patch

diff --git a/gdb/testsuite/gdb.base/relativedebug.exp b/gdb/testsuite/gdb.base/relativedebug.exp
index bf8d76887122..f882a5cf1676 100644
--- a/gdb/testsuite/gdb.base/relativedebug.exp
+++ b/gdb/testsuite/gdb.base/relativedebug.exp
@@ -13,7 +13,7 @@ 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-require {!target_info exists gdb,nosignals}
+require {!target_info exists gdb,nosignals} libc_has_debug_info
 
 standard_testfile .c
 
@@ -28,17 +28,6 @@  clean_restart ${binfile}
 
 runto_main
 
-set test "info sharedlibrary"
-gdb_test_multiple $test $test {
-    -re ".*\(\\*\)\[^\r\n\]*/libc\.so.*$gdb_prompt $" {
-	# Skip the test below if libc doesn't have debug info.
-	unsupported "libc doesn't have debug info"
-	return -1
-    }
-    -re ".*$gdb_prompt $" {
-    }
-}
-
 # pause () -> SIGALRM -> handler () -> abort ()
 gdb_test "continue" "Program received signal SIGABRT.*"
 
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index ddee928d5104..9af73bef8f09 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3699,6 +3699,60 @@  proc support_displaced_stepping {} {
     return 0
 }
 
+# Return 1 if GDB can find the libc debug info, or 0 and a reason string if it
+# can't.  This procedure is meant to be called by the require procedure.
+gdb_caching_proc libc_has_debug_info {} {
+    global srcdir subdir gdb_prompt inferior_exited_re
+
+    set me "libc_has_debug_info"
+
+    # Compile a test program.
+    set src {
+	int main (void) {
+	    printf ("Hello, world!\n");
+	    return 0;
+	}
+    }
+    if {![gdb_simple_compile $me $src executable {debug}]} {
+	return [list 0 "failed to compile test program"]
+    }
+
+    # No error message, compilation succeeded so now run it via gdb.
+
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+    gdb_load "$obj"
+    runto_main
+    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 {
+	    set libc_has_debug_info 0
+	    set message "libc not found in the inferior"
+	}
+    }
+    gdb_exit
+    remote_file build delete $obj
+
+    verbose "$me: returning $libc_has_debug_info" 2
+    if { $libc_has_debug_info } {
+	return $libc_has_debug_info
+    } else {
+	return [list $libc_has_debug_info $message]
+    }
+}
+
 # Run a test on the target to see if it supports vmx hardware.  Return 1 if so, 
 # 0 if it does not.  Based on 'check_vmx_hw_available' from the GCC testsuite.