[gdb/testsuite] Fix gdb.base/eh_return.exp

Message ID 20240125110720.21486-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Fix gdb.base/eh_return.exp |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom de Vries Jan. 25, 2024, 11:07 a.m. UTC
  On Fedora rawhide aarch64, I run into:
...
(gdb) PASS: gdb.base/eh_return.exp: set breakpoint on address
run ^M
Starting program: eh_return ^M
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
[Inferior 1 (process 1113051) exited normally]^M
(gdb) FAIL: gdb.base/eh_return.exp: hit breakpoint (the program exited)
...

This happens as follows: the test-case sets a breakpoint on the last
instruction of function eh2:
...
(gdb) break *0x00000000004103ec^M
...
and expects to hit the breakpoint, but instead the "br x6" is taken:
...
   0x00000000004103e0 <+176>:   cbz     x4, 0x4103ec <eh2+188>^M
   0x00000000004103e4 <+180>:   add     sp, sp, x5^M
   0x00000000004103e8 <+184>:   br      x6^M
   0x00000000004103ec <+188>:   ret^M
...

In contrast, with fedora f39 we have:
...
   0x00000000004103bc <+156>:   ldp     x2, x3, [sp, #48]^M
   0x00000000004103c0 <+160>:   ldp     x29, x30, [sp, #16]^M
   0x00000000004103c4 <+164>:   add     sp, sp, #0x50^M
   0x00000000004103c8 <+168>:   add     sp, sp, x4^M
   0x00000000004103cc <+172>:   ret^M

...
and the breakpoint is reached.

Fix this by detecting that the breakpoint is not hit, and declaring the test
unsupported.

Tested on aarch64-linux.

PR testsuite/31291
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31291
---
 gdb/testsuite/gdb.base/eh_return.exp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)


base-commit: 726f209eb1b05842d816eac8b0b8f9c7f6cd9fbc
  

Comments

Tom Tromey Jan. 25, 2024, 2:50 p.m. UTC | #1
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> +gdb_expect {
Tom> +    -re "Breakpoint .*\r\n$gdb_prompt $" {
Tom> +	pass $test
Tom> +    }
Tom> +    -re "$inferior_exited_re normally.*\r\n$gdb_prompt $" {
Tom> +	unsupported $test
Tom> +    }
Tom> +    -re "\r\n$gdb_prompt $" {

I don't really know, but should these use -wrap instead of manually
matching the prompt regexp?

Tom
  
Tom de Vries Jan. 25, 2024, 2:53 p.m. UTC | #2
On 1/25/24 15:50, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> +gdb_expect {
> Tom> +    -re "Breakpoint .*\r\n$gdb_prompt $" {
> Tom> +	pass $test
> Tom> +    }
> Tom> +    -re "$inferior_exited_re normally.*\r\n$gdb_prompt $" {
> Tom> +	unsupported $test
> Tom> +    }
> Tom> +    -re "\r\n$gdb_prompt $" {
> 
> I don't really know, but should these use -wrap instead of manually
> matching the prompt regexp?

-wrap is implemented in gdb_test_multiple, this uses gdb_expect because 
otherwise the builtin handling of inferior_exited_re triggers.

Thanks,
- Tom
  
Tom Tromey Jan. 25, 2024, 2:54 p.m. UTC | #3
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:

Tom> On 1/25/24 15:50, Tom Tromey wrote:
>>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> +gdb_expect {
Tom> +    -re "Breakpoint .*\r\n$gdb_prompt $" {
Tom> +	pass $test
Tom> +    }
Tom> +    -re "$inferior_exited_re normally.*\r\n$gdb_prompt $" {
Tom> +	unsupported $test
Tom> +    }
Tom> +    -re "\r\n$gdb_prompt $" {
>> I don't really know, but should these use -wrap instead of manually
>> matching the prompt regexp?

Tom> -wrap is implemented in gdb_test_multiple, this uses gdb_expect
Tom>  because otherwise the builtin handling of inferior_exited_re
Tom> triggers.

Oh oops.  Thanks.

I guess you could use -early maybe?  But TBH I think this is ok.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  
Tom de Vries Jan. 25, 2024, 3:27 p.m. UTC | #4
On 1/25/24 15:54, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> 
> Tom> On 1/25/24 15:50, Tom Tromey wrote:
>>>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
> Tom> +gdb_expect {
> Tom> +    -re "Breakpoint .*\r\n$gdb_prompt $" {
> Tom> +	pass $test
> Tom> +    }
> Tom> +    -re "$inferior_exited_re normally.*\r\n$gdb_prompt $" {
> Tom> +	unsupported $test
> Tom> +    }
> Tom> +    -re "\r\n$gdb_prompt $" {
>>> I don't really know, but should these use -wrap instead of manually
>>> matching the prompt regexp?
> 
> Tom> -wrap is implemented in gdb_test_multiple, this uses gdb_expect
> Tom>  because otherwise the builtin handling of inferior_exited_re
> Tom> triggers.
> 
> Oh oops.  Thanks.
> 
> I guess you could use -early maybe?  But TBH I think this is ok.

Yeah, I tried that but I didn't manage to make that work.

I considered debugging that, but decided I didn't have the time, so I 
went with this instead.

Thanks for the review, committed.

- Tom

> Approved-By: Tom Tromey <tom@tromey.com>
> 
> Tom
  

Patch

diff --git a/gdb/testsuite/gdb.base/eh_return.exp b/gdb/testsuite/gdb.base/eh_return.exp
index b055058066b..9fefc890b28 100644
--- a/gdb/testsuite/gdb.base/eh_return.exp
+++ b/gdb/testsuite/gdb.base/eh_return.exp
@@ -79,4 +79,18 @@  gdb_assert [gdb_breakpoint "*$address" no-message] "set breakpoint on address"
 # breakpoint, so instead, run to the breakpoint.
 gdb_run_cmd
 
-gdb_test "" "Breakpoint .*" "hit breakpoint"
+set test "hit breakpoint"
+gdb_expect {
+    -re "Breakpoint .*\r\n$gdb_prompt $" {
+	pass $test
+    }
+    -re "$inferior_exited_re normally.*\r\n$gdb_prompt $" {
+	unsupported $test
+    }
+    -re "\r\n$gdb_prompt $" {
+	fail $test
+    }
+    default {
+	fail $test
+    }
+}