diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp --- a/lldb/source/Core/ValueObjectChild.cpp +++ b/lldb/source/Core/ValueObjectChild.cpp @@ -165,10 +165,6 @@ } else if (addr == 0) { m_error.SetErrorString("parent is NULL"); } else { - // 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 @@ -187,11 +183,15 @@ if (bitfield_end > *type_bit_size) { uint64_t overhang_bytes = (bitfield_end - *type_bit_size + 7) / 8; - m_value.GetScalar() += overhang_bytes; + m_byte_offset += overhang_bytes; m_bitfield_bit_offset -= overhang_bytes * 8; } } } + + // Set this object's scalar value to the address of its value by + // adding its byte offset to the parent address + m_value.GetScalar() += m_byte_offset; } } break; diff --git a/lldb/test/API/lang/c/bitfields/TestBitfields.py b/lldb/test/API/lang/c/bitfields/TestBitfields.py --- a/lldb/test/API/lang/c/bitfields/TestBitfields.py +++ b/lldb/test/API/lang/c/bitfields/TestBitfields.py @@ -147,6 +147,27 @@ self.expect("v/x large_packed", VARIABLES_DISPLAYED_CORRECTLY, substrs=["a = 0x0000000cbbbbaaaa", "b = 0x0000000dffffeee"]) + # BitFields exhibit crashes in record layout on Windows + # (http://llvm.org/pr21800) + @skipIfWindows + def test_expression_bug(self): + # Ensure evaluating (emulating) an expression does not break bitfield + # values for already parsed variables. The expression is run twice + # because the very first expression can resume a target (to allocate + # memory, etc.) even if it is not being jitted. + self.build() + lldbutil.run_to_line_breakpoint(self, lldb.SBFileSpec("main.c"), + self.line) + self.expect("v/x large_packed", VARIABLES_DISPLAYED_CORRECTLY, + substrs=["a = 0x0000000cbbbbaaaa", "b = 0x0000000dffffeee"]) + self.expect("expr --allow-jit false -- more_bits.a", VARIABLES_DISPLAYED_CORRECTLY, + substrs=['uint32_t', '3']) + self.expect("v/x large_packed", VARIABLES_DISPLAYED_CORRECTLY, + substrs=["a = 0x0000000cbbbbaaaa", "b = 0x0000000dffffeee"]) + self.expect("expr --allow-jit false -- more_bits.a", VARIABLES_DISPLAYED_CORRECTLY, + substrs=['uint32_t', '3']) + 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