From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B8CC33858C50 for ; Wed, 23 Mar 2022 15:30:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B8CC33858C50 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-QzGID8OTNEOgueLa2f4DdQ-1; Wed, 23 Mar 2022 11:30:24 -0400 X-MC-Unique: QzGID8OTNEOgueLa2f4DdQ-1 Received: by mail-wm1-f69.google.com with SMTP id o10-20020a1c4d0a000000b0038c6e5fcbaeso721730wmh.9 for ; Wed, 23 Mar 2022 08:30:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Gby97sh3PDLm2C1z4SkWMh7nPYGiSYPyeUjnlRh7yoY=; b=3AQKyLgdxL8bs4kGy5kLf2G+x2yW27lKBgsGhiwih9dgQH5HRzls5ublVCeAwI02Ea DA8P3xktTPh+vuFo88OVzbXV54UPr2FjqIi48u6XTAeBOK7Keoxgq38Uagn1XaL6kgmr loMwvhs0xtvHnKT4EDcoeOBY8YaomDrDCDTNKqoeju+7sxdWJHfbWE1TpB7P21NoBFYR JqR3sqnCqEo5lNzzRYgsA0OYYQg4cjZq8QGDyrQ8g70EQMStUZ+mMsUjKD+WASrdMwWB 0uuTxhB1Nu7th+Qxc/18PKL1X4Vh+Vvk1ys3LGf+ND/furFncAII0FtaveEPvvn0VhOV a1PA== X-Gm-Message-State: AOAM533Tf2j2FYHMK1k/9bg1GKXzRg1MBfK5nlOgOiBPxxwOL7tSae5B XQ3aInQ1AQlYiqXKuWDiET7muoz7WdYstBwnuIILuMs7ufOQxWRRY5jZmZdlvu7kFoEXYmyYFHt juht/9YJNnIOSLJnuU19H9A== X-Received: by 2002:adf:f40c:0:b0:203:e768:ae54 with SMTP id g12-20020adff40c000000b00203e768ae54mr343153wro.488.1648049422852; Wed, 23 Mar 2022 08:30:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhYcgDQHZFSLWDFyhT0FzG+yrPEUr5AT04Rjn1b7kxQ+HGeFpCUNrEXr8sGelWcvBvBaWIUg== X-Received: by 2002:adf:f40c:0:b0:203:e768:ae54 with SMTP id g12-20020adff40c000000b00203e768ae54mr343133wro.488.1648049422552; Wed, 23 Mar 2022 08:30:22 -0700 (PDT) Received: from localhost (host109-158-45-15.range109-158.btcentralplus.com. [109.158.45.15]) by smtp.gmail.com with ESMTPSA id a18-20020a05600c349200b0038ca453a887sm4323009wmq.19.2022.03.23.08.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 08:30:22 -0700 (PDT) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Cc: Andrew Burgess Subject: Re: [PATCHv3] gdb/python: add gdb.format_address function In-Reply-To: References: <20220304105031.2706582-1-aburgess@redhat.com> <20220307123317.3966024-1-aburgess@redhat.com> <87o81yruo9.fsf@redhat.com> Date: Wed, 23 Mar 2022 15:30:20 +0000 Message-ID: <87ils4sn3n.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Mar 2022 15:30:28 -0000 Simon Marchi via Gdb-patches writes: > On 2022-03-22 09:19, Andrew Burgess wrote: >> Simon Marchi via Gdb-patches 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 ^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 ^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 ^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 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 " \ + "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.