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; }
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; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits