[gdb/testsuite] Fix compare-sections.exp FAIL

Message ID 33d0f2eb-4802-8b06-44bf-3e4299c5fdb4@foss.arm.com
State New, archived
Headers

Commit Message

Thomas Preud'homme Sept. 6, 2017, 4:58 p.m. UTC
  Hi,

compare-sections.exp has two cases that are not handled appropriately:
1) value read from read-only section is negative
2) error while patching that section

This patch adapts the regular expression to allow a minus sign to deal
with 1) and test for the error message to not set written if read-only
section cannot be written to so as to solve 2).

ChangeLog entry is as follows:

*** gdb/testsuite/ChangeLog ***

2017-09-05  Thomas Preud'homme  <thomas.preudhomme@arm.com>

	* gdb.base/compare-sections.exp (get value of read-only section): Allow
	minus sign in the answer.
	(corrupt read-only section): Don't mark it pass if patching failed.

Without this patch I get a Tcl error on the first test while it now
PASSes and the second one is marked UNSUPPORTED.

Is this ok for master?

Best regards,

Thomas
  

Comments

Pedro Alves Sept. 6, 2017, 5:13 p.m. UTC | #1
On 09/06/2017 05:58 PM, Thomas Preudhomme wrote:

> 
> diff --git a/gdb/testsuite/gdb.base/compare-sections.exp b/gdb/testsuite/gdb.base/compare-sections.exp
> index e4b99216408f86745a890f80175e2f26c39303b5..8a0cf89a4c7c51299c59f59175865b5eb211f213 100644
> --- a/gdb/testsuite/gdb.base/compare-sections.exp
> +++ b/gdb/testsuite/gdb.base/compare-sections.exp
> @@ -118,7 +118,7 @@ with_test_prefix "read-only" {
>  
>      set test "get value of read-only section"
>      gdb_test_multiple "print /d *(unsigned char *) $ro_address" "$test" {
> -	-re " = (\[0-9\]*).*$gdb_prompt $" {
> +	-re " = (-?\[0-9\]+).*$gdb_prompt $" {

This is reading bytes off of memory, as we can infer from
use of "unsigned char".   The test is most probably using
explicit /d to avoid printing the number as a character.
I think it'd be clearer to change the "/d" to "/u", here
and below too.

Also, I think treating as negative integer would actually
be buggy because if the value happens to be 0xff, then you
get back -1, which would incorrectly match here:

    if {$orig == -1} {
	untested "couldn't read address of read-only section"
	return -1
    }
>  	    set orig $expect_out(1,string)
>  	    pass "$test"
>  	}
> @@ -136,6 +136,8 @@ with_test_prefix "read-only" {
>      set written -1
>      set test "corrupt read-only section"
>      gdb_test_multiple "print /d *(unsigned char *) $ro_address = $patch" "$test" {
> +	-re " = .*Cannot access memory at address $ro_address.*$gdb_prompt $" {

Add:
 	    pass "$test (cannot write)"

> +	}
>  	-re " = (\[0-9\]*).*$gdb_prompt $" {
>  	    set written $expect_out(1,string)
>  	    pass "$test"
> 

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/testsuite/gdb.base/compare-sections.exp b/gdb/testsuite/gdb.base/compare-sections.exp
index e4b99216408f86745a890f80175e2f26c39303b5..8a0cf89a4c7c51299c59f59175865b5eb211f213 100644
--- a/gdb/testsuite/gdb.base/compare-sections.exp
+++ b/gdb/testsuite/gdb.base/compare-sections.exp
@@ -118,7 +118,7 @@  with_test_prefix "read-only" {
 
     set test "get value of read-only section"
     gdb_test_multiple "print /d *(unsigned char *) $ro_address" "$test" {
-	-re " = (\[0-9\]*).*$gdb_prompt $" {
+	-re " = (-?\[0-9\]+).*$gdb_prompt $" {
 	    set orig $expect_out(1,string)
 	    pass "$test"
 	}
@@ -136,6 +136,8 @@  with_test_prefix "read-only" {
     set written -1
     set test "corrupt read-only section"
     gdb_test_multiple "print /d *(unsigned char *) $ro_address = $patch" "$test" {
+	-re " = .*Cannot access memory at address $ro_address.*$gdb_prompt $" {
+	}
 	-re " = (\[0-9\]*).*$gdb_prompt $" {
 	    set written $expect_out(1,string)
 	    pass "$test"