public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug c++/29011] Python Value.dynamic_cast does not work as expected
Date: Mon, 11 Dec 2023 14:53:05 +0000	[thread overview]
Message-ID: <bug-29011-4717-EfhHaZzL4i@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-29011-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=29011

--- Comment #5 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Hannes Domani <ssbssa@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0238b543f3c294fc8512021a40b708e8ddc72bb2

commit 0238b543f3c294fc8512021a40b708e8ddc72bb2
Author: Hannes Domani <ssbssa@yahoo.de>
Date:   Tue Mar 29 20:05:06 2022 +0200

    Fix dynamic_cast

    PR29011 notes that dynamic_cast does not work correctly if
    classes with virtual methods are involved, some of the results
    wrongly point into the vtable of the derived class:
    ```
    (gdb) p vlr
    $1 = (VirtualLeftRight *) 0x162240
    (gdb) p vl
    $2 = (VirtualLeft *) 0x162240
    (gdb) p vr
    $3 = (VirtualRight *) 0x162250
    (gdb) p dynamic_cast<VirtualLeftRight*>(vlr)
    $4 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
    (gdb) p dynamic_cast<VirtualLeftRight*>(vl)
    $5 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
    (gdb) p dynamic_cast<VirtualLeftRight*>(vr)
    $6 = (VirtualLeftRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
    (gdb) p dynamic_cast<VirtualLeft*>(vlr)
    $7 = (VirtualLeft *) 0x162240
    (gdb) p dynamic_cast<VirtualLeft*>(vl)
    $8 = (VirtualLeft *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
    (gdb) p dynamic_cast<VirtualLeft*>(vr)
    $9 = (VirtualLeft *) 0x162240
    (gdb) p dynamic_cast<VirtualRight*>(vlr)
    $10 = (VirtualRight *) 0x162250
    (gdb) p dynamic_cast<VirtualRight*>(vl)
    $11 = (VirtualRight *) 0x162250
    (gdb) p dynamic_cast<VirtualRight*>(vr)
    $12 = (VirtualRight *) 0x13fab89b0 <vtable for VirtualLeftRight+16>
    ```

    For the cases where the dynamic_cast type is the same as the
    original type, it used the ARG value for the result, which in
    case of pointer types was already the dereferenced value.

    And the TEM value at the value address was created with the
    pointer/reference type, not the actual class type.

    With these fixed, the dynamic_cast results make more sense:
    ```
    (gdb) p vlr
    $1 = (VirtualLeftRight *) 0x692240
    (gdb) p vl
    $2 = (VirtualLeft *) 0x692240
    (gdb) p vr
    $3 = (VirtualRight *) 0x692250
    (gdb) p dynamic_cast<VirtualLeftRight*>(vlr)
    $4 = (VirtualLeftRight *) 0x692240
    (gdb) p dynamic_cast<VirtualLeftRight*>(vl)
    $5 = (VirtualLeftRight *) 0x692240
    (gdb) p dynamic_cast<VirtualLeftRight*>(vr)
    $6 = (VirtualLeftRight *) 0x692240
    (gdb) p dynamic_cast<VirtualLeft*>(vlr)
    $7 = (VirtualLeft *) 0x692240
    (gdb) p dynamic_cast<VirtualLeft*>(vl)
    $8 = (VirtualLeft *) 0x692240
    (gdb) p dynamic_cast<VirtualLeft*>(vr)
    $9 = (VirtualLeft *) 0x692240
    (gdb) p dynamic_cast<VirtualRight*>(vlr)
    $10 = (VirtualRight *) 0x692250
    (gdb) p dynamic_cast<VirtualRight*>(vl)
    $11 = (VirtualRight *) 0x692250
    (gdb) p dynamic_cast<VirtualRight*>(vr)
    $12 = (VirtualRight *) 0x692250
    ```

    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29011
    Approved-By: Tom Tromey <tom@tromey.com>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-12-11 14:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30 23:55 [Bug python/29011] New: " evan_l00 at qq dot com
2022-03-31 15:38 ` [Bug python/29011] " ssbssa at sourceware dot org
2022-03-31 17:09 ` simark at simark dot ca
2022-04-02 16:00 ` tromey at sourceware dot org
2023-07-31 14:45 ` [Bug c++/29011] " tromey at sourceware dot org
2023-12-11 14:53 ` cvs-commit at gcc dot gnu.org [this message]
2023-12-11 14:55 ` ssbssa at sourceware dot org

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=bug-29011-4717-EfhHaZzL4i@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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).