[Lldb-commits] [PATCH] D151497: [lldb] Improve function caller error message
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu May 25 14:07:15 PDT 2023
JDevlieghere created this revision.
JDevlieghere added reviewers: jingham, aprantl, bulbazord, mib.
Herald added a project: All.
JDevlieghere requested review of this revision.
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: Can't make a function caller while the process is exited: the process must be stopped to allocate memory.
rdar://109731325
https://reviews.llvm.org/D151497
Files:
lldb/source/Expression/UserExpression.cpp
lldb/source/Expression/UtilityFunction.cpp
lldb/test/Shell/Expr/TestFunctionCaller.test
Index: lldb/test/Shell/Expr/TestFunctionCaller.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Expr/TestFunctionCaller.test
@@ -0,0 +1,3 @@
+# RUN: %clangxx_host %p/Inputs/call-function.cpp -g -o %t
+# RUN: %lldb %t -o 'r' -o 'expr strlen("")' | FileCheck %s
+# CHECK: error: Can't make a function caller while the process is exited: the process must be stopped to allocate memory.
Index: lldb/source/Expression/UtilityFunction.cpp
===================================================================
--- lldb/source/Expression/UtilityFunction.cpp
+++ lldb/source/Expression/UtilityFunction.cpp
@@ -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;
@@ -67,8 +68,10 @@
// 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");
+ 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;
}
Index: lldb/source/Expression/UserExpression.cpp
===================================================================
--- lldb/source/Expression/UserExpression.cpp
+++ lldb/source/Expression/UserExpression.cpp
@@ -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"
using namespace lldb_private;
@@ -205,8 +206,10 @@
// 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");
+ error.SetErrorStringWithFormatv(
+ "Can't make a function caller while the process is {0}: the process "
+ "must be stopped to allocate memory.",
+ StateAsCString(process->GetState()));
return execution_results;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151497.525784.patch
Type: text/x-patch
Size: 2451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230525/0566b9cf/attachment.bin>
More information about the lldb-commits
mailing list