Skip to content

[lldb] Improve error message when evaluating expression when not stopped #6922

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 1 commit into from
May 26, 2023
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
14 changes: 9 additions & 5 deletions lldb/source/Expression/UserExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"

#ifdef LLDB_ENABLE_SWIFT
Expand Down Expand Up @@ -206,15 +207,18 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,

return execution_results;
}
// Since we might need to call allocate memory and maybe call code to make
// the caller, we need to be stopped.

// Since we might need to allocate memory, we need to be stopped to run
// an expression.
if (process != nullptr && process->GetState() != lldb::eStateStopped) {
error.SetErrorString("Can't make a function caller while the process is "
"running");
error.SetErrorStringWithFormatv(
"unable to evaluate expression while the process is {0}: the process "
"must be stopped because the expression might require allocating "
"memory.",
StateAsCString(process->GetState()));
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
// change the execution policy if we have the special top-level policy that
Expand Down
9 changes: 6 additions & 3 deletions lldb/source/Expression/UtilityFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lldb/Target/Target.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/Stream.h"

using namespace lldb_private;
Expand Down Expand Up @@ -64,11 +65,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
// Since we might need to 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");
error.SetErrorStringWithFormatv(
"Can't make a function caller while the process is {0}: the process "
"must be stopped to allocate memory.",
StateAsCString(process_sp->GetState()));
return nullptr;
}

Expand Down
3 changes: 3 additions & 0 deletions lldb/test/Shell/Expr/TestExited.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RUN: %clangxx_host %p/Inputs/call-function.cpp -g -o %t
# RUN: %lldb %t -o 'r' -o 'expr strlen("")' 2>&1 | FileCheck %s
# CHECK: error: unable to evaluate expression while the process is exited: the process must be stopped because the expression might require allocating memory.