]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove duplicated code on checking address 0x0 is accessiable
authorYao Qi <yao@codesourcery.com>
Thu, 7 Aug 2014 08:09:38 +0000 (16:09 +0800)
committerYao Qi <yao@codesourcery.com>
Sat, 9 Aug 2014 00:46:32 +0000 (08:46 +0800)
I find some gdb.python tests fail on arm-none-eabi target, because the
tests assume that memory on address 0x is inaccessible.  Some tests
(in gdb.base) are aware of this, so do a "x 0" check first.  However,
the code is copy-n-paste.

This patch is to move the "x 0" check to a procedure in lib/gdb.exp,
and get needed tests call it.  The original code matches pattern
"0x0:\[ \t\]*Error accessing memory address 0x0\r\n$gdb_prompt $", but
I remove it from the new proc is_address_zero_readable, because GDB
doesn't emit such message any more.

gdb/testsuite:

2014-08-09  Yao Qi  <yao@codesourcery.com>

* gdb.base/display.exp: Invoke is_address_zero_readable.
* gdb.guile/scm-value.exp (test_value_in_inferior): Likewise.
* gdb.python/py-value.exp (test_value_in_inferior): Likewise.
* gdb.base/hbreak-unmapped.exp: Return if
is_address_zero_readable returns true.
* gdb.base/signest.exp: Likewise.
* gdb.base/signull.exp: Likewise.
* gdb.base/sigbpt.exp: Likewise.
* gdb.guile/scm-disasm.exp: Do the test if
is_address_zero_readable returns false.
* gdb.guile/scm-pretty-print.exp (run_lang_tests): Likewise.
* gdb.python/py-arch.exp: Likewise.
* gdb.python/py-prettyprint.exp (run_lang_tests): Likewise.
* lib/gdb.exp (is_address_zero_readable): New proc.

13 files changed:
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/display.exp
gdb/testsuite/gdb.base/hbreak-unmapped.exp
gdb/testsuite/gdb.base/sigbpt.exp
gdb/testsuite/gdb.base/signest.exp
gdb/testsuite/gdb.base/signull.exp
gdb/testsuite/gdb.guile/scm-disasm.exp
gdb/testsuite/gdb.guile/scm-pretty-print.exp
gdb/testsuite/gdb.guile/scm-value.exp
gdb/testsuite/gdb.python/py-arch.exp
gdb/testsuite/gdb.python/py-prettyprint.exp
gdb/testsuite/gdb.python/py-value.exp
gdb/testsuite/lib/gdb.exp

index aa2eae0c5a659bd77f3e8b86bbf477f5c104db25..6ae9f6eaa33a7e429e5f129a783599aac6550570 100644 (file)
@@ -1,3 +1,20 @@
+2014-08-09  Yao Qi  <yao@codesourcery.com>
+
+       * gdb.base/display.exp: Invoke is_address_zero_readable.
+       * gdb.guile/scm-value.exp (test_value_in_inferior): Likewise.
+       * gdb.python/py-value.exp (test_value_in_inferior): Likewise.
+       * gdb.base/hbreak-unmapped.exp: Return if
+       is_address_zero_readable returns true.
+       * gdb.base/signest.exp: Likewise.
+       * gdb.base/signull.exp: Likewise.
+       * gdb.base/sigbpt.exp: Likewise.
+       * gdb.guile/scm-disasm.exp: Do the test if
+       is_address_zero_readable returns false.
+       * gdb.guile/scm-pretty-print.exp (run_lang_tests): Likewise.
+       * gdb.python/py-arch.exp: Likewise.
+       * gdb.python/py-prettyprint.exp (run_lang_tests): Likewise.
+       * lib/gdb.exp (is_address_zero_readable): New proc.
+
 2014-08-09  Yao Qi  <yao@codesourcery.com>
 
        PR testsuite/13443
index a9875e0a33bbc8219eab7c35d4681230feda1430..b2bb0e78a04cf0eaf0bb31abea6494e8bbb21ffe 100644 (file)
@@ -106,14 +106,7 @@ gdb_test "undisp" \
 # Test displaying a variable that is temporarily at a bad address.
 # But if we can examine what's at memory address 0, then we'll also be
 # able to display it without error.  Don't run the test in that case.
