Skip to content

Commit e31f994

Browse files
committed
[lldb] Improve error message when evaluating expression when not stopped
When trying to run an expression after a process has existed, you currently are shown the following error message: (lldb) p strlen("") error: Can't make a function caller while the process is running This error is wrong and pretty uninformative. After this patch, the following error message is shown: (lldb) p strlen("") error: unable to evaluate expression while the process is exited: the process must be stopped because the expression might require allocating memory. rdar://109731325 Differential revision: https://reviews.llvm.org/D151497
1 parent 08be7a4 commit e31f994

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lldb/source/Expression/UserExpression.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "lldb/Utility/ConstString.h"
4040
#include "lldb/Utility/LLDBLog.h"
4141
#include "lldb/Utility/Log.h"
42+
#include "lldb/Utility/State.h"
4243
#include "lldb/Utility/StreamString.h"
4344

4445
using namespace lldb_private;
@@ -202,15 +203,18 @@ UserExpression::Evaluate(ExecutionContext &exe_ctx,
202203

203204
return execution_results;
204205
}
205-
// Since we might need to call allocate memory and maybe call code to make
206-
// the caller, we need to be stopped.
206+
207+
// Since we might need to allocate memory, we need to be stopped to run
208+
// an expression.
207209
if (process != nullptr && process->GetState() != lldb::eStateStopped) {
208-
error.SetErrorString("Can't make a function caller while the process is "
209-
"running");
210+
error.SetErrorStringWithFormatv(
211+
"unable to evaluate expression while the process is {0}: the process "
212+
"must be stopped because the expression might require allocating "
213+
"memory.",
214+
StateAsCString(process->GetState()));
210215
return execution_results;
211216
}
212217

213-
214218
// Explicitly force the IR interpreter to evaluate the expression when the
215219
// there is no process that supports running the expression for us. Don't
216220
// change the execution policy if we have the special top-level policy that

lldb/source/Expression/UtilityFunction.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Target/Target.h"
2222
#include "lldb/Utility/ConstString.h"
2323
#include "lldb/Utility/Log.h"
24+
#include "lldb/Utility/State.h"
2425
#include "lldb/Utility/Stream.h"
2526

2627
using namespace lldb_private;
@@ -64,11 +65,13 @@ FunctionCaller *UtilityFunction::MakeFunctionCaller(
6465
error.SetErrorString("Can't make a function caller without a process.");
6566
return nullptr;
6667
}
67-
// Since we might need to call allocate memory and maybe call code to make
68+
// Since we might need to allocate memory and maybe call code to make
6869
// the caller, we need to be stopped.
6970
if (process_sp->GetState() != lldb::eStateStopped) {
70-
error.SetErrorString("Can't make a function caller while the process is "
71-
"running");
71+
error.SetErrorStringWithFormatv(
72+
"Can't make a function caller while the process is {0}: the process "
73+
"must be stopped to allocate memory.",
74+
StateAsCString(process_sp->GetState()));
7275
return nullptr;
7376
}
7477

lldb/test/Shell/Expr/TestExited.test

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

0 commit comments

Comments
 (0)