[gdb/testsuite] Fix gdb.base/branch-to-self.exp on arm-linux

Message ID 20250118080826.24861-1-tdevries@suse.de
State Committed
Headers
Series [gdb/testsuite] Fix gdb.base/branch-to-self.exp on arm-linux |

Checks

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

Commit Message

Tom de Vries Jan. 18, 2025, 8:08 a.m. UTC
  On arm-linux (ubuntu 24.04 with gcc 13.3.0) with target board unix/-marm and
test-case gdb.base/branch-to-self.exp I run into:
...
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, main () at branch-to-self.c:38^M
38        for (;;); /* loop-line */^M
(gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
si^M
0x0040058c      38        for (;;); /* loop-line */^M
(gdb) FAIL: $exp: single-step: si
...

In contrast, on the same machine but with debian testing and gcc 14.2.0 we have:
...
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2, main () at branch-to-self.c:38^M
38        for (;;); /* loop-line */^M
(gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
si^M
^M
Breakpoint 2, main () at branch-to-self.c:38^M
38        for (;;); /* loop-line */^M
(gdb) PASS: $exp: single-step: stepi
...

The difference is in the instruction(s) generated for the loop.

In the passing case, we have:
...
 588:   eafffffe        b       588 <main+0x24>
...
and in the failing case:
...
 588:   e320f000        nop     {0}
 58c:   eafffffd        b       588 <main+0x24>
...

The purpose of this part of test-case is to:
- generate a branch instruction that jumps to itself, and
- set a breakpoint on it, and check that stepi-ing from that breakpoint
  triggers the breakpoint again.

As we can see, in the failing case we failed to generate a branch instruction
that jumps to itself, and consequently we cannot expect to hit the breakpoint
again after issuing a single si.

Fix this by issue stepi until we hit the breakpoint.

Tested on arm-linux.
---
 gdb/testsuite/gdb.base/branch-to-self.exp | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)


base-commit: 26dd9cb647140db87a5a530fd9f044d356e081de
  

Comments

Thiago Jung Bauermann Jan. 21, 2025, 11:32 p.m. UTC | #1
Hello Tom,

Tom de Vries <tdevries@suse.de> writes:

> On arm-linux (ubuntu 24.04 with gcc 13.3.0) with target board unix/-marm and
> test-case gdb.base/branch-to-self.exp I run into:
> ...
> (gdb) continue^M
> Continuing.^M
> ^M
> Breakpoint 2, main () at branch-to-self.c:38^M
> 38        for (;;); /* loop-line */^M
> (gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
> si^M
> 0x0040058c      38        for (;;); /* loop-line */^M
> (gdb) FAIL: $exp: single-step: si
> ...
>
> In contrast, on the same machine but with debian testing and gcc 14.2.0 we have:
> ...
> (gdb) continue^M
> Continuing.^M
> ^M
> Breakpoint 2, main () at branch-to-self.c:38^M
> 38        for (;;); /* loop-line */^M
> (gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
> si^M
> ^M
> Breakpoint 2, main () at branch-to-self.c:38^M
> 38        for (;;); /* loop-line */^M
> (gdb) PASS: $exp: single-step: stepi
> ...
>
> The difference is in the instruction(s) generated for the loop.
>
> In the passing case, we have:
> ...
>  588:   eafffffe        b       588 <main+0x24>
> ...
> and in the failing case:
> ...
>  588:   e320f000        nop     {0}
>  58c:   eafffffd        b       588 <main+0x24>
> ...
>
> The purpose of this part of test-case is to:
> - generate a branch instruction that jumps to itself, and
> - set a breakpoint on it, and check that stepi-ing from that breakpoint
>   triggers the breakpoint again.
>
> As we can see, in the failing case we failed to generate a branch instruction
> that jumps to itself, and consequently we cannot expect to hit the breakpoint
> again after issuing a single si.
>
> Fix this by issue stepi until we hit the breakpoint.
>
> Tested on arm-linux.
> ---
>  gdb/testsuite/gdb.base/branch-to-self.exp | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)

Thank you for fixing the problem!

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>

--
Thiago
  
Tom de Vries Jan. 22, 2025, 9:46 a.m. UTC | #2
On 1/22/25 00:32, Thiago Jung Bauermann wrote:
> Hello Tom,
> 
> Tom de Vries <tdevries@suse.de> writes:
> 
>> On arm-linux (ubuntu 24.04 with gcc 13.3.0) with target board unix/-marm and
>> test-case gdb.base/branch-to-self.exp I run into:
>> ...
>> (gdb) continue^M
>> Continuing.^M
>> ^M
>> Breakpoint 2, main () at branch-to-self.c:38^M
>> 38        for (;;); /* loop-line */^M
>> (gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
>> si^M
>> 0x0040058c      38        for (;;); /* loop-line */^M
>> (gdb) FAIL: $exp: single-step: si
>> ...
>>
>> In contrast, on the same machine but with debian testing and gcc 14.2.0 we have:
>> ...
>> (gdb) continue^M
>> Continuing.^M
>> ^M
>> Breakpoint 2, main () at branch-to-self.c:38^M
>> 38        for (;;); /* loop-line */^M
>> (gdb) PASS: $exp: single-step: continue to breakpoint: hit breakpoint
>> si^M
>> ^M
>> Breakpoint 2, main () at branch-to-self.c:38^M
>> 38        for (;;); /* loop-line */^M
>> (gdb) PASS: $exp: single-step: stepi
>> ...
>>
>> The difference is in the instruction(s) generated for the loop.
>>
>> In the passing case, we have:
>> ...
>>   588:   eafffffe        b       588 <main+0x24>
>> ...
>> and in the failing case:
>> ...
>>   588:   e320f000        nop     {0}
>>   58c:   eafffffd        b       588 <main+0x24>
>> ...
>>
>> The purpose of this part of test-case is to:
>> - generate a branch instruction that jumps to itself, and
>> - set a breakpoint on it, and check that stepi-ing from that breakpoint
>>    triggers the breakpoint again.
>>
>> As we can see, in the failing case we failed to generate a branch instruction
>> that jumps to itself, and consequently we cannot expect to hit the breakpoint
>> again after issuing a single si.
>>
>> Fix this by issue stepi until we hit the breakpoint.
>>
>> Tested on arm-linux.
>> ---
>>   gdb/testsuite/gdb.base/branch-to-self.exp | 17 ++++++++++++++++-
>>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> Thank you for fixing the problem!
> 

Hi Thiago,

thanks for the review.

I've pushed this.

Thanks,
- Tom

> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> 
> --
> Thiago
  

Patch

diff --git a/gdb/testsuite/gdb.base/branch-to-self.exp b/gdb/testsuite/gdb.base/branch-to-self.exp
index 9b4f7467498..71859d71e0d 100644
--- a/gdb/testsuite/gdb.base/branch-to-self.exp
+++ b/gdb/testsuite/gdb.base/branch-to-self.exp
@@ -35,7 +35,22 @@  with_test_prefix "single-step" {
     gdb_test "break ${testfile}.c:${line_num}" "Breakpoint .*" \
 	"set breakpoint"
     gdb_continue_to_breakpoint "hit breakpoint"
-    gdb_test "si" ".*${testfile}.c:${line_num}.*"
+
+    set stepi_count 1
+    gdb_test_multiple "stepi" "" {
+	-re -wrap ".*${testfile}.c:${line_num}.*" {
+	    pass $gdb_test_name
+	}
+	-re -wrap "" {
+	    if { $stepi_count == 10 } {
+		fail $gdb_test_name
+	    } else {
+		incr stepi_count
+		send_gdb "stepi\n"
+		exp_continue
+	    }
+	}
+    }
 }
 
 with_test_prefix "break-cond" {