Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Roman Popov <ripopov@gmail.com>
To: gdb@sourceware.org
Subject: Re: GDB returns wrong type when traversing optimized-out Fields
Date: Mon, 05 Feb 2018 04:07:00 -0000	[thread overview]
Message-ID: <CAATAM3Gu06j32JrVH=c9UU75knn7yUtZtY1hHwe5wLcsRp04Rw@mail.gmail.com> (raw)
In-Reply-To: <CAATAM3HO7rR4AOUepvgCAfy8KxmjoeXpQsAAdEA826D8+z_WmA@mail.gmail.com>

I apologize for code typo in previous email. Here is correct code sample:

template <unsigned v1, unsigned v2>
struct TRAITS {
    static const unsigned val1 = v1;
    static const unsigned val2 = v2;
};
template < class TRAITS >
struct foo {
    static const unsigned x1 = TRAITS::val1;
    static const unsigned x2 = TRAITS::val2;
};

int main () {
    foo<TRAITS<1,2>> f1;
    // SET BREAKPOINT HERE
    return 0;
}

-Roman


2018-02-04 20:02 GMT-08:00 Roman Popov <ripopov@gmail.com>:

> Hi all,
> I've encountered strange GDB behavior when requesting a value of
> optimized-away field.
> Instead of returning None or raising exception, GDB returns an
> optimizied-out value of wrong type.
>
> Here is a small reproducer *optimize_out.cpp*:
>
> template <unsigned v1, unsigned v2>
> struct TRAITS {
>     static const unsigned val1 = v1;
>     static const unsigned val2 = v2;
> };
> template < class TRAITS >
> struct foo {
>     static const unsigned x1 = TRAITS::v1;
>     static const unsigned x2 = TRAITS::v2;
> };
>
> int main () {
>     foo<TRAITS<1,2>> f1;
>     // SET BREAKPOINT HERE
>     return 0;
> }
>
> # Using g++ 7.3
> $ g++ -g optimize_out.cpp
>
> # Using gdb 8.1
> $ gdb a.out
>
> (gdb) break optimize_out.cpp:14
> (gdb) r
> (gdb) p f1
> $1 = {static x1 = <optimized out>, static x2 = <optimized out>}
>
> Ok, looks good.  Now traverse fields:
>
> (gdb) python
> >f1 = gdb.parse_and_eval("f1")
> >for field in f1.type.fields():
> >    print ("field name: ", field.name, "field type: ", field.type)
> >    field_val = f1[field]
> >    print ("optout?: ",field_val.is_optimized_out, "type:
> ",field_val.type)
> >end
> field name:  x1 field type:  const unsigned int
> optout?:  True type:  foo<TRAITS<1, 2> >
> field name:  x2 field type:  const unsigned int
> optout?:  True type:  foo<TRAITS<1, 2> >
>
>
>
> So type we get is foo<TRAITS<1, 2> >, not unsigned int.
>
> Looks like GDB-MI has same behavior. At least this code sample totatlly
> confuses GDB GUI I use.
>
> Thanks,
> Roman
>


  reply	other threads:[~2018-02-05  4:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-05  4:02 Roman Popov
2018-02-05  4:07 ` Roman Popov [this message]
2018-02-05  5:39   ` Simon Marchi
2018-02-05  6:20     ` Roman Popov

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='CAATAM3Gu06j32JrVH=c9UU75knn7yUtZtY1hHwe5wLcsRp04Rw@mail.gmail.com' \
    --to=ripopov@gmail.com \
    --cc=gdb@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