This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GDB returns wrong type when traversing optimized-out Fields


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]