public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "mehmetgelisin at aol dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug gdb/27750] local variables have wrong address and values on sparc64
Date: Fri, 10 Sep 2021 19:39:10 +0000	[thread overview]
Message-ID: <bug-27750-4717-vswE8ept9t@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27750-4717@http.sourceware.org/bugzilla/>

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

Mehmet gelisin <mehmetgelisin at aol dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mehmetgelisin at aol dot com

--- Comment #17 from Mehmet gelisin <mehmetgelisin at aol dot com> ---
gdb: fix value_subscript when array upper bound is not known
http://www-look-4.com/

    Since commit 7c6f27129631 ("gdb: make get_discrete_bounds check for
    non-constant range bounds"), subscripting  flexible array member fails:
    http://www.compilatori.com/
        struct no_size
        {
          int n;
          int items[]; http://www.wearelondonmade.com/
        };

        (gdb) p *ns http://www.jopspeech.com/
        $1 = {n = 3, items = 0x5555555592a4}
        (gdb) p ns->items[0]
        Cannot access memory at address 0xfffe555b733a0164 http://joerg.li/
        (gdb) p *((int *) 0x5555555592a4)
        $2 = 101  <--- we would expect that
        (gdb) p &ns->items[0] http://connstr.net/ 
        $3 = (int *) 0xfffe5559ee829a24  <--- wrong address

    Since the flexible array member (items) http://embermanchester.uk/  has an
unspecified size, the array type
    created for it in the DWARF http://www.slipstone.co.uk/  doesn't have
dimensions (this is with gcc 9.3.0,
    Ubuntu 20.04):

        0x000000a4:   DW_TAG_array_type
                        DW_AT_type [DW_FORM_ref4]   http://www.logoarts.co.uk/ 
   (0x00000038 "int")
                        DW_AT_sibling [DW_FORM_ref4]    (0x000000b3)

        0x000000ad:     DW_TAG_subrange_type
                          DW_AT_type [DW_FORM_ref4]     (0x00000031 "long
unsigned int")

    This causes GDB to create a range type (TYPE_CODE_RANGE) with a defined
    constant low bound (dynamic_prop with kind PROP_CONST) and an undefined
    high bound (dynamic_prop with kind PROP_UNDEFINED).
http://www.acpirateradio.co.uk/ 

    value_subscript gets both bounds of that range using
    get_discrete_bounds.  Before commit 7c6f27129631, get_discrete_bounds
    didn't check the kind of the dynamic_props and would just blindly read
    them as if they were PROP_CONST.  It would return 0 for the high bound,
    because we zero-initialize the range_bounds structure.  And it didn't
    really matter in this case, because the returned high bound wasn't used
    in the end. https://waytowhatsnext.com/ 

    Commit 7c6f27129631 changed get_discrete_bounds to return a failure if
    either the low or high bound is not a constant, to make sure we don't
    read a dynamic prop that isn't a PROP_CONST as a PROP_CONST.  This
    change made get_discrete_bounds start to return a failure for that
    range, and as a result would not set https://www.webb-dev.co.uk/  *lowp and
*highp.  And since
    value_subscript doesn't check get_discrete_bounds' return value, it just
    carries on an uses an uninitialized value for the low bound.  If
    value_subscript did check the return value of get_discrete_bounds, we
    would get an error message instead of a bogus value.  But it would still
    be a bug, as we wouldn't be able to print the flexible array member's
    elements. http://www.iu-bloomington.com/ 

    Looking at value_subscript, we see that the low bound is always needed,
    but the high bound is only needed if !c_style.  So, change
    value_subscript to use get_discrete_low_bound and
    get_discrete_high_bound separately.  This fixes the case described
    above, where the low bound is known but the high bound isn't (and is not
    needed).  This restores the original behavior without accessing a
    dynamic_prop in a wrong way.

    A test is added.  In addition to the case described above, a case with
    an array member of size 0 is added, which is a GNU C extension that
    existed before flexible array members were introduced.  That case
    currently fails when compiled with gcc <= 8.  gcc <= 8 produces DWARF
    similar to the one shown above, while gcc 9 adds a DW_AT_count of 0 in
    there, which makes the high bound known.  A case where an array member
    of size 0 is the only member of the struct is also added, as that was
    how PR 28675 was originally reported, and it's an interesting corner
    case that I think could trigger other funny bugs.
https://komiya-dental.com/

    Question about the implementation: in value_subscript, I made it such
    that if the low or high bound is unknown, we fall back to zero.  That
    effectively makes it the same as it was before 7c6f27129631.  But should
    we instead error() out?

    gdb/ChangeLog:

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

  parent reply	other threads:[~2021-09-10 19:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-17 16:15 [Bug gdb/27750] New: " dclarke at blastwave dot org
2021-04-17 16:51 ` [Bug gdb/27750] " tromey at sourceware dot org
2021-04-17 17:53 ` dclarke at blastwave dot org
2021-04-17 17:55 ` dclarke at blastwave dot org
2021-04-17 17:56 ` dclarke at blastwave dot org
2021-04-17 20:32 ` tromey at sourceware dot org
2021-04-17 22:55 ` dclarke at blastwave dot org
2021-04-18  1:21 ` simark at simark dot ca
2021-04-18  1:57 ` tromey at sourceware dot org
2021-04-19  0:51 ` simark at simark dot ca
2021-04-19 10:44 ` dclarke at blastwave dot org
2021-04-19 12:31 ` glaubitz at physik dot fu-berlin.de
2021-04-19 13:29 ` tromey at sourceware dot org
2021-06-27 17:54 ` ahmedsayeed1982 at yahoo dot com
2021-08-10 12:45 ` ucelsanicin at yahoo dot com
2021-08-23  6:05 ` marlenesanchez231+gaby at gmail dot com
2021-08-23  6:54 ` mark at klomp dot org
2021-09-02 11:06 ` donipah907 at mtlcz dot com
2021-09-06  9:09 ` focixujo at livinginsurance dot co.uk
2021-09-10 19:39 ` mehmetgelisin at aol dot com [this message]
2021-09-14 12:54 ` jarilittlenen at yahoo dot com
2021-09-22 10:19 ` diheto5497 at secbuf dot com
2021-09-28  1:38 ` marlenesanchez231+jaime at gmail dot com
2021-10-09 11:00 ` gulsenenginar at aol dot com
2021-10-10 16:11 ` oficaj3 at gmail dot com
2021-10-19  7:13 ` progonsaytu at gmail dot com
2021-10-24 10:01 ` glassmtech at ukr dot net

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-27750-4717-vswE8ept9t@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).