Index: include/lldb/Symbol/CompilerType.h =================================================================== --- include/lldb/Symbol/CompilerType.h +++ include/lldb/Symbol/CompilerType.h @@ -287,9 +287,8 @@ struct IntegralTemplateArgument; - uint64_t GetByteSize(ExecutionContextScope *exe_scope) const; - - uint64_t GetBitSize(ExecutionContextScope *exe_scope) const; + llvm::Optional GetByteSize(ExecutionContextScope *exe_scope) const; + llvm::Optional GetBitSize(ExecutionContextScope *exe_scope) const; lldb::Encoding GetEncoding(uint64_t &count) const; Index: include/lldb/Target/ProcessStructReader.h =================================================================== --- include/lldb/Target/ProcessStructReader.h +++ include/lldb/Target/ProcessStructReader.h @@ -60,18 +60,20 @@ return; auto size = field_type.GetByteSize(nullptr); // no support for things larger than a uint64_t (yet) - if (size > 8) + if (!size || *size > 8) return; ConstString const_name = ConstString(name.c_str()); size_t byte_index = static_cast(bit_offset / 8); m_fields[const_name] = - FieldImpl{field_type, byte_index, static_cast(size)}; + FieldImpl{field_type, byte_index, static_cast(*size)}; } - size_t total_size = struct_type.GetByteSize(nullptr); - lldb::DataBufferSP buffer_sp(new DataBufferHeap(total_size, 0)); + auto total_size = struct_type.GetByteSize(nullptr); + if (!total_size) + return; + lldb::DataBufferSP buffer_sp(new DataBufferHeap(*total_size, 0)); Status error; process->ReadMemoryFromInferior(base_addr, buffer_sp->GetBytes(), - total_size, error); + *total_size, error); if (error.Fail()) return; m_data = DataExtractor(buffer_sp, m_byte_order, m_addr_byte_size); Index: source/API/SBType.cpp =================================================================== --- source/API/SBType.cpp +++ source/API/SBType.cpp @@ -103,10 +103,10 @@ } uint64_t SBType::GetByteSize() { - if (!IsValid()) - return 0; - - return m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr); + if (IsValid()) + if (auto size = m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr)) + return *size; + return 0; } bool SBType::IsPointerType() { Index: source/Commands/CommandObjectMemory.cpp =================================================================== --- source/Commands/CommandObjectMemory.cpp +++ source/Commands/CommandObjectMemory.cpp @@ -524,15 +524,15 @@ --pointer_count; } - m_format_options.GetByteSizeValue() = clang_ast_type.GetByteSize(nullptr); - - if (m_format_options.GetByteSizeValue() == 0) { + auto size = clang_ast_type.GetByteSize(nullptr); + if (!size) { result.AppendErrorWithFormat( "unable to get the byte size of the type '%s'\n", view_as_type_cstr); result.SetStatus(eReturnStatusFailed); return false; } + m_format_options.GetByteSizeValue() = *size; if (!m_format_options.GetCountValue().OptionWasSet()) m_format_options.GetCountValue() = 1; @@ -647,12 +647,15 @@ if (!m_format_options.GetFormatValue().OptionWasSet()) m_format_options.GetFormatValue().SetCurrentValue(eFormatDefault); - bytes_read = clang_ast_type.GetByteSize(nullptr) * - m_format_options.GetCountValue().GetCurrentValue(); + auto size = clang_ast_type.GetByteSize(nullptr); + if (!size) { + result.AppendError("can't get size of type"); + return false; + } + bytes_read = *size * m_format_options.GetCountValue().GetCurrentValue(); if (argc > 0) - addr = addr + (clang_ast_type.GetByteSize(nullptr) * - m_memory_options.m_offset.GetCurrentValue()); + addr = addr + (*size * m_memory_options.m_offset.GetCurrentValue()); } else if (m_format_options.GetFormatValue().GetCurrentValue() != eFormatCString) { data_sp.reset(new DataBufferHeap(total_byte_size, '\0')); @@ -1066,7 +1069,10 @@ m_memory_options.m_expr.GetStringValue(), frame, result_sp)) && result_sp) { uint64_t value = result_sp->GetValueAsUnsigned(0); - switch (result_sp->GetCompilerType().GetByteSize(nullptr)) { + auto size = result_sp->GetCompilerType().GetByteSize(nullptr); + if (!size) + return false; + switch (*size) { case 1: { uint8_t byte = (uint8_t)value; buffer.CopyData(&byte, 1); Index: source/Core/Value.cpp =================================================================== --- source/Core/Value.cpp +++ source/Core/Value.cpp @@ -224,8 +224,9 @@ { const CompilerType &ast_type = GetCompilerType(); if (ast_type.IsValid()) - byte_size = ast_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr); + if (auto size = ast_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)) + byte_size = *size; } break; } @@ -345,8 +346,9 @@ uint32_t limit_byte_size = UINT32_MAX; if (ast_type.IsValid()) { - limit_byte_size = ast_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr); + if (auto size = ast_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)) + limit_byte_size = *size; } if (limit_byte_size <= m_value.GetByteSize()) { Index: source/Core/ValueObject.cpp =================================================================== --- source/Core/ValueObject.cpp +++ source/Core/ValueObject.cpp @@ -756,10 +756,12 @@ ExecutionContext exe_ctx(GetExecutionContextRef()); - const uint64_t item_type_size = pointee_or_element_compiler_type.GetByteSize( + auto item_type_size = pointee_or_element_compiler_type.GetByteSize( exe_ctx.GetBestExecutionContextScope()); - const uint64_t bytes = item_count * item_type_size; - const uint64_t offset = item_idx * item_type_size; + if (!item_type_size) + return 0; + const uint64_t bytes = item_count * *item_type_size; + const uint64_t offset = item_idx * *item_type_size; if (item_idx == 0 && item_count == 1) // simply a deref { @@ -822,10 +824,10 @@ } } break; case eAddressTypeHost: { - const uint64_t max_bytes = + auto max_bytes = GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope()); - if (max_bytes > offset) { - size_t bytes_read = std::min(max_bytes - offset, bytes); + if (max_bytes && *max_bytes > offset) { + size_t bytes_read = std::min(*max_bytes - offset, bytes); addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS); if (addr == 0 || addr == LLDB_INVALID_ADDRESS) break; @@ -1818,14 +1820,15 @@ return synthetic_child_sp; if (!can_create) - return ValueObjectSP(); + return {}; ExecutionContext exe_ctx(GetExecutionContextRef()); - - ValueObjectChild *synthetic_child = new ValueObjectChild( - *this, type, name_const_str, - type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, - false, false, eAddressTypeInvalid, 0); + auto size = type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); + if (!size) + return {}; + ValueObjectChild *synthetic_child = + new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0, + false, false, eAddressTypeInvalid, 0); if (synthetic_child) { AddSyntheticChild(name_const_str, synthetic_child); synthetic_child_sp = synthetic_child->GetSP(); @@ -1856,16 +1859,17 @@ return synthetic_child_sp; if (!can_create) - return ValueObjectSP(); + return {}; const bool is_base_class = true; ExecutionContext exe_ctx(GetExecutionContextRef()); - - ValueObjectChild *synthetic_child = new ValueObjectChild( - *this, type, name_const_str, - type.GetByteSize(exe_ctx.GetBestExecutionContextScope()), offset, 0, 0, - is_base_class, false, eAddressTypeInvalid, 0); + auto size = type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); + if (!size) + return {}; + ValueObjectChild *synthetic_child = + new ValueObjectChild(*this, type, name_const_str, *size, offset, 0, 0, + is_base_class, false, eAddressTypeInvalid, 0); if (synthetic_child) { AddSyntheticChild(name_const_str, synthetic_child); synthetic_child_sp = synthetic_child->GetSP(); Index: source/Core/ValueObjectConstResult.cpp =================================================================== --- source/Core/ValueObjectConstResult.cpp +++ source/Core/ValueObjectConstResult.cpp @@ -198,10 +198,11 @@ uint64_t ValueObjectConstResult::GetByteSize() { ExecutionContext exe_ctx(GetExecutionContextRef()); - - if (m_byte_size == 0) - SetByteSize( - GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())); + if (m_byte_size == 0) { + if (auto size = + GetCompilerType().GetByteSize(exe_ctx.GetBestExecutionContextScope())) + SetByteSize(*size); + } return m_byte_size; } Index: source/Core/ValueObjectMemory.cpp =================================================================== --- source/Core/ValueObjectMemory.cpp +++ source/Core/ValueObjectMemory.cpp @@ -138,7 +138,9 @@ uint64_t ValueObjectMemory::GetByteSize() { if (m_type_sp) return m_type_sp->GetByteSize(); - return m_compiler_type.GetByteSize(nullptr); + if (auto size = m_compiler_type.GetByteSize(nullptr)) + return *size; + return 0; } lldb::ValueType ValueObjectMemory::GetValueType() const { Index: source/Core/ValueObjectVariable.cpp =================================================================== --- source/Core/ValueObjectVariable.cpp +++ source/Core/ValueObjectVariable.cpp @@ -112,7 +112,8 @@ if (!type.IsValid()) return 0; - return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); + auto size = type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); + return size ? *size : 0; } lldb::ValueType ValueObjectVariable::GetValueType() const { Index: source/DataFormatters/TypeFormat.cpp =================================================================== --- source/DataFormatters/TypeFormat.cpp +++ source/DataFormatters/TypeFormat.cpp @@ -94,16 +94,18 @@ return false; } + ExecutionContextScope *exe_scope = + exe_ctx.GetBestExecutionContextScope(); + auto size = compiler_type.GetByteSize(exe_scope); + if (!size) + return false; StreamString sstr; - ExecutionContextScope *exe_scope( - exe_ctx.GetBestExecutionContextScope()); compiler_type.DumpTypeValue( - &sstr, // The stream to use for display - GetFormat(), // Format to display this type with - data, // Data to extract from - 0, // Byte offset into "m_data" - compiler_type.GetByteSize( - exe_scope), // Byte size of item in "m_data" + &sstr, // The stream to use for display + GetFormat(), // Format to display this type with + data, // Data to extract from + 0, // Byte offset into "m_data" + *size, // Byte size of item in "m_data" valobj->GetBitfieldBitSize(), // Bitfield bit size valobj->GetBitfieldBitOffset(), // Bitfield bit offset exe_scope); Index: source/DataFormatters/VectorType.cpp =================================================================== --- source/DataFormatters/VectorType.cpp +++ source/DataFormatters/VectorType.cpp @@ -174,10 +174,10 @@ auto container_size = container_type.GetByteSize(exe_scope); auto element_size = element_type.GetByteSize(exe_scope); - if (element_size) { - if (container_size % element_size) + if (container_size && element_size && *element_size) { + if (*container_size % *element_size) return 0; - return container_size / element_size; + return *container_size / *element_size; } return 0; } @@ -197,8 +197,11 @@ lldb::ValueObjectSP GetChildAtIndex(size_t idx) override { if (idx >= CalculateNumChildren()) - return lldb::ValueObjectSP(); - auto offset = idx * m_child_type.GetByteSize(nullptr); + return {}; + auto size = m_child_type.GetByteSize(nullptr); + if (!size) + return {}; + auto offset = idx * *size; StreamString idx_name; idx_name.Printf("[%" PRIu64 "]", (uint64_t)idx); ValueObjectSP child_sp(m_backend.GetSyntheticChildAtOffset( Index: source/Expression/Materializer.cpp =================================================================== --- source/Expression/Materializer.cpp +++ source/Expression/Materializer.cpp @@ -46,7 +46,8 @@ } void Materializer::Entity::SetSizeAndAlignmentFromType(CompilerType &type) { - m_size = type.GetByteSize(nullptr); + if (auto size = type.GetByteSize(nullptr)) + m_size = *size; uint32_t bit_alignment = type.GetTypeBitAlign(); @@ -794,7 +795,11 @@ ExecutionContextScope *exe_scope = map.GetBestExecutionContextScope(); - size_t byte_size = m_type.GetByteSize(exe_scope); + auto byte_size = m_type.GetByteSize(exe_scope); + if (!byte_size) { + err.SetErrorString("can't get size of type"); + return; + } size_t bit_align = m_type.GetTypeBitAlign(); size_t byte_align = (bit_align + 7) / 8; @@ -805,10 +810,10 @@ const bool zero_memory = true; m_temporary_allocation = map.Malloc( - byte_size, byte_align, + *byte_size, byte_align, lldb::ePermissionsReadable | lldb::ePermissionsWritable, IRMemoryMap::eAllocationPolicyMirror, zero_memory, alloc_error); - m_temporary_allocation_size = byte_size; + m_temporary_allocation_size = *byte_size; if (!alloc_error.Success()) { err.SetErrorStringWithFormat( Index: source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp =================================================================== --- source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp +++ source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp @@ -1470,14 +1470,16 @@ if (compiler_type) { bool is_signed = false; size_t bit_width = 0; - if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - bit_width = compiler_type.GetBitSize(&thread); - } else if (compiler_type.IsPointerOrReferenceType()) { - bit_width = compiler_type.GetBitSize(&thread); - } else { + auto bit_size = compiler_type.GetBitSize(&thread); + if (!bit_size) + return false; + if (compiler_type.IsIntegerOrEnumerationType(is_signed)) + bit_width = *bit_size; + else if (compiler_type.IsPointerOrReferenceType()) + bit_width = *bit_size; + else // We only handle integer, pointer and reference types currently... return false; - } if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) { if (value_idx < 4) { @@ -1574,9 +1576,11 @@ const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfoByName("r0", 0); if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - size_t bit_width = compiler_type.GetBitSize(&thread); + auto bit_width = compiler_type.GetBitSize(&thread); + if (!bit_width) + return return_valobj_sp; - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 128: @@ -1592,14 +1596,16 @@ const RegisterInfo *r3_reg_info = reg_ctx->GetRegisterInfoByName("r3", 0); if (r1_reg_info && r2_reg_info && r3_reg_info) { - const size_t byte_size = compiler_type.GetByteSize(&thread); + auto byte_size = compiler_type.GetByteSize(&thread); + if (!byte_size) + return return_valobj_sp; ProcessSP process_sp(thread.GetProcess()); - if (byte_size <= r0_reg_info->byte_size + r1_reg_info->byte_size + - r2_reg_info->byte_size + - r3_reg_info->byte_size && + if (*byte_size <= r0_reg_info->byte_size + r1_reg_info->byte_size + + r2_reg_info->byte_size + + r3_reg_info->byte_size && process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue r0_reg_value; RegisterValue r1_reg_value; Index: source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp =================================================================== --- source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp +++ source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp @@ -1762,90 +1762,92 @@ return false; CompilerType value_type = value->GetCompilerType(); - if (value_type) { - bool is_signed = false; - size_t bit_width = 0; - if (value_type.IsIntegerOrEnumerationType(is_signed)) { - bit_width = value_type.GetBitSize(&thread); - } else if (value_type.IsPointerOrReferenceType()) { - bit_width = value_type.GetBitSize(&thread); - } else { - // We only handle integer, pointer and reference types currently... - return false; - } + auto bit_size = value_type.GetBitSize(&thread); + if (!bit_size) + return false; - if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) { - if (value_idx < 8) { - // Arguments 1-6 are in x0-x5... - const RegisterInfo *reg_info = nullptr; - // Search by generic ID first, then fall back to by name - uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber( - eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + value_idx); - if (arg_reg_num != LLDB_INVALID_REGNUM) { - reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num); - } else { - switch (value_idx) { - case 0: - reg_info = reg_ctx->GetRegisterInfoByName("x0"); - break; - case 1: - reg_info = reg_ctx->GetRegisterInfoByName("x1"); - break; - case 2: - reg_info = reg_ctx->GetRegisterInfoByName("x2"); - break; - case 3: - reg_info = reg_ctx->GetRegisterInfoByName("x3"); - break; - case 4: - reg_info = reg_ctx->GetRegisterInfoByName("x4"); - break; - case 5: - reg_info = reg_ctx->GetRegisterInfoByName("x5"); - break; - case 6: - reg_info = reg_ctx->GetRegisterInfoByName("x6"); - break; - case 7: - reg_info = reg_ctx->GetRegisterInfoByName("x7"); - break; - } + bool is_signed = false; + size_t bit_width = 0; + if (value_type.IsIntegerOrEnumerationType(is_signed)) { + bit_width = *bit_size; + } else if (value_type.IsPointerOrReferenceType()) { + bit_width = *bit_size; + } else { + // We only handle integer, pointer and reference types currently... + return false; + } + + if (bit_width <= (exe_ctx.GetProcessRef().GetAddressByteSize() * 8)) { + if (value_idx < 8) { + // Arguments 1-6 are in x0-x5... + const RegisterInfo *reg_info = nullptr; + // Search by generic ID first, then fall back to by name + uint32_t arg_reg_num = reg_ctx->ConvertRegisterKindToRegisterNumber( + eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + value_idx); + if (arg_reg_num != LLDB_INVALID_REGNUM) { + reg_info = reg_ctx->GetRegisterInfoAtIndex(arg_reg_num); + } else { + switch (value_idx) { + case 0: + reg_info = reg_ctx->GetRegisterInfoByName("x0"); + break; + case 1: + reg_info = reg_ctx->GetRegisterInfoByName("x1"); + break; + case 2: + reg_info = reg_ctx->GetRegisterInfoByName("x2"); + break; + case 3: + reg_info = reg_ctx->GetRegisterInfoByName("x3"); + break; + case 4: + reg_info = reg_ctx->GetRegisterInfoByName("x4"); + break; + case 5: + reg_info = reg_ctx->GetRegisterInfoByName("x5"); + break; + case 6: + reg_info = reg_ctx->GetRegisterInfoByName("x6"); + break; + case 7: + reg_info = reg_ctx->GetRegisterInfoByName("x7"); + break; } + } - if (reg_info) { - RegisterValue reg_value; + if (reg_info) { + RegisterValue reg_value; - if (reg_ctx->ReadRegister(reg_info, reg_value)) { - if (is_signed) - reg_value.SignExtend(bit_width); - if (!reg_value.GetScalarValue(value->GetScalar())) - return false; - continue; - } - } - return false; - } else { - if (sp == 0) { - // Read the stack pointer if we already haven't read it - sp = reg_ctx->GetSP(0); - if (sp == 0) + if (reg_ctx->ReadRegister(reg_info, reg_value)) { + if (is_signed) + reg_value.SignExtend(bit_width); + if (!reg_value.GetScalarValue(value->GetScalar())) return false; + continue; } - - // Arguments 5 on up are on the stack - const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8; - Status error; - if (!exe_ctx.GetProcessRef().ReadScalarIntegerFromMemory( - sp, arg_byte_size, is_signed, value->GetScalar(), error)) + } + return false; + } else { + if (sp == 0) { + // Read the stack pointer if we already haven't read it + sp = reg_ctx->GetSP(0); + if (sp == 0) return false; + } - sp += arg_byte_size; - // Align up to the next 8 byte boundary if needed - if (sp % 8) { - sp >>= 3; - sp += 1; - sp <<= 3; - } + // Arguments 5 on up are on the stack + const uint32_t arg_byte_size = (bit_width + (8 - 1)) / 8; + Status error; + if (!exe_ctx.GetProcessRef().ReadScalarIntegerFromMemory( + sp, arg_byte_size, is_signed, value->GetScalar(), error)) + return false; + + sp += arg_byte_size; + // Align up to the next 8 byte boundary if needed + if (sp % 8) { + sp >>= 3; + sp += 1; + sp <<= 3; } } } @@ -2109,13 +2111,12 @@ uint32_t &NGRN, // NGRN (see ABI documentation) uint32_t &NSRN, // NSRN (see ABI documentation) DataExtractor &data) { - const size_t byte_size = value_type.GetByteSize(nullptr); - - if (byte_size == 0) + auto byte_size = value_type.GetByteSize(nullptr); + if (!byte_size || *byte_size == 0) return false; std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); Status error; @@ -2127,7 +2128,9 @@ if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) { if (!base_type) return false; - const size_t base_byte_size = base_type.GetByteSize(nullptr); + auto base_byte_size = base_type.GetByteSize(nullptr); + if (!base_byte_size) + return false; uint32_t data_offset = 0; for (uint32_t i = 0; i < homogeneous_count; ++i) { @@ -2138,7 +2141,7 @@ if (reg_info == nullptr) return false; - if (base_byte_size > reg_info->byte_size) + if (*base_byte_size > reg_info->byte_size) return false; RegisterValue reg_value; @@ -2147,11 +2150,11 @@ return false; // Make sure we have enough room in "heap_data_ap" - if ((data_offset + base_byte_size) <= heap_data_ap->GetByteSize()) { + if ((data_offset + *base_byte_size) <= heap_data_ap->GetByteSize()) { const size_t bytes_copied = reg_value.GetAsMemoryData( - reg_info, heap_data_ap->GetBytes() + data_offset, base_byte_size, + reg_info, heap_data_ap->GetBytes() + data_offset, *base_byte_size, byte_order, error); - if (bytes_copied != base_byte_size) + if (bytes_copied != *base_byte_size) return false; data_offset += bytes_copied; ++NSRN; @@ -2166,10 +2169,10 @@ } const size_t max_reg_byte_size = 16; - if (byte_size <= max_reg_byte_size) { - size_t bytes_left = byte_size; + if (*byte_size <= max_reg_byte_size) { + size_t bytes_left = *byte_size; uint32_t data_offset = 0; - while (data_offset < byte_size) { + while (data_offset < *byte_size) { if (NGRN >= 8) return false; @@ -2261,7 +2264,9 @@ if (!reg_ctx) return return_valobj_sp; - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr); if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) { @@ -2270,7 +2275,7 @@ bool success = false; if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) { // Extract the register context so we can read arguments from registers - if (byte_size <= 8) { + if (*byte_size <= 8) { const RegisterInfo *x0_reg_info = reg_ctx->GetRegisterInfoByName("x0", 0); if (x0_reg_info) { @@ -2278,7 +2283,7 @@ thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info, 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; case 16: // uint128_t @@ -2288,10 +2293,10 @@ reg_ctx->GetRegisterInfoByName("x1", 0); if (x1_reg_info) { - if (byte_size <= + if (*byte_size <= x0_reg_info->byte_size + x1_reg_info->byte_size) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); RegisterValue x0_reg_value; @@ -2356,7 +2361,7 @@ if (type_flags & eTypeIsComplex) { // Don't handle complex yet. } else { - if (byte_size <= sizeof(long double)) { + if (*byte_size <= sizeof(long double)) { const RegisterInfo *v0_reg_info = reg_ctx->GetRegisterInfoByName("v0", 0); RegisterValue v0_value; @@ -2364,13 +2369,13 @@ DataExtractor data; if (v0_value.GetData(data)) { lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = data.GetDouble(&offset); success = true; - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { value.GetScalar() = data.GetLongDouble(&offset); success = true; } @@ -2384,14 +2389,14 @@ return_valobj_sp = ValueObjectConstResult::Create( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { - if (byte_size > 0) { + if (*byte_size > 0) { const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0); if (v0_info) { - if (byte_size <= v0_info->byte_size) { + if (*byte_size <= v0_info->byte_size) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); RegisterValue reg_value; if (reg_ctx->ReadRegister(v0_info, reg_value)) { Index: source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp =================================================================== --- source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp +++ source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp @@ -824,18 +824,15 @@ // We currently only support extracting values with Clang QualTypes. Do we // care about others? CompilerType compiler_type(value->GetCompilerType()); - if (compiler_type) { + auto bit_size = compiler_type.GetBitSize(&thread); + if (bit_size) { bool is_signed; - - if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), - compiler_type.GetBitSize(&thread), is_signed, + if (compiler_type.IsIntegerOrEnumerationType(is_signed)) + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread.GetProcess().get(), current_stack_argument); - } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), - compiler_type.GetBitSize(&thread), false, + else if (compiler_type.IsPointerType()) + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread.GetProcess().get(), current_stack_argument); - } } } @@ -936,14 +933,15 @@ bool is_signed; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - size_t bit_width = compiler_type.GetBitSize(&thread); - + auto bit_width = compiler_type.GetBitSize(&thread); + if (!bit_width) + return return_valobj_sp; unsigned eax_id = reg_ctx->GetRegisterInfoByName("eax", 0)->kinds[eRegisterKindLLDB]; unsigned edx_id = reg_ctx->GetRegisterInfoByName("edx", 0)->kinds[eRegisterKindLLDB]; - switch (bit_width) { + switch (*bit_width) { default: case 128: // Scalar can't hold 128-bit literals, so we don't handle this Index: source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp =================================================================== --- source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp +++ source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp @@ -1471,10 +1471,10 @@ if (compiler_type) { bool is_signed = false; size_t bit_width = 0; - if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - bit_width = compiler_type.GetBitSize(&thread); - } else if (compiler_type.IsPointerOrReferenceType()) { - bit_width = compiler_type.GetBitSize(&thread); + if (compiler_type.IsIntegerOrEnumerationType(is_signed) || + compiler_type.IsPointerOrReferenceType()) { + if (auto size = compiler_type.GetBitSize(&thread)) + bit_width = *size; } else { // We only handle integer, pointer and reference types currently... return false; @@ -1580,11 +1580,13 @@ const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1); - size_t bit_width = compiler_type.GetBitSize(&thread); - size_t byte_size = compiler_type.GetByteSize(&thread); + auto bit_width = compiler_type.GetBitSize(&thread); + auto byte_size = compiler_type.GetByteSize(&thread); + if (!bit_width || !byte_size) + return return_valobj_sp; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 64: { @@ -1631,28 +1633,28 @@ UINT32_MAX; value.GetScalar() = ptr; } else if (compiler_type.IsVectorType(nullptr, nullptr)) { - if (IsArmHardFloat(thread) && (byte_size == 8 || byte_size == 16)) { + if (IsArmHardFloat(thread) && (*byte_size == 8 || *byte_size == 16)) { is_vfp_candidate = true; vfp_byte_size = 8; - vfp_count = (byte_size == 8 ? 1 : 2); - } else if (byte_size <= 16) { + vfp_count = (*byte_size == 8 ? 1 : 2); + } else if (*byte_size <= 16) { DataBufferHeap buffer(16, 0); uint32_t *buffer_ptr = (uint32_t *)buffer.GetBytes(); - for (uint32_t i = 0; 4 * i < byte_size; ++i) { + for (uint32_t i = 0; 4 * i < *byte_size; ++i) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo( eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1 + i); buffer_ptr[i] = reg_ctx->ReadRegisterAsUnsigned(reg_info, 0) & UINT32_MAX; } - value.SetBytes(buffer.GetBytes(), byte_size); + value.SetBytes(buffer.GetBytes(), *byte_size); } else { - if (!GetReturnValuePassedInMemory(thread, reg_ctx, byte_size, value)) + if (!GetReturnValuePassedInMemory(thread, reg_ctx, *byte_size, value)) return return_valobj_sp; } } else if (compiler_type.IsFloatingPointType(float_count, is_complex)) { if (float_count == 1 && !is_complex) { - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 64: { @@ -1700,9 +1702,9 @@ } else if (is_complex && float_count == 2) { if (IsArmHardFloat(thread)) { is_vfp_candidate = true; - vfp_byte_size = byte_size / 2; + vfp_byte_size = *byte_size / 2; vfp_count = 2; - } else if (!GetReturnValuePassedInMemory(thread, reg_ctx, bit_width / 8, + } else if (!GetReturnValuePassedInMemory(thread, reg_ctx, *bit_width / 8, value)) return return_valobj_sp; } else @@ -1715,19 +1717,20 @@ compiler_type.IsHomogeneousAggregate(&base_type); if (homogeneous_count > 0 && homogeneous_count <= 4) { + auto base_byte_size = base_type.GetByteSize(nullptr); if (base_type.IsVectorType(nullptr, nullptr)) { - uint64_t base_byte_size = base_type.GetByteSize(nullptr); - if (base_byte_size == 8 || base_byte_size == 16) { + if (base_byte_size && + (*base_byte_size == 8 || *base_byte_size == 16)) { is_vfp_candidate = true; vfp_byte_size = 8; - vfp_count = - (base_type.GetByteSize(nullptr) == 8 ? homogeneous_count - : homogeneous_count * 2); + vfp_count = (*base_byte_size == 8 ? homogeneous_count + : homogeneous_count * 2); } } else if (base_type.IsFloatingPointType(float_count, is_complex)) { if (float_count == 1 && !is_complex) { is_vfp_candidate = true; - vfp_byte_size = base_type.GetByteSize(nullptr); + if (base_byte_size) + vfp_byte_size = *base_byte_size; vfp_count = homogeneous_count; } } @@ -1742,12 +1745,13 @@ compiler_type.GetFieldAtIndex(index, name, NULL, NULL, NULL); if (base_type.IsFloatingPointType(float_count, is_complex)) { + auto base_byte_size = base_type.GetByteSize(nullptr); if (float_count == 2 && is_complex) { - if (index != 0 && - vfp_byte_size != base_type.GetByteSize(nullptr)) + if (index != 0 && base_byte_size && + vfp_byte_size != *base_byte_size) break; - else - vfp_byte_size = base_type.GetByteSize(nullptr); + else if (base_byte_size) + vfp_byte_size = *base_byte_size; } else break; } else @@ -1763,13 +1767,13 @@ } } - if (byte_size <= 4) { + if (*byte_size <= 4) { RegisterValue r0_reg_value; uint32_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r0_reg_info, 0) & UINT32_MAX; - value.SetBytes(&raw_value, byte_size); + value.SetBytes(&raw_value, *byte_size); } else if (!is_vfp_candidate) { - if (!GetReturnValuePassedInMemory(thread, reg_ctx, byte_size, value)) + if (!GetReturnValuePassedInMemory(thread, reg_ctx, *byte_size, value)) return return_valobj_sp; } } else { @@ -1781,7 +1785,7 @@ ProcessSP process_sp(thread.GetProcess()); ByteOrder byte_order = process_sp->GetByteOrder(); - DataBufferSP data_sp(new DataBufferHeap(byte_size, 0)); + DataBufferSP data_sp(new DataBufferHeap(*byte_size, 0)); uint32_t data_offset = 0; for (uint32_t reg_index = 0; reg_index < vfp_count; reg_index++) { @@ -1816,7 +1820,7 @@ } } - if (data_offset == byte_size) { + if (data_offset == *byte_size) { DataExtractor data; data.SetByteOrder(byte_order); data.SetAddressByteSize(process_sp->GetAddressByteSize()); Index: source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp =================================================================== --- source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp +++ source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp @@ -1767,10 +1767,13 @@ if (value_type) { bool is_signed = false; size_t bit_width = 0; + auto bit_size = value_type.GetBitSize(&thread); + if (!bit_size) + return false; if (value_type.IsIntegerOrEnumerationType(is_signed)) { - bit_width = value_type.GetBitSize(&thread); + bit_width = *bit_size; } else if (value_type.IsPointerOrReferenceType()) { - bit_width = value_type.GetBitSize(&thread); + bit_width = *bit_size; } else { // We only handle integer, pointer and reference types currently... return false; @@ -2083,13 +2086,13 @@ uint32_t &NGRN, // NGRN (see ABI documentation) uint32_t &NSRN, // NSRN (see ABI documentation) DataExtractor &data) { - const size_t byte_size = value_type.GetByteSize(nullptr); + auto byte_size = value_type.GetByteSize(nullptr); - if (byte_size == 0) + if (byte_size || *byte_size == 0) return false; std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); Status error; @@ -2101,7 +2104,9 @@ if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) { if (!base_type) return false; - const size_t base_byte_size = base_type.GetByteSize(nullptr); + auto base_byte_size = base_type.GetByteSize(nullptr); + if (!base_byte_size) + return false; uint32_t data_offset = 0; for (uint32_t i = 0; i < homogeneous_count; ++i) { @@ -2112,7 +2117,7 @@ if (reg_info == nullptr) return false; - if (base_byte_size > reg_info->byte_size) + if (*base_byte_size > reg_info->byte_size) return false; RegisterValue reg_value; @@ -2121,11 +2126,11 @@ return false; // Make sure we have enough room in "heap_data_ap" - if ((data_offset + base_byte_size) <= heap_data_ap->GetByteSize()) { + if ((data_offset + *base_byte_size) <= heap_data_ap->GetByteSize()) { const size_t bytes_copied = reg_value.GetAsMemoryData( - reg_info, heap_data_ap->GetBytes() + data_offset, base_byte_size, + reg_info, heap_data_ap->GetBytes() + data_offset, *base_byte_size, byte_order, error); - if (bytes_copied != base_byte_size) + if (bytes_copied != *base_byte_size) return false; data_offset += bytes_copied; ++NSRN; @@ -2140,10 +2145,10 @@ } const size_t max_reg_byte_size = 16; - if (byte_size <= max_reg_byte_size) { - size_t bytes_left = byte_size; + if (*byte_size <= max_reg_byte_size) { + size_t bytes_left = *byte_size; uint32_t data_offset = 0; - while (data_offset < byte_size) { + while (data_offset < *byte_size) { if (NGRN >= 8) return false; @@ -2228,7 +2233,9 @@ if (!reg_ctx) return return_valobj_sp; - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr); if (type_flags & eTypeIsScalar || type_flags & eTypeIsPointer) { @@ -2237,7 +2244,7 @@ bool success = false; if (type_flags & eTypeIsInteger || type_flags & eTypeIsPointer) { // Extract the register context so we can read arguments from registers - if (byte_size <= 8) { + if (*byte_size <= 8) { const RegisterInfo *x0_reg_info = nullptr; x0_reg_info = reg_ctx->GetRegisterInfo(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1); @@ -2246,7 +2253,7 @@ thread.GetRegisterContext()->ReadRegisterAsUnsigned(x0_reg_info, 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; case 16: // uint128_t @@ -2257,10 +2264,10 @@ LLDB_REGNUM_GENERIC_ARG2); if (x1_reg_info) { - if (byte_size <= + if (*byte_size <= x0_reg_info->byte_size + x1_reg_info->byte_size) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); RegisterValue x0_reg_value; @@ -2325,7 +2332,7 @@ if (type_flags & eTypeIsComplex) { // Don't handle complex yet. } else { - if (byte_size <= sizeof(long double)) { + if (*byte_size <= sizeof(long double)) { const RegisterInfo *v0_reg_info = reg_ctx->GetRegisterInfoByName("v0", 0); RegisterValue v0_value; @@ -2333,13 +2340,13 @@ DataExtractor data; if (v0_value.GetData(data)) { lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = data.GetDouble(&offset); success = true; - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { value.GetScalar() = data.GetLongDouble(&offset); success = true; } @@ -2352,13 +2359,13 @@ if (success) return_valobj_sp = ValueObjectConstResult::Create( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); - } else if (type_flags & eTypeIsVector && byte_size <= 16) { - if (byte_size > 0) { + } else if (type_flags & eTypeIsVector && *byte_size <= 16) { + if (*byte_size > 0) { const RegisterInfo *v0_info = reg_ctx->GetRegisterInfoByName("v0", 0); if (v0_info) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = exe_ctx.GetProcessRef().GetByteOrder(); RegisterValue reg_value; if (reg_ctx->ReadRegister(v0_info, reg_value)) { @@ -2375,7 +2382,7 @@ } } } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass || - (type_flags & eTypeIsVector && byte_size > 16)) { + (type_flags & eTypeIsVector && *byte_size > 16)) { DataExtractor data; uint32_t NGRN = 0; // Search ABI docs for NGRN Index: source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp =================================================================== --- source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp +++ source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp @@ -308,15 +308,14 @@ // Currently: Support for extracting values with Clang QualTypes only. CompilerType compiler_type(value->GetCompilerType()); - if (compiler_type) { + auto bit_size = compiler_type.GetBitSize(&thread); + if (bit_size) { bool is_signed; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), - compiler_type.GetBitSize(&thread), is_signed, + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread.GetProcess().get(), current_stack_argument); } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), - compiler_type.GetBitSize(&thread), false, + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread.GetProcess().get(), current_stack_argument); } } @@ -514,7 +513,9 @@ (type_flags & eTypeIsEnumeration)) //'Integral' + 'Floating Point' { value.SetValueType(Value::eValueTypeScalar); - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; bool success = false; if (type_flags & eTypeIsInteger) // 'Integral' except enum @@ -528,7 +529,7 @@ 0xffffffff) << 32; - switch (byte_size) { + switch (*byte_size) { default: break; @@ -584,7 +585,7 @@ thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsFloat) // 'Floating Point' { - if (byte_size <= 12) // handles float, double, long double, __float80 + if (*byte_size <= 12) // handles float, double, long double, __float80 { const RegisterInfo *st0_info = reg_ctx->GetRegisterInfoByName("st0", 0); RegisterValue st0_value; @@ -595,21 +596,20 @@ lldb::offset_t offset = 0; long double value_long_double = data.GetLongDouble(&offset); - if (byte_size == 4) // float is 4 bytes - { + // float is 4 bytes. + if (*byte_size == 4) { float value_float = (float)value_long_double; value.GetScalar() = value_float; success = true; - } else if (byte_size == 8) // double is 8 bytes - { + } else if (*byte_size == 8) { + // double is 8 bytes // On Android Platform: long double is also 8 bytes It will be // handled here only. double value_double = (double)value_long_double; value.GetScalar() = value_double; success = true; - } else if (byte_size == - 12) // long double and __float80 are 12 bytes on i386 - { + } else if (*byte_size == 12) { + // long double and __float80 are 12 bytes on i386. value.GetScalar() = value_long_double; success = true; } @@ -619,7 +619,7 @@ if (success) return_valobj_sp = ValueObjectConstResult::Create( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); - } else if (byte_size == 16) // handles __float128 + } else if (*byte_size == 16) // handles __float128 { lldb::addr_t storage_addr = (uint32_t)( thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) & @@ -637,18 +637,18 @@ // ToDo: Yet to be implemented } else if (type_flags & eTypeIsVector) // 'Packed' { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size > 0) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size > 0) { const RegisterInfo *vec_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0); if (vec_reg == nullptr) vec_reg = reg_ctx->GetRegisterInfoByName("mm0", 0); if (vec_reg) { - if (byte_size <= vec_reg->byte_size) { + if (*byte_size <= vec_reg->byte_size) { ProcessSP process_sp(thread.GetProcess()); if (process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue reg_value; if (reg_ctx->ReadRegister(vec_reg, reg_value)) { @@ -665,14 +665,14 @@ } } } - } else if (byte_size <= vec_reg->byte_size * 2) { + } else if (*byte_size <= vec_reg->byte_size * 2) { const RegisterInfo *vec_reg2 = reg_ctx->GetRegisterInfoByName("xmm1", 0); if (vec_reg2) { ProcessSP process_sp(thread.GetProcess()); if (process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue reg_value; RegisterValue reg_value2; Index: source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp =================================================================== --- source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp +++ source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp @@ -812,9 +812,11 @@ // In MIPS register "r2" (v0) holds the integer function return values const RegisterInfo *r2_reg_info = reg_ctx->GetRegisterInfoByName("r2", 0); - size_t bit_width = return_compiler_type.GetBitSize(&thread); + auto bit_width = return_compiler_type.GetBitSize(&thread); + if (!bit_width) + return return_valobj_sp; if (return_compiler_type.IsIntegerOrEnumerationType(is_signed)) { - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 64: { @@ -873,7 +875,7 @@ uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_reg_info, 0); if (count != 1 && is_complex) return return_valobj_sp; - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 32: @@ -905,7 +907,7 @@ lldb::offset_t offset = 0; if (count == 1 && !is_complex) { - switch (bit_width) { + switch (*bit_width) { default: return return_valobj_sp; case 64: { Index: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp =================================================================== --- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp +++ source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp @@ -762,7 +762,9 @@ Target *target = exe_ctx.GetTargetPtr(); const ArchSpec target_arch = target->GetArchitecture(); ByteOrder target_byte_order = target_arch.GetByteOrder(); - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr); uint32_t fp_flag = target_arch.GetFlags() & lldb_private::ArchSpec::eMIPS_ABI_FP_mask; @@ -781,7 +783,7 @@ uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; @@ -822,7 +824,7 @@ // Don't handle complex yet. } else if (IsSoftFloat(fp_flag)) { uint64_t raw_value = reg_ctx->ReadRegisterAsUnsigned(r2_info, 0); - switch (byte_size) { + switch (*byte_size) { case 4: value.GetScalar() = *((float *)(&raw_value)); success = true; @@ -847,7 +849,7 @@ } } else { - if (byte_size <= sizeof(long double)) { + if (*byte_size <= sizeof(long double)) { const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0); RegisterValue f0_value; @@ -858,13 +860,13 @@ f0_value.GetData(f0_data); lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = (float)f0_data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = (double)f0_data.GetDouble(&offset); success = true; - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { const RegisterInfo *f2_info = reg_ctx->GetRegisterInfoByName("f2", 0); RegisterValue f2_value; @@ -879,21 +881,21 @@ if (target_byte_order == eByteOrderLittle) { copy_from_extractor = &f0_data; copy_from_extractor->CopyByteOrderedData( - 0, 8, data_sp->GetBytes(), byte_size - 8, target_byte_order); + 0, 8, data_sp->GetBytes(), *byte_size - 8, target_byte_order); f2_value.GetData(f2_data); copy_from_extractor = &f2_data; copy_from_extractor->CopyByteOrderedData( - 0, 8, data_sp->GetBytes() + 8, byte_size - 8, + 0, 8, data_sp->GetBytes() + 8, *byte_size - 8, target_byte_order); } else { copy_from_extractor = &f0_data; copy_from_extractor->CopyByteOrderedData( - 0, 8, data_sp->GetBytes() + 8, byte_size - 8, + 0, 8, data_sp->GetBytes() + 8, *byte_size - 8, target_byte_order); f2_value.GetData(f2_data); copy_from_extractor = &f2_data; copy_from_extractor->CopyByteOrderedData( - 0, 8, data_sp->GetBytes(), byte_size - 8, target_byte_order); + 0, 8, data_sp->GetBytes(), *byte_size - 8, target_byte_order); } return_valobj_sp = ValueObjectConstResult::Create( @@ -910,7 +912,7 @@ } else if (type_flags & eTypeIsStructUnion || type_flags & eTypeIsClass || type_flags & eTypeIsVector) { // Any structure of up to 16 bytes in size is returned in the registers. - if (byte_size <= 16) { + if (*byte_size <= 16) { DataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, target_byte_order, target->GetArchitecture().GetAddressByteSize()); @@ -968,8 +970,9 @@ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); - const size_t field_byte_width = - field_compiler_type.GetByteSize(nullptr); + auto field_byte_width = field_compiler_type.GetByteSize(nullptr); + if (!field_byte_width) + return return_valobj_sp; DataExtractor *copy_from_extractor = nullptr; uint64_t return_value[2]; @@ -977,7 +980,7 @@ if (idx == 0) { // This case is for long double type. - if (field_byte_width == 16) { + if (*field_byte_width == 16) { // If structure contains long double type, then it is returned // in fp0/fp1 registers. @@ -995,7 +998,7 @@ return_value[0] = f1_data.GetU64(&offset); } - f0_data.SetData(return_value, field_byte_width, + f0_data.SetData(return_value, *field_byte_width, target_byte_order); } copy_from_extractor = &f0_data; // This is in f0, copy from @@ -1009,13 +1012,13 @@ // Sanity check to avoid crash if (!copy_from_extractor || - field_byte_width > copy_from_extractor->GetByteSize()) + *field_byte_width > copy_from_extractor->GetByteSize()) return return_valobj_sp; // copy the register contents into our data buffer copy_from_extractor->CopyByteOrderedData( - 0, field_byte_width, - data_sp->GetBytes() + (field_bit_offset / 8), field_byte_width, + 0, *field_byte_width, + data_sp->GetBytes() + (field_bit_offset / 8), *field_byte_width, target_byte_order); } @@ -1038,12 +1041,11 @@ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); - const size_t field_byte_width = - field_compiler_type.GetByteSize(nullptr); + auto field_byte_width = field_compiler_type.GetByteSize(nullptr); // if we don't know the size of the field (e.g. invalid type), just // bail out - if (field_byte_width == 0) + if (!field_byte_width || *field_byte_width == 0) break; uint32_t field_byte_offset = field_bit_offset / 8; @@ -1055,24 +1057,24 @@ if (integer_bytes < 8) { // We have not yet consumed r2 completely. - if (integer_bytes + field_byte_width + padding <= 8) { + if (integer_bytes + *field_byte_width + padding <= 8) { // This field fits in r2, copy its value from r2 to our result // structure - integer_bytes = integer_bytes + field_byte_width + + integer_bytes = integer_bytes + *field_byte_width + padding; // Increase the consumed bytes. use_r2 = 1; } else { // There isn't enough space left in r2 for this field, so this // will be in r3. - integer_bytes = integer_bytes + field_byte_width + + integer_bytes = integer_bytes + *field_byte_width + padding; // Increase the consumed bytes. use_r3 = 1; } } // We already have consumed at-least 8 bytes that means r2 is done, // and this field will be in r3. Check if this field can fit in r3. - else if (integer_bytes + field_byte_width + padding <= 16) { - integer_bytes = integer_bytes + field_byte_width + padding; + else if (integer_bytes + *field_byte_width + padding <= 16) { + integer_bytes = integer_bytes + *field_byte_width + padding; use_r3 = 1; } else { // There isn't any space left for this field, this should not @@ -1085,7 +1087,7 @@ } // Vector types up to 16 bytes are returned in GP return registers if (type_flags & eTypeIsVector) { - if (byte_size <= 8) + if (*byte_size <= 8) use_r2 = 1; else { use_r2 = 1; Index: source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp =================================================================== --- source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp +++ source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp @@ -398,19 +398,18 @@ // We currently only support extracting values with Clang QualTypes. Do we // care about others? CompilerType compiler_type = value->GetCompilerType(); - if (!compiler_type) + auto bit_size = compiler_type.GetBitSize(&thread); + if (!bit_size) return false; bool is_signed; - - if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - is_signed, thread, argument_register_ids, - current_argument_register, current_stack_argument); - } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - false, thread, argument_register_ids, - current_argument_register, current_stack_argument); - } + if (compiler_type.IsIntegerOrEnumerationType(is_signed)) + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread, + argument_register_ids, current_argument_register, + current_stack_argument); + else if (compiler_type.IsPointerType()) + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } return true; @@ -467,8 +466,12 @@ error.SetErrorString( "We don't support returning complex values at present"); else { - size_t bit_width = compiler_type.GetBitSize(frame_sp.get()); - if (bit_width <= 64) { + auto bit_width = compiler_type.GetBitSize(frame_sp.get()); + if (!bit_width) { + error.SetErrorString("can't get type size"); + return error; + } + if (*bit_width <= 64) { DataExtractor data; Status data_error; size_t num_bytes = new_value_sp->GetData(data, data_error); @@ -526,11 +529,13 @@ if (type_flags & eTypeIsInteger) { // Extract the register context so we can read arguments from registers - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( reg_ctx->GetRegisterInfoByName("r3", 0), 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; @@ -570,18 +575,18 @@ if (type_flags & eTypeIsComplex) { // Don't handle complex yet. } else { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size <= sizeof(long double)) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0); RegisterValue f1_value; if (reg_ctx->ReadRegister(f1_info, f1_value)) { DataExtractor data; if (f1_value.GetData(data)) { lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = (float)data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = (double)data.GetDouble(&offset); success = true; } @@ -603,15 +608,15 @@ return_valobj_sp = ValueObjectConstResult::Create( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size > 0) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size > 0) { const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0); if (altivec_reg) { - if (byte_size <= altivec_reg->byte_size) { + if (*byte_size <= altivec_reg->byte_size) { ProcessSP process_sp(thread.GetProcess()); if (process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue reg_value; if (reg_ctx->ReadRegister(altivec_reg, reg_value)) { @@ -620,9 +625,10 @@ altivec_reg, heap_data_ap->GetBytes(), heap_data_ap->GetByteSize(), byte_order, error)) { DataExtractor data(DataBufferSP(heap_data_ap.release()), - byte_order, process_sp->GetTarget() - .GetArchitecture() - .GetAddressByteSize()); + byte_order, + process_sp->GetTarget() + .GetArchitecture() + .GetAddressByteSize()); return_valobj_sp = ValueObjectConstResult::Create( &thread, return_compiler_type, ConstString(""), data); } @@ -652,11 +658,13 @@ if (!reg_ctx_sp) return return_valobj_sp; - const size_t bit_width = return_compiler_type.GetBitSize(&thread); + auto bit_width = return_compiler_type.GetBitSize(&thread); + if (!bit_width) + return return_valobj_sp; if (return_compiler_type.IsAggregateType()) { Target *target = exe_ctx.GetTargetPtr(); bool is_memory = true; - if (bit_width <= 128) { + if (*bit_width <= 128) { ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder(); DataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, target_byte_order, @@ -694,15 +702,17 @@ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); - const size_t field_bit_width = field_compiler_type.GetBitSize(&thread); + auto field_bit_width = field_compiler_type.GetBitSize(&thread); + if (!field_bit_width) + return return_valobj_sp; // If there are any unaligned fields, this is stored in memory. - if (field_bit_offset % field_bit_width != 0) { + if (field_bit_offset % *field_bit_width != 0) { is_memory = true; break; } - uint32_t field_byte_width = field_bit_width / 8; + uint32_t field_byte_width = *field_bit_width / 8; uint32_t field_byte_offset = field_bit_offset / 8; DataExtractor *copy_from_extractor = nullptr; @@ -735,13 +745,13 @@ } } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) { // Structs with long doubles are always passed in memory. - if (field_bit_width == 128) { + if (*field_bit_width == 128) { is_memory = true; break; - } else if (field_bit_width == 64) { + } else if (*field_bit_width == 64) { copy_from_offset = 0; fp_bytes += field_byte_width; - } else if (field_bit_width == 32) { + } else if (*field_bit_width == 32) { // This one is kind of complicated. If we are in an "eightbyte" // with another float, we'll be stuffed into an xmm register with // it. If we are in an "eightbyte" with one or more ints, then we Index: source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp =================================================================== --- source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp +++ source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp @@ -280,18 +280,19 @@ // We currently only support extracting values with Clang QualTypes. Do we // care about others? CompilerType compiler_type = value->GetCompilerType(); - if (!compiler_type) + auto bit_size = compiler_type.GetBitSize(&thread); + if (!bit_size) return false; bool is_signed; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - is_signed, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - false, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } } @@ -349,8 +350,12 @@ error.SetErrorString( "We don't support returning complex values at present"); else { - size_t bit_width = compiler_type.GetBitSize(frame_sp.get()); - if (bit_width <= 64) { + auto bit_width = compiler_type.GetBitSize(frame_sp.get()); + if (!bit_width) { + error.SetErrorString("can't get size of type"); + return error; + } + if (*bit_width <= 64) { DataExtractor data; Status data_error; size_t num_bytes = new_value_sp->GetData(data, data_error); @@ -571,7 +576,8 @@ ReturnValueExtractor(Thread &thread, CompilerType &type, RegisterContext *reg_ctx, ProcessSP process_sp) : m_thread(thread), m_type(type), - m_byte_size(m_type.GetByteSize(nullptr)), + m_byte_size(m_type.GetByteSize(nullptr) ? *m_type.GetByteSize(nullptr) + : 0), m_data_ap(new DataBufferHeap(m_byte_size, 0)), m_reg_ctx(reg_ctx), m_process_sp(process_sp), m_byte_order(process_sp->GetByteOrder()), m_addr_size( @@ -639,7 +645,7 @@ uint64_t raw_data; auto reg = GetFPR(reg_index); if (!reg.GetRawData(raw_data)) - return ValueSP(); + return {}; // build value from data ValueSP value_sp(NewScalarValue(type)); @@ -647,8 +653,10 @@ DataExtractor de(&raw_data, sizeof(raw_data), m_byte_order, m_addr_size); offset_t offset = 0; - size_t byte_size = type.GetByteSize(nullptr); - switch (byte_size) { + auto byte_size = type.GetByteSize(nullptr); + if (!byte_size) + return {}; + switch (*byte_size) { case sizeof(float): value_sp->GetScalar() = (float)de.GetDouble(&offset); break; @@ -755,7 +763,7 @@ uint64_t addr; auto reg = GetGPR(0); if (!reg.GetRawData(addr)) - return ValueObjectSP(); + return {}; Status error; size_t rc = m_process_sp->ReadMemory(addr, m_data_ap->GetBytes(), @@ -772,34 +780,36 @@ uint32_t n = m_type.GetNumChildren(omit_empty_base_classes, nullptr); if (!n) { LLDB_LOG(m_log, LOG_PREFIX "No children found in struct"); - return ValueObjectSP(); + return {}; } // case 2: homogeneous double or float aggregate CompilerType elem_type; if (m_type.IsHomogeneousAggregate(&elem_type)) { uint32_t type_flags = elem_type.GetTypeInfo(); - uint64_t elem_size = elem_type.GetByteSize(nullptr); + auto elem_size = elem_type.GetByteSize(nullptr); + if (!elem_size) + return {}; if (type_flags & eTypeIsComplex || !(type_flags & eTypeIsFloat)) { LLDB_LOG(m_log, LOG_PREFIX "Unexpected type found in homogeneous aggregate"); - return ValueObjectSP(); + return {}; } for (uint32_t i = 0; i < n; i++) { ValueSP val_sp = GetFloatValue(elem_type, i); if (!val_sp) - return ValueObjectSP(); + return {}; // copy to buffer Status error; size_t rc = val_sp->GetScalar().GetAsMemoryData( - m_data_ap->GetBytes() + m_dst_offs, elem_size, m_byte_order, error); - if (rc != elem_size) { + m_data_ap->GetBytes() + m_dst_offs, *elem_size, m_byte_order, error); + if (rc != *elem_size) { LLDB_LOG(m_log, LOG_PREFIX "Failed to get float data"); - return ValueObjectSP(); + return {}; } - m_dst_offs += elem_size; + m_dst_offs += *elem_size; } return BuildValueObject(); } Index: source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp =================================================================== --- source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp +++ source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp @@ -376,18 +376,19 @@ // We currently only support extracting values with Clang QualTypes. Do we // care about others? CompilerType compiler_type = value->GetCompilerType(); - if (!compiler_type) + auto bit_size = compiler_type.GetBitSize(&thread); + if (!bit_size) return false; bool is_signed; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - is_signed, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - false, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } } @@ -445,8 +446,12 @@ error.SetErrorString( "We don't support returning complex values at present"); else { - size_t bit_width = compiler_type.GetBitSize(frame_sp.get()); - if (bit_width <= 64) { + auto bit_width = compiler_type.GetBitSize(frame_sp.get()); + if (!bit_width) { + error.SetErrorString("can't get type size"); + return error; + } + if (*bit_width <= 64) { const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0); RegisterValue f0_value; DataExtractor data; @@ -508,11 +513,13 @@ if (type_flags & eTypeIsInteger) { // Extract the register context so we can read arguments from registers - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( reg_ctx->GetRegisterInfoByName("r2", 0), 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; @@ -552,21 +559,21 @@ if (type_flags & eTypeIsComplex) { // Don't handle complex yet. } else { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size <= sizeof(long double)) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0); RegisterValue f0_value; if (reg_ctx->ReadRegister(f0_info, f0_value)) { DataExtractor data; if (f0_value.GetData(data)) { lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = (float)data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = (double)data.GetDouble(&offset); success = true; - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { // Don't handle long double yet. } } Index: source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp =================================================================== --- source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp +++ source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp @@ -1263,18 +1263,19 @@ // We currently only support extracting values with Clang QualTypes. Do we // care about others? CompilerType compiler_type = value->GetCompilerType(); - if (!compiler_type) + auto bit_size = compiler_type.GetBitSize(&thread); + if (!bit_size) return false; bool is_signed; if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - is_signed, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, is_signed, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } else if (compiler_type.IsPointerType()) { - ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), - false, thread, argument_register_ids, - current_argument_register, current_stack_argument); + ReadIntegerArgument(value->GetScalar(), *bit_size, false, thread, + argument_register_ids, current_argument_register, + current_stack_argument); } } @@ -1332,8 +1333,12 @@ error.SetErrorString( "We don't support returning complex values at present"); else { - size_t bit_width = compiler_type.GetBitSize(frame_sp.get()); - if (bit_width <= 64) { + auto bit_width = compiler_type.GetBitSize(frame_sp.get()); + if (!bit_width) { + error.SetErrorString("can't get type size"); + return error; + } + if (*bit_width <= 64) { const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0); RegisterValue xmm0_value; @@ -1396,11 +1401,13 @@ if (type_flags & eTypeIsInteger) { // Extract the register context so we can read arguments from registers - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (!byte_size) + return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( reg_ctx->GetRegisterInfoByName("rax", 0), 0); const bool is_signed = (type_flags & eTypeIsSigned) != 0; - switch (byte_size) { + switch (*byte_size) { default: break; @@ -1440,8 +1447,8 @@ if (type_flags & eTypeIsComplex) { // Don't handle complex yet. } else { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size <= sizeof(long double)) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0); RegisterValue xmm0_value; @@ -1449,13 +1456,13 @@ DataExtractor data; if (xmm0_value.GetData(data)) { lldb::offset_t offset = 0; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { value.GetScalar() = (float)data.GetFloat(&offset); success = true; - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { value.GetScalar() = (double)data.GetDouble(&offset); success = true; - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { // Don't handle long double since that can be encoded as 80 bit // floats... } @@ -1478,19 +1485,19 @@ return_valobj_sp = ValueObjectConstResult::Create( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { - const size_t byte_size = return_compiler_type.GetByteSize(nullptr); - if (byte_size > 0) { + auto byte_size = return_compiler_type.GetByteSize(nullptr); + if (byte_size && *byte_size > 0) { const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0); if (altivec_reg == nullptr) altivec_reg = reg_ctx->GetRegisterInfoByName("mm0", 0); if (altivec_reg) { - if (byte_size <= altivec_reg->byte_size) { + if (*byte_size <= altivec_reg->byte_size) { ProcessSP process_sp(thread.GetProcess()); if (process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue reg_value; if (reg_ctx->ReadRegister(altivec_reg, reg_value)) { @@ -1507,14 +1514,14 @@ } } } - } else if (byte_size <= altivec_reg->byte_size * 2) { + } else if (*byte_size <= altivec_reg->byte_size * 2) { const RegisterInfo *altivec_reg2 = reg_ctx->GetRegisterInfoByName("xmm1", 0); if (altivec_reg2) { ProcessSP process_sp(thread.GetProcess()); if (process_sp) { std::unique_ptr heap_data_ap( - new DataBufferHeap(byte_size, 0)); + new DataBufferHeap(*byte_size, 0)); const ByteOrder byte_order = process_sp->GetByteOrder(); RegisterValue reg_value; RegisterValue reg_value2; @@ -1564,11 +1571,13 @@ if (!reg_ctx_sp) return return_valobj_sp; - const size_t bit_width = return_compiler_type.GetBitSize(&thread); + auto bit_width = return_compiler_type.GetBitSize(&thread); + if (!bit_width) + return return_valobj_sp; if (return_compiler_type.IsAggregateType()) { Target *target = exe_ctx.GetTargetPtr(); bool is_memory = true; - if (bit_width <= 128) { + if (*bit_width <= 128) { ByteOrder target_byte_order = target->GetArchitecture().GetByteOrder(); DataBufferSP data_sp(new DataBufferHeap(16, 0)); DataExtractor return_ext(data_sp, target_byte_order, @@ -1615,20 +1624,20 @@ CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); - const size_t field_bit_width = field_compiler_type.GetBitSize(&thread); + auto field_bit_width = field_compiler_type.GetBitSize(&thread); // if we don't know the size of the field (e.g. invalid type), just // bail out - if (field_bit_width == 0) + if (!field_bit_width || *field_bit_width == 0) break; // If there are any unaligned fields, this is stored in memory. - if (field_bit_offset % field_bit_width != 0) { + if (field_bit_offset % *field_bit_width != 0) { is_memory = true; break; } - uint32_t field_byte_width = field_bit_width / 8; + uint32_t field_byte_width = *field_bit_width / 8; uint32_t field_byte_offset = field_bit_offset / 8; DataExtractor *copy_from_extractor = nullptr; @@ -1661,10 +1670,10 @@ } } else if (field_compiler_type.IsFloatingPointType(count, is_complex)) { // Structs with long doubles are always passed in memory. - if (field_bit_width == 128) { + if (*field_bit_width == 128) { is_memory = true; break; - } else if (field_bit_width == 64) { + } else if (*field_bit_width == 64) { // These have to be in a single xmm register. if (fp_bytes == 0) copy_from_extractor = &xmm0_data; @@ -1673,7 +1682,7 @@ copy_from_offset = 0; fp_bytes += field_byte_width; - } else if (field_bit_width == 32) { + } else if (*field_bit_width == 32) { // This one is kind of complicated. If we are in an "eightbyte" // with another float, we'll be stuffed into an xmm register with // it. If we are in an "eightbyte" with one or more ints, then we Index: source/Plugins/ExpressionParser/Clang/IRForTarget.cpp =================================================================== --- source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -310,12 +310,14 @@ lldb::TargetSP target_sp(m_execution_unit.GetTarget()); lldb_private::ExecutionContext exe_ctx(target_sp, true); - if (m_result_type.GetBitSize(exe_ctx.GetBestExecutionContextScope()) == 0) { + auto bit_size = + m_result_type.GetBitSize(exe_ctx.GetBestExecutionContextScope()); + if (!bit_size) { lldb_private::StreamString type_desc_stream; m_result_type.DumpTypeDescription(&type_desc_stream); if (log) - log->Printf("Result type has size 0"); + log->Printf("Result type has unknown size"); m_error_stream.Printf("Error [IRForTarget]: Size of result type '%s' " "couldn't be determined\n", @@ -334,7 +336,10 @@ if (log) log->Printf("Creating a new result global: \"%s\" with size 0x%" PRIx64, - m_result_name.GetCString(), m_result_type.GetByteSize(nullptr)); + m_result_name.GetCString(), + m_result_type.GetByteSize(nullptr) + ? *m_result_type.GetByteSize(nullptr) + : 0); // Construct a new result global and set up its metadata @@ -1367,7 +1372,9 @@ value_type = global_variable->getType(); } - const uint64_t value_size = compiler_type.GetByteSize(nullptr); + auto value_size = compiler_type.GetByteSize(nullptr); + if (!value_size) + return false; lldb::offset_t value_alignment = (compiler_type.GetTypeBitAlign() + 7ull) / 8ull; @@ -1378,13 +1385,13 @@ lldb_private::ClangUtil::GetQualType(compiler_type) .getAsString() .c_str(), - PrintType(value_type).c_str(), value_size, value_alignment); + PrintType(value_type).c_str(), *value_size, value_alignment); } if (named_decl && !m_decl_map->AddValueToStruct( named_decl, lldb_private::ConstString(name.c_str()), llvm_value_ptr, - value_size, value_alignment)) { + *value_size, value_alignment)) { if (!global_variable->hasExternalLinkage()) return true; else Index: source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp +++ source/Plugins/Language/CPlusPlus/CxxStringTypes.cpp @@ -100,8 +100,11 @@ if (!wchar_compiler_type) return false; - const uint32_t wchar_size = wchar_compiler_type.GetBitSize( - nullptr); // Safe to pass NULL for exe_scope here + // Safe to pass nullptr for exe_scope here. + auto size = wchar_compiler_type.GetBitSize(nullptr); + if (!size) + return false; + const uint32_t wchar_size = *size; StringPrinter::ReadStringAndDumpToStreamOptions options(valobj); options.SetLocation(valobj_addr); @@ -194,8 +197,11 @@ if (!wchar_compiler_type) return false; - const uint32_t wchar_size = wchar_compiler_type.GetBitSize( - nullptr); // Safe to pass NULL for exe_scope here + // Safe to pass nullptr for exe_scope here. + auto size = wchar_compiler_type.GetBitSize(nullptr); + if (!size) + return false; + const uint32_t wchar_size = *size; StringPrinter::ReadBufferAndDumpToStreamOptions options(valobj); options.SetData(data); Index: source/Plugins/Language/CPlusPlus/LibCxx.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/LibCxx.cpp +++ source/Plugins/Language/CPlusPlus/LibCxx.cpp @@ -225,9 +225,14 @@ m_pair_ptr = nullptr; return false; } - CompilerType pair_type(__i_->GetCompilerType().GetTypeTemplateArgument(0)); - std::string name; uint64_t bit_offset_ptr; uint32_t bitfield_bit_size_ptr; bool is_bitfield_ptr; - pair_type = pair_type.GetFieldAtIndex(0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr); + CompilerType pair_type( + __i_->GetCompilerType().GetTypeTemplateArgument(0)); + std::string name; + uint64_t bit_offset_ptr; + uint32_t bitfield_bit_size_ptr; + bool is_bitfield_ptr; + pair_type = pair_type.GetFieldAtIndex( + 0, name, &bit_offset_ptr, &bitfield_bit_size_ptr, &is_bitfield_ptr); if (!pair_type) { m_pair_ptr = nullptr; return false; @@ -235,27 +240,38 @@ auto addr(m_pair_ptr->GetValueAsUnsigned(LLDB_INVALID_ADDRESS)); m_pair_ptr = nullptr; - if (addr && addr!=LLDB_INVALID_ADDRESS) { - ClangASTContext *ast_ctx = llvm::dyn_cast_or_null(pair_type.GetTypeSystem()); + if (addr && addr != LLDB_INVALID_ADDRESS) { + ClangASTContext *ast_ctx = + llvm::dyn_cast_or_null(pair_type.GetTypeSystem()); if (!ast_ctx) return false; - CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier(ConstString(), { - {"ptr0",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"ptr1",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"ptr2",ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, - {"cw",ast_ctx->GetBasicType(lldb::eBasicTypeBool)}, - {"payload",pair_type} - }); - DataBufferSP buffer_sp(new DataBufferHeap(tree_node_type.GetByteSize(nullptr),0)); + CompilerType tree_node_type = ast_ctx->CreateStructForIdentifier( + ConstString(), + {{"ptr0", + ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, + {"ptr1", + ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, + {"ptr2", + ast_ctx->GetBasicType(lldb::eBasicTypeVoid).GetPointerType()}, + {"cw", ast_ctx->GetBasicType(lldb::eBasicTypeBool)}, + {"payload", pair_type}}); + auto size = tree_node_type.GetByteSize(nullptr); + if (!size) + return false; + DataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); ProcessSP process_sp(target_sp->GetProcessSP()); Status error; - process_sp->ReadMemory(addr, buffer_sp->GetBytes(), buffer_sp->GetByteSize(), error); + process_sp->ReadMemory(addr, buffer_sp->GetBytes(), + buffer_sp->GetByteSize(), error); if (error.Fail()) return false; - DataExtractor extractor(buffer_sp, process_sp->GetByteOrder(), process_sp->GetAddressByteSize()); - auto pair_sp = CreateValueObjectFromData("pair", extractor, valobj_sp->GetExecutionContextRef(), tree_node_type); + DataExtractor extractor(buffer_sp, process_sp->GetByteOrder(), + process_sp->GetAddressByteSize()); + auto pair_sp = CreateValueObjectFromData( + "pair", extractor, valobj_sp->GetExecutionContextRef(), + tree_node_type); if (pair_sp) - m_pair_sp = pair_sp->GetChildAtIndex(4,true); + m_pair_sp = pair_sp->GetChildAtIndex(4, true); } } } @@ -560,6 +576,8 @@ ->GetScratchClangASTContext() ->GetBasicType(lldb::eBasicTypeWChar) .GetByteSize(nullptr); + if (!wchar_t_size) + return false; options.SetData(extractor); options.SetStream(&stream); @@ -568,7 +586,7 @@ options.SetSourceSize(size); options.SetBinaryZeroIsTerminator(false); - switch (wchar_t_size) { + switch (*wchar_t_size) { case 1: StringPrinter::ReadBufferAndDumpToStream< lldb_private::formatters::StringPrinter::StringElementType::UTF8>( Index: source/Plugins/Language/CPlusPlus/LibCxxBitset.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/LibCxxBitset.cpp +++ source/Plugins/Language/CPlusPlus/LibCxxBitset.cpp @@ -79,17 +79,22 @@ CompilerType type; ValueObjectSP chunk; // For small bitsets __first_ is not an array, but a plain size_t. - if (m_first->GetCompilerType().IsArrayType(&type, nullptr, nullptr)) - chunk = m_first->GetChildAtIndex( - idx / type.GetBitSize(ctx.GetBestExecutionContextScope()), true); - else { + if (m_first->GetCompilerType().IsArrayType(&type, nullptr, nullptr)) { + auto bit_size = type.GetBitSize(ctx.GetBestExecutionContextScope()); + if (!bit_size || *bit_size == 0) + return {}; + chunk = m_first->GetChildAtIndex(idx / *bit_size, true); + } else { type = m_first->GetCompilerType(); chunk = m_first; } if (!type || !chunk) - return ValueObjectSP(); + return {}; - size_t chunk_idx = idx % type.GetBitSize(ctx.GetBestExecutionContextScope()); + auto bit_size = type.GetBitSize(ctx.GetBestExecutionContextScope()); + if (!bit_size || *bit_size == 0) + return {}; + size_t chunk_idx = idx % *bit_size; uint8_t value = !!(chunk->GetValueAsUnsigned(0) & (uint64_t(1) << chunk_idx)); DataExtractor data(&value, sizeof(value), m_byte_order, m_byte_size); Index: source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp +++ source/Plugins/Language/CPlusPlus/LibCxxInitializerList.cpp @@ -94,12 +94,11 @@ if (!m_element_type.IsValid()) return false; - m_element_size = m_element_type.GetByteSize(nullptr); - - if (m_element_size > 0) - m_start = - m_backend.GetChildMemberWithName(g___begin_, true) - .get(); // store raw pointers or end up with a circular dependency + if (auto size = m_element_type.GetByteSize(nullptr)) { + m_element_size = *size; + // Store raw pointers or end up with a circular dependency. + m_start = m_backend.GetChildMemberWithName(g___begin_, true).get(); + } return false; } Index: source/Plugins/Language/CPlusPlus/LibCxxVector.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/LibCxxVector.cpp +++ source/Plugins/Language/CPlusPlus/LibCxxVector.cpp @@ -145,14 +145,16 @@ if (!data_type_finder_sp) return false; m_element_type = data_type_finder_sp->GetCompilerType().GetPointeeType(); - m_element_size = m_element_type.GetByteSize(nullptr); - - if (m_element_size > 0) { - // store raw pointers or end up with a circular dependency - m_start = - m_backend.GetChildMemberWithName(ConstString("__begin_"), true).get(); - m_finish = - m_backend.GetChildMemberWithName(ConstString("__end_"), true).get(); + if (auto size = m_element_type.GetByteSize(nullptr)) { + m_element_size = *size; + + if (m_element_size > 0) { + // store raw pointers or end up with a circular dependency + m_start = + m_backend.GetChildMemberWithName(ConstString("__begin_"), true).get(); + m_finish = + m_backend.GetChildMemberWithName(ConstString("__end_"), true).get(); + } } return false; } @@ -192,27 +194,29 @@ if (iter != end) return iter->second; if (idx >= m_count) - return ValueObjectSP(); + return {}; if (m_base_data_address == 0 || m_count == 0) - return ValueObjectSP(); + return {}; if (!m_bool_type) - return ValueObjectSP(); + return {}; size_t byte_idx = (idx >> 3); // divide by 8 to get byte index size_t bit_index = (idx & 7); // efficient idx % 8 for bit index lldb::addr_t byte_location = m_base_data_address + byte_idx; ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP()); if (!process_sp) - return ValueObjectSP(); + return {}; uint8_t byte = 0; uint8_t mask = 0; Status err; size_t bytes_read = process_sp->ReadMemory(byte_location, &byte, 1, err); if (err.Fail() || bytes_read == 0) - return ValueObjectSP(); + return {}; mask = 1 << bit_index; bool bit_set = ((byte & mask) != 0); - DataBufferSP buffer_sp( - new DataBufferHeap(m_bool_type.GetByteSize(nullptr), 0)); + auto size = m_bool_type.GetByteSize(nullptr); + if (!size) + return {}; + DataBufferSP buffer_sp(new DataBufferHeap(*size, 0)); if (bit_set && buffer_sp && buffer_sp->GetBytes()) { // regardless of endianness, anything non-zero is true *(buffer_sp->GetBytes()) = 1; Index: source/Plugins/Language/CPlusPlus/LibStdcpp.cpp =================================================================== --- source/Plugins/Language/CPlusPlus/LibStdcpp.cpp +++ source/Plugins/Language/CPlusPlus/LibStdcpp.cpp @@ -297,8 +297,11 @@ if (!wchar_compiler_type) return false; - const uint32_t wchar_size = wchar_compiler_type.GetBitSize( - nullptr); // Safe to pass NULL for exe_scope here + // Safe to pass nullptr for exe_scope here. + auto size = wchar_compiler_type.GetBitSize(nullptr); + if (!size) + return false; + const uint32_t wchar_size = *size; StringPrinter::ReadStringAndDumpToStreamOptions options(valobj); Status error; Index: source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp =================================================================== --- source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp +++ source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp @@ -513,10 +513,11 @@ CompilerType ivar_type = encoding_to_type_sp->RealizeType(type, for_expression); if (ivar_type) { + auto ivar_size = ivar_type.GetByteSize(nullptr); LLDB_LOGV(log, "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = " "{3}, type_size = {4}", - name, type, offset_ptr, size, ivar_type.GetByteSize(nullptr)); + name, type, offset_ptr, size, ivar_size ? *ivar_size : 0); Scalar offset_scalar; Status error; const int offset_ptr_size = 4; Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -1850,12 +1850,13 @@ clang_type = ClangASTContext::CreateMemberPointerType( class_clang_type, pointee_clang_type); - byte_size = clang_type.GetByteSize(nullptr); - - type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, - byte_size, NULL, LLDB_INVALID_UID, - Type::eEncodingIsUID, NULL, clang_type, - Type::eResolveStateForward)); + if (auto clang_type_size = clang_type.GetByteSize(nullptr)) { + byte_size = *clang_type_size; + type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, + byte_size, NULL, LLDB_INVALID_UID, + Type::eEncodingIsUID, NULL, clang_type, + Type::eResolveStateForward)); + } } break; @@ -2045,7 +2046,10 @@ clang_type.IsIntegerOrEnumerationType(is_signed); if (tag == DW_TAG_template_value_parameter && uval64_valid) { - llvm::APInt apint(clang_type.GetBitSize(nullptr), uval64, is_signed); + auto size = clang_type.GetBitSize(nullptr); + if (!size) + return false; + llvm::APInt apint(*size, uval64, is_signed); template_param_infos.args.push_back( clang::TemplateArgument(*ast, llvm::APSInt(apint, !is_signed), ClangUtil::GetQualType(clang_type))); Index: source/Symbol/ClangASTContext.cpp =================================================================== --- source/Symbol/ClangASTContext.cpp +++ source/Symbol/ClangASTContext.cpp @@ -1141,9 +1141,10 @@ uint32_t ClangASTContext::GetPointerByteSize() { if (m_pointer_byte_size == 0) - m_pointer_byte_size = GetBasicType(lldb::eBasicTypeVoid) - .GetPointerType() - .GetByteSize(nullptr); + if (auto size = GetBasicType(lldb::eBasicTypeVoid) + .GetPointerType() + .GetByteSize(nullptr)) + m_pointer_byte_size = *size; return m_pointer_byte_size; } @@ -4505,7 +4506,8 @@ // TODO: the real stride will be >= this value.. find the real one! if (stride) - *stride = element_type.GetByteSize(nullptr); + if (auto size = element_type.GetByteSize(nullptr)) + *stride = *size; return element_type; } @@ -6682,9 +6684,11 @@ CompilerType base_class_clang_type(getASTContext(), base_class->getType()); child_name = base_class_clang_type.GetTypeName().AsCString(""); - uint64_t base_class_clang_type_bit_size = - base_class_clang_type.GetBitSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); + auto size = base_class_clang_type.GetBitSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); + if (!size) + return {}; + uint64_t base_class_clang_type_bit_size = *size; // Base classes bit sizes should be a multiple of 8 bits in size assert(base_class_clang_type_bit_size % 8 == 0); @@ -6712,8 +6716,11 @@ // alignment (field_type_info.second) from the AST context. CompilerType field_clang_type(getASTContext(), field->getType()); assert(field_idx < record_layout.getFieldCount()); - child_byte_size = field_clang_type.GetByteSize( + auto size = field_clang_type.GetByteSize( exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); + if (!size) + return {}; + child_byte_size = *size; const uint32_t child_bit_size = child_byte_size * 8; // Figure out the field offset within the current struct/union/class @@ -6884,10 +6891,12 @@ // We have a pointer to an simple type if (idx == 0 && pointee_clang_type.GetCompleteType()) { - child_byte_size = pointee_clang_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = 0; - return pointee_clang_type; + if (auto size = pointee_clang_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL)) { + child_byte_size = *size; + child_byte_offset = 0; + return pointee_clang_type; + } } } } @@ -6905,10 +6914,12 @@ ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]", static_cast(idx)); child_name.assign(element_name); - child_byte_size = element_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; - return element_type; + if (auto size = element_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL)) { + child_byte_size = *size; + child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; + return element_type; + } } } } @@ -6922,10 +6933,12 @@ CompilerType element_type(getASTContext(), array->getElementType()); if (element_type.GetCompleteType()) { child_name = llvm::formatv("[{0}]", idx); - child_byte_size = element_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; - return element_type; + if (auto size = element_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL)) { + child_byte_size = *size; + child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; + return element_type; + } } } } @@ -6959,10 +6972,12 @@ // We have a pointer to an simple type if (idx == 0) { - child_byte_size = pointee_clang_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = 0; - return pointee_clang_type; + if (auto size = pointee_clang_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL)) { + child_byte_size = *size; + child_byte_offset = 0; + return pointee_clang_type; + } } } break; @@ -6994,10 +7009,12 @@ // We have a pointer to an simple type if (idx == 0) { - child_byte_size = pointee_clang_type.GetByteSize( - exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - child_byte_offset = 0; - return pointee_clang_type; + if (auto size = pointee_clang_type.GetByteSize( + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL)) { + child_byte_size = *size; + child_byte_offset = 0; + return pointee_clang_type; + } } } } Index: source/Symbol/CompilerType.cpp =================================================================== --- source/Symbol/CompilerType.cpp +++ source/Symbol/CompilerType.cpp @@ -504,15 +504,18 @@ // Exploring the type //---------------------------------------------------------------------- -uint64_t CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const { - if (IsValid()) { +llvm::Optional +CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const { + if (IsValid()) return m_type_system->GetBitSize(m_type, exe_scope); - } - return 0; + return {}; } -uint64_t CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const { - return (GetBitSize(exe_scope) + 7) / 8; +llvm::Optional +CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const { + if (auto bit_size = GetBitSize(exe_scope)) + return (*bit_size + 7) / 8; + return {}; } size_t CompilerType::GetTypeBitAlign() const { @@ -816,7 +819,9 @@ if (encoding == lldb::eEncodingInvalid || count != 1) return false; - const uint64_t byte_size = GetByteSize(nullptr); + auto byte_size = GetByteSize(nullptr); + if (!byte_size) + return false; lldb::offset_t offset = data_byte_offset; switch (encoding) { case lldb::eEncodingInvalid: @@ -824,15 +829,15 @@ case lldb::eEncodingVector: break; case lldb::eEncodingUint: - if (byte_size <= sizeof(unsigned long long)) { - uint64_t uval64 = data.GetMaxU64(&offset, byte_size); - if (byte_size <= sizeof(unsigned int)) { + if (*byte_size <= sizeof(unsigned long long)) { + uint64_t uval64 = data.GetMaxU64(&offset, *byte_size); + if (*byte_size <= sizeof(unsigned int)) { value = (unsigned int)uval64; return true; - } else if (byte_size <= sizeof(unsigned long)) { + } else if (*byte_size <= sizeof(unsigned long)) { value = (unsigned long)uval64; return true; - } else if (byte_size <= sizeof(unsigned long long)) { + } else if (*byte_size <= sizeof(unsigned long long)) { value = (unsigned long long)uval64; return true; } else @@ -841,15 +846,15 @@ break; case lldb::eEncodingSint: - if (byte_size <= sizeof(long long)) { - int64_t sval64 = data.GetMaxS64(&offset, byte_size); - if (byte_size <= sizeof(int)) { + if (*byte_size <= sizeof(long long)) { + int64_t sval64 = data.GetMaxS64(&offset, *byte_size); + if (*byte_size <= sizeof(int)) { value = (int)sval64; return true; - } else if (byte_size <= sizeof(long)) { + } else if (*byte_size <= sizeof(long)) { value = (long)sval64; return true; - } else if (byte_size <= sizeof(long long)) { + } else if (*byte_size <= sizeof(long long)) { value = (long long)sval64; return true; } else @@ -858,10 +863,10 @@ break; case lldb::eEncodingIEEE754: - if (byte_size <= sizeof(long double)) { + if (*byte_size <= sizeof(long double)) { uint32_t u32; uint64_t u64; - if (byte_size == sizeof(float)) { + if (*byte_size == sizeof(float)) { if (sizeof(float) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((float *)&u32); @@ -871,7 +876,7 @@ value = *((float *)&u64); return true; } - } else if (byte_size == sizeof(double)) { + } else if (*byte_size == sizeof(double)) { if (sizeof(double) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((double *)&u32); @@ -881,7 +886,7 @@ value = *((double *)&u64); return true; } - } else if (byte_size == sizeof(long double)) { + } else if (*byte_size == sizeof(long double)) { if (sizeof(long double) == sizeof(uint32_t)) { u32 = data.GetU32(&offset); value = *((long double *)&u32); @@ -912,12 +917,15 @@ if (encoding == lldb::eEncodingInvalid || count != 1) return false; - const uint64_t bit_width = GetBitSize(nullptr); + auto bit_width = GetBitSize(nullptr); + if (!bit_width) + return false; + // This function doesn't currently handle non-byte aligned assignments - if ((bit_width % 8) != 0) + if ((*bit_width % 8) != 0) return false; - const uint64_t byte_size = (bit_width + 7) / 8; + const uint64_t byte_size = (*bit_width + 7) / 8; switch (encoding) { case lldb::eEncodingInvalid: break; @@ -994,20 +1002,23 @@ if (!GetCompleteType()) return false; - const uint64_t byte_size = + auto byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); - if (data.GetByteSize() < byte_size) { - lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0')); + if (!byte_size) + return false; + + if (data.GetByteSize() < *byte_size) { + lldb::DataBufferSP data_sp(new DataBufferHeap(*byte_size, '\0')); data.SetData(data_sp); } - uint8_t *dst = const_cast(data.PeekData(0, byte_size)); + uint8_t *dst = const_cast(data.PeekData(0, *byte_size)); if (dst != nullptr) { if (address_type == eAddressTypeHost) { if (addr == 0) return false; // The address is an address in this process, so just copy it - memcpy(dst, reinterpret_cast(addr), byte_size); + memcpy(dst, reinterpret_cast(addr), *byte_size); return true; } else { Process *process = nullptr; @@ -1015,7 +1026,7 @@ process = exe_ctx->GetProcessPtr(); if (process) { Status error; - return process->ReadMemory(addr, dst, byte_size, error) == byte_size; + return process->ReadMemory(addr, dst, *byte_size, error) == *byte_size; } } } @@ -1036,13 +1047,15 @@ if (!GetCompleteType()) return false; - const uint64_t byte_size = + auto byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL); + if (!byte_size) + return false; - if (byte_size > 0) { + if (*byte_size > 0) { if (address_type == eAddressTypeHost) { // The address is an address in this process, so just copy it - memcpy((void *)addr, new_value.GetData(), byte_size); + memcpy((void *)addr, new_value.GetData(), *byte_size); return true; } else { Process *process = nullptr; @@ -1050,8 +1063,8 @@ process = exe_ctx->GetProcessPtr(); if (process) { Status error; - return process->WriteMemory(addr, new_value.GetData(), byte_size, - error) == byte_size; + return process->WriteMemory(addr, new_value.GetData(), *byte_size, + error) == *byte_size; } } } Index: source/Symbol/Type.cpp =================================================================== --- source/Symbol/Type.cpp +++ source/Symbol/Type.cpp @@ -321,7 +321,8 @@ if (encoding_type) m_byte_size = encoding_type->GetByteSize(); if (m_byte_size == 0) - m_byte_size = GetLayoutCompilerType().GetByteSize(nullptr); + if (auto size = GetLayoutCompilerType().GetByteSize(nullptr)) + m_byte_size = *size; } break; // If we are a pointer or reference, then this is just a pointer size;