public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp
@ 2022-03-29 13:37 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-03-29 13:37 UTC (permalink / raw)
  To: gdb-cvs

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

commit 4daa9f295d07917610f0972e0cd45df8c51e69a2
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Mar 23 15:23:47 2022 +0000

    gdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp
    
    The test gdb.python/py-format-address.exp, added in commit:
    
      commit 25209e2c6979c3838e14e099f0333609810db280
      Date:   Sat Oct 23 09:59:25 2021 +0100
    
          gdb/python: add gdb.format_address function
    
    included 3 copy & paste errors where the wrong address was used in the
    expected output patterns.
    
    The test compiles two almost identical test binaries (one function
    changes its name, that's the only difference), two inferiors are
    created, each inferior using one of the test binaries.
    
    We then take the address of the name changing function in both
    inferiors ('foo' in inferior 1 and 'bar' in inferior 2) and the tests
    are carried out using these addresses.
    
    What we're checking for is that symbols 'foo' and 'bar' show up in the
    correct inferior, and that (as this test is for a Python API feature),
    the user can have one inferior selected, but ask about the other
    inferior, and see the correct symbol in the result.
    
    The hope is that the two binaries will be laid out identically by the
    compiler, and that 'foo' and 'bar' will be at the same address.  This
    is fine, unless the executable is compiled as PIE (position
    independent executable), in which case there is a problem.
    
    The problem is that though inferior 1 is set running, the inferior 2
    never is.  If the executables are compiled as PIE, then the address in
    the inferior 2 will not have been resolved, while the address in the
    inferior 1 will have been, and so the two addresses we use in the
    tests will be different.
    
    This issue was reported here:
    
      https://sourceware.org/pipermail/gdb-patches/2022-March/186911.html
    
    The first part of the fix is to use the correct address variable in
    the expected output patterns, with this change the tests pass even
    when the executables are compiled as PIE.
    
    A second part of this fix is to pass the 'nopie' option when we
    compile the tests, this should ensure that the address obtained in
    inferior 2 is the same as the address from inferior 1, which makes the
    test more useful.

Diff:
---
 gdb/testsuite/gdb.python/py-format-address.exp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp
index 5c808299d34..bbfe658c0bb 100644
--- a/gdb/testsuite/gdb.python/py-format-address.exp
+++ b/gdb/testsuite/gdb.python/py-format-address.exp
@@ -20,6 +20,7 @@ foreach func_name { foo bar } {
     if {[build_executable "build binary with ${func_name} function" \
 	     "$testfile-${func_name}" $srcfile \
 	     [list debug \
+		  nopie \
 		  additional_flags=-DFUNCTION_NAME=${func_name}]] == -1} {
 	return -1
     }
@@ -138,19 +139,19 @@ set bar_addr [get_hexadecimal_valueof "&bar" "UNKNOWN"]
 # architecture, this should display the 'bar' symbol rather than
 # 'foo'.
 gdb_test "python print(\"Got: \" + gdb.format_address($bar_addr))" \
-    "Got: $foo_addr <bar>" \
+    "Got: $bar_addr <bar>" \
     "gdb.format_address for bar, while inferior 2 is selected"
 
 # And again, but this time, specificy the program space and
 # architecture.
 gdb_test "python print(\"Got: \" + gdb.format_address($bar_addr, inf2.progspace, inf2.architecture()))" \
-    "Got: $foo_addr <bar>" \
+    "Got: $bar_addr <bar>" \
     "gdb.format_address for bar, while inferior 2 is selected, pass progspace and architecture"
 
 # Reselect inferior 1, and then format an address from inferior 2.
 gdb_test "inferior 1" ".*"
 gdb_test "python print(\"Got: \" + gdb.format_address($bar_addr, inf2.progspace, inf2.architecture()))" \
-    "Got: $foo_addr <bar>" \
+    "Got: $bar_addr <bar>" \
     "gdb.format_address for bar, while inferior 1 is selected, pass progspace and architecture"
 
 # Try pasing incorrect object types for program space and architecture.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-29 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 13:37 [binutils-gdb] gdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp 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).