diff options
15 files changed, 269 insertions, 83 deletions
diff --git a/lldb/include/lldb/Core/RegisterValue.h b/lldb/include/lldb/Core/RegisterValue.h index c01a92a6ba1..27b69fd9b6e 100644 --- a/lldb/include/lldb/Core/RegisterValue.h +++ b/lldb/include/lldb/Core/RegisterValue.h @@ -51,24 +51,28 @@ namespace lldb_private { { } + explicit RegisterValue (uint8_t inst) : m_type (eTypeUInt8) { m_data.uint8 = inst; } + explicit RegisterValue (uint16_t inst) : m_type (eTypeUInt16) { m_data.uint16 = inst; } + explicit RegisterValue (uint32_t inst) : m_type (eTypeUInt32) { m_data.uint32 = inst; } + explicit RegisterValue (uint64_t inst) : m_type (eTypeUInt64) { @@ -76,30 +80,35 @@ namespace lldb_private { } #if defined (ENABLE_128_BIT_SUPPORT) + explicit RegisterValue (__uint128_t inst) : m_type (eTypeUInt128) { m_data.uint128 = inst; } #endif + explicit RegisterValue (float value) : m_type (eTypeFloat) { m_data.ieee_float = value; } + explicit RegisterValue (double value) : m_type (eTypeDouble) { m_data.ieee_double = value; } + explicit RegisterValue (long double value) : m_type (eTypeLongDouble) { m_data.ieee_long_double = value; } + explicit RegisterValue (uint8_t *bytes, size_t length, lldb::ByteOrder byte_order) { SetBytes (bytes, length, byte_order); diff --git a/lldb/include/lldb/Target/RegisterContext.h b/lldb/include/lldb/Target/RegisterContext.h index dcfd4e3a874..06742d2d7b1 100644 --- a/lldb/include/lldb/Target/RegisterContext.h +++ b/lldb/include/lldb/Target/RegisterContext.h @@ -142,10 +142,15 @@ public: uint64_t ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value); + uint64_t + ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value); + bool WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval); bool + WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval); + bool ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum); //------------------------------------------------------------------ diff --git a/lldb/include/lldb/Target/ThreadPlanCallFunction.h b/lldb/include/lldb/Target/ThreadPlanCallFunction.h index 127e17a9a52..3f2ac4a901c 100644 --- a/lldb/include/lldb/Target/ThreadPlanCallFunction.h +++ b/lldb/include/lldb/Target/ThreadPlanCallFunction.h @@ -80,7 +80,28 @@ public: { return true; } - + + // To get the return value from a function call you must create a + // lldb::ValueSP that contains a valid clang type in its context and call + // RequestReturnValue. The ValueSP will be stored and when the function is + // done executing, the object will check if there is a requested return + // value. If there is, the return value will be retrieved using the + // ABI::GetReturnValue() for the ABI in the process. Then after the thread + // plan is complete, you can call "GetReturnValue()" to retrieve the value + // that was extracted. + + const lldb::ValueSP & + GetReturnValue () + { + return m_return_value_sp; + } + + void + RequestReturnValue (lldb::ValueSP &return_value_sp) + { + m_return_value_sp = return_value_sp; + } + // Return the stack pointer that the function received // on entry. Any stack address below this should be // considered invalid after the function has been @@ -112,7 +133,6 @@ private: bool BreakpointsExplainStop (); - bool m_use_abi; bool m_valid; bool m_stop_other_threads; Address m_function_addr; @@ -125,6 +145,7 @@ private: LanguageRuntime *m_cxx_language_runtime; LanguageRuntime *m_objc_language_runtime; Thread::ThreadStateCheckpoint m_stored_thread_state; + lldb::ValueSP m_return_value_sp; // If this contains a valid pointer, use the ABI to extract values when complete bool m_takedown_done; // We want to ensure we only do the takedown once. This ensures that. DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction); diff --git a/lldb/include/lldb/lldb-forward-rtti.h b/lldb/include/lldb/lldb-forward-rtti.h index ae07c0615cf..abfe843e1f8 100644 --- a/lldb/include/lldb/lldb-forward-rtti.h +++ b/lldb/include/lldb/lldb-forward-rtti.h @@ -71,6 +71,8 @@ namespace lldb { typedef SharedPtr<lldb_private::UserSettingsController>::Type UserSettingsControllerSP; typedef SharedPtr<lldb_private::UnwindPlan>::Type UnwindPlanSP; typedef SharedPtr<lldb_private::ValueObject>::Type ValueObjectSP; + typedef SharedPtr<lldb_private::Value>::Type ValueSP; + typedef SharedPtr<lldb_private::ValueList>::Type ValueListSP; typedef SharedPtr<lldb_private::Variable>::Type VariableSP; typedef SharedPtr<lldb_private::VariableList>::Type VariableListSP; typedef SharedPtr<lldb_private::ValueObjectList>::Type ValueObjectListSP; diff --git a/lldb/source/Expression/ClangExpressionParser.cpp b/lldb/source/Expression/ClangExpressionParser.cpp index 028f99ab7e2..2ba15fe4581 100644 --- a/lldb/source/Expression/ClangExpressionParser.cpp +++ b/lldb/source/Expression/ClangExpressionParser.cpp @@ -52,7 +52,13 @@ #include "llvm/ADT/StringRef.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" + +#define USE_STANDARD_JIT +#if defined (USE_STANDARD_JIT) #include "llvm/ExecutionEngine/JIT.h" +#else +#include "llvm/ExecutionEngine/MCJIT.h" +#endif #include "llvm/LLVMContext.h" #include "llvm/Module.h" #include "llvm/Support/ErrorHandling.h" @@ -550,12 +556,24 @@ ClangExpressionParser::MakeJIT (lldb::addr_t &func_allocation_addr, llvm::TargetMachine::setRelocationModel(llvm::Reloc::PIC_); +#if defined (USE_STANDARD_JIT) m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, &error_string, jit_memory_manager, CodeGenOpt::Less, true, CodeModel::Small)); +#else + EngineBuilder builder(module); + builder.setEngineKind(EngineKind::JIT) + .setErrorStr(&error_string) + .setJITMemoryManager(jit_memory_manager) + .setOptLevel(CodeGenOpt::Less) + .setAllocateGVsWithCode(true) + .setCodeModel(CodeModel::Small) + .setUseMCJIT(true); + m_execution_engine.reset(builder.create()); +#endif if (!m_execution_engine.get()) { 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 d0b85039c57..fee09935842 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 @@ -70,9 +70,6 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread, addr_t *arg5_ptr, addr_t *arg6_ptr) const { - if (arg4_ptr || arg5_ptr || arg6_ptr) - return false; - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (log) @@ -89,32 +86,58 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread, if (!reg_ctx) return false; - RegisterValue reg_value; + const RegisterInfo *reg_info = NULL; if (arg1_ptr) { + reg_info = reg_ctx->GetRegisterInfoByName("rdi", 0); if (log) - log->Printf("About to write arg1 (0x%llx) into RDI", (uint64_t)*arg1_ptr); + log->Printf("About to write arg1 (0x%llx) into %s", (uint64_t)*arg1_ptr, reg_info->name); - reg_value.SetUInt64(*arg1_ptr); - if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rdi", 0), reg_value)) + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg1_ptr)) return false; if (arg2_ptr) { + reg_info = reg_ctx->GetRegisterInfoByName("rsi", 0); if (log) - log->Printf("About to write arg2 (0x%llx) into RSI", (uint64_t)*arg2_ptr); - - reg_value.SetUInt64(*arg2_ptr); - if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rsi", 0), reg_value)) + log->Printf("About to write arg2 (0x%llx) into %s", (uint64_t)*arg2_ptr, reg_info->name); + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg2_ptr)) return false; if (arg3_ptr) { + reg_info = reg_ctx->GetRegisterInfoByName("rdx", 0); if (log) - log->Printf("About to write arg3 (0x%llx) into RDX", (uint64_t)*arg3_ptr); - reg_value.SetUInt64(*arg3_ptr); - if (!reg_ctx->WriteRegister(reg_ctx->GetRegisterInfoByName("rdx", 0), reg_value)) + log->Printf("About to write arg3 (0x%llx) into %s", (uint64_t)*arg3_ptr, reg_info->name); + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg3_ptr)) return false; + + if (arg4_ptr) + { + reg_info = reg_ctx->GetRegisterInfoByName("rcx", 0); + if (log) + log->Printf("About to write arg4 (0x%llx) into %s", (uint64_t)*arg4_ptr, reg_info->name); + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg4_ptr)) + return false; + + if (arg5_ptr) + { + reg_info = reg_ctx->GetRegisterInfoByName("r8", 0); + if (log) + log->Printf("About to write arg5 (0x%llx) into %s", (uint64_t)*arg5_ptr, reg_info->name); + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg5_ptr)) + return false; + + if (arg6_ptr) + { + reg_info = reg_ctx->GetRegisterInfoByName("r9", 0); + if (log) + log->Printf("About to write arg6 (0x%llx) into %s", (uint64_t)*arg6_ptr, reg_info->name); + if (!reg_ctx->WriteRegisterFromUnsigned (reg_info, *arg6_ptr)) + return false; + } + } + } } } } @@ -130,6 +153,7 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread, // The return address is pushed onto the stack (yes after the alignment...) sp -= 8; + RegisterValue reg_value; reg_value.SetUInt64 (return_addr); if (log) @@ -145,8 +169,7 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread, if (log) log->Printf("Writing SP (0x%llx) down", (uint64_t)sp); - reg_value.SetUInt64(sp); - if (!reg_ctx->WriteRegister (reg_ctx->GetRegisterInfoByName("rsp"), reg_value)) + if (!reg_ctx->WriteRegisterFromUnsigned (reg_ctx->GetRegisterInfoByName("rsp"), sp)) return false; // %rip is set to the address of the called function. @@ -154,9 +177,7 @@ ABISysV_x86_64::PrepareTrivialCall (Thread &thread, if (log) log->Printf("Writing new IP (0x%llx) down", (uint64_t)func_addr); - reg_value.SetUInt64(func_addr); - - if (!reg_ctx->WriteRegister(pc_reg_info, func_addr)) + if (!reg_ctx->WriteRegisterFromUnsigned (pc_reg_info, func_addr)) return false; return true; @@ -222,13 +243,13 @@ static bool ReadIntegerArgument(Scalar &scalar, default: return false; case 8: - scalar = (uint8_t)(arg_contents & 0xff); + scalar = (uint8_t)(arg_contents & 0xffu); break; case 16: - scalar = (uint16_t)(arg_contents & 0xffff); + scalar = (uint16_t)(arg_contents & 0xffffu); break; case 32: - scalar = (uint32_t)(arg_contents & 0xffffffff); + scalar = (uint32_t)(arg_contents & 0xffffffffu); break; case 64: scalar = (uint64_t)arg_contents; diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp index e042cb280bc..554f5193135 100644 --- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp +++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTrampolineHandler.cpp @@ -381,9 +381,9 @@ AppleObjCTrampolineHandler::AppleObjCVTables::InitializeVTableSymbols () bool AppleObjCTrampolineHandler::AppleObjCVTables::RefreshTrampolines (void *baton, - StoppointCallbackContext *context, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id) + StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) { AppleObjCVTables *vtable_handler = (AppleObjCVTables *) baton; if (vtable_handler->InitializeVTableSymbols()) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 5e685e000c7..fdd3fe2591b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -45,8 +45,7 @@ GDBRemoteCommunicationClient::GDBRemoteCommunicationClient(bool is_platform) : m_supports_vCont_s (eLazyBoolCalculate), m_supports_vCont_S (eLazyBoolCalculate), m_qHostInfo_is_valid (eLazyBoolCalculate), - m_supports__m (eLazyBoolCalculate), - m_supports__M (eLazyBoolCalculate), + m_supports_alloc_dealloc_memory (eLazyBoolCalculate), m_supports_qProcessInfoPID (true), m_supports_qfProcessInfo (true), m_supports_qUserName (true), @@ -132,8 +131,7 @@ GDBRemoteCommunicationClient::ResetDiscoverableSettings() m_supports_vCont_s = eLazyBoolCalculate; m_supports_vCont_S = eLazyBoolCalculate; m_qHostInfo_is_valid = eLazyBoolCalculate; - m_supports__m = eLazyBoolCalculate; - m_supports__M = eLazyBoolCalculate; + m_supports_alloc_dealloc_memory = eLazyBoolCalculate; m_supports_qProcessInfoPID = true; m_supports_qfProcessInfo = true; @@ -1021,9 +1019,9 @@ GDBRemoteCommunicationClient::GetHostArchitecture () addr_t GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) { - if (m_supports__M != eLazyBoolNo) + if (m_supports_alloc_dealloc_memory != eLazyBoolNo) { - m_supports__M = eLazyBoolYes; + m_supports_alloc_dealloc_memory = eLazyBoolYes; char packet[64]; const int packet_len = ::snprintf (packet, sizeof(packet), "_M%zx,%s%s%s", size, permissions & lldb::ePermissionsReadable ? "r" : "", @@ -1034,7 +1032,7 @@ GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) if (SendPacketAndWaitForResponse (packet, packet_len, response, false)) { if (response.IsUnsupportedResponse()) - m_supports__M = eLazyBoolNo; + m_supports_alloc_dealloc_memory = eLazyBoolNo; else if (!response.IsErrorResponse()) return response.GetHexMaxU64(false, LLDB_INVALID_ADDRESS); } @@ -1045,9 +1043,9 @@ GDBRemoteCommunicationClient::AllocateMemory (size_t size, uint32_t permissions) bool GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr) { - if (m_supports__m != eLazyBoolNo) + if (m_supports_alloc_dealloc_memory != eLazyBoolNo) { - m_supports__m = eLazyBoolYes; + m_supports_alloc_dealloc_memory = eLazyBoolYes; char packet[64]; const int packet_len = ::snprintf(packet, sizeof(packet), "_m%llx", (uint64_t)addr); assert (packet_len < sizeof(packet)); @@ -1057,7 +1055,7 @@ GDBRemoteCommunicationClient::DeallocateMemory (addr_t addr) if (response.IsOKResponse()) return true; else if (response.IsUnsupportedResponse()) - m_supports__m = eLazyBoolNo; + m_supports_alloc_dealloc_memory = eLazyBoolNo; } } return false; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h index e1d17be8105..727bc4e4f88 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h @@ -306,15 +306,9 @@ public: SetCurrentThreadForRun (int tid); lldb_private::LazyBool - SupportsAllocateMemory () const + SupportsAllocDeallocMemory () const { - return m_supports__M; - } - - lldb_private::LazyBool - SupportsDeallocateMemory () const - { - return m_supports__m; + return m_supports_alloc_dealloc_memory; } protected: @@ -331,8 +325,7 @@ protected: lldb_private::LazyBool m_supports_vCont_s; lldb_private::LazyBool m_supports_vCont_S; lldb_private::LazyBool m_qHostInfo_is_valid; - lldb_private::LazyBool m_supports__m; - lldb_private::LazyBool m_supports__M; + lldb_private::LazyBool m_supports_alloc_dealloc_memory; bool m_supports_qProcessInfoPID:1, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 14f31004a85..172a1cf0f77 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -34,6 +34,7 @@ #include "lldb/Core/State.h" #include "lldb/Core/StreamString.h" #include "lldb/Core/Timer.h" +#include "lldb/Core/Value.h" #include "lldb/Host/TimeValue.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/DynamicLoader.h" @@ -654,14 +655,18 @@ ProcessGDBRemote::DidLaunchOrAttach () // Fill in what is missing in the triple const llvm::Triple &remote_triple = gdb_remote_arch.GetTriple(); llvm::Triple &target_triple = target_arch.GetTriple(); - if (target_triple.getVendor() == llvm::Triple::UnknownVendor) + if (target_triple.getVendorName().size() == 0) + { target_triple.setVendor (remote_triple.getVendor()); - if (target_triple.getOS() == llvm::Triple::UnknownOS) - target_triple.setOS (remote_triple.getOS()); + if (target_triple.getOSName().size() == 0) + { + target_triple.setOS (remote_triple.getOS()); - if (target_triple.getEnvironment() == llvm::Triple::UnknownEnvironment) - target_triple.setEnvironment (remote_triple.getEnvironment()); + if (target_triple.getEnvironmentName().size() == 0) + target_triple.setEnvironment (remote_triple.getEnvironment()); + } + } } } else @@ -1545,7 +1550,7 @@ ProcessGDBRemote::DoAllocateMemory (size_t size, uint32_t permissions, Error &er { addr_t allocated_addr = LLDB_INVALID_ADDRESS; - LazyBool supported = m_gdb_comm.SupportsAllocateMemory(); + LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory(); switch (supported) { case eLazyBoolCalculate: @@ -1596,31 +1601,44 @@ ProcessGDBRemote::DoAllocateMemory (size_t size, uint32_t permissions, Error &er AddressRange mmap_range; if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, mmap_range)) { - lldb::ThreadPlanSP call_plan_sp (new ThreadPlanCallFunction (*thread, - mmap_range.GetBaseAddress(), - stop_other_threads, - discard_on_error, - &arg1_addr, - &arg2_len, - &arg3_prot, - &arg4_flags, - &arg5_fd, - &arg6_offset)); + ThreadPlanCallFunction *call_function_thread_plan = new ThreadPlanCallFunction (*thread, + mmap_range.GetBaseAddress(), + stop_other_threads, + discard_on_error, + &arg1_addr, + &arg2_len, + &arg3_prot, + &arg4_flags, + &arg5_fd, + &arg6_offset); + lldb::ThreadPlanSP call_plan_sp (call_function_thread_plan); if (call_plan_sp) { + ValueSP return_value_sp (new Value); + ClangASTContext *clang_ast_context = m_target.GetScratchClangASTContext(); + lldb::clang_type_t clang_void_ptr_type = clang_ast_context->GetVoidPtrType(false); + return_value_sp->SetValueType (Value::eValueTypeScalar); + return_value_sp->SetContext (Value::eContextTypeClangType, clang_void_ptr_type); + call_function_thread_plan->RequestReturnValue (return_value_sp); + StreamFile error_strm; StackFrame *frame = thread->GetStackFrameAtIndex (0).get(); if (frame) { ExecutionContext exe_ctx; frame->CalculateExecutionContext (exe_ctx); - ExecutionResults results = RunThreadPlan (exe_ctx, - call_plan_sp, - stop_other_threads, - try_all_threads, - discard_on_error, - single_thread_timeout_usec, - error_strm); + ExecutionResults result = RunThreadPlan (exe_ctx, + call_plan_sp, + stop_other_threads, + try_all_threads, + discard_on_error, + single_thread_timeout_usec, + error_strm); + if (result == eExecutionCompleted) + { + allocated_addr = return_value_sp->GetScalar().ULongLong(); + m_addr_to_mmap_size[allocated_addr] = size; + } } } } @@ -1641,8 +1659,91 @@ Error ProcessGDBRemote::DoDeallocateMemory (lldb::addr_t addr) { Error error; - if (!m_gdb_comm.DeallocateMemory (addr)) - error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr); + LazyBool supported = m_gdb_comm.SupportsAllocDeallocMemory(); + + switch (supported) + { + case eLazyBoolCalculate: + // We should never be deallocating memory without allocating memory + // first so we should never get eLazyBoolCalculate + error.SetErrorString ("tried to deallocate memory without ever allocating memory"); + break; + + case eLazyBoolYes: + if (!m_gdb_comm.DeallocateMemory (addr)) + error.SetErrorStringWithFormat("unable to deallocate memory at 0x%llx", addr); + break; + + case eLazyBoolNo: + // Call munmap() to create executable memory in the inferior.. + { + MMapMap::iterator pos = m_addr_to_mmap_size.find(addr); + if (pos != m_addr_to_mmap_size.end()) + { + Thread *thread = GetThreadList().GetSelectedThread().get(); + if (thread == NULL) + thread = GetThreadList().GetThreadAtIndex(0).get(); + + const bool append = true; + const bool include_symbols = true; + SymbolContextList sc_list; + const uint32_t count = m_target.GetImages().FindFunctions (ConstString ("munmap"), + eFunctionNameTypeFull, + include_symbols, + append, + sc_list); + if (count > 0) + { + SymbolContext sc; + if (sc_list.GetContextAtIndex(0, sc)) + { + const uint32_t range_scope = eSymbolContextFunction | eSymbolContextSymbol; + const bool use_inline_block_range = false; + const bool stop_other_threads = true; + const bool discard_on_error = true; + const bool try_all_threads = true; + const uint32_t single_thread_timeout_usec = 500000; + addr_t arg1_addr = addr; + addr_t arg2_len = pos->second; + + AddressRange munmap_range; + if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, munmap_range)) + { + lldb::ThreadPlanSP call_plan_sp (new ThreadPlanCallFunction (*thread, + munmap_range.GetBaseAddress(), + stop_other_threads, + discard_on_error, + &arg1_addr, + &arg2_len)); + if (call_plan_sp) + { + StreamFile error_strm; + StackFrame *frame = thread->GetStackFrameAtIndex (0).get(); + if (frame) + { + ExecutionContext exe_ctx; + frame->CalculateExecutionContext (exe_ctx); + ExecutionResults result = RunThreadPlan (exe_ctx, + call_plan_sp, + stop_other_threads, + try_all_threads, + discard_on_error, + single_thread_timeout_usec, + error_strm); + if (result == eExecutionCompleted) + { + m_addr_to_mmap_size.erase (pos); + } + } + } + } + } + } + } + } + break; + } + return error; } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index cf03604a182..21646cbf286 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -303,6 +303,7 @@ protected: lldb::thread_t m_async_thread; typedef std::vector<lldb::tid_t> tid_collection; typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection; + typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap; tid_collection m_continue_c_tids; // 'c' for continue tid_sig_collection m_continue_C_tids; // 'C' for continue with signal tid_collection m_continue_s_tids; // 's' for step @@ -312,7 +313,7 @@ protected: bool m_waiting_for_attach; bool m_local_debugserver; // Is the debugserver process we are talking to local or on another machine. std::vector<lldb::user_id_t> m_thread_observation_bps; - + MMapMap m_addr_to_mmap_size; bool StartAsyncThread (); diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp index 3e9cef34c19..8ed7edaedb4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp @@ -43,7 +43,6 @@ ThreadGDBRemote::ThreadGDBRemote (ProcessGDBRemote &process, lldb::tid_t tid) : m_dispatch_queue_name (), m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS) { -// ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD | GDBR_LOG_VERBOSE, "ThreadGDBRemote::ThreadGDBRemote ( pid = %i, tid = 0x%4.4x, )", m_process.GetID(), GetID()); ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", this, m_process.GetID(), GetID()); } diff --git a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp index ee427ee9cdd..e7269326588 100644 --- a/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp +++ b/lldb/source/Plugins/UnwindAssembly/InstEmulation/UnwindAssemblyInstEmulation.cpp @@ -84,7 +84,9 @@ UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly (AddressRange& m_pushed_regs.clear(); m_initial_sp = (1ull << ((addr_byte_size * 8) - 1)); - SetRegisterValue (m_cfa_reg_info, m_initial_sp); + RegisterValue cfa_reg_value; + cfa_reg_value.SetUInt (m_initial_sp, m_cfa_reg_info.byte_size); + SetRegisterValue (m_cfa_reg_info, cfa_reg_value); const InstructionList &inst_list = disasm_sp->GetInstructionList (); const size_t num_instructions = inst_list.GetSize(); diff --git a/lldb/source/Target/RegisterContext.cpp b/lldb/source/Target/RegisterContext.cpp index 169ab743f58..a7856c6332c 100644 --- a/lldb/source/Target/RegisterContext.cpp +++ b/lldb/source/Target/RegisterContext.cpp @@ -150,14 +150,18 @@ uint64_t RegisterContext::ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value) { if (reg != LLDB_INVALID_REGNUM) + return ReadRegisterAsUnsigned (GetRegisterInfoAtIndex (reg), fail_value); + return fail_value; +} + +uint64_t +RegisterContext::ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value) +{ + if (reg_info) { - const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg); - if (reg_info) - { - RegisterValue value; - if (ReadRegister (reg_info, value)) - return value.GetAsUInt64(); - } + RegisterValue value; + if (ReadRegister (reg_info, value)) + return value.GetAsUInt64(); } return fail_value; } @@ -167,7 +171,12 @@ RegisterContext::WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval) { if (reg == LLDB_INVALID_REGNUM) return false; - const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg); + return WriteRegisterFromUnsigned (GetRegisterInfoAtIndex (reg), uval); +} + +bool +RegisterContext::WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval) +{ if (reg_info) { RegisterValue value; diff --git a/lldb/source/Target/ThreadPlanCallFunction.cpp b/lldb/source/Target/ThreadPlanCallFunction.cpp index fee0cbd1c7c..371f3a46007 100644 --- a/lldb/source/Target/ThreadPlanCallFunction.cpp +++ b/lldb/source/Target/ThreadPlanCallFunction.cpp @@ -272,6 +272,13 @@ ThreadPlanCallFunction::DoTakedown () LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); if (!m_takedown_done) { + // TODO: how do we tell if all went well? + if (m_return_value_sp) + { + const ABI *abi = m_thread.GetProcess().GetABI().get(); + if (abi) + abi->GetReturnValue(m_thread, *m_return_value_sp); + } if (log) log->Printf ("DoTakedown called for thread 0x%4.4x, m_valid: %d complete: %d.\n", m_thread.GetID(), m_valid, IsPlanComplete()); m_takedown_done = true; |