+2017-09-26  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+           Pedro Alves  <palves@redhat.com>
+
+       * gdb.base/compare-sections.exp (get value of read-only section): Read
+       as unsigned value.
+       (corrupt read-only section): Likewise and don't set written if patching
+       failed.
+
 2017-09-21  Kevin Buettner  <kevinb@redhat.com>
 
        * gdb.python/py-thrhandle.c, gdb.python/py-thrhandle.exp: New
 
     set orig -1
 
     set test "get value of read-only section"
-    gdb_test_multiple "print /d *(unsigned char *) $ro_address" "$test" {
+    gdb_test_multiple "print /u *(unsigned char *) $ro_address" "$test" {
        -re " = (\[0-9\]*).*$gdb_prompt $" {
            set orig $expect_out(1,string)
            pass "$test"
     # Write PATCH to memory.
     set written -1
     set test "corrupt read-only section"
-    gdb_test_multiple "print /d *(unsigned char *) $ro_address = $patch" "$test" {
+    gdb_test_multiple "print /u *(unsigned char *) $ro_address = $patch" "$test" {
+       -re " = .*Cannot access memory at address $ro_address.*$gdb_prompt $" {
+           pass "$test (cannot write)"
+       }
        -re " = (\[0-9\]*).*$gdb_prompt $" {
            set written $expect_out(1,string)
            pass "$test"