Skip to content

Commit caa5e8c

Browse files
authored
Merge pull request #5587 from jimingham/expr-require-stop-weed
Don't try to create Expressions when the process is running.
2 parents be09589 + 32955b4 commit caa5e8c

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

lldb/source/Expression/FunctionCaller.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,31 @@ bool FunctionCaller::WriteFunctionWrapper(
6565
ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) {
6666
Process *process = exe_ctx.GetProcessPtr();
6767

68-
if (!process)
68+
if (!process) {
69+
diagnostic_manager.Printf(eDiagnosticSeverityError, "no process.");
6970
return false;
70-
71+
}
72+
7173
lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());
7274

73-
if (process != jit_process_sp.get())
75+
if (process != jit_process_sp.get()) {
76+
diagnostic_manager.Printf(eDiagnosticSeverityError,
77+
"process does not match the stored process.");
7478
return false;
75-
76-
if (!m_compiled)
79+
}
80+
81+
if (process->GetState() != lldb::eStateStopped) {
82+
diagnostic_manager.Printf(eDiagnosticSeverityError,
83+
"process is not stopped");
7784
return false;
85+
}
7886

87+
if (!m_compiled) {
88+
diagnostic_manager.Printf(eDiagnosticSeverityError,
89+
"function not compiled");
90+
return false;
91+
}
92+
7993
if (m_JITted)
8094
return true;
8195

@@ -212,6 +226,17 @@ bool FunctionCaller::WriteFunctionArguments(
212226
bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
213227
lldb::addr_t &args_addr_ref,
214228
DiagnosticManager &diagnostic_manager) {
229+
// Since we might need to call allocate memory and maybe call code to make
230+
// the caller, we need to be stopped.
231+
Process *process = exe_ctx.GetProcessPtr();
232+
if (!process) {
233+
diagnostic_manager.PutString(eDiagnosticSeverityError, "no process");
234+
return false;
235+
}
236+
if (process->GetState() != lldb::eStateStopped) {
237+
diagnostic_manager.PutString(eDiagnosticSeverityError, "process running");
238+
return false;
239+
}
215240
if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
216241
return false;
217242
if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager))

lldb/source/Expression/UserExpression.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,22 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
182182

183183
Process *process = exe_ctx.GetProcessPtr();
184184

185-
if (process == nullptr || process->GetState() != lldb::eStateStopped) {
186-
if (execution_policy == eExecutionPolicyAlways) {
187-
LLDB_LOG(log, "== [UserExpression::Evaluate] Expression may not run, but "
188-
"is not constant ==");
185+
if (process == nullptr && execution_policy == eExecutionPolicyAlways) {
186+
LLDB_LOG(log, "== [UserExpression::Evaluate] No process, but the policy is "
187+
"eExecutionPolicyAlways");
189188

190-
error.SetErrorString("expression needed to run but couldn't");
189+
error.SetErrorString("expression needed to run but couldn't: no process");
191190

192-
return execution_results;
193-
}
191+
return execution_results;
194192
}
193+
// Since we might need to call allocate memory and maybe call code to make
194+
// the caller, we need to be stopped.
195+
if (process != nullptr && process->GetState() != lldb::eStateStopped) {
196+
error.SetErrorString("Can't make a function caller while the process is "
197+
"running");
198+
return execution_results;
199+
}
200+
195201

196202
// Explicitly force the IR interpreter to evaluate the expression when the
197203
// there is no process that supports running the expression for us. Don't

lldb/source/Expression/UtilityFunction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ FunctionCaller *UtilityFunction::MakeFunctionCaller(
6464
error.SetErrorString("Can't make a function caller without a process.");
6565
return nullptr;
6666
}
67+
// Since we might need to call allocate memory and maybe call code to make
68+
// the caller, we need to be stopped.
69+
if (process_sp->GetState() != lldb::eStateStopped) {
70+
error.SetErrorString("Can't make a function caller while the process is "
71+
"running");
72+
return nullptr;
73+
}
6774

6875
Address impl_code_address;
6976
impl_code_address.SetOffset(StartAddress());

lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
9999
return false;
100100
}
101101

102+
// Since we might need to call allocate memory and maybe call code to make
103+
// the caller, we need to be stopped.
104+
if (process->GetState() != lldb::eStateStopped) {
105+
diagnostic_manager.PutString(eDiagnosticSeverityError, "process running");
106+
return false;
107+
}
102108
//////////////////////////
103109
// Parse the expression
104110
//

lldb/source/Target/Process.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,10 @@ uint32_t Process::AssignIndexIDToThread(uint64_t thread_id) {
14311431
}
14321432

14331433
StateType Process::GetState() {
1434-
return m_public_state.GetValue();
1434+
if (CurrentThreadIsPrivateStateThread())
1435+
return m_private_state.GetValue();
1436+
else
1437+
return m_public_state.GetValue();
14351438
}
14361439

14371440
void Process::SetPublicState(StateType new_state, bool restarted) {

0 commit comments

Comments
 (0)