public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/testsuite: Allow for failure to read some memory addresses
@ 2018-07-04 18:13 Andrew Burgess
  2018-07-07  2:16 ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2018-07-04 18:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

In the gdb.base/examine-backward.exp test script, we check to see if
address zero is readable, and then read memory first forward from
address zero, and then backward from address zero.

The problem is, being able to read address zero does not guarantee
that you'll be able to read from the other end of the address space,
and the test probably shouldn't assume that is the case.

This patch extends the success conditions so that, even if GDB fails
to read memory, so long as the error message indicates that GDB was
trying to access the correct location, then we consider this a pass.
The test is, I think, trying to show that GDB can compute the correct
address when going backward from zero, being able to access the memory
at that address is secondary.

One further change is that, when we examined the memory at address
zero, the regexp used to match the address expected that the zero
address would have two '0' digits as the least significant digits.  As
GDB strips leading zeros from addresses this was causing the test to
fail.  I've reduced the zero address to a single 0 digit.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.exp: Be more forgiving of failures to
	read some addresses.  Update zero address pattern.
---
 gdb/testsuite/ChangeLog                     |  5 ++++
 gdb/testsuite/gdb.base/examine-backward.exp | 42 ++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.base/examine-backward.exp b/gdb/testsuite/gdb.base/examine-backward.exp
index be80b841aa..a47e3507c3 100644
--- a/gdb/testsuite/gdb.base/examine-backward.exp
+++ b/gdb/testsuite/gdb.base/examine-backward.exp
@@ -83,18 +83,46 @@ with_test_prefix "memory page boundary" {
 }
 
 with_test_prefix "address zero boundary" {
+    global gdb_prompt
+
     if {[is_address_zero_readable]} {
         set address_zero "0x0"
         set byte "\t0x\[0-9a-f\]+"
         gdb_test "x/3xb ${address_zero}" \
-            "0x\[0-9a-f\]+00.*:${byte}${byte}${byte}" \
+            "0x\[0-9a-f\]*0.*:${byte}${byte}${byte}" \
             "examine 3 bytes forward from ${address_zero}"
-        gdb_test "x/-6x" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}" \
-            "examine 6 bytes backward"
-        gdb_test "x/-3x ${address_zero}" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}" \
-            "examine 3 bytes backward from ${address_zero}"
+
+	set test "examine 6 bytes backward"
+	gdb_test_multiple "x/-6x" "$test" {
+	    -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+		pass $test
+	    }
+	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+		# We test that we can read zero, but that's no
+		# guarantee that we can read from the other end of the
+		# address space.  If we get an error about trying to
+		# read from the expected address then we count that as
+		# a pass, GDB did try to read the correct location.
+		pass $test
+	    }
+	    -re "$gdb_prompt $" {
+		fail $test
+	    }
+	}
+
+	set test "examine 3 bytes backward from ${address_zero}"
+	gdb_test_multiple "x/-3x ${address_zero}" "$test" {
+	    -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+		pass $test
+	    }
+	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+		# See previous test for why this is a pass.
+		pass $test
+	    }
+	    -re "$gdb_prompt $" {
+		fail $test
+	    }
+	}
     }
 }
 
-- 
2.14.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdb/testsuite: Allow for failure to read some memory addresses
  2018-07-04 18:13 [PATCH] gdb/testsuite: Allow for failure to read some memory addresses Andrew Burgess
@ 2018-07-07  2:16 ` Simon Marchi
  2018-07-07 10:33   ` Andrew Burgess
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2018-07-07  2:16 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2018-07-04 02:13 PM, Andrew Burgess wrote:
> In the gdb.base/examine-backward.exp test script, we check to see if
> address zero is readable, and then read memory first forward from
> address zero, and then backward from address zero.
> 
> The problem is, being able to read address zero does not guarantee
> that you'll be able to read from the other end of the address space,
> and the test probably shouldn't assume that is the case.
> 
> This patch extends the success conditions so that, even if GDB fails
> to read memory, so long as the error message indicates that GDB was
> trying to access the correct location, then we consider this a pass.
> The test is, I think, trying to show that GDB can compute the correct
> address when going backward from zero, being able to access the memory
> at that address is secondary.
> 
> One further change is that, when we examined the memory at address
> zero, the regexp used to match the address expected that the zero
> address would have two '0' digits as the least significant digits.  As
> GDB strips leading zeros from addresses this was causing the test to
> fail.  I've reduced the zero address to a single 0 digit.

