Index: lldb/include/lldb/Core/ValueObject.h =================================================================== --- lldb/include/lldb/Core/ValueObject.h +++ lldb/include/lldb/Core/ValueObject.h @@ -358,7 +358,7 @@ virtual bool CanProvideValue(); // Subclasses must implement the functions below. - virtual uint64_t GetByteSize() = 0; + virtual llvm::Optional GetByteSize() = 0; virtual lldb::ValueType GetValueType() const = 0; Index: lldb/include/lldb/Core/ValueObjectCast.h =================================================================== --- lldb/include/lldb/Core/ValueObjectCast.h +++ lldb/include/lldb/Core/ValueObjectCast.h @@ -30,7 +30,7 @@ ConstString name, const CompilerType &cast_type); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; size_t CalculateNumChildren(uint32_t max) override; Index: lldb/include/lldb/Core/ValueObjectChild.h =================================================================== --- lldb/include/lldb/Core/ValueObjectChild.h +++ lldb/include/lldb/Core/ValueObjectChild.h @@ -30,7 +30,7 @@ public: ~ValueObjectChild() override; - uint64_t GetByteSize() override { return m_byte_size; } + llvm::Optional GetByteSize() override { return m_byte_size; } lldb::offset_t GetByteOffset() override { return m_byte_offset; } Index: lldb/include/lldb/Core/ValueObjectConstResult.h =================================================================== --- lldb/include/lldb/Core/ValueObjectConstResult.h +++ lldb/include/lldb/Core/ValueObjectConstResult.h @@ -62,7 +62,7 @@ static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const Status &error); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; lldb::ValueType GetValueType() const override; @@ -113,7 +113,7 @@ CompilerType GetCompilerTypeImpl() override; ConstString m_type_name; - uint64_t m_byte_size; + llvm::Optional m_byte_size; ValueObjectConstResultImpl m_impl; Index: lldb/include/lldb/Core/ValueObjectDynamicValue.h =================================================================== --- lldb/include/lldb/Core/ValueObjectDynamicValue.h +++ lldb/include/lldb/Core/ValueObjectDynamicValue.h @@ -34,7 +34,7 @@ public: ~ValueObjectDynamicValue() override; - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; ConstString GetTypeName() override; Index: lldb/include/lldb/Core/ValueObjectMemory.h =================================================================== --- lldb/include/lldb/Core/ValueObjectMemory.h +++ lldb/include/lldb/Core/ValueObjectMemory.h @@ -40,7 +40,7 @@ const Address &address, const CompilerType &ast_type); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; ConstString GetTypeName() override; Index: lldb/include/lldb/Core/ValueObjectRegister.h =================================================================== --- lldb/include/lldb/Core/ValueObjectRegister.h +++ lldb/include/lldb/Core/ValueObjectRegister.h @@ -36,7 +36,7 @@ lldb::RegisterContextSP ®_ctx_sp, uint32_t set_idx); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; lldb::ValueType GetValueType() const override { return lldb::eValueTypeRegisterSet; @@ -86,7 +86,7 @@ lldb::RegisterContextSP ®_ctx_sp, uint32_t reg_num); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; lldb::ValueType GetValueType() const override { return lldb::eValueTypeRegister; Index: lldb/include/lldb/Core/ValueObjectSyntheticFilter.h =================================================================== --- lldb/include/lldb/Core/ValueObjectSyntheticFilter.h +++ lldb/include/lldb/Core/ValueObjectSyntheticFilter.h @@ -36,7 +36,7 @@ public: ~ValueObjectSynthetic() override; - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; ConstString GetTypeName() override; Index: lldb/include/lldb/Core/ValueObjectVariable.h =================================================================== --- lldb/include/lldb/Core/ValueObjectVariable.h +++ lldb/include/lldb/Core/ValueObjectVariable.h @@ -37,7 +37,7 @@ static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp); - uint64_t GetByteSize() override; + llvm::Optional GetByteSize() override; ConstString GetTypeName() override; Index: lldb/include/lldb/Expression/ExpressionVariable.h =================================================================== --- lldb/include/lldb/Expression/ExpressionVariable.h +++ lldb/include/lldb/Expression/ExpressionVariable.h @@ -32,7 +32,7 @@ virtual ~ExpressionVariable(); - size_t GetByteSize() { return m_frozen_sp->GetByteSize(); } + llvm::Optional GetByteSize() { return m_frozen_sp->GetByteSize(); } ConstString GetName() { return m_frozen_sp->GetName(); } Index: lldb/include/lldb/Target/StackFrameRecognizer.h =================================================================== --- lldb/include/lldb/Target/StackFrameRecognizer.h +++ lldb/include/lldb/Target/StackFrameRecognizer.h @@ -155,7 +155,9 @@ SetName(parent.GetName()); } - uint64_t GetByteSize() override { return m_parent->GetByteSize(); } + llvm::Optional GetByteSize() override { + return m_parent->GetByteSize(); + } lldb::ValueType GetValueType() const override { return m_type; } bool UpdateValue() override { if (!m_parent->UpdateValueIfNeeded()) return false; Index: lldb/source/API/SBValue.cpp =================================================================== --- lldb/source/API/SBValue.cpp +++ lldb/source/API/SBValue.cpp @@ -333,7 +333,7 @@ ValueLocker locker; lldb::ValueObjectSP value_sp(GetSP(locker)); if (value_sp) { - result = value_sp->GetByteSize(); + result = value_sp->GetByteSize().getValueOr(0); } return result; Index: lldb/source/Commands/CommandObjectWatchpoint.cpp =================================================================== --- lldb/source/Commands/CommandObjectWatchpoint.cpp +++ lldb/source/Commands/CommandObjectWatchpoint.cpp @@ -905,7 +905,7 @@ // We're in business. // Find out the size of this variable. size = m_option_watchpoint.watch_size == 0 - ? valobj_sp->GetByteSize() + ? valobj_sp->GetByteSize().getValueOr(0) : m_option_watchpoint.watch_size; } compiler_type = valobj_sp->GetCompilerType(); Index: lldb/source/Core/ValueObject.cpp =================================================================== --- lldb/source/Core/ValueObject.cpp +++ lldb/source/Core/ValueObject.cpp @@ -849,7 +849,7 @@ uint64_t count = 0; const Encoding encoding = GetCompilerType().GetEncoding(count); - const size_t byte_size = GetByteSize(); + const size_t byte_size = GetByteSize().getValueOr(0); Value::ValueType value_type = m_value.GetValueType(); @@ -1524,7 +1524,7 @@ uint64_t count = 0; const Encoding encoding = GetCompilerType().GetEncoding(count); - const size_t byte_size = GetByteSize(); + const size_t byte_size = GetByteSize().getValueOr(0); Value::ValueType value_type = m_value.GetValueType(); @@ -1741,13 +1741,13 @@ uint32_t bit_field_offset = from; if (GetDataExtractor().GetByteOrder() == eByteOrderBig) bit_field_offset = - GetByteSize() * 8 - bit_field_size - bit_field_offset; + GetByteSize().getValueOr(0) * 8 - bit_field_size - bit_field_offset; // We haven't made a synthetic array member for INDEX yet, so lets make // one and cache it for any future reference. ValueObjectChild *synthetic_child = new ValueObjectChild( - *this, GetCompilerType(), index_const_str, GetByteSize(), 0, - bit_field_size, bit_field_offset, false, false, eAddressTypeInvalid, - 0); + *this, GetCompilerType(), index_const_str, + GetByteSize().getValueOr(0), 0, bit_field_size, bit_field_offset, + false, false, eAddressTypeInvalid, 0); // Cache the value if we got one back... if (synthetic_child) { Index: lldb/source/Core/ValueObjectCast.cpp =================================================================== --- lldb/source/Core/ValueObjectCast.cpp +++ lldb/source/Core/ValueObjectCast.cpp @@ -47,7 +47,7 @@ return children_count <= max ? children_count : max; } -uint64_t ValueObjectCast::GetByteSize() { +llvm::Optional ValueObjectCast::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); return m_value.GetValueByteSize(nullptr, &exe_ctx); } Index: lldb/source/Core/ValueObjectConstResult.cpp =================================================================== --- lldb/source/Core/ValueObjectConstResult.cpp +++ lldb/source/Core/ValueObjectConstResult.cpp @@ -179,8 +179,7 @@ ValueObjectConstResult::ValueObjectConstResult(ExecutionContextScope *exe_scope, ValueObjectManager &manager, const Status &error) - : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0), - m_impl(this) { + : ValueObject(exe_scope, manager), m_impl(this) { m_error = error; SetIsConstant(); } @@ -189,8 +188,7 @@ ValueObjectManager &manager, const Value &value, ConstString name, Module *module) - : ValueObject(exe_scope, manager), m_type_name(), m_byte_size(0), - m_impl(this) { + : ValueObject(exe_scope, manager), m_impl(this) { m_value = value; m_name = name; ExecutionContext exe_ctx; @@ -208,9 +206,9 @@ return eValueTypeConstResult; } -uint64_t ValueObjectConstResult::GetByteSize() { +llvm::Optional ValueObjectConstResult::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); - if (m_byte_size == 0) { + if (!m_byte_size) { if (auto size = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())) SetByteSize(*size); Index: lldb/source/Core/ValueObjectDynamicValue.cpp =================================================================== --- lldb/source/Core/ValueObjectDynamicValue.cpp +++ lldb/source/Core/ValueObjectDynamicValue.cpp @@ -98,7 +98,7 @@ return m_parent->GetNumChildren(max); } -uint64_t ValueObjectDynamicValue::GetByteSize() { +llvm::Optional ValueObjectDynamicValue::GetByteSize() { const bool success = UpdateValueIfNeeded(false); if (success && m_dynamic_type_info.HasType()) { ExecutionContext exe_ctx(GetExecutionContextRef()); Index: lldb/source/Core/ValueObjectMemory.cpp =================================================================== --- lldb/source/Core/ValueObjectMemory.cpp +++ lldb/source/Core/ValueObjectMemory.cpp @@ -139,13 +139,11 @@ return child_count <= max ? child_count : max; } -uint64_t ValueObjectMemory::GetByteSize() { +llvm::Optional ValueObjectMemory::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); if (m_type_sp) - return m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope()) - .getValueOr(0); - return m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()) - .getValueOr(0); + return m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope()); + return m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); } lldb::ValueType ValueObjectMemory::GetValueType() const { Index: lldb/source/Core/ValueObjectRegister.cpp =================================================================== --- lldb/source/Core/ValueObjectRegister.cpp +++ lldb/source/Core/ValueObjectRegister.cpp @@ -81,7 +81,7 @@ return 0; } -uint64_t ValueObjectRegisterSet::GetByteSize() { return 0; } +llvm::Optional ValueObjectRegisterSet::GetByteSize() { return 0; } bool ValueObjectRegisterSet::UpdateValue() { m_error.Clear(); @@ -229,7 +229,9 @@ return children_count <= max ? children_count : max; } -uint64_t ValueObjectRegister::GetByteSize() { return m_reg_info.byte_size; } +llvm::Optional ValueObjectRegister::GetByteSize() { + return m_reg_info.byte_size; +} bool ValueObjectRegister::UpdateValue() { m_error.Clear(); Index: lldb/source/Core/ValueObjectSyntheticFilter.cpp =================================================================== --- lldb/source/Core/ValueObjectSyntheticFilter.cpp +++ lldb/source/Core/ValueObjectSyntheticFilter.cpp @@ -121,7 +121,9 @@ return (m_might_have_children != eLazyBoolNo); } -uint64_t ValueObjectSynthetic::GetByteSize() { return m_parent->GetByteSize(); } +llvm::Optional ValueObjectSynthetic::GetByteSize() { + return m_parent->GetByteSize(); +} lldb::ValueType ValueObjectSynthetic::GetValueType() const { return m_parent->GetValueType(); Index: lldb/source/Core/ValueObjectVariable.cpp =================================================================== --- lldb/source/Core/ValueObjectVariable.cpp +++ lldb/source/Core/ValueObjectVariable.cpp @@ -105,15 +105,15 @@ return child_count <= max ? child_count : max; } -uint64_t ValueObjectVariable::GetByteSize() { +llvm::Optional ValueObjectVariable::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); CompilerType type(GetCompilerType()); if (!type.IsValid()) - return 0; + return {}; - return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()).getValueOr(0); + return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); } lldb::ValueType ValueObjectVariable::GetValueType() const { Index: lldb/source/Expression/ExpressionVariable.cpp =================================================================== --- lldb/source/Expression/ExpressionVariable.cpp +++ lldb/source/Expression/ExpressionVariable.cpp @@ -16,10 +16,10 @@ ExpressionVariable::~ExpressionVariable() {} uint8_t *ExpressionVariable::GetValueBytes() { - const size_t byte_size = m_frozen_sp->GetByteSize(); - if (byte_size > 0) { - if (m_frozen_sp->GetDataExtractor().GetByteSize() < byte_size) { - m_frozen_sp->GetValue().ResizeData(byte_size); + llvm::Optional byte_size = m_frozen_sp->GetByteSize(); + if (byte_size && *byte_size) { + if (m_frozen_sp->GetDataExtractor().GetByteSize() < *byte_size) { + m_frozen_sp->GetValue().ResizeData(*byte_size); m_frozen_sp->GetValue().GetData(m_frozen_sp->GetDataExtractor()); } return const_cast( Index: lldb/source/Expression/Materializer.cpp =================================================================== --- lldb/source/Expression/Materializer.cpp +++ lldb/source/Expression/Materializer.cpp @@ -67,7 +67,7 @@ const bool zero_memory = false; lldb::addr_t mem = map.Malloc( - m_persistent_variable_sp->GetByteSize(), 8, + m_persistent_variable_sp->GetByteSize().getValueOr(0), 8, lldb::ePermissionsReadable | lldb::ePermissionsWritable, IRMemoryMap::eAllocationPolicyMirror, zero_memory, allocate_error); @@ -106,7 +106,8 @@ Status write_error; map.WriteMemory(mem, m_persistent_variable_sp->GetValueBytes(), - m_persistent_variable_sp->GetByteSize(), write_error); + m_persistent_variable_sp->GetByteSize().getValueOr(0), + write_error); if (!write_error.Success()) { err.SetErrorStringWithFormat( @@ -234,7 +235,7 @@ map.GetBestExecutionContextScope(), m_persistent_variable_sp.get()->GetCompilerType(), m_persistent_variable_sp->GetName(), location, eAddressTypeLoad, - m_persistent_variable_sp->GetByteSize()); + m_persistent_variable_sp->GetByteSize().getValueOr(0)); if (frame_top != LLDB_INVALID_ADDRESS && frame_bottom != LLDB_INVALID_ADDRESS && location >= frame_bottom && @@ -279,7 +280,8 @@ LLDB_LOGF(log, "Dematerializing %s from 0x%" PRIx64 " (size = %llu)", m_persistent_variable_sp->GetName().GetCString(), (uint64_t)mem, - (unsigned long long)m_persistent_variable_sp->GetByteSize()); + (unsigned long long)m_persistent_variable_sp->GetByteSize() + .getValueOr(0)); // Read the contents of the spare memory area @@ -288,7 +290,7 @@ Status read_error; map.ReadMemory(m_persistent_variable_sp->GetValueBytes(), mem, - m_persistent_variable_sp->GetByteSize(), read_error); + m_persistent_variable_sp->GetByteSize().getValueOr(0), read_error); if (!read_error.Success()) { err.SetErrorStringWithFormat( @@ -369,10 +371,11 @@ if (!err.Success()) { dump_stream.Printf(" \n"); } else { - DataBufferHeap data(m_persistent_variable_sp->GetByteSize(), 0); + DataBufferHeap data( + m_persistent_variable_sp->GetByteSize().getValueOr(0), 0); map.ReadMemory(data.GetBytes(), target_address, - m_persistent_variable_sp->GetByteSize(), err); + m_persistent_variable_sp->GetByteSize().getValueOr(0), err); if (!err.Success()) { dump_stream.Printf(" \n"); @@ -621,8 +624,8 @@ Status extract_error; - map.GetMemoryData(data, m_temporary_allocation, valobj_sp->GetByteSize(), - extract_error); + map.GetMemoryData(data, m_temporary_allocation, + valobj_sp->GetByteSize().getValueOr(0), extract_error); if (!extract_error.Success()) { err.SetErrorStringWithFormat("couldn't get the data for variable %s", @@ -919,7 +922,7 @@ ret->ValueUpdated(); - const size_t pvar_byte_size = ret->GetByteSize(); + const size_t pvar_byte_size = ret->GetByteSize().getValueOr(0); uint8_t *pvar_data = ret->GetValueBytes(); map.ReadMemory(pvar_data, address, pvar_byte_size, read_error); Index: lldb/source/Target/StackFrame.cpp =================================================================== --- lldb/source/Target/StackFrame.cpp +++ lldb/source/Target/StackFrame.cpp @@ -1408,7 +1408,7 @@ } int64_t child_offset = child_sp->GetByteOffset(); - int64_t child_size = child_sp->GetByteSize(); + int64_t child_size = child_sp->GetByteSize().getValueOr(0); if (offset >= child_offset && offset < (child_offset + child_size)) { return GetValueForOffset(frame, child_sp, offset - child_offset); @@ -1441,8 +1441,8 @@ } if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) { - int64_t index = offset / pointee->GetByteSize(); - offset = offset % pointee->GetByteSize(); + int64_t index = offset / pointee->GetByteSize().getValueOr(1); + offset = offset % pointee->GetByteSize().getValueOr(1); const bool can_create = true; pointee = base->GetSyntheticArrayMember(index, can_create); }