[lldb] Fix "frame var" for large bitfields

The problem here is in the "sliding" code in
ValueObjectChild::UpdateValue. It modifies m_bitfield_bit_offset and
m_value to ensure the bitfield value fits the window given by the
underlying type.

However, this is broken next time UpdateValue is called, because it
updates the m_value value from the parent. However, the value cannot be
slid again because the m_bitfield_bit_offset is already modified.

It seems this can happen only under specific circumstances. One way to
trigger is is to run an expression which can be interpreted (jitting it
causes a new StackFrame and ValueObject variables to be created).

I fix this bug by modifying m_byte_offset instead of m_scalar, and
ensuring the changes are folded into m_scalar regardless of how many
times UpdateValue is called.

Differential Revision: https://reviews.llvm.org/D88992
This commit is contained in:
Pavel Labath 2020-10-07 17:57:16 +02:00
parent d4a7c70751
commit 19d64138e6
2 changed files with 26 additions and 5 deletions

View File

@ -165,10 +165,6 @@ bool ValueObjectChild::UpdateValue() {
} 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 @@ bool ValueObjectChild::UpdateValue() {
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;

View File

@ -147,6 +147,27 @@ class BitfieldsTestCase(TestBase):
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