From: Andrew Burgess <aburgess@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: [PATCHv3] gdb/python: add gdb.format_address function
Date: Tue, 29 Mar 2022 14:38:27 +0100 [thread overview]
Message-ID: <87pmm4anfw.fsf@redhat.com> (raw)
In-Reply-To: <7afdf076-59f9-4655-0dc8-1ac2f9d07e70@polymtl.ca>
Simon Marchi <simon.marchi@polymtl.ca> writes:
>> Hi Simon,
>>
>> Sorry for that. I can't reproduce these failures, but I suspect I know
>> what's going on. Could you try the patch below please and confirm that
>> this fixes the issues.
>>
>> Many thanks,
>> Andrew
>>
>> ---
>>
>> commit d6eb0c69d3919a1b3862d29c788415ca9f7bbeb4
>> 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), if the two binaries are
>> laid out the same by the compiler, and loaded at the same locations in
>> memory, then the two addresses would have been the same. However,
>> this is not the case for everyone, and so some folk were seeing test
>> failures:
>>
>> https://sourceware.org/pipermail/gdb-patches/2022-March/186911.html
>>
>> This commit fixes the errors by using the correct addresses.
>
> Hi Andrew,
>
> I looked into this separately because I failed to see your message. In
> the end I came up with the same change, but the reason the addresses are
> different is that the executables are PIE. Inferior 1 is running, so
> the function address is relocated:
>
> print /x &foo^M
> $2 = 0x555555555129^M
>
> Inferior 2 is not running, so the function address is unrelocated:
>
> print /x &bar^M
> $3 = 0x1129^M
>
> So, the patch LGTM, but you can clarify the commit message if you want.
I pushed the patch below.
This updates the commit message, but also, I pass the 'nopie' option
when compiling the test binaries, which should make the test more useful
(the addresses should now be the same).
Thanks,
Andrew
---
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 --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.
prev parent reply other threads:[~2022-03-29 13:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-11 16:17 [PATCH] gdb/python: add gdb.Architecture.format_address Andrew Burgess
2022-02-11 18:54 ` Eli Zaretskii
2022-02-21 17:27 ` Andrew Burgess
2022-02-21 18:02 ` Eli Zaretskii
2022-02-22 13:56 ` Andrew Burgess
2022-02-22 14:48 ` Eli Zaretskii
2022-02-23 14:20 ` Andrew Burgess
2022-03-03 16:49 ` Andrew Burgess
2022-03-03 18:35 ` Craig Blackmore
2022-03-04 10:51 ` Andrew Burgess
2022-03-04 10:50 ` [PATCHv2] " Andrew Burgess
2022-03-04 15:22 ` Simon Marchi
2022-03-07 12:33 ` [PATCHv3] gdb/python: add gdb.format_address function Andrew Burgess
2022-03-21 17:53 ` Andrew Burgess
2022-03-21 18:23 ` Simon Marchi
2022-03-22 13:19 ` Andrew Burgess
2022-03-23 12:14 ` Simon Marchi
2022-03-23 15:30 ` Andrew Burgess
2022-03-28 21:59 ` Simon Marchi
2022-03-29 13:38 ` Andrew Burgess [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pmm4anfw.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).