This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Harden gdb.base/bp-permanent.exp


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0ff6fcb2f0f2e3c0de3708ec41fb849d1461c9d7

commit 0ff6fcb2f0f2e3c0de3708ec41fb849d1461c9d7
Author: Luis Machado <lgustavo@codesourcery.com>
Date:   Mon Apr 13 14:45:56 2015 -0300

    Harden gdb.base/bp-permanent.exp
    
    This testcase does not work as expected in QEMU (aarch64 QEMU in my case). It
    fails when trying to manually write the breakpoint instruction to a certain
    PC address.
    
    (gdb) p /x addr_bp[0] = buffer[0]^M
    Cannot access memory at address 0x400834^M
    (gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[0] = buffer[0]
    p /x addr_bp[1] = buffer[1]^M
    Cannot access memory at address 0x400835^M
    (gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[1] = buffer[1]
    p /x addr_bp[2] = buffer[2]^M
    Cannot access memory at address 0x400836^M
    (gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[2] = buffer[2]
    p /x addr_bp[3] = buffer[3]^M
    Cannot access memory at address 0x400837^M
    (gdb) PASS: gdb.base/bp-permanent.exp: always_inserted=off, sw_watchpoint=0: setup: p /x addr_bp[3] = buffer[3]
    
    The following patch prevents a number of failures by detecting this and bailing out in case the target has such a restriction. Writing to .text from within the program isn't any better. It just leads to a SIGSEGV.
    
    Before the patch:
    
                    === gdb Summary ===
    
    After the patch:
    
                    === gdb Summary ===
    
    gdb/testsuite/ChangeLog:
    2015-04-13  Luis Machado  <lgustavo@codesourcery.com>
    
    	* gdb.base/bp-permanent.exp (test): Handle the case of being unable
    	to write to the .text section.

Diff:
---
 gdb/testsuite/ChangeLog                 |  5 +++++
 gdb/testsuite/gdb.base/bp-permanent.exp | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index e01fd38..a2f7328 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,10 @@
 2015-04-13  Luis Machado  <lgustavo@codesourcery.com>
 
+	* gdb.base/bp-permanent.exp (test): Handle the case of being unable
+	to write to the .text section.
+
+2015-04-13  Luis Machado  <lgustavo@codesourcery.com>
+
 	* gdb.base/coredump-filter.exp: Restrict test to Linux systems only.
 	Handle the case of targets that do not provide PID information.
 
diff --git a/gdb/testsuite/gdb.base/bp-permanent.exp b/gdb/testsuite/gdb.base/bp-permanent.exp
index 81a5293..e802eee 100644
--- a/gdb/testsuite/gdb.base/bp-permanent.exp
+++ b/gdb/testsuite/gdb.base/bp-permanent.exp
@@ -104,7 +104,18 @@ proc test {always_inserted sw_watchpoint} {
 	# to memory manually.
 	set count [expr $address_after_bp - $address_bp]
 	for {set i 0} {$i < $count} {incr i} {
-	    gdb_test "p /x addr_bp\[$i\] = buffer\[$i\]" " = .*"
+	    gdb_test_multiple "p /x addr_bp\[$i\] = buffer\[$i\]" $test {
+		-re "Cannot access memory at address $hex.*$gdb_prompt $" {
+		    # Some targets (QEMU for one) will disallow writes to the
+		    # .text section under certain circumstances.  It is no use
+		    # continuing with the test at this point.  Just return.
+		    unsupported "Cannot modify memory"
+		    return
+		}
+		-re " = .*$gdb_prompt $" {
+		    pass $test
+		}
+	    }
 	}
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]