[lldb-dev] [Bug 47743] New: LLDB displays wrong values for packed bitfields

via lldb-dev lldb-dev at lists.llvm.org
Tue Oct 6 11:26:22 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47743

            Bug ID: 47743
           Summary: LLDB displays wrong values for packed bitfields
           Product: lldb
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: lldb-dev at lists.llvm.org
          Reporter: cameron at moodycamel.com
                CC: jdevlieghere at apple.com, llvm-bugs at lists.llvm.org

When an 'unsigned' bitfield is in a packed structure, its bits may straddle two
aligned dwords in memory.

LLDB calculates the value by reading a single dword from the byte offset of the
first unsigned, then shifting and masking using the bitfield offset/size.
However, when the value straddles two unsigned dwords, the byte offset + bit
offset + size extends past the end of the first dword, and the displayed value
is cut off (missing trailing bits).

To reproduce on a little-endian machine:

struct __attribute__((packed)) foo
{
        unsigned : 31;
        unsigned u11Sample : 11;
        unsigned : 22;
};

__attribute__((noinline))
int quux(struct foo* f)
{
        // break here and inspect f->u11Sample
        // the value should be 0x50, but it's not displayed as such
        return f->u11Sample;
}

int main()
{
        struct foo f = { 0 };
        f.u11Sample = 0x50;
        return quux(&f);
}

To reproduce on a big-endian machine use this struct definition instead:

struct __attribute__((packed)) foo
{
        unsigned : 22;
        unsigned u11Sample : 11;
        unsigned : 31;
};


As a starting point for whoever wants to investigate this, put a breakpoint on
'valobj->GetData(data, error);' (near line 91) in TypeFormat.cpp. Observe the
data read, as well as the
m_byte_offset/m_bitfield_bit_size/m_bitfield_bit_offset in valobj (it's of type
ValueObjectChild).

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20201006/daec1e6b/attachment.html>


More information about the lldb-dev mailing list