public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: Disable address space randomization for a test
@ 2018-07-30 18:50 Andrew Burgess
  2018-07-30 18:56 ` Paul Koning
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2018-07-30 18:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

The gdb.opt/inline-break.exp test script relies on capturing a $pc
value in one run of GDB, then restarting GDB and placing a breakpoint
at the previously captured $pc and checking we get the expected
behaviour.

With address space randomization on then the captured $pc value is
almost never valid in the second run of GDB, and so the test fails.

Disabling address space randomization where appropriate fixes this
issue.

gdb/testsuite/ChangeLog:

	* gdb.opt/inline-break.exp: Disable address space randomization
	for the two runs where we care about addresses being consistent.
---
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.opt/inline-break.exp | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/testsuite/gdb.opt/inline-break.exp b/gdb/testsuite/gdb.opt/inline-break.exp
index aed38ed631f..00a5467d617 100644
--- a/gdb/testsuite/gdb.opt/inline-break.exp
+++ b/gdb/testsuite/gdb.opt/inline-break.exp
@@ -264,6 +264,12 @@ set line [gdb_get_line_number "break here"]
 with_test_prefix "line number" {
     clean_restart $binfile
 
+    # At the end of this test we store a $pc value, then restart GDB,
+    # and use this $pc value to place a breakpoint.  If address space
+    # randomization is on, then the chance of this $pc value being
+    # correct in a second GDB instance is pretty small.
+    gdb_test "set disable-randomization off"
+
     if {![runto main]} {
 	untested "could not run to main"
 	continue
@@ -289,6 +295,12 @@ with_test_prefix "address" {
 
     clean_restart $binfile
 
+    # We're about to reuse the $pc value from a prevous run of GDB.
+    # Ensure address space randomization is off so that the inferior
+    # is placed at the same address as previous, and the stored $pc
+    # will still be valid.
+    gdb_test "set disable-randomization off"
+
     if {![runto main]} {
 	untested "could not run to main"
 	continue
-- 
2.14.4

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-30 18:50 [PATCH] gdb: Disable address space randomization for a test Andrew Burgess
@ 2018-07-30 18:56 ` Paul Koning
  2018-07-30 19:02   ` Andrew Burgess
  2018-07-31 14:23   ` Tom Tromey
  0 siblings, 2 replies; 7+ messages in thread
From: Paul Koning @ 2018-07-30 18:56 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches



> On Jul 30, 2018, at 2:50 PM, Andrew Burgess <andrew.burgess@embecosm.com> wrote:
> 
> The gdb.opt/inline-break.exp test script relies on capturing a $pc
> value in one run of GDB, then restarting GDB and placing a breakpoint
> at the previously captured $pc and checking we get the expected
> behaviour.
> 
> With address space randomization on then the captured $pc value is
> almost never valid in the second run of GDB, and so the test fails.
> 
> Disabling address space randomization where appropriate fixes this
> issue.
> 
> ...
> 
> +    # At the end of this test we store a $pc value, then restart GDB,
> +    # and use this $pc value to place a breakpoint.  If address space
> +    # randomization is on, then the chance of this $pc value being
> +    # correct in a second GDB instance is pretty small.
> +    gdb_test "set disable-randomization off"

Does that turn off address randomization?  The keyword implies the opposite (double negative, so "disable... off" means "turn on").

Also, does this work on every target OS?

	paul

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-30 18:56 ` Paul Koning
@ 2018-07-30 19:02   ` Andrew Burgess
  2018-07-30 19:49     ` Simon Marchi
  2018-07-31 14:23   ` Tom Tromey
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2018-07-30 19:02 UTC (permalink / raw)
  To: Paul Koning; +Cc: gdb-patches

* Paul Koning <paulkoning@comcast.net> [2018-07-30 14:56:32 -0400]:

> 
> 
> > On Jul 30, 2018, at 2:50 PM, Andrew Burgess <andrew.burgess@embecosm.com> wrote:
> > 
> > The gdb.opt/inline-break.exp test script relies on capturing a $pc
> > value in one run of GDB, then restarting GDB and placing a breakpoint
> > at the previously captured $pc and checking we get the expected
> > behaviour.
> > 
> > With address space randomization on then the captured $pc value is
> > almost never valid in the second run of GDB, and so the test fails.
> > 
> > Disabling address space randomization where appropriate fixes this
> > issue.
> > 
> > ...
> > 
> > +    # At the end of this test we store a $pc value, then restart GDB,
> > +    # and use this $pc value to place a breakpoint.  If address space
> > +    # randomization is on, then the chance of this $pc value being
> > +    # correct in a second GDB instance is pretty small.
> > +    gdb_test "set disable-randomization off"
> 
> Does that turn off address randomization?  The keyword implies the
> opposite (double negative, so "disable... off" means "turn on").

That's a very good question... now I just have to figure out why my
incorrect patch fixed the problem I was seeing.... watch this space...

> Also, does this work on every target OS?

That's a good question, I don't have an answer for you.

