================ @@ -125,19 +127,51 @@ ExecutionContext::ExecutionContext(const ExecutionContextRef *exe_ctx_ref_ptr, } } -ExecutionContext::ExecutionContext(const ExecutionContextRef *exe_ctx_ref_ptr, - std::unique_lock<std::recursive_mutex> &lock) - : m_target_sp(), m_process_sp(), m_thread_sp(), m_frame_sp() { - if (exe_ctx_ref_ptr) { - m_target_sp = exe_ctx_ref_ptr->GetTargetSP(); - if (m_target_sp) { - lock = std::unique_lock<std::recursive_mutex>(m_target_sp->GetAPIMutex()); +llvm::Expected<CompleteExecutionContext> +lldb_private::GetCompleteExecutionContext( + const lldb::ExecutionContextRefSP &exe_ctx_ref_ptr) { + return GetCompleteExecutionContext(exe_ctx_ref_ptr.get()); +} - m_process_sp = exe_ctx_ref_ptr->GetProcessSP(); - m_thread_sp = exe_ctx_ref_ptr->GetThreadSP(); - m_frame_sp = exe_ctx_ref_ptr->GetFrameSP(); - } +llvm::Expected<CompleteExecutionContext> +lldb_private::GetCompleteExecutionContext( + const ExecutionContextRef *exe_ctx_ref_ptr) { + if (!exe_ctx_ref_ptr) + return llvm::createStringError( + "ExecutionContext created with an empty ExecutionContextRef"); + + lldb::TargetSP target_sp = exe_ctx_ref_ptr->GetTargetSP(); + if (!target_sp) + return llvm::createStringError( + "ExecutionContext created with a null target"); + + auto api_lock = + std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); + + auto process_sp = exe_ctx_ref_ptr->GetProcessSP(); + if (!process_sp) + return llvm::createStringError( + "ExecutionContext created with a null process"); + + ProcessRunLock::ProcessRunLocker stop_locker; + if (!stop_locker.TryLock(&process_sp->GetRunLock())) { + auto *error_msg = + "Attempted to create an ExecutionContext with a running process"; + LLDB_LOG(GetLog(LLDBLog::API), error_msg); ---------------- JDevlieghere wrote:
I don't think we should be logging to the API log from here. I would drop this and use LLDB_LOG_ERROR with the API log instead of llvm::consumeError at the call sites. That also helps convey that the error is not totally important. https://github.com/llvm/llvm-project/pull/152020 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits