Skip test 'watch -location nullptr->p->x' if null pointer can be dereferenced

Message ID 1401254631-11264-1-git-send-email-yao@codesourcery.com
State Committed
Headers

Commit Message

Yao Qi May 28, 2014, 5:23 a.m. UTC
  gdb.base/watchpoint.exp has a test below which expects to see "Cannot
access memory at address 0x0" when a null pointer is dereferenced.

    gdb_test "watch -location nullptr->p->x" \
	"Cannot access memory at address 0x0"

This assumption is not true when the target is no-mmu, so we get

watch -location nullptr->p->x
Hardware watchpoint 28: -location nullptr->p->x
(gdb) FAIL: gdb.base/watchpoint.exp: watch -location nullptr->p->x

This patch is to check whether null pointer can be dereferenced first
and the then do the test.

gdb/testsuite:

2014-05-28  Yao Qi  <yao@codesourcery.com>

	* gdb.base/watchpoint.exp (test_watch_location): Check null
	pointer can be dereferenced.  If not, do the test, otherwise
	skip it.
---
 gdb/testsuite/gdb.base/watchpoint.exp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
  

Comments

Pedro Alves May 30, 2014, 12:12 p.m. UTC | #1
On 05/28/2014 06:23 AM, Yao Qi wrote:
> gdb.base/watchpoint.exp has a test below which expects to see "Cannot
> access memory at address 0x0" when a null pointer is dereferenced.
> 
>     gdb_test "watch -location nullptr->p->x" \
> 	"Cannot access memory at address 0x0"
> 
> This assumption is not true when the target is no-mmu, so we get
> 
> watch -location nullptr->p->x
> Hardware watchpoint 28: -location nullptr->p->x
> (gdb) FAIL: gdb.base/watchpoint.exp: watch -location nullptr->p->x
> 
> This patch is to check whether null pointer can be dereferenced first
> and the then do the test.

s/the then/then/

> gdb/testsuite:
> 
> 2014-05-28  Yao Qi  <yao@codesourcery.com>
> 
> 	* gdb.base/watchpoint.exp (test_watch_location): Check null
> 	pointer can be dereferenced.  If not, do the test, otherwise
> 	skip it.

OK.

Thanks,
  
Yao Qi June 1, 2014, 3:49 a.m. UTC | #2
On 05/30/2014 08:12 PM, Pedro Alves wrote:
> s/the then/then/
> 

Fixed.

>> > gdb/testsuite:
>> > 
>> > 2014-05-28  Yao Qi  <yao@codesourcery.com>
>> > 
>> > 	* gdb.base/watchpoint.exp (test_watch_location): Check null
>> > 	pointer can be dereferenced.  If not, do the test, otherwise
>> > 	skip it.
> OK.

Patch is pushed in.
  

Patch

diff --git a/gdb/testsuite/gdb.base/watchpoint.exp b/gdb/testsuite/gdb.base/watchpoint.exp
index 1123824..c41b4fd 100644
--- a/gdb/testsuite/gdb.base/watchpoint.exp
+++ b/gdb/testsuite/gdb.base/watchpoint.exp
@@ -595,11 +595,21 @@  proc test_disable_enable_software_watchpoint {} {
 }
 
 proc test_watch_location {} {
+    global gdb_prompt
+
     gdb_breakpoint [gdb_get_line_number "func5 breakpoint here"]
     gdb_continue_to_breakpoint "func5 breakpoint here"
 
-    gdb_test "watch -location nullptr->p->x" \
-	"Cannot access memory at address 0x0"
+    # Check first if a null pointer can be dereferenced on the target.
+    gdb_test_multiple "p *nullptr" "" {
+	-re "Cannot access memory at address 0x0.*$gdb_prompt $" {
+	    gdb_test "watch -location nullptr->p->x" \
+		"Cannot access memory at address 0x0"
+	}
+	-re ".*$gdb_prompt $" {
+	    # Null pointer dereference is legitimate.
+	}
+    }
 
     gdb_test "watch -location *x" "atchpoint .*: .*" "watch -location .x"