Hi Andrew,

This probably means that we could run the test even if address 0 is not readable?
On x86_64, I get:

(gdb) x/3b 0
0x0:	Cannot access memory at address 0x0
(gdb) x/-6b
0xfffffffffffffffb:	Cannot access memory at address 0xfffffffffffffffb

It's not the exact same result as if address 0 is readable (since we didn't
get to read all three bytes in the first command), but it still reaches
the goal of the test.

> +	set test "examine 6 bytes backward"
> +	gdb_test_multiple "x/-6x" "$test" {
> +	    -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
> +		pass $test
> +	    }
> +	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
> +		# We test that we can read zero, but that's no
> +		# guarantee that we can read from the other end of the
> +		# address space.  If we get an error about trying to
> +		# read from the expected address then we count that as
> +		# a pass, GDB did try to read the correct location.
> +		pass $test
> +	    }
> +	    -re "$gdb_prompt $" {
> +		fail $test
> +	    }

Is the last stanza necessary?  From what I remember, if it doesn't match
any other one, it will already fail the test.

Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdb/testsuite: Allow for failure to read some memory addresses
  2018-07-07  2:16 ` Simon Marchi
@ 2018-07-07 10:33   ` Andrew Burgess
  2018-07-07 14:05     ` Simon Marchi
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Burgess @ 2018-07-07 10:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

* Simon Marchi <simark@simark.ca> [2018-07-06 22:14:59 -0400]:

> On 2018-07-04 02:13 PM, Andrew Burgess wrote:
> > In the gdb.base/examine-backward.exp test script, we check to see if
> > address zero is readable, and then read memory first forward from
> > address zero, and then backward from address zero.
> > 
> > The problem is, being able to read address zero does not guarantee
> > that you'll be able to read from the other end of the address space,
> > and the test probably shouldn't assume that is the case.
> > 
> > This patch extends the success conditions so that, even if GDB fails
> > to read memory, so long as the error message indicates that GDB was
> > trying to access the correct location, then we consider this a pass.
> > The test is, I think, trying to show that GDB can compute the correct
> > address when going backward from zero, being able to access the memory
> > at that address is secondary.
> > 
> > One further change is that, when we examined the memory at address
> > zero, the regexp used to match the address expected that the zero
> > address would have two '0' digits as the least significant digits.  As
> > GDB strips leading zeros from addresses this was causing the test to
> > fail.  I've reduced the zero address to a single 0 digit.
> 
> Hi Andrew,
> 
> This probably means that we could run the test even if address 0 is not readable?
> On x86_64, I get:
> 
> (gdb) x/3b 0
> 0x0:	Cannot access memory at address 0x0
> (gdb) x/-6b
> 0xfffffffffffffffb:	Cannot access memory at address 0xfffffffffffffffb
> 
> It's not the exact same result as if address 0 is readable (since we didn't
> get to read all three bytes in the first command), but it still reaches
> the goal of the test.
> 
> > +	set test "examine 6 bytes backward"
> > +	gdb_test_multiple "x/-6x" "$test" {
> > +	    -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
> > +		pass $test
> > +	    }
> > +	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
> > +		# We test that we can read zero, but that's no
> > +		# guarantee that we can read from the other end of the
> > +		# address space.  If we get an error about trying to
> > +		# read from the expected address then we count that as
> > +		# a pass, GDB did try to read the correct location.
> > +		pass $test
> > +	    }
> > +	    -re "$gdb_prompt $" {
> > +		fail $test
> > +	    }
> 
> Is the last stanza necessary?  From what I remember, if it doesn't match
> any other one, it will already fail the test.

Thanks for the feedback.

I've updated the test so it now runs more of the tests even when
address 0x0 is not readable.

I've removed the extra fail conditions, because, as you point out they
are covered by gdb_test_multiple anyway.

Thanks,
Andrew

---

[PATCH] gdb/testsuite: Allow for failure to read some memory addresses

In the gdb.base/examine-backward.exp test script, we check to see if
address zero is readable, and then read memory first forward from
address zero, and then backward from address zero.

The problem is, being able to read address zero does not guarantee
that you'll be able to read from the other end of the address space,
and the test probably shouldn't assume that is the case.

This patch updates the test script so that even if address zero is
known non-readable, we still run the tests, the tests in question are
mostly about, can GDB calculate the correct address to read from, we
can confirm this even if the final read ultimately fails.  We also no
longer assume that if address zero is readable, then the other end of
the address space will be readable.

One further change is that, when we examined the memory at address
zero, the regexp used to match the address expected that the zero
address would have two '0' digits as the least significant digits.  As
GDB strips leading zeros from addresses this was causing the test to
fail.  I've reduced the zero address to a single 0 digit.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.exp: Still run tests around address
	0x0, even if address 0x0 is not readable.  Update the pattern for
	matching address 0x0 in expected output.
---
 gdb/testsuite/ChangeLog                     |  6 +++
 gdb/testsuite/gdb.base/examine-backward.exp | 68 ++++++++++++++++++++++++-----
 2 files changed, 62 insertions(+), 12 deletions(-)

diff --git a/gdb/testsuite/gdb.base/examine-backward.exp b/gdb/testsuite/gdb.base/examine-backward.exp
index be80b841aa8..60e8e254abf 100644
--- a/gdb/testsuite/gdb.base/examine-backward.exp
+++ b/gdb/testsuite/gdb.base/examine-backward.exp
@@ -83,18 +83,62 @@ with_test_prefix "memory page boundary" {
 }
 
 with_test_prefix "address zero boundary" {
-    if {[is_address_zero_readable]} {
-        set address_zero "0x0"
-        set byte "\t0x\[0-9a-f\]+"
-        gdb_test "x/3xb ${address_zero}" \
-            "0x\[0-9a-f\]+00.*:${byte}${byte}${byte}" \
-            "examine 3 bytes forward from ${address_zero}"
-        gdb_test "x/-6x" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}" \
-            "examine 6 bytes backward"
-        gdb_test "x/-3x ${address_zero}" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}" \
-            "examine 3 bytes backward from ${address_zero}"
+    global gdb_prompt
+
+    set address_zero "0x0"
+    set byte "\t0x\[0-9a-f\]+"
+
+    set test "examine 3 bytes forward from ${address_zero}"
+    gdb_test_multiple "x/3xb ${address_zero}" "$test" {
+	-re "0x\[0-9a-f\]*0.*:${byte}${byte}${byte}\[\r\n\]*$gdb_prompt $" {
+	    pass $test
+	}
+	-re "0x\[0-9a-f\]*0.*:\tCannot access memory at address 0x\[0-9a-f\]*0\[\r\n\]*$gdb_prompt $" {
+	    # If we failed to read address 0 then this is fine, so
+	    # long as we're not expecting to be able to read from
+	    # address 0.
+	    if {![is_address_zero_readable]} {
+		# The next test assumes that the last address examined
+		# would be 0x2.  As we just failed to read address 0x0
+		# things are going to go wrong unless we now tell GDB
+		# to examine address 0x2.  We assume here that if we
+		# can't read 0x0 we can't read 0x2 either.
+		gdb_test "x/3xb 0x2" "Cannot access memory at address 0x\[0-9a-f\]*2" \
+		    "set last examined address to 0x2"
+		pass $test
+	    } else {
+		fail $test
+	    }
+	}
+    }
+
+    set test "examine 6 bytes backward"
+    gdb_test_multiple "x/-6x" "$test" {
+	-re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+	    pass $test
+	}
+	-re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+	    # We may, or may not have managed to read from address 0x0
+	    # in the previous test, however, being able to read 0x0 is
+	    # no guarantee that we can read from the other end of the
+	    # address space.  If we get an error about trying to read
+	    # from the expected address then we count that as a pass,
+	    # GDB did try to read the correct location, and this test
+	    # is (mostly) about does GDB calculate the correct address
+	    # when wrapping around.
+	    pass $test
+	}
+    }
+
+    set test "examine 3 bytes backward from ${address_zero}"
+    gdb_test_multiple "x/-3x ${address_zero}" "$test" {
+	-re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+	    pass $test
+	}
+	-re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+	    # See previous test for why this is a pass.
+	    pass $test
+	}
     }
 }
 
-- 
2.14.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] gdb/testsuite: Allow for failure to read some memory addresses
  2018-07-07 10:33   ` Andrew Burgess
