[Lldb-commits] [PATCH] D65492: Adjust a ValueObjectChild's offset when the child is a bitfield

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 30 17:19:41 PDT 2019


aprantl created this revision.
aprantl added reviewers: jingham, jasonmolenda.
Herald added a project: LLDB.

If a bitfield doesn't fit into the child_byte_size'd window at child_byte_offset, move the window (= child_byte_offset) forward until it fits.

This was not in the big-endian-derived DWARF 2 bitfield attributes because their offsets were counted from the end of the window, so they always fit.

rdar://problem/53132189


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65492

Files:
  lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
  lldb/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
  lldb/source/Core/ValueObject.cpp


Index: lldb/source/Core/ValueObject.cpp
===================================================================
--- lldb/source/Core/ValueObject.cpp
+++ lldb/source/Core/ValueObject.cpp
@@ -618,6 +618,18 @@
     if (!child_name_str.empty())
       child_name.SetCString(child_name_str.c_str());
 
+    // If a bitfield doesn't fit into the child_byte_size'd window at
+    // child_byte_offset, move the window (= child_byte_offset)
+    // forward until it fits.
+    uint32_t child_bit_size = child_byte_size * 8;
+    if (child_bitfield_bit_size + child_bitfield_bit_offset > child_bit_size) {
+      uint32_t overhang_bits =
+          (child_bitfield_bit_size + child_bitfield_bit_offset) - child_bit_size;
+      uint32_t overhang_bytes = (overhang_bits + 7) / 8;
+      child_byte_offset += overhang_bytes;
+      child_bitfield_bit_offset -= overhang_bytes * 8;
+    }
+
     valobj = new ValueObjectChild(
         *this, child_compiler_type, child_name, child_byte_size,
         child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
Index: lldb/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
+++ lldb/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
@@ -90,6 +90,14 @@
     packed.b = 10;
     packed.c = 0x7112233;
 
+    struct LargePackedBits {
+        unsigned long a: 36;
+        unsigned long b: 36;
+    } __attribute__((packed));
+
+    struct LargePackedBits large_packed =
+      (struct LargePackedBits){ 0xcbbbbaaaa, 0xdffffeeee };
+    
     return 0;               //// Set break point at this line.
 
 }
Index: lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
+++ lldb/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
@@ -148,6 +148,9 @@
                 '(uint8_t:1) b17 = \'\\0\'',
                 ])
 
+        self.expect("v/x large_packed", VARIABLES_DISPLAYED_CORRECTLY,
+                    substrs=["a = 0x0000000cbbbbaaaa", "b = 0x0000000dffffeee"])
+
 
     @add_test_categories(['pyapi'])
     # BitFields exhibit crashes in record layout on Windows


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65492.212476.patch
Type: text/x-patch
Size: 2328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190731/89e3e143/attachment.bin>


More information about the lldb-commits mailing list