public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
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: Wed, 23 Mar 2022 15:30:20 +0000	[thread overview]
Message-ID: <87ils4sn3n.fsf@redhat.com> (raw)
In-Reply-To: <a356d9d1-e645-5f88-1e83-1a4dd639ae2d@polymtl.ca>

Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

> On 2022-03-22 09:19, Andrew Burgess wrote:
>> Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>> 
>>>> diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
>>>> index 0f273b344e4..53906ce506e 100644
>>>> --- a/gdb/python/py-arch.c
>>>> +++ b/gdb/python/py-arch.c
>>>> @@ -62,16 +62,25 @@ arch_object_data_init (struct gdbarch *gdbarch)
>>>>  }
>>>>
>>>>  /* Returns the struct gdbarch value corresponding to the given Python
>>>> -   architecture object OBJ.  */
>>>> +   architecture object OBJ, which must be a gdb.Architecture object.  */
>>>>
>>>>  struct gdbarch *
>>>>  arch_object_to_gdbarch (PyObject *obj)
>>>>  {
>>>> -  arch_object *py_arch = (arch_object *) obj;
>>>> +  gdb_assert (PyObject_TypeCheck (obj, &arch_object_type));
>>>
>>> Since we have a function for that, I'd do:
>>>
>>>   gdb_assert (gdbpy_is_architecture (obj));
>>>
>>>> diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
>>>> index 1e01068c59b..f9f2a969e2b 100644
>>>> --- a/gdb/python/py-progspace.c
>>>> +++ b/gdb/python/py-progspace.c
>>>> @@ -504,6 +504,23 @@ pspace_to_pspace_object (struct program_space *pspace)
>>>>    return gdbpy_ref<>::new_reference (result);
>>>>  }
>>>>
>>>> +/* See python-internal.h.  */
>>>> +
>>>> +struct program_space *
>>>> +progspace_object_to_program_space (PyObject *obj)
>>>> +{
>>>> +  gdb_assert (PyObject_TypeCheck (obj, &pspace_object_type));
>>>
>>> Same here, use gdbpy_is_progspace.
>>>
>>> Otherwise, LGTM.
>> 
>> Thanks, I made those changes and pushed this patch.
>> 
>> Andrew
>> 
>
> Hmm, I see these failures:
>
> 145 python print("Got: " + gdb.format_address(0x1129))^M
> 146 Got: 0x1129 <bar>^M
> 147 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 2 is selected
> 148 python print("Got: " + gdb.format_address(0x1129, inf2.progspace, inf2.architecture()))^M
> 149 Got: 0x1129 <bar>^M
> 150 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 2 is selected, pass progspace and architecture
> 151 inferior 1^M
> 152 [Switching to inferior 1 [process 1874961] (/home/smarchi/build/binutils-gdb/gdb/testsuite/outputs/gdb.python/py-format-address/py-format-address-foo)]^M
> 153 [Switching to thread 1.1 (process 1874961)]^M
> 154 #0  main () at /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.python/py-format-address.c:31^M
> 155 31        return FUNCTION_NAME ();^M
> 156 (gdb) PASS: gdb.python/py-format-address.exp: inferior 1
> 157 python print("Got: " + gdb.format_address(0x1129, inf2.progspace, inf2.architecture()))^M
> 158 Got: 0x1129 <bar>^M
> 159 (gdb) FAIL: gdb.python/py-format-address.exp: gdb.format_address for bar, while inferior 1 is selected, pass progspace and architecture

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.

diff --git a/gdb/testsuite/gdb.python/py-format-address.exp b/gdb/testsuite/gdb.python/py-format-address.exp
index 5c808299d34..70ca5d5ae59 100644
--- a/gdb/testsuite/gdb.python/py-format-address.exp
+++ b/gdb/testsuite/gdb.python/py-format-address.exp
@@ -138,19 +138,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.


  reply	other threads:[~2022-03-23 15:30 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 [this message]
2022-03-28 21:59             ` Simon Marchi
2022-03-29 13:38               ` Andrew Burgess

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=87ils4sn3n.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).