public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Make gdb.base/solib-search.exp more robust
@ 2024-01-01  7:49 Tom de Vries
  2024-01-08  9:38 ` Tom de Vries
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2024-01-01  7:49 UTC (permalink / raw)
  To: gdb-patches

On aarch64-linux, with gcc 13.2.1, I run into:
...
 (gdb) backtrace^M
 #0  break_here () at solib-search.c:30^M
 #1  0x0000fffff7f20194 in lib2_func4 () at solib-search-lib2.c:50^M
 #2  0x0000fffff7f70194 in lib1_func3 () at solib-search-lib1.c:50^M
 #3  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
 #4  0x0000fffff7f70174 in lib1_func1 () at solib-search-lib1.c:30^M
 #5  0x00000000004101b4 in main () at solib-search.c:23^M
 (gdb) PASS: gdb.base/solib-search.exp: \
   backtrace (with wrong libs) (data collection)
 FAIL: gdb.base/solib-search.exp: backtrace (with wrong libs)
...

The FAIL is generated by this code in the test-case:
...
    if { $expect_fail } {
	# If the backtrace output is correct the test isn't sufficiently
	# testing what it should.
	if { $count == $total_expected } {
	    set fail 1
	}
...

The test-case:
- builds two versions of two shared libs, a "right" and "wrong" version, the
  difference being an additional dummy function (called spacer function),
- uses the "right" version to generate a core file,
- uses the "wrong" version to interpret the core file, and
- generates a backtrace.

The intent is that the backtrace is incorrect due to using the "wrong"
version, but actually it's correct.  This is because the spacer functions
aren't large enough.

Fix this by increasing the size of the spacer functions by adding a dummy
loop, after which we have, as expected, an incorrect backtrace:
...
 (gdb) backtrace^M
 #0  break_here () at solib-search.c:30^M
 #1  0x0000fffff7f201c0 in ?? ()^M
 #2  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
 #3  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
 #4  0x0000fffff7f70174 in lib1_func1 () at solib-search-lib1.c:30^M
 #5  0x00000000004101b4 in main () at solib-search.c:23^M
 (gdb) PASS: gdb.base/solib-search.exp: \
   backtrace (with wrong libs) (data collection)
 PASS: gdb.base/solib-search.exp: backtrace (with wrong libs)
...

Tested on aarch64-linux.
---
 gdb/testsuite/gdb.base/solib-search-lib1.c | 3 +++
 gdb/testsuite/gdb.base/solib-search-lib2.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/gdb/testsuite/gdb.base/solib-search-lib1.c b/gdb/testsuite/gdb.base/solib-search-lib1.c
index 76338a8e216..6a4cc9aa1a7 100644
--- a/gdb/testsuite/gdb.base/solib-search-lib1.c
+++ b/gdb/testsuite/gdb.base/solib-search-lib1.c
@@ -39,6 +39,9 @@ lib1_func1 (void)
 void
 lib1_spacer (void)
 {
+  int i;
+  for (i = 0; i < 10; ++i)
+    ;
 }
 
 #endif
diff --git a/gdb/testsuite/gdb.base/solib-search-lib2.c b/gdb/testsuite/gdb.base/solib-search-lib2.c
index bf7c7bd071c..fb004d7377f 100644
--- a/gdb/testsuite/gdb.base/solib-search-lib2.c
+++ b/gdb/testsuite/gdb.base/solib-search-lib2.c
@@ -39,6 +39,9 @@ lib2_func2 (void)
 void
 lib2_spacer (void)
 {
+  int i;
+  for (i = 0; i < 10; ++i)
+    ;
 }
 
 #endif

base-commit: ee0dbcf99efb17573724f1ede3a12491d7e81d19
-- 
2.35.3


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

* Re: [PATCH] [gdb/testsuite] Make gdb.base/solib-search.exp more robust
  2024-01-01  7:49 [PATCH] [gdb/testsuite] Make gdb.base/solib-search.exp more robust Tom de Vries
@ 2024-01-08  9:38 ` Tom de Vries
  0 siblings, 0 replies; 2+ messages in thread
From: Tom de Vries @ 2024-01-08  9:38 UTC (permalink / raw)
  To: gdb-patches

