[Lldb-commits] [lldb] 19d6413 - [lldb] Fix "frame var" for large bitfields
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 8 09:43:02 PDT 2020
Author: Pavel Labath
Date: 2020-10-08T18:42:50+02:00
New Revision: 19d64138e6a708d1d0571da3ac51e1b4777c2b47
URL: https://github.com/llvm/llvm-project/commit/19d64138e6a708d1d0571da3ac51e1b4777c2b47
DIFF: https://github.com/llvm/llvm-project/commit/19d64138e6a708d1d0571da3ac51e1b4777c2b47.diff
LOG: [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
Added:
Modified:
lldb/source/Core/ValueObjectChild.cpp
lldb/test/API/lang/c/bitfields/TestBitfields.py
Removed:
################################################################################
diff --git a/lldb/source/Core/ValueObjectChild.cpp b/lldb/source/Core/ValueObjectChild.cpp
index 1059c8f34b3b..63661a482313 100644
--- a/lldb/source/Core/ValueObjectChild.cpp
+++ b/lldb/source/Core/ValueObjectChild.cpp
@@ -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;
diff --git a/lldb/test/API/lang/c/bitfields/TestBitfields.py b/lldb/test/API/lang/c/bitfields/TestBitfields.py
index 7b28a321ff61..d838a886bf2d 100644
--- a/lldb/test/API/lang/c/bitfields/TestBitfields.py
+++ b/lldb/test/API/lang/c/bitfields/TestBitfields.py
@@ -147,6 +147,27 @@ def test_and_run_command(self):
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
More information about the lldb-commits
mailing list