Fix GetAddressOf for children of pointer ValueObjectConstResult* variables.

The original code always set the m_live_address of children of the ValueObjects that
use ValueObjectConstResultImpl backends to the parent m_live_address + child_byte_offset.
That is correct for structure types, but wrong for pointer types, since m_live_address
for a pointer type is the address of the storage for the pointer, not of the pointee.

Also added a test which was failing before this patch.
This commit is contained in:
Jim Ingham
2022-12-08 11:00:08 -08:00
parent f472da190b
commit 3b7ac5b295
4 changed files with 67 additions and 4 deletions

View File

@@ -89,13 +89,20 @@ ValueObject *ValueObjectConstResultImpl::CreateChildAtIndex(
if (!child_name_str.empty())
child_name.SetCString(child_name_str.c_str());
lldb::addr_t child_live_addr = LLDB_INVALID_ADDRESS;
// Transfer the live address (with offset) to the child. But if
// the parent is a pointer, the live address is where that pointer
// value lives in memory, so the children live addresses aren't
// offsets from that value, they are just other load addresses that
// are recorded in the Value of the child ValueObjects.
if (m_live_address != LLDB_INVALID_ADDRESS) {
if (!compiler_type.IsPointerType())
child_live_addr = m_live_address + child_byte_offset;
}
valobj = new ValueObjectConstResultChild(
*m_impl_backend, child_compiler_type, child_name, child_byte_size,
child_byte_offset, child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent,
m_live_address == LLDB_INVALID_ADDRESS
? m_live_address
: m_live_address + child_byte_offset,
child_is_base_class, child_is_deref_of_parent, child_live_addr,
language_flags);
}