diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp index ccb06d8ff4d59..5792c13373c1e 100644 --- a/lldb/source/Commands/CommandObjectMemory.cpp +++ b/lldb/source/Commands/CommandObjectMemory.cpp @@ -925,9 +925,12 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame, ValueObjectSP result_sp; auto status = process.GetTarget().EvaluateExpression(expression, &frame, result_sp); - if (status != eExpressionCompleted || !result_sp) + if (!result_sp) return llvm::createStringError( - "expression evaluation failed. pass a string instead"); + "No result returned from expression. Exit status: %d", status); + + if (status != eExpressionCompleted) + return result_sp->GetError().ToError(); result_sp = result_sp->GetQualifiedRepresentationIfAvailable( result_sp->GetDynamicValueType(), /*synthValue=*/true); @@ -1082,6 +1085,7 @@ class CommandObjectMemoryFind : public CommandObjectParsed { m_memory_options.m_expr.GetValueAs().value_or(""), m_exe_ctx.GetFrameRef(), *process); if (!result_or_err) { + result.AppendError("Expression evaluation failed: "); result.AppendError(llvm::toString(result_or_err.takeError())); return; } diff --git a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py b/lldb/test/API/functionalities/memory/find/TestMemoryFind.py index 72426e75e013e..a06b0d960889c 100644 --- a/lldb/test/API/functionalities/memory/find/TestMemoryFind.py +++ b/lldb/test/API/functionalities/memory/find/TestMemoryFind.py @@ -56,10 +56,23 @@ def test_memory_find(self): # Invalid expr is an error. self.expect( 'memory find -e "not_a_symbol" `&bytedata[0]` `&bytedata[15]`', + substrs=[ + "Expression evaluation failed:", + "use of undeclared identifier 'not_a_symbol'", + ], + error=True, + ) + + self.expect( + 'memory find -e "" `&bytedata[0]` `&bytedata[2]`', + substrs=[ + "Expression evaluation failed:", + "No result returned from expression. Exit status: 1", + ], error=True, - substrs=["error: expression evaluation failed. pass a string instead"], ) + # Valid expressions/strings self.expect( 'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`', substrs=["data found at location: 0x", "22 33 44 55 66"],