This is the mail archive of the gdb-prs@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]

[Bug gdb/20295] GDB segfaults printing structure member


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

Pedro Alves <palves at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |palves at redhat dot com

--- Comment #2 from Pedro Alves <palves at redhat dot com> ---
Thanks.  

So "a.j" is a bitfield, and gdb believes "a" is optimized out:

 (gdb) p a
 $1 = <optimized out>

however, printing "a.j" crashes, because gdb tries to extract the bitfield out
of the "a"'s contents, which are NULL.

This fixes the crash here:

 diff --git c/gdb/value.c w/gdb/value.c
 index cd59f43..3ad7999 100644
 --- c/gdb/value.c
 +++ w/gdb/value.c
 @@ -3954,7 +3954,7 @@ value_fetch_lazy (struct value *val)

        unpack_value_bitfield (val,
                              value_bitpos (val), value_bitsize (val),
 -                            value_contents_for_printing (parent),
 +                            value_contents (parent),
                              value_offset (val), parent);
      }
    else if (VALUE_LVAL (val) == lval_memory)

resulting in:

 (gdb) p a.j
 value has been optimized out

instead of the crash.

Haven't checked whether "a" should really be optimized out.  Is this what you
expected?

Haven't tried to run gdb's testsuite either.

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

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