From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B453938515FF; Wed, 30 Mar 2022 23:55:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B453938515FF From: "evan_l00 at qq dot com" To: gdb-prs@sourceware.org Subject: [Bug python/29011] New: Python Value.dynamic_cast does not work as expected Date: Wed, 30 Mar 2022 23:55:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: python X-Bugzilla-Version: 11.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: evan_l00 at qq dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2022 23:55:09 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29011 Bug ID: 29011 Summary: Python Value.dynamic_cast does not work as expected Product: gdb Version: 11.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: python Assignee: unassigned at sourceware dot org Reporter: evan_l00 at qq dot com Target Milestone: --- The document says that Value.dynamic_cast works like dynamic cast in C++, b= ut in the following experiment, it shows that the Value.cast works in C++, and Value.dynamic_cast gives some value I don't understand. I have asked on the stackoverflow in https://stackoverflow.com/questions/71644182/gdb-python-api-dynamic-cast-no= t-work-as-expected, but received a comment that says this might be a bug in the gdb. So I open = this ticket. This is the sample code class Base { public: virtual void p() {} int i =3D3; }; class Base2 { public: virtual void f() {} int i2 =3D4; }; class Derived: public Base, public Base2{ public: void p() override{} int t =3D4; }; int main() { auto* p =3D new Derived(); Base2* pb2 =3D p; Base* pb =3D p; return 0; } Run the code, and print the values of p, pb, and pb2 (gdb) p p $1 =3D (Derived *) 0x613c20 (gdb) p pb //=20 $2 =3D (Base *) 0x613c20 (gdb) p pb2 $3 =3D (Base2 *) 0x613c30 Then use python script to print the value as follows, the Value.dynamic_cast will give (gdb) py print(ppb2.dynamic_cast(ppb2.dynamic_type)) 0x400808 And the Value.cast gives the correct derived pointer, (gdb) py print(ppb2.cast(ppb2.dynamic_type)) 0x613c20 pp, ppb, and ppb2 are the corresponding values but in Python env, got from = the following code. (gdb) py pp =3D gdb.parse_and_eval('p') (gdb) py print(pp) 0x613c20 (gdb) py ppb2 =3D gdb.parse_and_eval('pb2') (gdb) py print(ppb2) 0x613c30 (gdb) py print(ppb2.cast(ppb2.dynamic_type)) 0x613c20 (gdb) py print(ppb2.dynamic_cast(ppb2.dynamic_type)) 0x400808 Why Value.dynamic_cast will give 0x400808 instead of 0x613c20 (the derived pointer)? --=20 You are receiving this mail because: You are on the CC list for the bug.=