|
24 | 24 | #endif
|
25 | 25 |
|
26 | 26 | #include "Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
|
| 27 | +#include "lldb/Core/Debugger.h" |
27 | 28 | #include "lldb/Core/Module.h"
|
28 | 29 | #include "lldb/Expression/DiagnosticManager.h"
|
29 | 30 | #include "lldb/Expression/ExpressionParser.h"
|
@@ -65,31 +66,49 @@ SwiftUserExpression::SwiftUserExpression(
|
65 | 66 | m_result_delegate(exe_scope.CalculateTarget(), *this, false),
|
66 | 67 | m_error_delegate(exe_scope.CalculateTarget(), *this, true),
|
67 | 68 | m_persistent_variable_delegate(*this) {
|
| 69 | + if (auto target = exe_scope.CalculateTarget()) |
| 70 | + m_debugger_id = target->GetDebugger().GetID(); |
68 | 71 | m_runs_in_playground_or_repl =
|
69 | 72 | options.GetREPLEnabled() || options.GetPlaygroundTransformEnabled();
|
70 | 73 | }
|
71 | 74 |
|
72 | 75 | SwiftUserExpression::~SwiftUserExpression() {}
|
73 | 76 |
|
74 | 77 | void SwiftUserExpression::WillStartExecuting() {
|
75 |
| - if (auto process = m_jit_process_wp.lock()) { |
| 78 | + if (auto process = m_jit_process_wp.lock()) |
76 | 79 | if (auto *swift_runtime = SwiftLanguageRuntime::Get(process))
|
77 | 80 | swift_runtime->WillStartExecutingUserExpression(
|
78 | 81 | m_runs_in_playground_or_repl);
|
79 | 82 | else
|
80 |
| - llvm_unreachable("Can't execute a swift expression without a runtime"); |
81 |
| - } else |
82 |
| - llvm_unreachable("Can't execute an expression without a process"); |
| 83 | + Debugger::ReportError( |
| 84 | + "Can't execute a swift expression without a runtime", |
| 85 | + m_debugger_id); |
| 86 | + else |
| 87 | + Debugger::ReportError("Can't execute an expression without a process", |
| 88 | + m_debugger_id); |
83 | 89 | }
|
84 | 90 |
|
85 | 91 | void SwiftUserExpression::DidFinishExecuting() {
|
86 |
| - if (auto process = m_jit_process_wp.lock()) { |
87 |
| - if (auto *swift_runtime = SwiftLanguageRuntime::Get(process)) |
88 |
| - swift_runtime->DidFinishExecutingUserExpression( |
89 |
| - m_runs_in_playground_or_repl); |
90 |
| - else |
91 |
| - llvm_unreachable("Can't execute a swift expression without a runtime"); |
| 92 | + auto process = m_jit_process_wp.lock(); |
| 93 | + if (!process) { |
| 94 | + Debugger::ReportError("Could not finish a expression without a process", |
| 95 | + m_debugger_id); |
| 96 | + return; |
| 97 | + } |
| 98 | + if (!process->IsValid()) { |
| 99 | + // This will cause SwiftLanguageRuntime::Get(process) tp fail. |
| 100 | + Debugger::ReportError("Could not finish swift expression because the " |
| 101 | + "process is being torn down", |
| 102 | + m_debugger_id); |
| 103 | + return; |
| 104 | + } |
| 105 | + auto *swift_runtime = SwiftLanguageRuntime::Get(process); |
| 106 | + if (!swift_runtime) { |
| 107 | + Debugger::ReportError("Could not finish swift expression without a runtime", |
| 108 | + m_debugger_id); |
| 109 | + return; |
92 | 110 | }
|
| 111 | + swift_runtime->DidFinishExecutingUserExpression(m_runs_in_playground_or_repl); |
93 | 112 | }
|
94 | 113 |
|
95 | 114 | /// Determine whether we have a Swift language symbol context. This handles
|
|
0 commit comments