Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <yao@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] Remove duplicated code on checking address 0x0 is accessiable
Date: Fri, 08 Aug 2014 11:15:00 -0000	[thread overview]
Message-ID: <1407496273-29483-1-git-send-email-yao@codesourcery.com> (raw)

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-08  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.
---
 gdb/testsuite/gdb.base/display.exp           |  9 +--------
 gdb/testsuite/gdb.base/hbreak-unmapped.exp   | 10 +++-------
 gdb/testsuite/gdb.base/sigbpt.exp            | 10 +++-------
 gdb/testsuite/gdb.base/signest.exp           | 10 +++-------
 gdb/testsuite/gdb.base/signull.exp           | 10 +++-------
 gdb/testsuite/gdb.guile/scm-disasm.exp       |  8 +++++---
 gdb/testsuite/gdb.guile/scm-pretty-print.exp |  4 +++-
 gdb/testsuite/gdb.guile/scm-value.exp        |  9 +--------
 gdb/testsuite/gdb.python/py-arch.exp         |  8 +++++---
 gdb/testsuite/gdb.python/py-prettyprint.exp  |  5 ++++-
 gdb/testsuite/gdb.python/py-value.exp        |  9 +--------
 gdb/testsuite/lib/gdb.exp                    | 18 ++++++++++++++++++
 12 files changed, 50 insertions(+), 60 deletions(-)

diff --git a/gdb/testsuite/gdb.base/display.exp b/gdb/testsuite/gdb.base/display.exp
index a9875e0..b2bb0e7 100644
--- a/gdb/testsuite/gdb.base/display.exp
+++ b/gdb/testsuite/gdb.base/display.exp
@@ -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"
diff --git a/gdb/testsuite/gdb.base/hbreak-unmapped.exp b/gdb/testsuite/gdb.base/hbreak-unmapped.exp
index 95668f2..b71770f 100644
--- a/gdb/testsuite/gdb.base/hbreak-unmapped.exp
+++ b/gdb/testsuite/gdb.base/hbreak-unmapped.exp
@@ -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
diff --git a/gdb/testsuite/gdb.base/sigbpt.exp b/gdb/testsuite/gdb.base/sigbpt.exp
index 142e739..b184e9e 100644
--- a/gdb/testsuite/gdb.base/sigbpt.exp
+++ b/gdb/testsuite/gdb.base/sigbpt.exp
@@ -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"
diff --git a/gdb/testsuite/gdb.base/signest.exp b/gdb/testsuite/gdb.base/signest.exp
index 258e86e..64ceb72 100644
--- a/gdb/testsuite/gdb.base/signest.exp
+++ b/gdb/testsuite/gdb.base/signest.exp
@@ -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).
diff --git a/gdb/testsuite/gdb.base/signull.exp b/gdb/testsuite/gdb.base/signull.exp
index 925c762..64f4e72 100644
--- a/gdb/testsuite/gdb.base/signull.exp
+++ b/gdb/testsuite/gdb.base/signull.exp
@@ -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,
diff --git a/gdb/testsuite/gdb.guile/scm-disasm.exp b/gdb/testsuite/gdb.guile/scm-disasm.exp
index 5a1dae3..ccc0c88 100644
--- a/gdb/testsuite/gdb.guile/scm-disasm.exp
+++ b/gdb/testsuite/gdb.guile/scm-disasm.exp
@@ -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.
 
diff --git a/gdb/testsuite/gdb.guile/scm-pretty-print.exp b/gdb/testsuite/gdb.guile/scm-pretty-print.exp
index 555d751..55a2393 100644
--- a/gdb/testsuite/gdb.guile/scm-pretty-print.exp
+++ b/gdb/testsuite/gdb.guile/scm-pretty-print.exp
@@ -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\""
diff --git a/gdb/testsuite/gdb.guile/scm-value.exp b/gdb/testsuite/gdb.guile/scm-value.exp
index 425873e..91e1a56 100644
--- a/gdb/testsuite/gdb.guile/scm-value.exp
+++ b/gdb/testsuite/gdb.guile/scm-value.exp
@@ -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"
diff --git a/gdb/testsuite/gdb.python/py-arch.exp b/gdb/testsuite/gdb.python/py-arch.exp
index a49d50a..554f05f 100644
--- a/gdb/testsuite/gdb.python/py-arch.exp
+++ b/gdb/testsuite/gdb.python/py-arch.exp
@@ -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"
+}
diff --git a/gdb/testsuite/gdb.python/py-prettyprint.exp b/gdb/testsuite/gdb.python/py-prettyprint.exp
index 491b52d..1096389 100644
--- a/gdb/testsuite/gdb.python/py-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/py-prettyprint.exp
@@ -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\""
diff --git a/gdb/testsuite/gdb.python/py-value.exp b/gdb/testsuite/gdb.python/py-value.exp
index 13433fd..0728266 100644
--- a/gdb/testsuite/gdb.python/py-value.exp
+++ b/gdb/testsuite/gdb.python/py-value.exp
@@ -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"
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 8cb98ae..92069c9 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -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 } {
-- 
1.9.0


             reply	other threads:[~2014-08-08 11:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-08 11:15 Yao Qi [this message]
2014-08-08 14:10 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1407496273-29483-1-git-send-email-yao@codesourcery.com \
    --to=yao@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox