[3/3,gdb/testsuite] Fix ctf test-cases on openSUSE Tumbleweed

Message ID 20220922152042.21914-3-tdevries@suse.de
State Committed
Headers
Series [1/3,gdb/symtab] Factor out elf_symfile_read_dwarf2 |

Commit Message

Tom de Vries Sept. 22, 2022, 3:20 p.m. UTC
  When running test-case gdb.base/ctf-constvars.exp on openSUSE Tumbleweed (with
system gcc version 12, providing gcc -gctf support, enabling the ctf test-cases
in the gdb testsuite), I run into:
...
(gdb) print vox^M
'vox' has unknown type; cast it to its declared type^M
(gdb) FAIL: gdb.base/ctf-constvars.exp: print vox
...

There are two causes for this:
- the linker flags are missing --ctf-variables, so the information for variable
  vox is missing (reported in PR29468), and
- the executable contains some dwarf2 due to some linked-in glibc objects,
  so the ctf info is ignored (reported in PR29160).

By using:
- maint set symbol-read-order ctf, and
- -Wl,--ctf-variable,
we can make the test-case and some similar test-cases pass.

The expection is gdb.ctf/funcreturn.exp, which is still failing because the
exec is also missing the function info.  A PR ld/29594 is open about that, so
add an xfail.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29160
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29468
---
 gdb/testsuite/gdb.base/ctf-constvars.exp  | 14 ++++++++++----
 gdb/testsuite/gdb.base/ctf-ptype.exp      | 15 ++++++++++-----
 gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp | 16 +++++++++++-----
 gdb/testsuite/gdb.ctf/funcreturn.exp      | 22 ++++++++++++++++------
 gdb/testsuite/gdb.ctf/multi.exp           | 15 ++++++++++-----
 5 files changed, 57 insertions(+), 25 deletions(-)
  

Comments

Tom de Vries Oct. 12, 2022, 3:11 p.m. UTC | #1
On 9/22/22 17:20, Tom de Vries via Gdb-patches wrote:
> When running test-case gdb.base/ctf-constvars.exp on openSUSE Tumbleweed (with
> system gcc version 12, providing gcc -gctf support, enabling the ctf test-cases
> in the gdb testsuite), I run into:
> ...
> (gdb) print vox^M
> 'vox' has unknown type; cast it to its declared type^M
> (gdb) FAIL: gdb.base/ctf-constvars.exp: print vox
> ...
> 
> There are two causes for this:
> - the linker flags are missing --ctf-variables, so the information for variable
>    vox is missing (reported in PR29468), and
> - the executable contains some dwarf2 due to some linked-in glibc objects,
>    so the ctf info is ignored (reported in PR29160).
> 
> By using:
> - maint set symbol-read-order ctf, and
> - -Wl,--ctf-variable,
> we can make the test-case and some similar test-cases pass.
> 

