<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LLDB displays wrong values for packed bitfields"
   href="https://bugs.llvm.org/show_bug.cgi?id=47743">47743</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LLDB displays wrong values for packed bitfields
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cameron@moodycamel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>