-set can_read_0 0
-gdb_test_multiple "x 0" "memory at address 0" {
-    -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
-    -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
-    -re ".*$gdb_prompt $" {
-       set can_read_0 1
-    }
-}
+set can_read_0 [is_address_zero_readable]
 
 if { !$can_read_0 } {
     gdb_test "disp *p_i" ".*: \\*p_i = 0"
index 95668f2fd62903c49a64c2ee907525cf6f4f4205..b71770fc0da6319d58ca04ce847d59481ceeec12 100644 (file)
@@ -29,13 +29,9 @@ if ![runto_main] {
 }
 
 # If we can read the memory at address 0, skip the test.
-gdb_test_multiple "x 0" "memory at address 0" {
-    -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
-    -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
-    -re ".*$gdb_prompt $" {
-       untested "Memory at address 0 is readable"
-       return
-    }
+if { [is_address_zero_readable] } {
+    untested "Memory at address 0 is readable"
+    return
 }
 
 delete_breakpoints
index 142e739dc583ce24a3c3f3525b575958f6e2efe4..b184e9effb0ecede4f3ecb8c913d02490fcd7621 100644 (file)
@@ -55,13 +55,9 @@ if ![runto_main] then {
 # especially on targets without an MMU.  Don't run the tests in that
 # case.
 
-gdb_test_multiple "x 0" "memory at address 0" {
-    -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
-    -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
-    -re ".*$gdb_prompt $" {
-       untested "Memory at address 0 is possibly executable"
-       return
-    }
+if { [is_address_zero_readable] } {
+    untested "Memory at address 0 is possibly executable"
+    return
 }
 
 gdb_test "break keeper"
index 258e86e07dec9363df9c85ad2fd9b65f3a030a3c..64ceb72fd1e7440f1682ad4b0cc59d4e2240a88f 100644 (file)
@@ -38,13 +38,9 @@ if ![runto_main] then {
 # especially on targets without an MMU.  Don't run the tests in that
 # case.
 
-gdb_test_multiple "x 0" "memory at address 0" {
-    -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
-    -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
-    -re ".*$gdb_prompt $" {
-       untested "Memory at address 0 is possibly executable"
-       return -1
-    }
+if { [is_address_zero_readable] } {
+    untested "Memory at address 0 is possibly executable"
+    return -1
 }
 
 # Run until we hit the SIGSEGV (or SIGBUS on some platforms).
index 925c762b3ecb4a865c938cfe0d52823ccc0bdea1..64f4e7288d308d2051d71d2a5e0e147a50927b0f 100644 (file)
@@ -56,13 +56,9 @@ if ![runto_main] then {
 # especially on targets without an MMU.  Don't run the tests in that
 # case.
 
-gdb_test_multiple "x 0" "memory at address 0" {
-    -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { }
-    -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { }
-    -re ".*$gdb_prompt $" {
-       untested "Memory at address 0 is possibly executable"
-       return
-    }
+if { [is_address_zero_readable] } {
+    untested "Memory at address 0 is possibly executable"
+    return
 }
 
 # If an attempt to call a NULL pointer leaves the inferior in main,
index 5a1dae357f0c0406ac3a314aad92d138cf6449b6..ccc0c88bc6bb352944370a91550b078d7e3edbd7 100644 (file)
@@ -83,9 +83,11 @@ gdb_test "guile (print (length insn-list4))" \
 
 test_disassemble_1 "basic" "pc" ""
 
-# Negative test
-gdb_test "guile (arch-disassemble arch 0 #:size 1)" \
-    "ERROR: Cannot access memory at address 0x.*" "test bad memory access"
+if { ![is_address_zero_readable] } {
+    # Negative test
+    gdb_test "guile (arch-disassemble arch 0 #:size 1)" \
+       "ERROR: Cannot access memory at address 0x.*" "test bad memory access"
+}
 
 # Test disassembly through a port.
 
index 555d7514d9265c97d26c49c12369eb36b34cf561..55a23936f37a49c8061fc76088e91c324d6f4e7f 100644 (file)
@@ -81,7 +81,9 @@ proc run_lang_tests {exefile lang} {
        gdb_scm_test_silent_cmd "set print elements 200" "" 1
     }
 
-    gdb_test "print ns2" "<error reading variable: ERROR: Cannot access memory at address 0x0>"
+    if { ![is_address_zero_readable] } {
+       gdb_test "print ns2" "<error reading variable: ERROR: Cannot access memory at address 0x0>"
+    }
 
     gdb_test "print x" " = \"this is x\""
     gdb_test "print cstring" " = \"const string\""
index 425873e9af5ef7784acc5895fd16df0682668564..91e1a560a83b76a53605b2b28a89d61ac5d87816 100644 (file)
@@ -105,14 +105,7 @@ proc test_value_in_inferior {} {
     # Test displaying a variable that is temporarily at a bad address.
     # But if we can examine what's at memory address 0, then we'll also be
     # able to display it without error.  Don't run the test in that case.
-    set can_read_0 0
-    gdb_test_multiple "x 0" "memory at address 0" {
-       -re "0x0:\[ \t\]*Cannot access memory at address 0x0\r\n$gdb_prompt $" { }
-       -re "0x0:\[ \t\]*Error accessing memory address 0x0\r\n$gdb_prompt $" { }
-       -re "\r\n$gdb_prompt $" {
-           set can_read_0 1
-       }
-    }
+    set can_read_0 [is_address_zero_readable]
 
     # Test memory error.
     set test "parse_and_eval with memory error"
index a49d50a421141a401aedc6b78eefc03471740326..554f05f4661681dc0c005fb77d16c78480590211 100644 (file)
@@ -57,6 +57,8 @@ gdb_test "python print (\"addr\" in insn)" "True" "test key addr"
 gdb_test "python print (\"asm\" in insn)" "True" "test key asm"
 gdb_test "python print (\"length\" in insn)" "True" "test key length"
 
-# Negative test
-gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
-  "test bad memory access"
+if { ![is_address_zero_readable] } {
+    # Negative test
+    gdb_test "python arch.disassemble(0, 0)" ".*gdb\.MemoryError.*" \
+       "test bad memory access"
+}
index 491b52d551efb3c8912689e9758080859d171f15..10963892504b302e87110a196d72f8cf797e1e66 100644 (file)
@@ -83,7 +83,10 @@ proc run_lang_tests {exefile lang} {
        gdb_py_test_silent_cmd "set print elements 200" "" 1
     }
 
-    gdb_test "print ns2" ".error reading variable: Cannot access memory at address 0x0."
+    if { ![is_address_zero_readable] } {
+       gdb_test "print ns2" \
+           ".error reading variable: Cannot access memory at address 0x0."
+    }
 
     gdb_test "print x" " = \"this is x\""
     gdb_test "print cstring" " = \"const string\""
index 13433fd93379be7eaa953af983e7a3687a7981b4..07282669e948e2ce500ccdffcea59c60356d3f04 100644 (file)
@@ -234,14 +234,7 @@ proc test_value_in_inferior {} {
   # Test displaying a variable that is temporarily at a bad address.
   # But if we can examine what's at memory address 0, then we'll also be
   # able to display it without error.  Don't run the test in that case.
-  set can_read_0 0
-  gdb_test_multiple "x 0" "memory at address 0" {
-      -re "0x0:\[ \t\]*Cannot access memory at address 0x0\r\n$gdb_prompt $" { }
-      -re "0x0:\[ \t\]*Error accessing memory address 0x0\r\n$gdb_prompt $" { }
-      -re "\r\n$gdb_prompt $" {
-         set can_read_0 1
-      }
-  }
+  set can_read_0 [is_address_zero_readable]
 
   # Test memory error.
   set test "parse_and_eval with memory error"
index 8cb98ae96446cbb1c63a2e8269eb367d034b6daa..92069c9a6c7a2e161d8181bc083a235a2e7e3bb2 100644 (file)
@@ -1946,6 +1946,24 @@ gdb_caching_proc is_elf_target {
     return 1
 }
 
+# Return 1 if the memory at address zero is readable.
+
+gdb_caching_proc is_address_zero_readable {
+    global gdb_prompt
+
+    set ret 0
+    gdb_test_multiple "x 0" "" {
+       -re "Cannot access memory at address 0x0.*$gdb_prompt $" {
+           set ret 0
+       }
+       -re ".*$gdb_prompt $" {
+           set ret 1
+       }
+    }
+
+    return $ret
+}
+
 # Produce source file NAME and write SOURCES into it.
 
 proc gdb_produce_source { name sources } {