[Lldb-commits] [lldb] 41b37f0 - [lldb] CommandObjectMemoryFind: Improve expression evaluation error messages (#144036)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Jun 13 04:43:30 PDT 2025
Author: Michael Buch
Date: 2025-06-13T12:43:27+01:00
New Revision: 41b37f05554ae59974675ae219430b5598c6159f
URL: https://github.com/llvm/llvm-project/commit/41b37f05554ae59974675ae219430b5598c6159f
DIFF: https://github.com/llvm/llvm-project/commit/41b37f05554ae59974675ae219430b5598c6159f.diff
LOG: [lldb] CommandObjectMemoryFind: Improve expression evaluation error messages (#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
| ^~~~~~~
```
Added:
Modified:
lldb/source/Commands/CommandObjectMemory.cpp
lldb/test/API/functionalities/memory/find/TestMemoryFind.py
Removed:
################################################################################
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"],
More information about the lldb-commits
mailing list