diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index e2847c778484..7d50e6d3c865 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -793,7 +793,7 @@ public: uint32_t item_count = 1); virtual uint64_t - GetData (DataExtractor& data); + GetData (DataExtractor& data, Error &error); virtual bool SetData (DataExtractor &data, Error &error); diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 4bd018352ff2..c379508ab05b 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -1569,8 +1569,9 @@ SBValue::GetData () if (value_sp) { DataExtractorSP data_sp(new DataExtractor()); - value_sp->GetData(*data_sp); - if (data_sp->GetByteSize() > 0) + Error error; + value_sp->GetData(*data_sp, error); + if (error.Success()) *sb_data = data_sp; } if (log) diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 10e5ab452f0f..f58271c0638d 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -978,14 +978,15 @@ ValueObject::GetPointeeData (DataExtractor& data, ValueObjectSP pointee_sp = Dereference(error); if (error.Fail() || pointee_sp.get() == NULL) return 0; - return pointee_sp->GetData(data); + return pointee_sp->GetData(data, error); } else { ValueObjectSP child_sp = GetChildAtIndex(0, true); if (child_sp.get() == NULL) return 0; - return child_sp->GetData(data); + Error error; + return child_sp->GetData(data, error); } return true; } @@ -1059,11 +1060,11 @@ ValueObject::GetPointeeData (DataExtractor& data, } uint64_t -ValueObject::GetData (DataExtractor& data) +ValueObject::GetData (DataExtractor& data, Error &error) { UpdateValueIfNeeded(false); ExecutionContext exe_ctx (GetExecutionContextRef()); - Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); + error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get()); if (error.Fail()) { if (m_data.GetByteSize()) diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp index 136c8c51e660..04f090dd15b6 100644 --- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp +++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp @@ -576,7 +576,11 @@ bool lldb_private::formatters::Char16SummaryProvider (ValueObject& valobj, Stream& stream) { DataExtractor data; - valobj.GetData(data); + Error error; + valobj.GetData(data, error); + + if (error.Fail()) + return false; std::string value; valobj.GetValueAsCString(lldb::eFormatUnicode16, value); @@ -590,7 +594,11 @@ bool lldb_private::formatters::Char32SummaryProvider (ValueObject& valobj, Stream& stream) { DataExtractor data; - valobj.GetData(data); + Error error; + valobj.GetData(data, error); + + if (error.Fail()) + return false; std::string value; valobj.GetValueAsCString(lldb::eFormatUnicode32, value); @@ -604,7 +612,11 @@ bool lldb_private::formatters::WCharSummaryProvider (ValueObject& valobj, Stream& stream) { DataExtractor data; - valobj.GetData(data); + Error error; + valobj.GetData(data, error); + + if (error.Fail()) + return false; clang::ASTContext* ast = valobj.GetClangType().GetASTContext(); @@ -1144,7 +1156,10 @@ lldb_private::formatters::NSAttributedStringSummaryProvider (ValueObject& valobj if (!child_ptr_sp) return false; DataExtractor data; - child_ptr_sp->GetData(data); + Error error; + child_ptr_sp->GetData(data, error); + if (error.Fail()) + return false; ValueObjectSP child_sp(child_ptr_sp->CreateValueObjectFromData("string_data", data, exe_ctx, type)); child_sp->GetValueAsUnsigned(0); if (child_sp) @@ -1218,7 +1233,10 @@ lldb_private::formatters::ObjCSELSummaryProvider (ValueObject& valobj, Stream& s else { DataExtractor data; - valobj.GetData(data); + Error error; + valobj.GetData(data, error); + if (error.Fail()) + return false; valobj_sp = ValueObject::CreateValueObjectFromData("text", data, exe_ctx, charstar); } diff --git a/lldb/source/DataFormatters/LibCxxList.cpp b/lldb/source/DataFormatters/LibCxxList.cpp index 9ec8a7855982..e542a98103f4 100644 --- a/lldb/source/DataFormatters/LibCxxList.cpp +++ b/lldb/source/DataFormatters/LibCxxList.cpp @@ -257,7 +257,11 @@ lldb_private::formatters::LibcxxStdListSyntheticFrontEnd::GetChildAtIndex (size_ return lldb::ValueObjectSP(); // we need to copy current_sp into a new object otherwise we will end up with all items named __value_ DataExtractor data; - current_sp->GetData(data); + Error error; + current_sp->GetData(data, error); + if (error.Fail()) + return lldb::ValueObjectSP(); + StreamString name; name.Printf("[%zu]",idx); return (m_children[idx] = ValueObject::CreateValueObjectFromData(name.GetData(), data, m_backend.GetExecutionContextRef(), m_element_type)); diff --git a/lldb/source/DataFormatters/LibCxxMap.cpp b/lldb/source/DataFormatters/LibCxxMap.cpp index 5daa40f15f3d..7d5c94f38e88 100644 --- a/lldb/source/DataFormatters/LibCxxMap.cpp +++ b/lldb/source/DataFormatters/LibCxxMap.cpp @@ -366,7 +366,13 @@ lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetChildAtIndex (size_t // at this point we have a valid // we need to copy current_sp into a new object otherwise we will end up with all items named __value_ DataExtractor data; - iterated_sp->GetData(data); + Error error; + iterated_sp->GetData(data, error); + if (error.Fail()) + { + m_tree = NULL; + return lldb::ValueObjectSP(); + } StreamString name; name.Printf("[%zu]",idx); return (m_children[idx] = ValueObject::CreateValueObjectFromData(name.GetData(), data, m_backend.GetExecutionContextRef(), m_element_type)); diff --git a/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp b/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp index 05b41d0de0c8..99cd08e346ef 100644 --- a/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp +++ b/lldb/source/DataFormatters/LibCxxUnorderedMap.cpp @@ -83,7 +83,10 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::GetChildAtInde StreamString stream; stream.Printf("[%zu]",idx); DataExtractor data; - val_hash.first->GetData(data); + Error error; + val_hash.first->GetData(data, error); + if (error.Fail()) + return lldb::ValueObjectSP(); const bool thread_and_frame_only_if_stopped = true; ExecutionContext exe_ctx = val_hash.first->GetExecutionContextRef().Lock(thread_and_frame_only_if_stopped); return val_hash.first->CreateValueObjectFromData(stream.GetData(), diff --git a/lldb/source/DataFormatters/TypeFormat.cpp b/lldb/source/DataFormatters/TypeFormat.cpp index a72f551c741f..1648a16dd1b0 100644 --- a/lldb/source/DataFormatters/TypeFormat.cpp +++ b/lldb/source/DataFormatters/TypeFormat.cpp @@ -64,7 +64,10 @@ TypeFormatImpl_Format::FormatObject (ValueObject *valobj, const RegisterInfo *reg_info = value.GetRegisterInfo(); if (reg_info) { - valobj->GetData(data); + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; StreamString reg_sstr; data.Dump (®_sstr, @@ -105,7 +108,12 @@ TypeFormatImpl_Format::FormatObject (ValueObject *valobj, } } else - valobj->GetData(data); + { + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; + } StreamString sstr; clang_type.DumpTypeValue (&sstr, // The stream to use for display @@ -203,7 +211,10 @@ TypeFormatImpl_EnumType::FormatObject (ValueObject *valobj, if (valobj_enum_type.IsValid() == false) return false; DataExtractor data; - valobj->GetData(data); + Error error; + valobj->GetData(data, error); + if (error.Fail()) + return false; ExecutionContext exe_ctx (valobj->GetExecutionContextRef()); StreamString sstr; valobj_enum_type.DumpTypeValue(&sstr, diff --git a/lldb/source/Expression/ClangUserExpression.cpp b/lldb/source/Expression/ClangUserExpression.cpp index 6b0eee8cf363..6586d10b1875 100644 --- a/lldb/source/Expression/ClangUserExpression.cpp +++ b/lldb/source/Expression/ClangUserExpression.cpp @@ -709,7 +709,7 @@ ClangUserExpression::PrepareToExecuteJITExpression (Stream &error_stream, if (!materialize_error.Success()) { - error_stream.Printf("Couldn't materialize struct: %s\n", materialize_error.AsCString()); + error_stream.Printf("Couldn't materialize: %s\n", materialize_error.AsCString()); return false; } } diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index 90687c0739d9..25ffd7b4b199 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -443,10 +443,26 @@ public: return; } + Error valobj_error = valobj_sp->GetError(); + + if (valobj_error.Fail()) + { + err.SetErrorStringWithFormat("couldn't get the value of variable %s: %s", m_variable_sp->GetName().AsCString(), valobj_error.AsCString()); + return; + } + if (m_is_reference) { DataExtractor valobj_extractor; - valobj_sp->GetData(valobj_extractor); + Error extract_error; + valobj_sp->GetData(valobj_extractor, extract_error); + + if (!extract_error.Success()) + { + err.SetErrorStringWithFormat("couldn't read contents of reference variable %s: %s", m_variable_sp->GetName().AsCString(), extract_error.AsCString()); + return; + } + lldb::offset_t offset = 0; lldb::addr_t reference_addr = valobj_extractor.GetAddress(&offset); @@ -478,8 +494,14 @@ public: else { DataExtractor data; - valobj_sp->GetData(data); - + Error extract_error; + valobj_sp->GetData(data, extract_error); + if (!extract_error.Success()) + { + err.SetErrorStringWithFormat("couldn't get the value of %s: %s", m_variable_sp->GetName().AsCString(), extract_error.AsCString()); + return; + } + if (m_temporary_allocation != LLDB_INVALID_ADDRESS) { err.SetErrorStringWithFormat("trying to create a temporary region for %s but one exists", m_variable_sp->GetName().AsCString()); diff --git a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp index abf873ff3dd1..c884b84e662b 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp @@ -522,7 +522,13 @@ ABIMacOSX_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObj if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType()) { DataExtractor data; - size_t num_bytes = new_value_sp->GetData(data); + Error data_error; + size_t num_bytes = new_value_sp->GetData(data, data_error); + if (data_error.Fail()) + { + error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString()); + return error; + } lldb::offset_t offset = 0; if (num_bytes <= 8) { diff --git a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp index 8596381b3cbc..178348919833 100644 --- a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp @@ -600,7 +600,13 @@ ABIMacOSX_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType()) { DataExtractor data; - size_t num_bytes = new_value_sp->GetData(data); + Error data_error; + size_t num_bytes = new_value_sp->GetData(data, data_error); + if (data_error.Fail()) + { + error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString()); + return error; + } lldb::offset_t offset = 0; if (num_bytes <= 8) { diff --git a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp index a8ef6a51399c..763a00aa9a7f 100644 --- a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp +++ b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp @@ -562,7 +562,13 @@ ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0); DataExtractor data; - size_t num_bytes = new_value_sp->GetData(data); + Error data_error; + size_t num_bytes = new_value_sp->GetData(data, data_error); + if (data_error.Fail()) + { + error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString()); + return error; + } lldb::offset_t offset = 0; if (num_bytes <= 8) { @@ -589,8 +595,14 @@ ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0); RegisterValue xmm0_value; DataExtractor data; - size_t num_bytes = new_value_sp->GetData(data); - + Error data_error; + size_t num_bytes = new_value_sp->GetData(data, data_error); + if (data_error.Fail()) + { + error.SetErrorStringWithFormat("Couldn't convert return value to raw data: %s", data_error.AsCString()); + return error; + } + unsigned char buffer[16]; ByteOrder byte_order = data.GetByteOrder();