@ 2018-07-07 14:05     ` Simon Marchi
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2018-07-07 14:05 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On 2018-07-07 06:32, Andrew Burgess wrote:
> * Simon Marchi <simark@simark.ca> [2018-07-06 22:14:59 -0400]:
> 
>> On 2018-07-04 02:13 PM, Andrew Burgess wrote:
>> > In the gdb.base/examine-backward.exp test script, we check to see if
>> > address zero is readable, and then read memory first forward from
>> > address zero, and then backward from address zero.
>> >
>> > The problem is, being able to read address zero does not guarantee
>> > that you'll be able to read from the other end of the address space,
>> > and the test probably shouldn't assume that is the case.
>> >
>> > This patch extends the success conditions so that, even if GDB fails
>> > to read memory, so long as the error message indicates that GDB was
>> > trying to access the correct location, then we consider this a pass.
>> > The test is, I think, trying to show that GDB can compute the correct
>> > address when going backward from zero, being able to access the memory
>> > at that address is secondary.
>> >
>> > One further change is that, when we examined the memory at address
>> > zero, the regexp used to match the address expected that the zero
>> > address would have two '0' digits as the least significant digits.  As
>> > GDB strips leading zeros from addresses this was causing the test to
>> > fail.  I've reduced the zero address to a single 0 digit.
>> 
>> Hi Andrew,
>> 
>> This probably means that we could run the test even if address 0 is 
>> not readable?
>> On x86_64, I get:
>> 
>> (gdb) x/3b 0
>> 0x0:	Cannot access memory at address 0x0
>> (gdb) x/-6b
>> 0xfffffffffffffffb:	Cannot access memory at address 0xfffffffffffffffb
>> 
>> It's not the exact same result as if address 0 is readable (since we 
>> didn't
>> get to read all three bytes in the first command), but it still 
>> reaches
>> the goal of the test.
>> 
>> > +	set test "examine 6 bytes backward"
>> > +	gdb_test_multiple "x/-6x" "$test" {
>> > +	    -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
>> > +		pass $test
>> > +	    }
>> > +	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
>> > +		# We test that we can read zero, but that's no
>> > +		# guarantee that we can read from the other end of the
>> > +		# address space.  If we get an error about trying to
>> > +		# read from the expected address then we count that as
>> > +		# a pass, GDB did try to read the correct location.
>> > +		pass $test
>> > +	    }
>> > +	    -re "$gdb_prompt $" {
>> > +		fail $test
>> > +	    }
>> 
>> Is the last stanza necessary?  From what I remember, if it doesn't 
>> match
>> any other one, it will already fail the test.
> 
> Thanks for the feedback.
> 
> I've updated the test so it now runs more of the tests even when
> address 0x0 is not readable.
> 
> I've removed the extra fail conditions, because, as you point out they
> are covered by gdb_test_multiple anyway.
> 
> Thanks,
> Andrew

Looks good, thanks!

Simon

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] gdb/testsuite: Allow for failure to read some memory addresses
@ 2018-02-02 19:42 Andrew Burgess
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2018-02-02 19:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

In the gdb.base/examine-backward.exp test script, we check to see if
address zero is readable, and then read memory first forward from
address zero, and then backward from address zero.

The problem is, being able to read address zero does not guarantee that
you'll be able to read from the other end of the address space, and the
test probably shouldn't assume that is the case.

This patch extends the success conditions so that, even if GDB fails to
read memory, so long as the error message indicates that GDB was trying
to access the correct location, then we consider this a pass.  The test
is, I think, trying to show that GDB can compute the correct address
when going backward from zero, being able to access the memory at that
address is secondary.

One further change is that, when we examined the memory at address zero,
the regexp used to match the address expected that the "zero address"
would have two '0' digits as the least significant digits.  As GDB
strips leading zeros from addresses, I assume that this test was
originally written for a target that inserts address flags into the most
significant part of the address, and so, the address zero, would appear
like: '0x<FLAGS>00000000' or similar.  On targets without address flags,
reading address zero just prints the address as '0x0'.  I've tweaked the
address pattern so either case should now pass.

gdb/testsuite/ChangeLog:

	* gdb.base/examine-backward.exp: Be more forgiving of failures to
	read some addresses.
---
 gdb/testsuite/ChangeLog                     |  5 ++++
 gdb/testsuite/gdb.base/examine-backward.exp | 42 ++++++++++++++++++++++++-----
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/gdb/testsuite/gdb.base/examine-backward.exp b/gdb/testsuite/gdb.base/examine-backward.exp
index be80b841aa8..548e72cc5cb 100644
--- a/gdb/testsuite/gdb.base/examine-backward.exp
+++ b/gdb/testsuite/gdb.base/examine-backward.exp
@@ -83,18 +83,46 @@ with_test_prefix "memory page boundary" {
 }
 
 with_test_prefix "address zero boundary" {
+    global gdb_prompt
+
     if {[is_address_zero_readable]} {
         set address_zero "0x0"
         set byte "\t0x\[0-9a-f\]+"
         gdb_test "x/3xb ${address_zero}" \
-            "0x\[0-9a-f\]+00.*:${byte}${byte}${byte}" \
+            "0x\[0-9a-f\]*0.*:${byte}${byte}${byte}" \
             "examine 3 bytes forward from ${address_zero}"
-        gdb_test "x/-6x" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}" \
-            "examine 6 bytes backward"
-        gdb_test "x/-3x ${address_zero}" \
-            "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}" \
-            "examine 3 bytes backward from ${address_zero}"
+
+	set test "examine 6 bytes backward"
+        gdb_test_multiple "x/-6x" "$test" {
+            -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+		pass $test
+	    }
+	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+		# We test that we can read zero, but that's no
+		# guarantee that we can read from the other end of the
+		# address space.  If we get an error about trying to
+		# read from the expected address then we count that as
+		# a pass, GDB did try to read the correct location.
+		pass $test
+	    }
+	    -re "$gdb_prompt $" {
+		fail $test
+	    }
+	}
+
+	set test "examine 3 bytes backward from ${address_zero}"
+        gdb_test_multiple "x/-3x ${address_zero}" "$test" {
+            -re "0x\[0-9a-f\]+fd.*:${byte}${byte}${byte}${byte}${byte}${byte}.*\[\r\n\]*$gdb_prompt $" {
+		pass $test
+	    }
+	    -re "0x\[0-9a-f\]+fd.*:\tCannot access memory at address 0x\[0-9a-f\]+fd.*\[\r\n\]*$gdb_prompt $" {
+		# See previous test for why this is a pass.
+		pass $test
+	    }
+	    -re "$gdb_prompt $" {
+		fail $test
+	    }
+	}
     }
 }
 
-- 
2.12.2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-07 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-04 18:13 [PATCH] gdb/testsuite: Allow for failure to read some memory addresses Andrew Burgess
2018-07-07  2:16 ` Simon Marchi
2018-07-07 10:33   ` Andrew Burgess
2018-07-07 14:05     ` Simon Marchi
  -- strict thread matches above, loose matches on Subject: below --
2018-02-02 19:42 Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).