From: Adrian Prantl Date: Tue, 21 Jul 2020 20:53:43 +0000 (-0700) Subject: Thread ExecutionContextScope through GetByteSize where possible (NFC-ish) X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=02f58373634fb87c728eb289a35b0819d7aafeee;p=android-x86%2Fexternal-llvm-project.git Thread ExecutionContextScope through GetByteSize where possible (NFC-ish) This patch has no effect for C and C++. In more dynamic languages, such as Objective-C and Swift GetByteSize() needs to call into the language runtime, so it's important to pass one in where possible. My primary motivation for this is some work I'm doing on the Swift branch, however, it looks like we are also seeing warnings in Objective-C that this may resolve. Everything in the SymbolFile hierarchy still passes in nullptrs, because we don't have an execution context in SymbolFile, since SymbolFile transcends processes. Differential Revision: https://reviews.llvm.org/D84267 --- diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index 280966a327e..7d5d71cbc55 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -177,7 +177,8 @@ public: /// Creating related types. /// \{ - CompilerType GetArrayElementType(uint64_t *stride = nullptr) const; + CompilerType GetArrayElementType(ExecutionContextScope *exe_scope, + uint64_t *stride = nullptr) const; CompilerType GetArrayType(uint64_t size) const; @@ -383,7 +384,8 @@ public: /// \} bool GetValueAsScalar(const DataExtractor &data, lldb::offset_t data_offset, - size_t data_byte_size, Scalar &value) const; + size_t data_byte_size, Scalar &value, + ExecutionContextScope *exe_scope) const; void Clear() { m_type = nullptr; m_type_system = nullptr; diff --git a/lldb/include/lldb/Symbol/Type.h b/lldb/include/lldb/Symbol/Type.h index 8735d016bb2..efd3ede0344 100644 --- a/lldb/include/lldb/Symbol/Type.h +++ b/lldb/include/lldb/Symbol/Type.h @@ -114,14 +114,15 @@ public: // Type instances. They can store a weak pointer to the Module; lldb::ModuleSP GetModule(); - void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name); + void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, + ExecutionContextScope *exe_scope); SymbolFile *GetSymbolFile() { return m_symbol_file; } const SymbolFile *GetSymbolFile() const { return m_symbol_file; } ConstString GetName(); - llvm::Optional GetByteSize(); + llvm::Optional GetByteSize(ExecutionContextScope *exe_scope); uint32_t GetNumChildren(bool omit_empty_base_classes); diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index e188f29354b..c1990950634 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -217,8 +217,9 @@ public: // Creating related types - virtual CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride) = 0; + virtual CompilerType + GetArrayElementType(lldb::opaque_compiler_type_t type, uint64_t *stride, + ExecutionContextScope *exe_scope) = 0; virtual CompilerType GetArrayType(lldb::opaque_compiler_type_t type, uint64_t size); diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp index 852630f2d01..1c1d4e3a3ed 100644 --- a/lldb/source/API/SBType.cpp +++ b/lldb/source/API/SBType.cpp @@ -214,8 +214,8 @@ SBType SBType::GetArrayElementType() { return LLDB_RECORD_RESULT(SBType()); CompilerType canonical_type = m_opaque_sp->GetCompilerType(true).GetCanonicalType(); - return LLDB_RECORD_RESULT( - SBType(TypeImplSP(new TypeImpl(canonical_type.GetArrayElementType())))); + return LLDB_RECORD_RESULT(SBType( + TypeImplSP(new TypeImpl(canonical_type.GetArrayElementType(nullptr))))); } SBType SBType::GetArrayType(uint64_t size) { diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index e50415f930b..0a14a25107a 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -1624,7 +1624,8 @@ static size_t LookupFunctionInModule(CommandInterpreter &interpreter, return 0; } -static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm, +static size_t LookupTypeInModule(Target *target, + CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name_cstr, bool name_is_regex) { TypeList type_list; @@ -1652,7 +1653,7 @@ static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm, // Resolve the clang type so that any forward references to types // that haven't yet been parsed will get parsed. type_sp->GetFullCompilerType(); - type_sp->GetDescription(&strm, eDescriptionLevelFull, true); + type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target); // Print all typedef chains TypeSP typedef_type_sp(type_sp); TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType()); @@ -1661,7 +1662,8 @@ static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm, strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); typedefed_type_sp->GetFullCompilerType(); - typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true); + typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true, + target); typedef_type_sp = typedefed_type_sp; typedefed_type_sp = typedef_type_sp->GetTypedefType(); } @@ -1671,9 +1673,9 @@ static size_t LookupTypeInModule(CommandInterpreter &interpreter, Stream &strm, return type_list.GetSize(); } -static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm, - Module &module, const char *name_cstr, - bool name_is_regex) { +static size_t LookupTypeHere(Target *target, CommandInterpreter &interpreter, + Stream &strm, Module &module, + const char *name_cstr, bool name_is_regex) { TypeList type_list; const uint32_t max_num_matches = UINT32_MAX; bool name_is_fully_qualified = false; @@ -1696,8 +1698,8 @@ static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm, // Resolve the clang type so that any forward references to types that // haven't yet been parsed will get parsed. type_sp->GetFullCompilerType(); - type_sp->GetDescription(&strm, eDescriptionLevelFull, true); - // Print all typedef chains + type_sp->GetDescription(&strm, eDescriptionLevelFull, true, target); + // Print all typedef chains. TypeSP typedef_type_sp(type_sp); TypeSP typedefed_type_sp(typedef_type_sp->GetTypedefType()); while (typedefed_type_sp) { @@ -1705,7 +1707,8 @@ static size_t LookupTypeHere(CommandInterpreter &interpreter, Stream &strm, strm.Printf(" typedef '%s': ", typedef_type_sp->GetName().GetCString()); typedefed_type_sp->GetFullCompilerType(); - typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true); + typedefed_type_sp->GetDescription(&strm, eDescriptionLevelFull, true, + target); typedef_type_sp = typedefed_type_sp; typedefed_type_sp = typedef_type_sp->GetTypedefType(); } @@ -3745,9 +3748,9 @@ public: return false; case eLookupTypeType: if (!m_options.m_str.empty()) { - if (LookupTypeHere(m_interpreter, result.GetOutputStream(), - *sym_ctx.module_sp, m_options.m_str.c_str(), - m_options.m_use_regex)) { + if (LookupTypeHere(&GetSelectedTarget(), m_interpreter, + result.GetOutputStream(), *sym_ctx.module_sp, + m_options.m_str.c_str(), m_options.m_use_regex)) { result.SetStatus(eReturnStatusSuccessFinishResult); return true; } @@ -3817,9 +3820,9 @@ public: case eLookupTypeType: if (!m_options.m_str.empty()) { - if (LookupTypeInModule(m_interpreter, result.GetOutputStream(), module, - m_options.m_str.c_str(), - m_options.m_use_regex)) { + if (LookupTypeInModule( + &GetSelectedTarget(), m_interpreter, result.GetOutputStream(), + module, m_options.m_str.c_str(), m_options.m_use_regex)) { result.SetStatus(eReturnStatusSuccessFinishResult); return true; } diff --git a/lldb/source/Core/Value.cpp b/lldb/source/Core/Value.cpp index fd5f7e2565d..64e9a507bcf 100644 --- a/lldb/source/Core/Value.cpp +++ b/lldb/source/Core/Value.cpp @@ -603,8 +603,9 @@ Scalar &Value::ResolveValue(ExecutionContext *exe_ctx) { Status error(GetValueAsData(exe_ctx, data, nullptr)); if (error.Success()) { Scalar scalar; - if (compiler_type.GetValueAsScalar(data, 0, data.GetByteSize(), - scalar)) { + if (compiler_type.GetValueAsScalar( + data, 0, data.GetByteSize(), scalar, + exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr)) { m_value = scalar; m_value_type = eValueTypeScalar; } else { diff --git a/lldb/source/Core/ValueObjectMemory.cpp b/lldb/source/Core/ValueObjectMemory.cpp index 91b2c608492..8e7d3ebc93f 100644 --- a/lldb/source/Core/ValueObjectMemory.cpp +++ b/lldb/source/Core/ValueObjectMemory.cpp @@ -140,9 +140,12 @@ size_t ValueObjectMemory::CalculateNumChildren(uint32_t max) { } uint64_t ValueObjectMemory::GetByteSize() { + ExecutionContext exe_ctx(GetExecutionContextRef()); if (m_type_sp) - return m_type_sp->GetByteSize().getValueOr(0); - return m_compiler_type.GetByteSize(nullptr).getValueOr(0); + return m_type_sp->GetByteSize(exe_ctx.GetBestExecutionContextScope()) + .getValueOr(0); + return m_compiler_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()) + .getValueOr(0); } lldb::ValueType ValueObjectMemory::GetValueType() const { diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp index af6df3ae6b4..6c824d1f772 100644 --- a/lldb/source/DataFormatters/FormatManager.cpp +++ b/lldb/source/DataFormatters/FormatManager.cpp @@ -237,7 +237,9 @@ void FormatManager::GetPossibleMatches( // stripped. uint64_t array_size; if (compiler_type.IsArrayType(nullptr, &array_size, nullptr)) { - CompilerType element_type = compiler_type.GetArrayElementType(); + ExecutionContext exe_ctx(valobj.GetExecutionContextRef()); + CompilerType element_type = compiler_type.GetArrayElementType( + exe_ctx.GetBestExecutionContextScope()); if (element_type.IsTypedefType()) { // Get the stripped element type and compute the stripped array type // from it. diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index 200204c12cd..6f8d9b15457 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -514,7 +514,7 @@ public: return; } - if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize()) { + if (data.GetByteSize() < m_variable_sp->GetType()->GetByteSize(scope)) { if (data.GetByteSize() == 0 && !m_variable_sp->LocationExpression().IsValid()) { err.SetErrorStringWithFormat("the variable '%s' has no location, " @@ -525,7 +525,7 @@ public: "size of variable %s (%" PRIu64 ") is larger than the ValueObject's size (%" PRIu64 ")", m_variable_sp->GetName().AsCString(), - m_variable_sp->GetType()->GetByteSize().getValueOr(0), + m_variable_sp->GetType()->GetByteSize(scope).getValueOr(0), data.GetByteSize()); } return; diff --git a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp index 983da26a2a6..09b319a84a0 100644 --- a/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp +++ b/lldb/source/Plugins/ABI/AArch64/ABIMacOSX_arm64.cpp @@ -492,7 +492,8 @@ static bool LoadValueFromConsecutiveGPRRegisters( uint32_t &NGRN, // NGRN (see ABI documentation) uint32_t &NSRN, // NSRN (see ABI documentation) DataExtractor &data) { - llvm::Optional byte_size = value_type.GetByteSize(nullptr); + llvm::Optional byte_size = + value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); if (!byte_size || *byte_size == 0) return false; @@ -509,7 +510,8 @@ static bool LoadValueFromConsecutiveGPRRegisters( if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) { if (!base_type) return false; - llvm::Optional base_byte_size = base_type.GetByteSize(nullptr); + llvm::Optional base_byte_size = + base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); if (!base_byte_size) return false; uint32_t data_offset = 0; @@ -646,7 +648,7 @@ ValueObjectSP ABIMacOSX_arm64::GetReturnValueObjectImpl( return return_valobj_sp; llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; diff --git a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp index 831c8aa0d76..1214195dcfc 100644 --- a/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp +++ b/lldb/source/Plugins/ABI/AArch64/ABISysV_arm64.cpp @@ -466,7 +466,8 @@ static bool LoadValueFromConsecutiveGPRRegisters( uint32_t &NGRN, // NGRN (see ABI documentation) uint32_t &NSRN, // NSRN (see ABI documentation) DataExtractor &data) { - llvm::Optional byte_size = value_type.GetByteSize(nullptr); + llvm::Optional byte_size = + value_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); if (byte_size || *byte_size == 0) return false; @@ -484,7 +485,8 @@ static bool LoadValueFromConsecutiveGPRRegisters( if (NSRN < 8 && (8 - NSRN) >= homogeneous_count) { if (!base_type) return false; - llvm::Optional base_byte_size = base_type.GetByteSize(nullptr); + llvm::Optional base_byte_size = + base_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()); if (!base_byte_size) return false; uint32_t data_offset = 0; @@ -614,7 +616,7 @@ ValueObjectSP ABISysV_arm64::GetReturnValueObjectImpl( return return_valobj_sp; llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; diff --git a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp index a212eef2ab8..540270fb954 100644 --- a/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp +++ b/lldb/source/Plugins/ABI/ARC/ABISysV_arc.cpp @@ -458,7 +458,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread, const uint32_t type_flags = compiler_type.GetTypeInfo(); // Integer return type. if (type_flags & eTypeIsInteger) { - const size_t byte_size = compiler_type.GetByteSize(nullptr).getValueOr(0); + const size_t byte_size = compiler_type.GetByteSize(&thread).getValueOr(0); auto raw_value = ReadRawValue(reg_ctx, byte_size); const bool is_signed = (type_flags & eTypeIsSigned) != 0; @@ -482,7 +482,7 @@ ABISysV_arc::GetReturnValueObjectSimple(Thread &thread, if (compiler_type.IsFloatingPointType(float_count, is_complex) && 1 == float_count && !is_complex) { - const size_t byte_size = compiler_type.GetByteSize(nullptr).getValueOr(0); + const size_t byte_size = compiler_type.GetByteSize(&thread).getValueOr(0); auto raw_value = ReadRawValue(reg_ctx, byte_size); if (!SetSizedFloat(value.GetScalar(), raw_value, byte_size)) diff --git a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp index 1a93bac564f..c63c569f875 100644 --- a/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp +++ b/lldb/source/Plugins/ABI/ARM/ABISysV_arm.cpp @@ -1718,7 +1718,7 @@ ValueObjectSP ABISysV_arm::GetReturnValueObjectImpl( if (homogeneous_count > 0 && homogeneous_count <= 4) { llvm::Optional base_byte_size = - base_type.GetByteSize(nullptr); + base_type.GetByteSize(&thread); if (base_type.IsVectorType(nullptr, nullptr)) { if (base_byte_size && (*base_byte_size == 8 || *base_byte_size == 16)) { @@ -1747,7 +1747,7 @@ ValueObjectSP ABISysV_arm::GetReturnValueObjectImpl( if (base_type.IsFloatingPointType(float_count, is_complex)) { llvm::Optional base_byte_size = - base_type.GetByteSize(nullptr); + base_type.GetByteSize(&thread); if (float_count == 2 && is_complex) { if (index != 0 && base_byte_size && vfp_byte_size != *base_byte_size) diff --git a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp index bb28a50e5f4..751555722da 100644 --- a/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp +++ b/lldb/source/Plugins/ABI/Mips/ABISysV_mips64.cpp @@ -753,7 +753,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl( const ArchSpec target_arch = target->GetArchitecture(); ByteOrder target_byte_order = target_arch.GetByteOrder(); llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; const uint32_t type_flags = return_compiler_type.GetTypeInfo(nullptr); @@ -962,7 +962,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl( return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); llvm::Optional field_byte_width = - field_compiler_type.GetByteSize(nullptr); + field_compiler_type.GetByteSize(&thread); if (!field_byte_width) return return_valobj_sp; @@ -1034,7 +1034,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl( CompilerType field_compiler_type = return_compiler_type.GetFieldAtIndex( idx, name, &field_bit_offset, nullptr, nullptr); llvm::Optional field_byte_width = - field_compiler_type.GetByteSize(nullptr); + field_compiler_type.GetByteSize(&thread); // if we don't know the size of the field (e.g. invalid type), just // bail out diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp index 6f5eded7b03..91d2e59ed63 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc.cpp @@ -527,7 +527,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple( // Extract the register context so we can read arguments from registers llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( @@ -574,7 +574,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple( // Don't handle complex yet. } else { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *f1_info = reg_ctx->GetRegisterInfoByName("f1", 0); RegisterValue f1_value; @@ -608,7 +608,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectSimple( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size > 0) { const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("v2", 0); if (altivec_reg) { diff --git a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp index 251ac972fd7..c7cb7736df9 100644 --- a/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp +++ b/lldb/source/Plugins/ABI/PowerPC/ABISysV_ppc64.cpp @@ -567,7 +567,7 @@ private: ReturnValueExtractor(Thread &thread, CompilerType &type, RegisterContext *reg_ctx, ProcessSP process_sp) : m_thread(thread), m_type(type), - m_byte_size(m_type.GetByteSize(nullptr).getValueOr(0)), + m_byte_size(m_type.GetByteSize(&thread).getValueOr(0)), m_data_up(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( @@ -643,7 +643,7 @@ private: DataExtractor de(&raw_data, sizeof(raw_data), m_byte_order, m_addr_size); offset_t offset = 0; - llvm::Optional byte_size = type.GetByteSize(nullptr); + llvm::Optional byte_size = type.GetByteSize(m_process_sp.get()); if (!byte_size) return {}; switch (*byte_size) { @@ -777,7 +777,8 @@ private: CompilerType elem_type; if (m_type.IsHomogeneousAggregate(&elem_type)) { uint32_t type_flags = elem_type.GetTypeInfo(); - llvm::Optional elem_size = elem_type.GetByteSize(nullptr); + llvm::Optional elem_size = + elem_type.GetByteSize(m_process_sp.get()); if (!elem_size) return {}; if (type_flags & eTypeIsComplex || !(type_flags & eTypeIsFloat)) { diff --git a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp index eced2adc759..29ad4d97e71 100644 --- a/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp +++ b/lldb/source/Plugins/ABI/SystemZ/ABISysV_s390x.cpp @@ -508,7 +508,7 @@ ValueObjectSP ABISysV_s390x::GetReturnValueObjectSimple( if (type_flags & eTypeIsInteger) { // Extract the register context so we can read arguments from registers. llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( @@ -555,7 +555,7 @@ ValueObjectSP ABISysV_s390x::GetReturnValueObjectSimple( // Don't handle complex yet. } else { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *f0_info = reg_ctx->GetRegisterInfoByName("f0", 0); RegisterValue f0_value; diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp index 2ac87d1512e..2f47d3f462d 100644 --- a/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp +++ b/lldb/source/Plugins/ABI/X86/ABISysV_i386.cpp @@ -387,7 +387,7 @@ ValueObjectSP ABISysV_i386::GetReturnValueObjectSimple( { value.SetValueType(Value::eValueTypeScalar); llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; bool success = false; @@ -512,7 +512,7 @@ ValueObjectSP ABISysV_i386::GetReturnValueObjectSimple( } else if (type_flags & eTypeIsVector) // 'Packed' { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size > 0) { const RegisterInfo *vec_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0); if (vec_reg == nullptr) diff --git a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp index 7729e58f858..2aa2c02b2e8 100644 --- a/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp +++ b/lldb/source/Plugins/ABI/X86/ABISysV_x86_64.cpp @@ -406,7 +406,7 @@ ValueObjectSP ABISysV_x86_64::GetReturnValueObjectSimple( // Extract the register context so we can read arguments from registers llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( @@ -453,7 +453,7 @@ ValueObjectSP ABISysV_x86_64::GetReturnValueObjectSimple( // Don't handle complex yet. } else { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0); @@ -492,7 +492,7 @@ ValueObjectSP ABISysV_x86_64::GetReturnValueObjectSimple( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size > 0) { const RegisterInfo *altivec_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0); diff --git a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp index 63b670b0727..06e0ce40836 100644 --- a/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp +++ b/lldb/source/Plugins/ABI/X86/ABIWindows_x86_64.cpp @@ -414,7 +414,7 @@ ValueObjectSP ABIWindows_x86_64::GetReturnValueObjectSimple( if (type_flags & eTypeIsInteger) { // Extract the register context so we can read arguments from registers llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (!byte_size) return return_valobj_sp; uint64_t raw_value = thread.GetRegisterContext()->ReadRegisterAsUnsigned( @@ -461,7 +461,7 @@ ValueObjectSP ABIWindows_x86_64::GetReturnValueObjectSimple( // Don't handle complex yet. } else { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size <= sizeof(long double)) { const RegisterInfo *xmm0_info = reg_ctx->GetRegisterInfoByName("xmm0", 0); @@ -499,7 +499,7 @@ ValueObjectSP ABIWindows_x86_64::GetReturnValueObjectSimple( thread.GetStackFrameAtIndex(0).get(), value, ConstString("")); } else if (type_flags & eTypeIsVector) { llvm::Optional byte_size = - return_compiler_type.GetByteSize(nullptr); + return_compiler_type.GetByteSize(&thread); if (byte_size && *byte_size > 0) { const RegisterInfo *xmm_reg = reg_ctx->GetRegisterInfoByName("xmm0", 0); diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index 8511e554509..b35bf07034b 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -305,9 +305,7 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) { } lldb::TargetSP target_sp(m_execution_unit.GetTarget()); - lldb_private::ExecutionContext exe_ctx(target_sp, true); - llvm::Optional bit_size = - m_result_type.GetBitSize(exe_ctx.GetBestExecutionContextScope()); + llvm::Optional bit_size = m_result_type.GetBitSize(target_sp.get()); if (!bit_size) { lldb_private::StreamString type_desc_stream; m_result_type.DumpTypeDescription(&type_desc_stream); @@ -330,7 +328,8 @@ bool IRForTarget::CreateResultVariable(llvm::Function &llvm_function) { m_result_name = lldb_private::ConstString("$RESULT_NAME"); LLDB_LOG(log, "Creating a new result global: \"{0}\" with size {1}", - m_result_name, m_result_type.GetByteSize(nullptr).getValueOr(0)); + m_result_name, + m_result_type.GetByteSize(target_sp.get()).getValueOr(0)); // Construct a new result global and set up its metadata @@ -1242,10 +1241,12 @@ bool IRForTarget::MaybeHandleVariable(Value *llvm_value_ptr) { value_type = global_variable->getType(); } - llvm::Optional value_size = compiler_type.GetByteSize(nullptr); + auto *target = m_execution_unit.GetTarget().get(); + llvm::Optional value_size = compiler_type.GetByteSize(target); if (!value_size) return false; - llvm::Optional opt_alignment = compiler_type.GetTypeBitAlign(nullptr); + llvm::Optional opt_alignment = + compiler_type.GetTypeBitAlign(target); if (!opt_alignment) return false; lldb::offset_t value_alignment = (*opt_alignment + 7ull) / 8ull; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 62b6eee4075..35e7c34734e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -209,11 +209,12 @@ TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc, GetClangASTImporter().RequireCompleteType(ClangUtil::GetQualType(type)); SymbolFileDWARF *dwarf = die.GetDWARF(); - TypeSP type_sp(new Type( - die.GetID(), dwarf, pcm_type_sp->GetName(), pcm_type_sp->GetByteSize(), - nullptr, LLDB_INVALID_UID, Type::eEncodingInvalid, - &pcm_type_sp->GetDeclaration(), type, Type::ResolveState::Forward, - TypePayloadClang(GetOwningClangModule(die)))); + TypeSP type_sp(new Type(die.GetID(), dwarf, pcm_type_sp->GetName(), + pcm_type_sp->GetByteSize(nullptr), nullptr, + LLDB_INVALID_UID, Type::eEncodingInvalid, + &pcm_type_sp->GetDeclaration(), type, + Type::ResolveState::Forward, + TypePayloadClang(GetOwningClangModule(die)))); dwarf->GetTypeList().Insert(type_sp); dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); @@ -810,7 +811,7 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc, bool is_signed = false; enumerator_clang_type.IsIntegerType(is_signed); ParseChildEnumerators(clang_type, is_signed, - type_sp->GetByteSize().getValueOr(0), die); + type_sp->GetByteSize(nullptr).getValueOr(0), die); } TypeSystemClang::CompleteTagDeclarationDefinition(clang_type); } else { @@ -1261,7 +1262,7 @@ TypeSP DWARFASTParserClang::ParseArrayType(const DWARFDIE &die, attrs.bit_stride = array_info->bit_stride; } if (attrs.byte_stride == 0 && attrs.bit_stride == 0) - attrs.byte_stride = element_type->GetByteSize().getValueOr(0); + attrs.byte_stride = element_type->GetByteSize(nullptr).getValueOr(0); CompilerType array_element_type = element_type->GetForwardCompilerType(); CompleteType(array_element_type); @@ -2057,7 +2058,7 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die, if (!layout_info.field_offsets.empty() || !layout_info.base_offsets.empty() || !layout_info.vbase_offsets.empty()) { if (type) - layout_info.bit_size = type->GetByteSize().getValueOr(0) * 8; + layout_info.bit_size = type->GetByteSize(nullptr).getValueOr(0) * 8; if (layout_info.bit_size == 0) layout_info.bit_size = die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; @@ -2079,7 +2080,7 @@ bool DWARFASTParserClang::CompleteEnumType(const DWARFDIE &die, bool is_signed = false; clang_type.IsIntegerType(is_signed); ParseChildEnumerators(clang_type, is_signed, - type->GetByteSize().getValueOr(0), die); + type->GetByteSize(nullptr).getValueOr(0), die); } TypeSystemClang::CompleteTagDeclarationDefinition(clang_type); } @@ -2567,7 +2568,7 @@ void DWARFASTParserClang::ParseSingleMember( this_field_info.bit_offset = data_bit_offset; } else { if (!byte_size) - byte_size = member_type->GetByteSize(); + byte_size = member_type->GetByteSize(nullptr); ObjectFile *objfile = die.GetDWARF()->GetObjectFile(); if (objfile->GetByteOrder() == eByteOrderLittle) { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 0b7e31ae2d1..5ce392a57e0 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1791,7 +1791,7 @@ SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() { lldb::addr_t byte_size = 1; if (var_sp->GetType()) byte_size = - var_sp->GetType()->GetByteSize().getValueOr(0); + var_sp->GetType()->GetByteSize(nullptr).getValueOr(0); m_global_aranges_up->Append(GlobalVariableMap::Entry( file_addr, byte_size, var_sp.get())); } @@ -3445,9 +3445,10 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc, new SymbolFileType(*this, GetUID(type_die_form.Reference()))); if (const_value.Form() && type_sp && type_sp->GetType()) - location.UpdateValue(const_value.Unsigned(), - type_sp->GetType()->GetByteSize().getValueOr(0), - die.GetCU()->GetAddressByteSize()); + location.UpdateValue( + const_value.Unsigned(), + type_sp->GetType()->GetByteSize(nullptr).getValueOr(0), + die.GetCU()->GetAddressByteSize()); var_sp = std::make_shared( die.GetID(), name, mangled, type_sp, scope, symbol_context_scope, diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp index cce06473d92..9f53e92afa0 100644 --- a/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ b/lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -460,7 +460,7 @@ lldb::TypeSP SymbolFileNativePDB::CreateModifierType(PdbTypeSymId type_id, lldb::TypeSP modified_type = GetOrCreateType(mr.ModifiedType); return std::make_shared(toOpaqueUid(type_id), this, ConstString(name), - modified_type->GetByteSize(), nullptr, + modified_type->GetByteSize(nullptr), nullptr, LLDB_INVALID_UID, Type::eEncodingIsUID, decl, ct, Type::ResolveState::Full); } @@ -584,7 +584,7 @@ lldb::TypeSP SymbolFileNativePDB::CreateTagType(PdbTypeSymId type_id, return std::make_shared( toOpaqueUid(type_id), this, ConstString(uname), - underlying_type->GetByteSize(), nullptr, LLDB_INVALID_UID, + underlying_type->GetByteSize(nullptr), nullptr, LLDB_INVALID_UID, lldb_private::Type::eEncodingIsUID, decl, ct, lldb_private::Type::ResolveState::Forward); } @@ -1376,9 +1376,10 @@ TypeSP SymbolFileNativePDB::CreateTypedef(PdbGlobalSymId id) { Declaration decl; return std::make_shared( - toOpaqueUid(id), this, ConstString(udt.Name), target_type->GetByteSize(), - nullptr, target_type->GetID(), lldb_private::Type::eEncodingIsTypedefUID, - decl, target_type->GetForwardCompilerType(), + toOpaqueUid(id), this, ConstString(udt.Name), + target_type->GetByteSize(nullptr), nullptr, target_type->GetID(), + lldb_private::Type::eEncodingIsTypedefUID, decl, + target_type->GetForwardCompilerType(), lldb_private::Type::ResolveState::Forward); } diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp index af11668dbfb..a1bde107bf7 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -4089,7 +4089,8 @@ unsigned TypeSystemClang::GetTypeQualifiers(lldb::opaque_compiler_type_t type) { CompilerType TypeSystemClang::GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride) { + uint64_t *stride, + ExecutionContextScope *exe_scope) { if (type) { clang::QualType qual_type(GetQualType(type)); @@ -4103,7 +4104,7 @@ TypeSystemClang::GetArrayElementType(lldb::opaque_compiler_type_t type, // TODO: the real stride will be >= this value.. find the real one! if (stride) - if (Optional size = element_type.GetByteSize(nullptr)) + if (Optional size = element_type.GetByteSize(exe_scope)) *stride = *size; return element_type; diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h index 9475e4d9f44..78c45ae32d3 100644 --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.h @@ -689,7 +689,8 @@ public: uint32_t opaque_payload); CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type, - uint64_t *stride) override; + uint64_t *stride, + ExecutionContextScope *exe_scope) override; CompilerType GetArrayType(lldb::opaque_compiler_type_t type, uint64_t size) override; diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index f819c9f8ce2..c27bba26a20 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -317,9 +317,10 @@ unsigned CompilerType::GetTypeQualifiers() const { // Creating related types -CompilerType CompilerType::GetArrayElementType(uint64_t *stride) const { +CompilerType CompilerType::GetArrayElementType(ExecutionContextScope *exe_scope, + uint64_t *stride) const { if (IsValid()) { - return m_type_system->GetArrayElementType(m_type, stride); + return m_type_system->GetArrayElementType(m_type, stride, exe_scope); } return CompilerType(); } @@ -766,8 +767,8 @@ LLVM_DUMP_METHOD void CompilerType::dump() const { bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data, lldb::offset_t data_byte_offset, - size_t data_byte_size, - Scalar &value) const { + size_t data_byte_size, Scalar &value, + ExecutionContextScope *exe_scope) const { if (!IsValid()) return false; @@ -780,7 +781,7 @@ bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data, if (encoding == lldb::eEncodingInvalid || count != 1) return false; - llvm::Optional byte_size = GetByteSize(nullptr); + llvm::Optional byte_size = GetByteSize(exe_scope); if (!byte_size) return false; lldb::offset_t offset = data_byte_offset; diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index 12c2077154b..51f56704cca 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/lldb/source/Symbol/SymbolContext.cpp @@ -204,7 +204,7 @@ void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, Type *func_type = function->GetType(); if (func_type) { s->Indent(" FuncType: "); - func_type->GetDescription(s, level, false); + func_type->GetDescription(s, level, false, target); s->EOL(); } } diff --git a/lldb/source/Symbol/Type.cpp b/lldb/source/Symbol/Type.cpp index 307e99ac84b..ecf0575b9a5 100644 --- a/lldb/source/Symbol/Type.cpp +++ b/lldb/source/Symbol/Type.cpp @@ -170,7 +170,7 @@ Type::Type() } void Type::GetDescription(Stream *s, lldb::DescriptionLevel level, - bool show_name) { + bool show_name, ExecutionContextScope *exe_scope) { *s << "id = " << (const UserID &)*this; // Call the name accessor to make sure we resolve the type name @@ -186,7 +186,7 @@ void Type::GetDescription(Stream *s, lldb::DescriptionLevel level, } // Call the get byte size accesor so we resolve our byte size - if (GetByteSize()) + if (GetByteSize(exe_scope)) s->Printf(", byte-size = %" PRIu64, m_byte_size); bool show_fullpaths = (level == lldb::eDescriptionLevelVerbose); m_decl.Dump(s, show_fullpaths); @@ -323,7 +323,9 @@ void Type::DumpValue(ExecutionContext *exe_ctx, Stream *s, GetForwardCompilerType().DumpValue( exe_ctx, s, format == lldb::eFormatDefault ? GetFormat() : format, data, - data_byte_offset, GetByteSize().getValueOr(0), + data_byte_offset, + GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr) + .getValueOr(0), 0, // Bitfield bit size 0, // Bitfield bit offset show_types, show_summary, verbose, 0); @@ -336,7 +338,7 @@ Type *Type::GetEncodingType() { return m_encoding_type; } -llvm::Optional Type::GetByteSize() { +llvm::Optional Type::GetByteSize(ExecutionContextScope *exe_scope) { if (m_byte_size_has_value) return m_byte_size; @@ -352,14 +354,14 @@ llvm::Optional Type::GetByteSize() { case eEncodingIsTypedefUID: { Type *encoding_type = GetEncodingType(); if (encoding_type) - if (llvm::Optional size = encoding_type->GetByteSize()) { + if (llvm::Optional size = encoding_type->GetByteSize(exe_scope)) { m_byte_size = *size; m_byte_size_has_value = true; return m_byte_size; } if (llvm::Optional size = - GetLayoutCompilerType().GetByteSize(nullptr)) { + GetLayoutCompilerType().GetByteSize(exe_scope)) { m_byte_size = *size; m_byte_size_has_value = true; return m_byte_size; @@ -430,7 +432,9 @@ bool Type::ReadFromMemory(ExecutionContext *exe_ctx, lldb::addr_t addr, return false; } - const uint64_t byte_size = GetByteSize().getValueOr(0); + const uint64_t byte_size = + GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : nullptr) + .getValueOr(0); if (data.GetByteSize() < byte_size) { lldb::DataBufferSP data_sp(new DataBufferHeap(byte_size, '\0')); data.SetData(data_sp);