[Lldb-commits] [lldb] [lldb] Guard SBFrame/SBThread methods against running processes (PR #152020)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Fri Aug 8 09:27:24 PDT 2025
================
@@ -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
More information about the lldb-commits
mailing list