gdb.base/watchpoint-unaligned.exp: Fix TCL error.

Message ID 20230412210846.127441-1-ahajkova@redhat.com
State New
Headers
Series gdb.base/watchpoint-unaligned.exp: Fix TCL error. |

Commit Message

Alexandra Petlanova Hajkova April 12, 2023, 9:08 p.m. UTC
  From: Alexandra Hajkova <ahajkova@redhat.com>

When running this test on aarch64 I've got TCL error:
ERROR:  can't read "wpoffset_to_wpnum(1)": no such element in array
ERROR:  tcl error code TCL READ VARNAME
ERROR:  tcl error info:
can't read "wpoffset_to_wpnum(1)": no such element in array ...

This patch adds checks whether the wpoffset_to_wpnum array member
exists to avoid the error.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30340
---
 .../gdb.base/watchpoint-unaligned.exp         | 38 ++++++++++---------
 1 file changed, 21 insertions(+), 17 deletions(-)
  

Comments

Luis Machado April 13, 2023, 1:55 p.m. UTC | #1
On 4/12/23 22:08, Alexandra Hájková via Gdb-patches wrote:
> From: Alexandra Hajkova <ahajkova@redhat.com>
> 
> When running this test on aarch64 I've got TCL error:
> ERROR:  can't read "wpoffset_to_wpnum(1)": no such element in array
> ERROR:  tcl error code TCL READ VARNAME
> ERROR:  tcl error info:
> can't read "wpoffset_to_wpnum(1)": no such element in array ...
> 
> This patch adds checks whether the wpoffset_to_wpnum array member
> exists to avoid the error.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30340
> ---
>   .../gdb.base/watchpoint-unaligned.exp         | 38 ++++++++++---------
>   1 file changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
> index ce5a1e5bf66..d470368a6e3 100644
> --- a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
> +++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
> @@ -121,27 +121,31 @@ foreach wpcount {4 7} {
>       gdb_test_no_output -nopass "set variable offset = 1"
>       set test "continue"
>       set got_hit 0
> -    gdb_test_multiple $test $test {
> -	-re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
> -	}
> -	-re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
> -	    set got_hit 1
> -	    send_gdb "continue\n"
> -	    exp_continue
> -	}
> -	-re " start_again .*\r\n$gdb_prompt $" {
> -	}
> +    if {[info exists wpoffset_to_wpnum(1)]} {
> +	    gdb_test_multiple $test $test {
> +		    -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
> +		    }
> +		    -re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
> +			    set got_hit 1
> +			    send_gdb "continue\n"
> +			    exp_continue
> +		    }
> +		    -re " start_again .*\r\n$gdb_prompt $" {
> +		    }
> +	    }
>       }
>       for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
> -	if {$wpoffset_to_wpnum($wpoffset)} {
> -	    gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
> -	}
> +	    if {[info exists wpoffset_to_wpnum($wpoffset)] &&
> +		    $wpoffset_to_wpnum($wpoffset)} {
> +		    gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
> +	    }
>       }
>       set test "wpcount($wpcount)"
> -    if {!$wpoffset_to_wpnum([expr $wpcount - 1])} {
> -	untested $test
> -	continue
> -    }
> +    if {[info exists wpoffset_to_wpnum([expr $wpcount - 1])] &&
> +	    !$wpoffset_to_wpnum([expr $wpcount - 1])} {
> +		    untested $test
> +		    continue
> +	    }
>       if {$wpcount > 4} {
>   	if {![istarget "s390*-*-*"]} {
>   	    setup_kfail tdep/22389 *-*-*

As I commented on the bug ticket, I think a better approach is to check for errors and then bail out of the test if one is found.

If we can't insert watchpoints, it is probably not worth continuing to run checks. We will end up with a pile of failures.
  

Patch

diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
index ce5a1e5bf66..d470368a6e3 100644
--- a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
+++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
@@ -121,27 +121,31 @@  foreach wpcount {4 7} {
     gdb_test_no_output -nopass "set variable offset = 1"
     set test "continue"
     set got_hit 0
-    gdb_test_multiple $test $test {
-	-re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
-	}
-	-re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
-	    set got_hit 1
-	    send_gdb "continue\n"
-	    exp_continue
-	}
-	-re " start_again .*\r\n$gdb_prompt $" {
-	}
+    if {[info exists wpoffset_to_wpnum(1)]} {
+	    gdb_test_multiple $test $test {
+		    -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
+		    }
+		    -re "$rwatch_exp $wpoffset_to_wpnum(1):.*alue = .*\r\n$gdb_prompt $" {
+			    set got_hit 1
+			    send_gdb "continue\n"
+			    exp_continue
+		    }
+		    -re " start_again .*\r\n$gdb_prompt $" {
+		    }
+	    }
     }
     for {set wpoffset 1} {$wpoffset <= $wpcount} {incr wpoffset} {
-	if {$wpoffset_to_wpnum($wpoffset)} {
-	    gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
-	}
+	    if {[info exists wpoffset_to_wpnum($wpoffset)] &&
+		    $wpoffset_to_wpnum($wpoffset)} {
+		    gdb_test_no_output "delete $wpoffset_to_wpnum($wpoffset)" ""
+	    }
     }
     set test "wpcount($wpcount)"
-    if {!$wpoffset_to_wpnum([expr $wpcount - 1])} {
-	untested $test
-	continue
-    }
+    if {[info exists wpoffset_to_wpnum([expr $wpcount - 1])] &&
+	    !$wpoffset_to_wpnum([expr $wpcount - 1])} {
+		    untested $test
+		    continue
+	    }
     if {$wpcount > 4} {
 	if {![istarget "s390*-*-*"]} {
 	    setup_kfail tdep/22389 *-*-*