From: Andrew Burgess Date: Wed, 23 Mar 2022 15:23:47 +0000 (+0000) Subject: gdb/testsuite: fix copy & paste error in gdb.python/py-format-address.exp X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4daa9f295d07917610f0972e0cd45df8c51e69a2;p=binutils-gdb.git 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 --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 " \ + "Got: $bar_addr " \ "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 " \ + "Got: $bar_addr " \ "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 " \ + "Got: $bar_addr " \ "gdb.format_address for bar, while inferior 1 is selected, pass progspace and architecture" # Try pasing incorrect object types for program space and architecture.