[Lldb-commits] [PATCH] D88992: [lldb] Fix "frame var" for large bitfields
Pavel Labath via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 7 11:20:18 PDT 2020
labath created this revision.
labath added reviewers: jingham, teemperor.
Herald added a reviewer: JDevlieghere.
Herald added a project: LLDB.
labath requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D88992
Files:
lldb/source/Core/ValueObjectChild.cpp
lldb/test/API/lang/c/bitfields/TestBitfields.py
Index: lldb/test/API/lang/c/bitfields/TestBitfields.py
===================================================================
--- lldb/test/API/lang/c/bitfields/TestBitfields.py
+++ 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_pr47743(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
Index: lldb/source/Core/ValueObjectChild.cpp
===================================================================
--- lldb/source/Core/ValueObjectChild.cpp
+++ 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() += GetByteOffset();
}
} break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88992.296749.patch
Type: text/x-patch
Size: 3174 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201007/2febcf48/attachment.bin>
More information about the lldb-commits
mailing list