On 1/1/24 08:49, Tom de Vries wrote:
> On aarch64-linux, with gcc 13.2.1, I run into:
> ...
>   (gdb) backtrace^M
>   #0  break_here () at solib-search.c:30^M
>   #1  0x0000fffff7f20194 in lib2_func4 () at solib-search-lib2.c:50^M
>   #2  0x0000fffff7f70194 in lib1_func3 () at solib-search-lib1.c:50^M
>   #3  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
>   #4  0x0000fffff7f70174 in lib1_func1 () at solib-search-lib1.c:30^M
>   #5  0x00000000004101b4 in main () at solib-search.c:23^M
>   (gdb) PASS: gdb.base/solib-search.exp: \
>     backtrace (with wrong libs) (data collection)
>   FAIL: gdb.base/solib-search.exp: backtrace (with wrong libs)
> ...
> 
> The FAIL is generated by this code in the test-case:
> ...
>      if { $expect_fail } {
> 	# If the backtrace output is correct the test isn't sufficiently
> 	# testing what it should.
> 	if { $count == $total_expected } {
> 	    set fail 1
> 	}
> ...
> 
> The test-case:
> - builds two versions of two shared libs, a "right" and "wrong" version, the
>    difference being an additional dummy function (called spacer function),
> - uses the "right" version to generate a core file,
> - uses the "wrong" version to interpret the core file, and
> - generates a backtrace.
> 
> The intent is that the backtrace is incorrect due to using the "wrong"
> version, but actually it's correct.  This is because the spacer functions
> aren't large enough.
> 
> Fix this by increasing the size of the spacer functions by adding a dummy
> loop, after which we have, as expected, an incorrect backtrace:
> ...
>   (gdb) backtrace^M
>   #0  break_here () at solib-search.c:30^M
>   #1  0x0000fffff7f201c0 in ?? ()^M
>   #2  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
>   #3  0x0000fffff7f20174 in lib2_func2 () at solib-search-lib2.c:30^M
>   #4  0x0000fffff7f70174 in lib1_func1 () at solib-search-lib1.c:30^M
>   #5  0x00000000004101b4 in main () at solib-search.c:23^M
>   (gdb) PASS: gdb.base/solib-search.exp: \
>     backtrace (with wrong libs) (data collection)
>   PASS: gdb.base/solib-search.exp: backtrace (with wrong libs)
> ...
> 

Pushed.

Thanks,
- Tom

> Tested on aarch64-linux.
> ---
>   gdb/testsuite/gdb.base/solib-search-lib1.c | 3 +++
>   gdb/testsuite/gdb.base/solib-search-lib2.c | 3 +++
>   2 files changed, 6 insertions(+)
> 
> diff --git a/gdb/testsuite/gdb.base/solib-search-lib1.c b/gdb/testsuite/gdb.base/solib-search-lib1.c
> index 76338a8e216..6a4cc9aa1a7 100644
> --- a/gdb/testsuite/gdb.base/solib-search-lib1.c
> +++ b/gdb/testsuite/gdb.base/solib-search-lib1.c
> @@ -39,6 +39,9 @@ lib1_func1 (void)
>   void
>   lib1_spacer (void)
>   {
> +  int i;
> +  for (i = 0; i < 10; ++i)
> +    ;
>   }
>   
>   #endif
> diff --git a/gdb/testsuite/gdb.base/solib-search-lib2.c b/gdb/testsuite/gdb.base/solib-search-lib2.c
> index bf7c7bd071c..fb004d7377f 100644
> --- a/gdb/testsuite/gdb.base/solib-search-lib2.c
> +++ b/gdb/testsuite/gdb.base/solib-search-lib2.c
> @@ -39,6 +39,9 @@ lib2_func2 (void)
>   void
>   lib2_spacer (void)
>   {
> +  int i;
> +  for (i = 0; i < 10; ++i)
> +    ;
>   }
>   
>   #endif
> 
> base-commit: ee0dbcf99efb17573724f1ede3a12491d7e81d19


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

end of thread, other threads:[~2024-01-08  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-01  7:49 [PATCH] [gdb/testsuite] Make gdb.base/solib-search.exp more robust Tom de Vries
2024-01-08  9:38 ` Tom de Vries

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).