https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/144036
We now bubble up the expression evaluation diagnostics to the user and also distinguish between "expression failed to parse/run" versus other ways in which expressions didn't complete (e.g., setup errors, etc.). Before: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead ``` After: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: No result returned from expression. Exit status: 1 (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: <user expression 0>:1:1: use of undeclared identifier 'invalid' 1 | invalid | ^~~~~~~ ``` >From 07de85fb74e512c354be135d4b62c4e154534dcc Mon Sep 17 00:00:00 2001 From: Michael Buch <michaelbuc...@gmail.com> Date: Fri, 13 Jun 2025 09:54:34 +0100 Subject: [PATCH] [lldb] CommandObjectMemoryFind: Improve epxression evaluation error messages We now bubble up the expression evaluation diagnostics to the user and also distinguish between "expression failed to parse/run" versus other ways in which expressions didn't complete (e.g., setup errors, etc.). Before: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: expression evaluation failed. pass a string instead ``` After: ``` (lldb) memory find -e "" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: No result returned from expression. Exit status: 1 (lldb) memory find -e "invalid" 0x16fdfedc0 0x16fdfede0 error: Expression evaluation failed: error: <user expression 0>:1:1: use of undeclared identifier 'invalid' 1 | invalid | ^~~~~~~ ``` --- lldb/source/Commands/CommandObjectMemory.cpp | 8 ++++++-- .../functionalities/memory/find/TestMemoryFind.py | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) 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<llvm::StringRef>().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"], _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits