Skip to content

Don't try to create Expressions when the process is running. #5587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions lldb/source/Expression/FunctionCaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,31 @@ bool FunctionCaller::WriteFunctionWrapper(
ExecutionContext &exe_ctx, DiagnosticManager &diagnostic_manager) {
Process *process = exe_ctx.GetProcessPtr();

if (!process)
if (!process) {
diagnostic_manager.Printf(eDiagnosticSeverityError, "no process.");
return false;

}

lldb::ProcessSP jit_process_sp(m_jit_process_wp.lock());

if (process != jit_process_sp.get())
if (process != jit_process_sp.get()) {
diagnostic_manager.Printf(eDiagnosticSeverityError,
"process does not match the stored process.");
return false;

if (!m_compiled)
}

if (process->GetState() != lldb::eStateStopped) {
diagnostic_manager.Printf(eDiagnosticSeverityError,
"process is not stopped");
return false;
}

if (!m_compiled) {
diagnostic_manager.Printf(eDiagnosticSeverityError,
"function not compiled");
return false;
}

if (m_JITted)
return true;

Expand Down Expand Up @@ -212,6 +226,17 @@ bool FunctionCaller::WriteFunctionArguments(
bool FunctionCaller::InsertFunction(ExecutionContext &exe_ctx,
lldb::addr_t &args_addr_ref,
DiagnosticManager &diagnostic_manager) {
// Since we might need to call allocate memory and maybe call code to make
// the caller, we need to be stopped.
Process *process = exe_ctx.GetProcessPtr();
if (!process) {
diagnostic_manager.PutString(eDiagnosticSeverityError, "no process");
return false;
}
if (process->GetState() != lldb::eStateStopped) {
diagnostic_manager.PutString(eDiagnosticSeverityError, "process running");
return false;
}
if (CompileFunction(exe_ctx.GetThreadSP(), diagnostic_manager) != 0)
return false;
if (!WriteFunctionWrapper(exe_ctx, diagnostic_manager))
Expand Down
20 changes: 13 additions & 7 deletions lldb/source/Expression/UserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,22 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,

Process *process = exe_ctx.GetProcessPtr();

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

error.SetErrorString("expression needed to run but couldn't");
error.SetErrorString("expression needed to run but couldn't: no process");

return execution_results;
}
return execution_results;
}
// Since we might need to call allocate memory and maybe call code to make
// the caller, we need to be stopped.
if (process != nullptr && process->GetState() != lldb::eStateStopped) {
error.SetErrorString("Can't make a function caller while the process is "
"running");
return execution_results;
}


// Explicitly force the IR interpreter to evaluate the expression when the
// there is no process that supports running the expression for us. Don't
Expand Down
7 changes: 7 additions & 0 deletions lldb/source/Expression/UtilityFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ FunctionCaller *UtilityFunction::MakeFunctionCaller(
error.SetErrorString("Can't make a function caller without a process.");
return nullptr;
}
// Since we might need to call allocate memory and maybe call code to make
// the caller, we need to be stopped.
if (process_sp->GetState() != lldb::eStateStopped) {
error.SetErrorString("Can't make a function caller while the process is "
"running");
return nullptr;
}

Address impl_code_address;
impl_code_address.SetOffset(StartAddress());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ bool ClangUtilityFunction::Install(DiagnosticManager &diagnostic_manager,
return false;
}

// Since we might need to call allocate memory and maybe call code to make
// the caller, we need to be stopped.
if (process->GetState() != lldb::eStateStopped) {
diagnostic_manager.PutString(eDiagnosticSeverityError, "process running");
return false;
}
//////////////////////////
// Parse the expression
//
Expand Down
5 changes: 4 additions & 1 deletion lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,10 @@ uint32_t Process::AssignIndexIDToThread(uint64_t thread_id) {
}

StateType Process::GetState() {
return m_public_state.GetValue();
if (CurrentThreadIsPrivateStateThread())
return m_private_state.GetValue();
else
return m_public_state.GetValue();
}

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