diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-03 14:10:23 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-07-03 14:10:23 +0000 |
| commit | 145449b1e420787bb99721a429341fa6be3adfb6 (patch) | |
| tree | 1d56ae694a6de602e348dd80165cf881a36600ed /lldb/source/Expression | |
| parent | ecbca9f5fb7d7613d2b94982c4825eb0d33d6842 (diff) | |
Vendor import of llvm-project main llvmorg-15-init-15358-g53dc0f107877.vendor/llvm-project/llvmorg-15-init-15358-g53dc0f107877
Diffstat (limited to 'lldb/source/Expression')
| -rw-r--r-- | lldb/source/Expression/DWARFExpression.cpp | 264 | ||||
| -rw-r--r-- | lldb/source/Expression/ExpressionVariable.cpp | 3 | ||||
| -rw-r--r-- | lldb/source/Expression/FunctionCaller.cpp | 12 | ||||
| -rw-r--r-- | lldb/source/Expression/IRExecutionUnit.cpp | 48 | ||||
| -rw-r--r-- | lldb/source/Expression/IRInterpreter.cpp | 68 | ||||
| -rw-r--r-- | lldb/source/Expression/IRMemoryMap.cpp | 13 | ||||
| -rw-r--r-- | lldb/source/Expression/LLVMUserExpression.cpp | 6 | ||||
| -rw-r--r-- | lldb/source/Expression/Materializer.cpp | 67 | ||||
| -rw-r--r-- | lldb/source/Expression/REPL.cpp | 1 | ||||
| -rw-r--r-- | lldb/source/Expression/UserExpression.cpp | 24 |
10 files changed, 319 insertions, 187 deletions
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp index ccd41fb4a94e..1f11907dc64c 100644 --- a/lldb/source/Expression/DWARFExpression.cpp +++ b/lldb/source/Expression/DWARFExpression.cpp @@ -16,6 +16,7 @@ #include "lldb/Core/Value.h" #include "lldb/Core/dwarf.h" #include "lldb/Utility/DataEncoder.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegisterValue.h" #include "lldb/Utility/Scalar.h" @@ -35,11 +36,14 @@ #include "lldb/Target/StackID.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" +#include "llvm/DebugInfo/DWARF/DWARFExpression.h" #include "Plugins/SymbolFile/DWARF/DWARFUnit.h" using namespace lldb; using namespace lldb_private; +using namespace lldb_private::dwarf; static lldb::addr_t ReadAddressFromDebugAddrSection(const DWARFUnit *dwarf_cu, @@ -60,8 +64,7 @@ DWARFExpression::DWARFExpression() : m_module_wp(), m_data() {} DWARFExpression::DWARFExpression(lldb::ModuleSP module_sp, const DataExtractor &data, const DWARFUnit *dwarf_cu) - : m_module_wp(), m_data(data), m_dwarf_cu(dwarf_cu), - m_reg_kind(eRegisterKindDWARF) { + : m_module_wp(), m_data(data), m_dwarf_cu(dwarf_cu) { if (module_sp) m_module_wp = module_sp; } @@ -126,7 +129,6 @@ private: } void DWARFExpression::GetDescription(Stream *s, lldb::DescriptionLevel level, - addr_t location_list_base_addr, ABI *abi) const { if (IsLocationList()) { // We have a location list @@ -856,29 +858,28 @@ bool DWARFExpression::Evaluate(ExecutionContext *exe_ctx, ModuleSP module_sp = m_module_wp.lock(); if (IsLocationList()) { - addr_t pc; + Address pc; StackFrame *frame = nullptr; - if (reg_ctx) - pc = reg_ctx->GetPC(); - else { + if (!reg_ctx || !reg_ctx->GetPCForSymbolication(pc)) { frame = exe_ctx->GetFramePtr(); if (!frame) return false; RegisterContextSP reg_ctx_sp = frame->GetRegisterContext(); if (!reg_ctx_sp) return false; - pc = reg_ctx_sp->GetPC(); + reg_ctx_sp->GetPCForSymbolication(pc); } if (func_load_addr != LLDB_INVALID_ADDRESS) { - if (pc == LLDB_INVALID_ADDRESS) { + if (!pc.IsValid()) { if (error_ptr) error_ptr->SetErrorString("Invalid PC in frame."); return false; } - if (llvm::Optional<DataExtractor> expr = - GetLocationExpression(func_load_addr, pc)) { + Target *target = exe_ctx->GetTargetPtr(); + if (llvm::Optional<DataExtractor> expr = GetLocationExpression( + func_load_addr, pc.GetLoadAddress(target))) { return DWARFExpression::Evaluate( exe_ctx, reg_ctx, module_sp, *expr, m_dwarf_cu, m_reg_kind, initial_value_ptr, object_address_ptr, result, error_ptr); @@ -941,6 +942,72 @@ void UpdateValueTypeFromLocationDescription(Log *log, const DWARFUnit *dwarf_cu, } } // namespace +/// Helper function to move common code used to resolve a file address and turn +/// into a load address. +/// +/// \param exe_ctx Pointer to the execution context +/// \param module_sp shared_ptr contains the module if we have one +/// \param error_ptr pointer to Status object if we have one +/// \param dw_op_type C-style string used to vary the error output +/// \param file_addr the file address we are trying to resolve and turn into a +/// load address +/// \param so_addr out parameter, will be set to load addresss or section offset +/// \param check_sectionoffset bool which determines if having a section offset +/// but not a load address is considerd a success +/// \returns llvm::Optional containing the load address if resolving and getting +/// the load address succeed or an empty Optinal otherwise. If +/// check_sectionoffset is true we consider LLDB_INVALID_ADDRESS a +/// success if so_addr.IsSectionOffset() is true. +static llvm::Optional<lldb::addr_t> +ResolveLoadAddress(ExecutionContext *exe_ctx, lldb::ModuleSP &module_sp, + Status *error_ptr, const char *dw_op_type, + lldb::addr_t file_addr, Address &so_addr, + bool check_sectionoffset = false) { + if (!module_sp) { + if (error_ptr) + error_ptr->SetErrorStringWithFormat( + "need module to resolve file address for %s", dw_op_type); + return {}; + } + + if (!module_sp->ResolveFileAddress(file_addr, so_addr)) { + if (error_ptr) + error_ptr->SetErrorString("failed to resolve file address in module"); + return {}; + } + + addr_t load_addr = so_addr.GetLoadAddress(exe_ctx->GetTargetPtr()); + + if (load_addr == LLDB_INVALID_ADDRESS && + (check_sectionoffset && !so_addr.IsSectionOffset())) { + if (error_ptr) + error_ptr->SetErrorString("failed to resolve load address"); + return {}; + } + + return load_addr; +} + +/// Helper function to move common code used to load sized data from a uint8_t +/// buffer. +/// +/// \param addr_bytes uint8_t buffer containg raw data +/// \param size_addr_bytes how large is the underlying raw data +/// \param byte_order what is the byter order of the underlyig data +/// \param size How much of the underlying data we want to use +/// \return The underlying data converted into a Scalar +static Scalar DerefSizeExtractDataHelper(uint8_t *addr_bytes, + size_t size_addr_bytes, + ByteOrder byte_order, size_t size) { + DataExtractor addr_data(addr_bytes, size_addr_bytes, byte_order, size); + + lldb::offset_t addr_data_offset = 0; + if (size <= 8) + return addr_data.GetMaxU64(&addr_data_offset, size); + else + return addr_data.GetAddress(&addr_data_offset); +} + bool DWARFExpression::Evaluate( ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::ModuleSP module_sp, const DataExtractor &opcodes, @@ -977,7 +1044,7 @@ bool DWARFExpression::Evaluate( uint64_t op_piece_offset = 0; Value pieces; // Used for DW_OP_piece - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); // A generic type is "an integral type that has the size of an address and an // unspecified signedness". For now, just use the signedness of the operand. // TODO: Implement a real typed stack, and store the genericness of the value @@ -1086,26 +1153,15 @@ bool DWARFExpression::Evaluate( case Value::ValueType::FileAddress: { auto file_addr = stack.back().GetScalar().ULongLong( LLDB_INVALID_ADDRESS); - if (!module_sp) { - if (error_ptr) - error_ptr->SetErrorString( - "need module to resolve file address for DW_OP_deref"); - return false; - } + Address so_addr; - if (!module_sp->ResolveFileAddress(file_addr, so_addr)) { - if (error_ptr) - error_ptr->SetErrorString( - "failed to resolve file address in module"); - return false; - } - addr_t load_Addr = so_addr.GetLoadAddress(exe_ctx->GetTargetPtr()); - if (load_Addr == LLDB_INVALID_ADDRESS) { - if (error_ptr) - error_ptr->SetErrorString("failed to resolve load address"); + auto maybe_load_addr = ResolveLoadAddress( + exe_ctx, module_sp, error_ptr, "DW_OP_deref", file_addr, so_addr); + + if (!maybe_load_addr) return false; - } - stack.back().GetScalar() = load_Addr; + + stack.back().GetScalar() = *maybe_load_addr; // Fall through to load address promotion code below. } LLVM_FALLTHROUGH; case Value::ValueType::Scalar: @@ -1216,6 +1272,47 @@ bool DWARFExpression::Evaluate( stack.back().GetScalar() = ptr; stack.back().ClearContext(); } break; + case Value::ValueType::FileAddress: { + auto file_addr = + stack.back().GetScalar().ULongLong(LLDB_INVALID_ADDRESS); + Address so_addr; + auto maybe_load_addr = + ResolveLoadAddress(exe_ctx, module_sp, error_ptr, + "DW_OP_deref_size", file_addr, so_addr, + /*check_sectionoffset=*/true); + + if (!maybe_load_addr) + return false; + + addr_t load_addr = *maybe_load_addr; + + if (load_addr == LLDB_INVALID_ADDRESS && so_addr.IsSectionOffset()) { + uint8_t addr_bytes[8]; + Status error; + + if (exe_ctx->GetTargetRef().ReadMemory( + so_addr, &addr_bytes, size, error, + /*force_live_memory=*/false) == size) { + ObjectFile *objfile = module_sp->GetObjectFile(); + + stack.back().GetScalar() = DerefSizeExtractDataHelper( + addr_bytes, size, objfile->GetByteOrder(), size); + stack.back().ClearContext(); + break; + } else { + if (error_ptr) + error_ptr->SetErrorStringWithFormat( + "Failed to dereference pointer for for DW_OP_deref_size: " + "%s\n", + error.AsCString()); + return false; + } + } + stack.back().GetScalar() = load_addr; + // Fall through to load address promotion code below. + } + + LLVM_FALLTHROUGH; case Value::ValueType::Scalar: case Value::ValueType::LoadAddress: if (exe_ctx) { @@ -1226,26 +1323,10 @@ bool DWARFExpression::Evaluate( Status error; if (process->ReadMemory(pointer_addr, &addr_bytes, size, error) == size) { - DataExtractor addr_data(addr_bytes, sizeof(addr_bytes), - process->GetByteOrder(), size); - lldb::offset_t addr_data_offset = 0; - switch (size) { - case 1: - stack.back().GetScalar() = addr_data.GetU8(&addr_data_offset); - break; - case 2: - stack.back().GetScalar() = addr_data.GetU16(&addr_data_offset); - break; - case 4: - stack.back().GetScalar() = addr_data.GetU32(&addr_data_offset); - break; - case 8: - stack.back().GetScalar() = addr_data.GetU64(&addr_data_offset); - break; - default: - stack.back().GetScalar() = - addr_data.GetAddress(&addr_data_offset); - } + + stack.back().GetScalar() = + DerefSizeExtractDataHelper(addr_bytes, sizeof(addr_bytes), + process->GetByteOrder(), size); stack.back().ClearContext(); } else { if (error_ptr) @@ -1268,7 +1349,6 @@ bool DWARFExpression::Evaluate( } break; - case Value::ValueType::FileAddress: case Value::ValueType::Invalid: if (error_ptr) error_ptr->SetErrorString("Invalid value for DW_OP_deref_size.\n"); @@ -2670,14 +2750,50 @@ static DataExtractor ToDataExtractor(const llvm::DWARFLocationExpression &loc, return DataExtractor(buffer_sp, byte_order, addr_size); } -llvm::Optional<DataExtractor> -DWARFExpression::GetLocationExpression(addr_t load_function_start, - addr_t addr) const { - Log *log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS); +bool DWARFExpression::DumpLocations(Stream *s, lldb::DescriptionLevel level, + addr_t load_function_start, addr_t addr, + ABI *abi) { + if (!IsLocationList()) { + DumpLocation(s, m_data, level, abi); + return true; + } + bool dump_all = addr == LLDB_INVALID_ADDRESS; + llvm::ListSeparator separator; + auto callback = [&](llvm::DWARFLocationExpression loc) -> bool { + if (loc.Range && + (dump_all || (loc.Range->LowPC <= addr && addr < loc.Range->HighPC))) { + uint32_t addr_size = m_data.GetAddressByteSize(); + DataExtractor data = ToDataExtractor(loc, m_data.GetByteOrder(), + m_data.GetAddressByteSize()); + s->AsRawOstream() << separator; + s->PutCString("["); + s->AsRawOstream() << llvm::format_hex(loc.Range->LowPC, + 2 + 2 * addr_size); + s->PutCString(", "); + s->AsRawOstream() << llvm::format_hex(loc.Range->HighPC, + 2 + 2 * addr_size); + s->PutCString(") -> "); + DumpLocation(s, data, level, abi); + return dump_all; + } + return true; + }; + if (!GetLocationExpressions(load_function_start, callback)) + return false; + return true; +} + +bool DWARFExpression::GetLocationExpressions( + addr_t load_function_start, + llvm::function_ref<bool(llvm::DWARFLocationExpression)> callback) const { + if (load_function_start == LLDB_INVALID_ADDRESS) + return false; + + Log *log = GetLog(LLDBLog::Expressions); std::unique_ptr<llvm::DWARFLocationTable> loctable_up = m_dwarf_cu->GetLocationTable(m_data); - llvm::Optional<DataExtractor> result; + uint64_t offset = 0; auto lookup_addr = [&](uint32_t index) -> llvm::Optional<llvm::object::SectionedAddress> { @@ -2697,19 +2813,32 @@ DWARFExpression::GetLocationExpression(addr_t load_function_start, addr_t slide = load_function_start - m_loclist_addresses->func_file_addr; loc->Range->LowPC += slide; loc->Range->HighPC += slide; - - if (loc->Range->LowPC <= addr && addr < loc->Range->HighPC) - result = ToDataExtractor(*loc, m_data.GetByteOrder(), - m_data.GetAddressByteSize()); } - return !result; + return callback(*loc); }; - llvm::Error E = loctable_up->visitAbsoluteLocationList( + llvm::Error error = loctable_up->visitAbsoluteLocationList( offset, llvm::object::SectionedAddress{m_loclist_addresses->cu_file_addr}, lookup_addr, process_list); - if (E) - LLDB_LOG_ERROR(log, std::move(E), "{0}"); - return result; + if (error) { + LLDB_LOG_ERROR(log, std::move(error), "{0}"); + return false; + } + return true; +} + +llvm::Optional<DataExtractor> +DWARFExpression::GetLocationExpression(addr_t load_function_start, + addr_t addr) const { + llvm::Optional<DataExtractor> data; + auto callback = [&](llvm::DWARFLocationExpression loc) { + if (loc.Range && loc.Range->LowPC <= addr && addr < loc.Range->HighPC) { + data = ToDataExtractor(loc, m_data.GetByteOrder(), + m_data.GetAddressByteSize()); + } + return !data; + }; + GetLocationExpressions(load_function_start, callback); + return data; } bool DWARFExpression::MatchesOperand(StackFrame &frame, @@ -2732,10 +2861,11 @@ bool DWARFExpression::MatchesOperand(StackFrame &frame, if (load_function_start == LLDB_INVALID_ADDRESS) return false; - addr_t pc = frame.GetFrameCodeAddress().GetLoadAddress( + addr_t pc = frame.GetFrameCodeAddressForSymbolication().GetLoadAddress( frame.CalculateTarget().get()); - if (llvm::Optional<DataExtractor> expr = GetLocationExpression(load_function_start, pc)) + if (llvm::Optional<DataExtractor> expr = + GetLocationExpression(load_function_start, pc)) opcodes = std::move(*expr); else return false; diff --git a/lldb/source/Expression/ExpressionVariable.cpp b/lldb/source/Expression/ExpressionVariable.cpp index 565a3d1a8161..da2f3b2a83fb 100644 --- a/lldb/source/Expression/ExpressionVariable.cpp +++ b/lldb/source/Expression/ExpressionVariable.cpp @@ -9,6 +9,7 @@ #include "lldb/Expression/ExpressionVariable.h" #include "lldb/Expression/IRExecutionUnit.h" #include "lldb/Target/Target.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" using namespace lldb_private; @@ -41,7 +42,7 @@ lldb::addr_t PersistentExpressionState::LookupSymbol(ConstString name) { void PersistentExpressionState::RegisterExecutionUnit( lldb::IRExecutionUnitSP &execution_unit_sp) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); m_execution_units.insert(execution_unit_sp); diff --git a/lldb/source/Expression/FunctionCaller.cpp b/lldb/source/Expression/FunctionCaller.cpp index 5f34675b4b64..307bed1ee3fd 100644 --- a/lldb/source/Expression/FunctionCaller.cpp +++ b/lldb/source/Expression/FunctionCaller.cpp @@ -24,6 +24,7 @@ #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallFunction.h" #include "lldb/Utility/DataExtractor.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/State.h" @@ -218,7 +219,7 @@ bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx, if (!WriteFunctionArguments(exe_ctx, args_addr_ref, diagnostic_manager)) return false; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP)); + Log *log = GetLog(LLDBLog::Step); LLDB_LOGF(log, "Call Address: 0x%" PRIx64 " Struct Address: 0x%" PRIx64 ".\n", m_jit_start_addr, args_addr_ref); @@ -229,8 +230,7 @@ lldb::ThreadPlanSP FunctionCaller::GetThreadPlanToCallFunction( ExecutionContext &exe_ctx, lldb::addr_t args_addr, const EvaluateExpressionOptions &options, DiagnosticManager &diagnostic_manager) { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); + Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); LLDB_LOGF(log, "-- [FunctionCaller::GetThreadPlanToCallFunction] Creating " @@ -269,8 +269,7 @@ bool FunctionCaller::FetchFunctionResults(ExecutionContext &exe_ctx, // then use GetReturnValueObject // to fetch the value. That way we can fetch any values we need. - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); + Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); LLDB_LOGF(log, "-- [FunctionCaller::FetchFunctionResults] Fetching function " @@ -343,8 +342,7 @@ lldb::ExpressionResults FunctionCaller::ExecuteFunction( return lldb::eExpressionSetupError; } - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); + Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); LLDB_LOGF(log, "== [FunctionCaller::ExecuteFunction] Executing function \"%s\" ==", diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp index 3c4a87c27e20..49fa72f7112d 100644 --- a/lldb/source/Expression/IRExecutionUnit.cpp +++ b/lldb/source/Expression/IRExecutionUnit.cpp @@ -21,6 +21,7 @@ #include "lldb/Core/Module.h" #include "lldb/Core/Section.h" #include "lldb/Expression/IRExecutionUnit.h" +#include "lldb/Host/HostInfo.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Symbol/SymbolFile.h" @@ -32,6 +33,7 @@ #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/../../source/Plugins/ObjectFile/JIT/ObjectFileJIT.h" @@ -70,8 +72,7 @@ lldb::addr_t IRExecutionUnit::WriteNow(const uint8_t *bytes, size_t size, return LLDB_INVALID_ADDRESS; } - if (Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (Log *log = GetLog(LLDBLog::Expressions)) { DataBufferHeap my_buffer(size, 0); Status err; ReadMemory(my_buffer.GetBytes(), allocation_process_addr, size, err); @@ -99,7 +100,7 @@ void IRExecutionUnit::FreeNow(lldb::addr_t allocation) { Status IRExecutionUnit::DisassembleFunction(Stream &stream, lldb::ProcessSP &process_wp) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); ExecutionContext exe_ctx(process_wp); @@ -150,7 +151,8 @@ Status IRExecutionUnit::DisassembleFunction(Stream &stream, return ret; } - lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0)); + lldb::WritableDataBufferSP buffer_sp( + new DataBufferHeap(func_range.second, 0)); Process *process = exe_ctx.GetProcessPtr(); Status err; @@ -254,7 +256,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, m_did_jit = true; - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); std::string error_string; @@ -306,27 +308,37 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr, class ObjectDumper : public llvm::ObjectCache { public: + ObjectDumper(FileSpec output_dir) : m_out_dir(output_dir) {} void notifyObjectCompiled(const llvm::Module *module, llvm::MemoryBufferRef object) override { int fd = 0; llvm::SmallVector<char, 256> result_path; std::string object_name_model = "jit-object-" + module->getModuleIdentifier() + "-%%%.o"; - (void)llvm::sys::fs::createUniqueFile(object_name_model, fd, result_path); - llvm::raw_fd_ostream fds(fd, true); - fds.write(object.getBufferStart(), object.getBufferSize()); - } + FileSpec model_spec + = m_out_dir.CopyByAppendingPathComponent(object_name_model); + std::string model_path = model_spec.GetPath(); + std::error_code result + = llvm::sys::fs::createUniqueFile(model_path, fd, result_path); + if (!result) { + llvm::raw_fd_ostream fds(fd, true); + fds.write(object.getBufferStart(), object.getBufferSize()); + } + } std::unique_ptr<llvm::MemoryBuffer> - getObject(const llvm::Module *module) override { + getObject(const llvm::Module *module) override { // Return nothing - we're just abusing the object-cache mechanism to dump // objects. return nullptr; - } + } + private: + FileSpec m_out_dir; }; - if (process_sp->GetTarget().GetEnableSaveObjects()) { - m_object_cache_up = std::make_unique<ObjectDumper>(); + FileSpec save_objects_dir = process_sp->GetTarget().GetSaveJITObjectsDir(); + if (save_objects_dir) { + m_object_cache_up = std::make_unique<ObjectDumper>(save_objects_dir); m_execution_engine_up->setObjectCache(m_object_cache_up.get()); } @@ -592,7 +604,7 @@ lldb::SectionType IRExecutionUnit::GetSectionTypeFromSectionName( uint8_t *IRExecutionUnit::MemoryManager::allocateCodeSection( uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); uint8_t *return_value = m_default_mm_up->allocateCodeSection( Size, Alignment, SectionID, SectionName); @@ -622,7 +634,7 @@ uint8_t *IRExecutionUnit::MemoryManager::allocateCodeSection( uint8_t *IRExecutionUnit::MemoryManager::allocateDataSection( uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName, bool IsReadOnly) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); uint8_t *return_value = m_default_mm_up->allocateDataSection( Size, Alignment, SectionID, SectionName, IsReadOnly); @@ -882,7 +894,7 @@ lldb::addr_t IRExecutionUnit::FindSymbol(lldb_private::ConstString name, void IRExecutionUnit::GetStaticInitializers( std::vector<lldb::addr_t> &static_initializers) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); llvm::GlobalVariable *global_ctors = m_module->getNamedGlobal("llvm.global_ctors"); @@ -950,7 +962,7 @@ IRExecutionUnit::MemoryManager::getSymbolAddress(const std::string &Name) { uint64_t IRExecutionUnit::MemoryManager::GetSymbolAddressAndPresence( const std::string &Name, bool &missing_weak) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); ConstString name_cs(Name.c_str()); @@ -977,7 +989,7 @@ void *IRExecutionUnit::MemoryManager::getPointerToNamedFunction( lldb::addr_t IRExecutionUnit::GetRemoteAddressForLocal(lldb::addr_t local_address) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); for (AllocationRecord &record : m_records) { if (local_address >= record.m_host_address && diff --git a/lldb/source/Expression/IRInterpreter.cpp b/lldb/source/Expression/IRInterpreter.cpp index 9b2af56dfc8a..a6efeb3f960f 100644 --- a/lldb/source/Expression/IRInterpreter.cpp +++ b/lldb/source/Expression/IRInterpreter.cpp @@ -16,6 +16,7 @@ #include "lldb/Utility/ConstString.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/Endian.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" @@ -41,6 +42,7 @@ #include <map> using namespace llvm; +using lldb_private::LLDBLog; static std::string PrintValue(const Value *value, bool truncate = false) { std::string s; @@ -95,8 +97,8 @@ public: ValueMap m_values; DataLayout &m_target_data; lldb_private::IRExecutionUnit &m_execution_unit; - const BasicBlock *m_bb; - const BasicBlock *m_prev_bb; + const BasicBlock *m_bb = nullptr; + const BasicBlock *m_prev_bb = nullptr; BasicBlock::const_iterator m_ii; BasicBlock::const_iterator m_ie; @@ -111,8 +113,7 @@ public: lldb_private::IRExecutionUnit &execution_unit, lldb::addr_t stack_frame_bottom, lldb::addr_t stack_frame_top) - : m_target_data(target_data), m_execution_unit(execution_unit), - m_bb(nullptr), m_prev_bb(nullptr) { + : m_target_data(target_data), m_execution_unit(execution_unit) { m_byte_order = (target_data.isLittleEndian() ? lldb::eByteOrderLittle : lldb::eByteOrderBig); m_addr_byte_size = (target_data.getPointerSize(0)); @@ -283,9 +284,11 @@ public: return true; // no offset to apply! SmallVector<Value *, 8> indices(op_cursor, op_end); - Type *src_elem_ty = cast<GEPOperator>(constant_expr)->getSourceElementType(); + + // DataLayout::getIndexedOffsetInType assumes the indices are + // instances of ConstantInt. uint64_t offset = m_target_data.getIndexedOffsetInType(src_elem_ty, indices); @@ -325,8 +328,7 @@ public: m_values[value] = data_address; - lldb_private::Log *log( - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + lldb_private::Log *log(GetLog(LLDBLog::Expressions)); if (log) { LLDB_LOGF(log, "Made an allocation for argument %s", @@ -465,12 +467,20 @@ static bool CanResolveConstant(llvm::Constant *constant) { case Instruction::BitCast: return CanResolveConstant(constant_expr->getOperand(0)); case Instruction::GetElementPtr: { + // Check that the base can be constant-resolved. ConstantExpr::const_op_iterator op_cursor = constant_expr->op_begin(); Constant *base = dyn_cast<Constant>(*op_cursor); - if (!base) + if (!base || !CanResolveConstant(base)) return false; - return CanResolveConstant(base); + // Check that all other operands are just ConstantInt. + for (Value *op : make_range(constant_expr->op_begin() + 1, + constant_expr->op_end())) { + ConstantInt *constant_int = dyn_cast<ConstantInt>(op); + if (!constant_int) + return false; + } + return true; } } } else { @@ -484,8 +494,7 @@ static bool CanResolveConstant(llvm::Constant *constant) { bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function, lldb_private::Status &error, const bool support_function_calls) { - lldb_private::Log *log( - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + lldb_private::Log *log(GetLog(LLDBLog::Expressions)); bool saw_function_with_body = false; for (Function &f : module) { @@ -637,8 +646,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb::addr_t stack_frame_bottom, lldb::addr_t stack_frame_top, lldb_private::ExecutionContext &exe_ctx) { - lldb_private::Log *log( - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + lldb_private::Log *log(GetLog(LLDBLog::Expressions)); if (log) { std::string s; @@ -1184,16 +1192,6 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const Value *pointer_operand = load_inst->getPointerOperand(); - Type *pointer_ty = pointer_operand->getType(); - PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty); - if (!pointer_ptr_ty) { - LLDB_LOGF(log, "getPointerOperand()->getType() is not a PointerType"); - error.SetErrorToGenericError(); - error.SetErrorString(interpreter_internal_error); - return false; - } - Type *target_ty = pointer_ptr_ty->getElementType(); - lldb::addr_t D = frame.ResolveValue(load_inst, module); lldb::addr_t P = frame.ResolveValue(pointer_operand, module); @@ -1222,6 +1220,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, return false; } + Type *target_ty = load_inst->getType(); size_t target_size = data_layout.getTypeStoreSize(target_ty); lldb_private::DataBufferHeap buffer(target_size, 0); @@ -1267,12 +1266,6 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, const Value *value_operand = store_inst->getValueOperand(); const Value *pointer_operand = store_inst->getPointerOperand(); - Type *pointer_ty = pointer_operand->getType(); - PointerType *pointer_ptr_ty = dyn_cast<PointerType>(pointer_ty); - if (!pointer_ptr_ty) - return false; - Type *target_ty = pointer_ptr_ty->getElementType(); - lldb::addr_t D = frame.ResolveValue(value_operand, module); lldb::addr_t P = frame.ResolveValue(pointer_operand, module); @@ -1301,6 +1294,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, return false; } + Type *target_ty = value_operand->getType(); size_t target_size = data_layout.getTypeStoreSize(target_ty); lldb_private::DataBufferHeap buffer(target_size, 0); @@ -1381,21 +1375,7 @@ bool IRInterpreter::Interpret(llvm::Module &module, llvm::Function &function, lldb_private::DiagnosticManager diagnostics; lldb_private::EvaluateExpressionOptions options; - // We generally receive a function pointer which we must dereference - llvm::Type *prototype = val->getType(); - if (!prototype->isPointerTy()) { - error.SetErrorToGenericError(); - error.SetErrorString("call need function pointer"); - return false; - } - - // Dereference the function pointer - prototype = prototype->getPointerElementType(); - if (!(prototype->isFunctionTy() || prototype->isFunctionVarArg())) { - error.SetErrorToGenericError(); - error.SetErrorString("call need function pointer"); - return false; - } + llvm::FunctionType *prototype = call_inst->getFunctionType(); // Find number of arguments const int numArgs = call_inst->arg_size(); diff --git a/lldb/source/Expression/IRMemoryMap.cpp b/lldb/source/Expression/IRMemoryMap.cpp index 9eee5cf5b9a2..6b8f7babc6f0 100644 --- a/lldb/source/Expression/IRMemoryMap.cpp +++ b/lldb/source/Expression/IRMemoryMap.cpp @@ -13,6 +13,7 @@ #include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/LLDBAssert.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Scalar.h" #include "lldb/Utility/Status.h" @@ -288,8 +289,7 @@ IRMemoryMap::Allocation::Allocation(lldb::addr_t process_alloc, lldb::addr_t IRMemoryMap::Malloc(size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, Status &error) { - lldb_private::Log *log( - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + lldb_private::Log *log(GetLog(LLDBLog::Expressions)); error.Clear(); lldb::ProcessSP process_sp; @@ -476,8 +476,7 @@ void IRMemoryMap::Free(lldb::addr_t process_address, Status &error) { } } - if (lldb_private::Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (lldb_private::Log *log = GetLog(LLDBLog::Expressions)) { LLDB_LOGF(log, "IRMemoryMap::Free (0x%" PRIx64 ") freed [0x%" PRIx64 "..0x%" PRIx64 ")", @@ -574,8 +573,7 @@ void IRMemoryMap::WriteMemory(lldb::addr_t process_address, break; } - if (lldb_private::Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (lldb_private::Log *log = GetLog(LLDBLog::Expressions)) { LLDB_LOGF(log, "IRMemoryMap::WriteMemory (0x%" PRIx64 ", 0x%" PRIxPTR ", 0x%" PRId64 ") went to [0x%" PRIx64 "..0x%" PRIx64 ")", @@ -704,8 +702,7 @@ void IRMemoryMap::ReadMemory(uint8_t *bytes, lldb::addr_t process_address, break; } - if (lldb_private::Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (lldb_private::Log *log = GetLog(LLDBLog::Expressions)) { LLDB_LOGF(log, "IRMemoryMap::ReadMemory (0x%" PRIx64 ", 0x%" PRIxPTR ", 0x%" PRId64 ") came from [0x%" PRIx64 "..0x%" PRIx64 ")", diff --git a/lldb/source/Expression/LLVMUserExpression.cpp b/lldb/source/Expression/LLVMUserExpression.cpp index 527dff8bf60f..d67660812150 100644 --- a/lldb/source/Expression/LLVMUserExpression.cpp +++ b/lldb/source/Expression/LLVMUserExpression.cpp @@ -30,6 +30,7 @@ #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" #include "lldb/Utility/ConstString.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" @@ -67,8 +68,7 @@ LLVMUserExpression::DoExecute(DiagnosticManager &diagnostic_manager, // The expression log is quite verbose, and if you're just tracking the // execution of the expression, it's quite convenient to have these logs come // out with the STEP log as well. - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); + Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); if (m_jit_start_addr == LLDB_INVALID_ADDRESS && !m_can_interpret) { diagnostic_manager.PutString( @@ -254,7 +254,7 @@ bool LLVMUserExpression::FinalizeJITExecution( DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx, lldb::ExpressionVariableSP &result, lldb::addr_t function_stack_bottom, lldb::addr_t function_stack_top) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); LLDB_LOGF(log, "-- [UserExpression::FinalizeJITExecution] Dematerializing " "after execution --"); diff --git a/lldb/source/Expression/Materializer.cpp b/lldb/source/Expression/Materializer.cpp index d40365d60fb3..9ee2d983ddfc 100644 --- a/lldb/source/Expression/Materializer.cpp +++ b/lldb/source/Expression/Materializer.cpp @@ -19,6 +19,7 @@ #include "lldb/Target/StackFrame.h" #include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegisterValue.h" @@ -58,7 +59,7 @@ public: } void MakeAllocation(IRMemoryMap &map, Status &err) { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); // Allocate a spare memory area to store the persistent variable's // contents. @@ -67,7 +68,7 @@ public: const bool zero_memory = false; lldb::addr_t mem = map.Malloc( - m_persistent_variable_sp->GetByteSize().getValueOr(0), 8, + m_persistent_variable_sp->GetByteSize().value_or(0), 8, lldb::ePermissionsReadable | lldb::ePermissionsWritable, IRMemoryMap::eAllocationPolicyMirror, zero_memory, allocate_error); @@ -106,7 +107,7 @@ public: Status write_error; map.WriteMemory(mem, m_persistent_variable_sp->GetValueBytes(), - m_persistent_variable_sp->GetByteSize().getValueOr(0), + m_persistent_variable_sp->GetByteSize().value_or(0), write_error); if (!write_error.Success()) { @@ -138,7 +139,7 @@ public: void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -190,7 +191,7 @@ public: void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -235,7 +236,7 @@ public: map.GetBestExecutionContextScope(), m_persistent_variable_sp.get()->GetCompilerType(), m_persistent_variable_sp->GetName(), location, eAddressTypeLoad, - m_persistent_variable_sp->GetByteSize().getValueOr(0)); + m_persistent_variable_sp->GetByteSize().value_or(0)); if (frame_top != LLDB_INVALID_ADDRESS && frame_bottom != LLDB_INVALID_ADDRESS && location >= frame_bottom && @@ -281,7 +282,7 @@ public: m_persistent_variable_sp->GetName().GetCString(), (uint64_t)mem, (unsigned long long)m_persistent_variable_sp->GetByteSize() - .getValueOr(0)); + .value_or(0)); // Read the contents of the spare memory area @@ -290,7 +291,8 @@ public: Status read_error; map.ReadMemory(m_persistent_variable_sp->GetValueBytes(), mem, - m_persistent_variable_sp->GetByteSize().getValueOr(0), read_error); + m_persistent_variable_sp->GetByteSize().value_or(0), + read_error); if (!read_error.Success()) { err.SetErrorStringWithFormat( @@ -371,11 +373,12 @@ public: if (!err.Success()) { dump_stream.Printf(" <could not be read>\n"); } else { - DataBufferHeap data( - m_persistent_variable_sp->GetByteSize().getValueOr(0), 0); + DataBufferHeap data(m_persistent_variable_sp->GetByteSize().value_or(0), + 0); map.ReadMemory(data.GetBytes(), target_address, - m_persistent_variable_sp->GetByteSize().getValueOr(0), err); + m_persistent_variable_sp->GetByteSize().value_or(0), + err); if (!err.Success()) { dump_stream.Printf(" <could not be read>\n"); @@ -412,9 +415,7 @@ uint32_t Materializer::AddPersistentVariable( class EntityVariable : public Materializer::Entity { public: EntityVariable(lldb::VariableSP &variable_sp) - : Entity(), m_variable_sp(variable_sp), m_is_reference(false), - m_temporary_allocation(LLDB_INVALID_ADDRESS), - m_temporary_allocation_size(0) { + : Entity(), m_variable_sp(variable_sp) { // Hard-coding to maximum size of a pointer since all variables are // materialized by reference m_size = 8; @@ -425,7 +426,7 @@ public: void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; if (log) { @@ -528,7 +529,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(scope).getValueOr(0), + m_variable_sp->GetType()->GetByteSize(scope).value_or(0), data.GetByteSize()); } return; @@ -594,7 +595,7 @@ public: void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; if (log) { @@ -625,7 +626,7 @@ public: Status extract_error; map.GetMemoryData(data, m_temporary_allocation, - valobj_sp->GetByteSize().getValueOr(0), extract_error); + valobj_sp->GetByteSize().value_or(0), extract_error); if (!extract_error.Success()) { err.SetErrorStringWithFormat("couldn't get the data for variable %s", @@ -748,9 +749,9 @@ public: private: lldb::VariableSP m_variable_sp; - bool m_is_reference; - lldb::addr_t m_temporary_allocation; - size_t m_temporary_allocation_size; + bool m_is_reference = false; + lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS; + size_t m_temporary_allocation_size = 0; lldb::DataBufferSP m_original_data; }; @@ -768,9 +769,7 @@ public: bool keep_in_memory, Materializer::PersistentVariableDelegate *delegate) : Entity(), m_type(type), m_is_program_reference(is_program_reference), - m_keep_in_memory(keep_in_memory), - m_temporary_allocation(LLDB_INVALID_ADDRESS), - m_temporary_allocation_size(0), m_delegate(delegate) { + m_keep_in_memory(keep_in_memory), m_delegate(delegate) { // Hard-coding to maximum size of a pointer since all results are // materialized by reference m_size = 8; @@ -924,7 +923,7 @@ public: ret->ValueUpdated(); - const size_t pvar_byte_size = ret->GetByteSize().getValueOr(0); + const size_t pvar_byte_size = ret->GetByteSize().value_or(0); uint8_t *pvar_data = ret->GetValueBytes(); map.ReadMemory(pvar_data, address, pvar_byte_size, read_error); @@ -1029,8 +1028,8 @@ private: bool m_is_program_reference; bool m_keep_in_memory; - lldb::addr_t m_temporary_allocation; - size_t m_temporary_allocation_size; + lldb::addr_t m_temporary_allocation = LLDB_INVALID_ADDRESS; + size_t m_temporary_allocation_size = 0; Materializer::PersistentVariableDelegate *m_delegate; }; @@ -1057,7 +1056,7 @@ public: void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -1106,7 +1105,7 @@ public: void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -1176,7 +1175,7 @@ public: void Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -1239,7 +1238,7 @@ public: void Dematerialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, lldb::addr_t process_address, lldb::addr_t frame_top, lldb::addr_t frame_bottom, Status &err) override { - Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); + Log *log = GetLog(LLDBLog::Expressions); const lldb::addr_t load_addr = process_address + m_offset; @@ -1377,8 +1376,7 @@ Materializer::Materialize(lldb::StackFrameSP &frame_sp, IRMemoryMap &map, return DematerializerSP(); } - if (Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (Log *log = GetLog(LLDBLog::Expressions)) { LLDB_LOGF( log, "Materializer::Materialize (frame_sp = %p, process_address = 0x%" PRIx64 @@ -1415,8 +1413,7 @@ void Materializer::Dematerializer::Dematerialize(Status &error, error.SetErrorToGenericError(); error.SetErrorString("Couldn't dematerialize: target is gone"); } else { - if (Log *log = - lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)) { + if (Log *log = GetLog(LLDBLog::Expressions)) { LLDB_LOGF(log, "Materializer::Dematerialize (frame_sp = %p, process_address " "= 0x%" PRIx64 ") about to dematerialize:", diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp index be41c60ebb5f..d7582af9b2ea 100644 --- a/lldb/source/Expression/REPL.cpp +++ b/lldb/source/Expression/REPL.cpp @@ -25,6 +25,7 @@ using namespace lldb_private; REPL::REPL(LLVMCastKind kind, Target &target) : m_target(target), m_kind(kind) { // Make sure all option values have sane defaults Debugger &debugger = m_target.GetDebugger(); + debugger.SetShowProgress(false); auto exe_ctx = debugger.GetCommandInterpreter().GetExecutionContext(); m_format_options.OptionParsingStarting(&exe_ctx); m_varobj_options.OptionParsingStarting(&exe_ctx); diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp index 692594b03f16..f821603f03e5 100644 --- a/lldb/source/Expression/UserExpression.cpp +++ b/lldb/source/Expression/UserExpression.cpp @@ -37,6 +37,7 @@ #include "lldb/Target/ThreadPlan.h" #include "lldb/Target/ThreadPlanCallUserExpression.h" #include "lldb/Utility/ConstString.h" +#include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" @@ -141,12 +142,12 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, llvm::StringRef expr, llvm::StringRef prefix, lldb::ValueObjectSP &result_valobj_sp, Status &error, std::string *fixed_expression, ValueObject *ctx_obj) { - Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_EXPRESSIONS | - LIBLLDB_LOG_STEP)); + Log *log(GetLog(LLDBLog::Expressions | LLDBLog::Step)); if (ctx_obj) { - static unsigned const ctx_type_mask = - lldb::TypeFlags::eTypeIsClass | lldb::TypeFlags::eTypeIsStructUnion; + static unsigned const ctx_type_mask = lldb::TypeFlags::eTypeIsClass | + lldb::TypeFlags::eTypeIsStructUnion | + lldb::TypeFlags::eTypeIsReference; if (!(ctx_obj->GetTypeInfo() & ctx_type_mask)) { LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of " "an invalid type, can't run expressions."); @@ -155,6 +156,21 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx, } } + if (ctx_obj && ctx_obj->GetTypeInfo() & lldb::TypeFlags::eTypeIsReference) { + Status error; + lldb::ValueObjectSP deref_ctx_sp = ctx_obj->Dereference(error); + if (!error.Success()) { + LLDB_LOG(log, "== [UserExpression::Evaluate] Passed a context object of " + "a reference type that can't be dereferenced, can't run " + "expressions."); + error.SetErrorString( + "passed context object of an reference type cannot be deferenced"); + return lldb::eExpressionSetupError; + } + + ctx_obj = deref_ctx_sp.get(); + } + lldb_private::ExecutionPolicy execution_policy = options.GetExecutionPolicy(); lldb::LanguageType language = options.GetLanguage(); const ResultType desired_type = options.DoesCoerceToId() |
