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

Phabricator via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 7 15:41:24 PDT 2019


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368226: Adjust a ValueObjectChild's offset when the child is a bitfield (authored by adrian, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65492?vs=212476&id=214021#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65492/new/

https://reviews.llvm.org/D65492

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


Index: lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
+++ lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/TestBitfields.py
@@ -146,6 +146,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
Index: lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
===================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/lang/c/bitfields/main.c
+++ lldb/trunk/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/trunk/source/Core/ValueObjectChild.cpp
===================================================================
--- lldb/trunk/source/Core/ValueObjectChild.cpp
+++ lldb/trunk/source/Core/ValueObjectChild.cpp
@@ -175,6 +175,30 @@
             // Set this object's scalar value to the address of its value by
             // adding its byte offset to the parent address
             m_value.GetScalar() += GetByteOffset();
+
+            // If a bitfield doesn't fit into the child_byte_size'd
+            // window at child_byte_offset, move the window forward
+            // until it fits.  The problem here is that Value has no
+            // notion of bitfields and thus the Value's DataExtractor
+            // is sized like the bitfields CompilerType; a sequence of
+            // bitfields, however, can be larger than their underlying
+            // type.
+            if (m_bitfield_bit_offset) {
+              const bool thread_and_frame_only_if_stopped = true;
+              ExecutionContext exe_ctx(GetExecutionContextRef().Lock(
+                  thread_and_frame_only_if_stopped));
+              if (auto type_bit_size = GetCompilerType().GetBitSize(
+                      exe_ctx.GetBestExecutionContextScope())) {
+                uint64_t bitfield_end =
+                    m_bitfield_bit_size + m_bitfield_bit_offset;
+                if (bitfield_end > *type_bit_size) {
+                  uint64_t overhang_bytes =
+                      (bitfield_end - *type_bit_size + 7) / 8;
+                  m_value.GetScalar() += overhang_bytes;
+                  m_bitfield_bit_offset -= overhang_bytes * 8;
+                }
+              }
+            }
           }
         } break;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65492.214021.patch
Type: text/x-patch
Size: 3029 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190807/936dfd75/attachment.bin>


More information about the lldb-commits mailing list