I ended up committing 908a926ec4e ("[gdb/testsuite] Fix ctf test-cases 
on openSUSE Tumbleweed"), which uses -Wl,--strip-debug instead of "maint 
set symbol-read-order ctf".

> The expection is gdb.ctf/funcreturn.exp, which is still failing because the
> exec is also missing the function info.  A PR ld/29594 is open about that, so
> add an xfail.
> 

That test-case is now passing, so that xfail is not committed.

Thanks,
- Tom

> Tested on x86_64-linux.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29160
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29468
> ---
>   gdb/testsuite/gdb.base/ctf-constvars.exp  | 14 ++++++++++----
>   gdb/testsuite/gdb.base/ctf-ptype.exp      | 15 ++++++++++-----
>   gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp | 16 +++++++++++-----
>   gdb/testsuite/gdb.ctf/funcreturn.exp      | 22 ++++++++++++++++------
>   gdb/testsuite/gdb.ctf/multi.exp           | 15 ++++++++++-----
>   5 files changed, 57 insertions(+), 25 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/ctf-constvars.exp b/gdb/testsuite/gdb.base/ctf-constvars.exp
> index 6255e9ed02b..f8d78acfcb5 100644
> --- a/gdb/testsuite/gdb.base/ctf-constvars.exp
> +++ b/gdb/testsuite/gdb.base/ctf-constvars.exp
> @@ -32,10 +32,16 @@ if [skip_ctf_tests] {
>   standard_testfile .c
>   
>   # Using `-gctf` generates full-fledged CTF debug information.
> -set opts "additional_flags=-gctf"
> -if { [prepare_for_testing "failed to prepare" ${testfile} \
> -	  [list $srcfile] [list $opts nowarnings]] } {
> -    return 0
> +set opts {}
> +lappend opts "additional_flags=-gctf"
> +lappend opts "additional_flags=-Wl,-ctf-variables"
> +lappend opts "nowarnings"
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
> +    if { [prepare_for_testing "failed to prepare" ${testfile} \
> +	      [list $srcfile] $opts] } {
> +	return 0
> +    }
>   }
>   
>   #
> diff --git a/gdb/testsuite/gdb.base/ctf-ptype.exp b/gdb/testsuite/gdb.base/ctf-ptype.exp
> index 48d39e56c7b..e9c5bce15c2 100644
> --- a/gdb/testsuite/gdb.base/ctf-ptype.exp
> +++ b/gdb/testsuite/gdb.base/ctf-ptype.exp
> @@ -26,11 +26,16 @@ set gcc_compiled [is_c_compiler_gcc]
>   standard_testfile .c
>   
>   # Using `-gctf` generates full-fledged CTF debug information.
> -set opts "additional_flags=-gctf"
> -
> -if { [prepare_for_testing "failed to prepare" ${testfile} \
> -	  [list $srcfile] [list $opts nowarnings]] } {
> -    return 0
> +set opts {}
> +lappend opts "additional_flags=-gctf"
> +lappend opts "additional_flags=-Wl,-ctf-variables"
> +lappend opts "nowarnings"
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
> +    if { [prepare_for_testing "failed to prepare" ${testfile} \
> +	      [list $srcfile] $opts] } {
> +	return 0
> +    }
>   }
>   
>   # Test ptype of unnamed enumeration members before any action causes
> diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
> index a43e36bbe68..d573e7d63ab 100644
> --- a/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
> +++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
> @@ -24,11 +24,17 @@ standard_testfile cross-tu-cyclic-1.c  cross-tu-cyclic-2.c \
>   	cross-tu-cyclic-3.c  cross-tu-cyclic-4.c
>   
>   # Using `-gctf` generates full-fledged CTF debug information.
> -set opts "additional_flags=-gctf -Wl,--export-dynamic"
> -if { [prepare_for_testing "failed to prepare" ${testfile} \
> -	  [list $srcfile $srcfile2 $srcfile3 $srcfile4] \
> -	  [list $opts nowarnings]] } {
> -    return 0
> +set opts {}
> +lappend opts "additional_flags=-gctf"
> +lappend opts "additional_flags=-Wl,--export-dynamic"
> +lappend opts "nowarnings"
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
> +    if { [prepare_for_testing "failed to prepare" ${testfile} \
> +	      [list $srcfile $srcfile2 $srcfile3 $srcfile4] \
> +	      $opts] } {
> +	return 0
> +    }
>   }
>   
>   # Same thing with struct and union.
> diff --git a/gdb/testsuite/gdb.ctf/funcreturn.exp b/gdb/testsuite/gdb.ctf/funcreturn.exp
> index ea01e860a84..ece2d013c07 100644
> --- a/gdb/testsuite/gdb.ctf/funcreturn.exp
> +++ b/gdb/testsuite/gdb.ctf/funcreturn.exp
> @@ -30,18 +30,28 @@ set gcc_compiled [is_c_compiler_gcc]
>   standard_testfile whatis.c
>   
>   # Using `-gctf` generates full-fledged CTF debug information.
> -set opts "additional_flags=-gctf -Wl,--export-dynamic"
> -
> +set opts {}
> +lappend opts "additional_flags=-gctf"
> +lappend opts "additional_flags=-Wl,--export-dynamic"
> +lappend opts "additional_flags=-Wl,-ctf-variables"
> +lappend opts "nowarnings"
>   if { [prepare_for_testing "failed to prepare" ${testfile} \
> -	  [list $srcfile] [list $opts nowarnings]] } {
> +	  [list $srcfile] $opts] } {
>       return 0
>   }
>   
>   # test print command with functions return type
>   set void "(void|)"
> -gdb_test "print v_char_func" \
> -    "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" \
> -    "print char function"
> +gdb_test_multiple "print v_char_func" "print char function" {
> +    -re -wrap "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" {
> +	pass $gdb_test_name
> +    }
> +    -re -wrap "$decimal = {<text variable, no debug info>} $hex <v_char_func>" {
> +	# The ld linker drops functions, see PR ld/29594.
> +	xfail $gdb_test_name
> +	return 0
> +    }
> +}
>   
>   gdb_test "print v_signed_char_func" \
>       "$decimal = \{signed char \\(\\)\} 0x\[0-9a-z\]+ <v_signed_char_func>.*" \
> diff --git a/gdb/testsuite/gdb.ctf/multi.exp b/gdb/testsuite/gdb.ctf/multi.exp
> index 07fd10a884c..ef37507d92b 100644
> --- a/gdb/testsuite/gdb.ctf/multi.exp
> +++ b/gdb/testsuite/gdb.ctf/multi.exp
> @@ -23,11 +23,16 @@ if [skip_ctf_tests] {
>   standard_testfile ctf-a.c ctf-b.c ctf-c.c
>   
>   # Using `-gctf` generates full-fledged CTF debug information.
> -set opts "additional_flags=-gctf -Wl,--export-dynamic"
> -if { [prepare_for_testing "failed to prepare" ${testfile} \
> -	  [list $srcfile $srcfile2 $srcfile3] \
> -	  [list $opts nowarnings]] } {
> -    return 0
> +set opts {}
> +lappend opts "additional_flags=-gctf"
> +lappend opts "additional_flags=-Wl,--export-dynamic"
> +lappend opts "nowarnings"
> +save_vars { GDBFLAGS } {
> +    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
> +    if { [prepare_for_testing "failed to prepare" ${testfile} \
> +	      [list $srcfile $srcfile2 $srcfile3] $opts] } {
> +	return 0
> +    }
>   }
>   
>   # Same thing with struct and union.
  

Patch

diff --git a/gdb/testsuite/gdb.base/ctf-constvars.exp b/gdb/testsuite/gdb.base/ctf-constvars.exp
index 6255e9ed02b..f8d78acfcb5 100644
--- a/gdb/testsuite/gdb.base/ctf-constvars.exp
+++ b/gdb/testsuite/gdb.base/ctf-constvars.exp
@@ -32,10 +32,16 @@  if [skip_ctf_tests] {
 standard_testfile .c
 
 # Using `-gctf` generates full-fledged CTF debug information.
-set opts "additional_flags=-gctf"
-if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list $srcfile] [list $opts nowarnings]] } {
-    return 0
+set opts {}
+lappend opts "additional_flags=-gctf"
+lappend opts "additional_flags=-Wl,-ctf-variables"
+lappend opts "nowarnings"
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
+    if { [prepare_for_testing "failed to prepare" ${testfile} \
+	      [list $srcfile] $opts] } {
+	return 0
+    }
 }
 
 #
diff --git a/gdb/testsuite/gdb.base/ctf-ptype.exp b/gdb/testsuite/gdb.base/ctf-ptype.exp
index 48d39e56c7b..e9c5bce15c2 100644
--- a/gdb/testsuite/gdb.base/ctf-ptype.exp
+++ b/gdb/testsuite/gdb.base/ctf-ptype.exp
@@ -26,11 +26,16 @@  set gcc_compiled [is_c_compiler_gcc]
 standard_testfile .c
 
 # Using `-gctf` generates full-fledged CTF debug information.
-set opts "additional_flags=-gctf"
-
-if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list $srcfile] [list $opts nowarnings]] } {
-    return 0
+set opts {}
+lappend opts "additional_flags=-gctf"
+lappend opts "additional_flags=-Wl,-ctf-variables"
+lappend opts "nowarnings"
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
+    if { [prepare_for_testing "failed to prepare" ${testfile} \
+	      [list $srcfile] $opts] } {
+	return 0
+    }
 }
 
 # Test ptype of unnamed enumeration members before any action causes