Thanks,
Andrew

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-30 19:02   ` Andrew Burgess
@ 2018-07-30 19:49     ` Simon Marchi
  2018-07-31 12:47       ` Andrew Burgess
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2018-07-30 19:49 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Paul Koning, gdb-patches

On 2018-07-30 15:01, Andrew Burgess wrote:
>> Does that turn off address randomization?  The keyword implies the
>> opposite (double negative, so "disable... off" means "turn on").
> 
> That's a very good question... now I just have to figure out why my
> incorrect patch fixed the problem I was seeing.... watch this space...

GDB usually disables address randomization by default, so I was also 
wondering why this would be needed.  Do you have a scenario where GDB 
doesn't disable it by default?

Simon

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-30 19:49     ` Simon Marchi
@ 2018-07-31 12:47       ` Andrew Burgess
  2018-07-31 13:32         ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2018-07-31 12:47 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Paul Koning, gdb-patches

* Simon Marchi <simon.marchi@polymtl.ca> [2018-07-30 15:49:01 -0400]:

> On 2018-07-30 15:01, Andrew Burgess wrote:
> > > Does that turn off address randomization?  The keyword implies the
> > > opposite (double negative, so "disable... off" means "turn on").
> > 
> > That's a very good question... now I just have to figure out why my
> > incorrect patch fixed the problem I was seeing.... watch this space...
> 
> GDB usually disables address randomization by default, so I was also
> wondering why this would be needed.  Do you have a scenario where GDB
> doesn't disable it by default?

Thank you to you both for pointing me in the right direction.

It turned out the mistake was user error.  I've recently switched to a
jenkins/docker combo to try and streamline testing my patches.

When running GDB under docker I'm having to supply the '--privileged'
flag in order to allow GDB to function correctly.

The problem was that I use a separate docker instance to build GDB and
then a set of instances to test GDB in different modes (native,
gdbserver, etc).  When testing GDB I supplied the '--privileged', but
not when building GDB.  As a result configure decided that my system
didn't support the personality API, and so all the code to disable
address space randomization was not compiled into GDB.

As for why I failed to spot this, again user error, but far less
interesting, I forgot I pushed a change to the scripts I used for
comparing test results.

Anyway, sorry for the noise, and thanks for the help figuring out my
mistakes.

Thanks,
Andrew

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-31 12:47       ` Andrew Burgess
@ 2018-07-31 13:32         ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2018-07-31 13:32 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Paul Koning, gdb-patches

On 2018-07-31 08:47, Andrew Burgess wrote:
> * Simon Marchi <simon.marchi@polymtl.ca> [2018-07-30 15:49:01 -0400]:
> 
>> On 2018-07-30 15:01, Andrew Burgess wrote:
>> > > Does that turn off address randomization?  The keyword implies the
>> > > opposite (double negative, so "disable... off" means "turn on").
>> >
>> > That's a very good question... now I just have to figure out why my
>> > incorrect patch fixed the problem I was seeing.... watch this space...
>> 
>> GDB usually disables address randomization by default, so I was also
>> wondering why this would be needed.  Do you have a scenario where GDB
>> doesn't disable it by default?
> 
> Thank you to you both for pointing me in the right direction.
> 
> It turned out the mistake was user error.  I've recently switched to a
> jenkins/docker combo to try and streamline testing my patches.
> 
> When running GDB under docker I'm having to supply the '--privileged'
> flag in order to allow GDB to function correctly.
> 
> The problem was that I use a separate docker instance to build GDB and
> then a set of instances to test GDB in different modes (native,
> gdbserver, etc).  When testing GDB I supplied the '--privileged', but
> not when building GDB.  As a result configure decided that my system
> didn't support the personality API, and so all the code to disable
> address space randomization was not compiled into GDB.
> 
> As for why I failed to spot this, again user error, but far less
> interesting, I forgot I pushed a change to the scripts I used for
> comparing test results.
> 
> Anyway, sorry for the noise, and thanks for the help figuring out my
> mistakes.
> 
> Thanks,
> Andrew

Well, that's good information to know, thanks!

Simon

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

* Re: [PATCH] gdb: Disable address space randomization for a test
  2018-07-30 18:56 ` Paul Koning
  2018-07-30 19:02   ` Andrew Burgess
@ 2018-07-31 14:23   ` Tom Tromey
  1 sibling, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2018-07-31 14:23 UTC (permalink / raw)
  To: Paul Koning; +Cc: Andrew Burgess, gdb-patches

Paul> Also, does this work on every target OS?

It doesn't.  The target has to implement the
supports_disable_randomization method, and then actually implement the
disabling.  At least macOS doesn't do this (see
https://sourceware.org/bugzilla/show_bug.cgi?id=23365), and probably
others as well.

Tom

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30 18:50 [PATCH] gdb: Disable address space randomization for a test Andrew Burgess
2018-07-30 18:56 ` Paul Koning
2018-07-30 19:02   ` Andrew Burgess
2018-07-30 19:49     ` Simon Marchi
2018-07-31 12:47       ` Andrew Burgess
2018-07-31 13:32         ` Simon Marchi
2018-07-31 14:23   ` Tom Tromey

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).