diff --git a/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
index a43e36bbe68..d573e7d63ab 100644
--- a/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
+++ b/gdb/testsuite/gdb.ctf/cross-tu-cyclic.exp
@@ -24,11 +24,17 @@  standard_testfile cross-tu-cyclic-1.c  cross-tu-cyclic-2.c \
 	cross-tu-cyclic-3.c  cross-tu-cyclic-4.c
 
 # Using `-gctf` generates full-fledged CTF debug information.
-set opts "additional_flags=-gctf -Wl,--export-dynamic"
-if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list $srcfile $srcfile2 $srcfile3 $srcfile4] \
-	  [list $opts nowarnings]] } {
-    return 0
+set opts {}
+lappend opts "additional_flags=-gctf"
+lappend opts "additional_flags=-Wl,--export-dynamic"
+lappend opts "nowarnings"
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
+    if { [prepare_for_testing "failed to prepare" ${testfile} \
+	      [list $srcfile $srcfile2 $srcfile3 $srcfile4] \
+	      $opts] } {
+	return 0
+    }
 }
 
 # Same thing with struct and union.
diff --git a/gdb/testsuite/gdb.ctf/funcreturn.exp b/gdb/testsuite/gdb.ctf/funcreturn.exp
index ea01e860a84..ece2d013c07 100644
--- a/gdb/testsuite/gdb.ctf/funcreturn.exp
+++ b/gdb/testsuite/gdb.ctf/funcreturn.exp
@@ -30,18 +30,28 @@  set gcc_compiled [is_c_compiler_gcc]
 standard_testfile whatis.c
 
 # Using `-gctf` generates full-fledged CTF debug information.
-set opts "additional_flags=-gctf -Wl,--export-dynamic"
-
+set opts {}
+lappend opts "additional_flags=-gctf"
+lappend opts "additional_flags=-Wl,--export-dynamic"
+lappend opts "additional_flags=-Wl,-ctf-variables"
+lappend opts "nowarnings"
 if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list $srcfile] [list $opts nowarnings]] } {
+	  [list $srcfile] $opts] } {
     return 0
 }
 
 # test print command with functions return type
 set void "(void|)"
-gdb_test "print v_char_func" \
-    "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" \
-    "print char function"
+gdb_test_multiple "print v_char_func" "print char function" {
+    -re -wrap "$decimal = \{char \\(\\)\} 0x\[0-9a-z\]+ <v_char_func>.*" {
+	pass $gdb_test_name
+    }
+    -re -wrap "$decimal = {<text variable, no debug info>} $hex <v_char_func>" {
+	# The ld linker drops functions, see PR ld/29594.
+	xfail $gdb_test_name
+	return 0
+    }
+}
 
 gdb_test "print v_signed_char_func" \
     "$decimal = \{signed char \\(\\)\} 0x\[0-9a-z\]+ <v_signed_char_func>.*" \
diff --git a/gdb/testsuite/gdb.ctf/multi.exp b/gdb/testsuite/gdb.ctf/multi.exp
index 07fd10a884c..ef37507d92b 100644
--- a/gdb/testsuite/gdb.ctf/multi.exp
+++ b/gdb/testsuite/gdb.ctf/multi.exp
@@ -23,11 +23,16 @@  if [skip_ctf_tests] {
 standard_testfile ctf-a.c ctf-b.c ctf-c.c
 
 # Using `-gctf` generates full-fledged CTF debug information.
-set opts "additional_flags=-gctf -Wl,--export-dynamic"
-if { [prepare_for_testing "failed to prepare" ${testfile} \
-	  [list $srcfile $srcfile2 $srcfile3] \
-	  [list $opts nowarnings]] } {
-    return 0
+set opts {}
+lappend opts "additional_flags=-gctf"
+lappend opts "additional_flags=-Wl,--export-dynamic"
+lappend opts "nowarnings"
+save_vars { GDBFLAGS } {
+    append GDBFLAGS " -iex \"maint set symbol-read-order ctf\""
+    if { [prepare_for_testing "failed to prepare" ${testfile} \
+	      [list $srcfile $srcfile2 $srcfile3] $opts] } {
+	return 0
+    }
 }
 
 # Same thing with struct and union.