Skip to content

Commit 0d2e9fa

Browse files
Michael137tomtor
authored andcommitted
[lldb] CommandObjectMemoryFind: Improve expression evaluation error messages (llvm#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 | ^~~~~~~ ```
1 parent 98f29b0 commit 0d2e9fa

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,9 +925,12 @@ EvaluateExpression(llvm::StringRef expression, StackFrame &frame,
925925
ValueObjectSP result_sp;
926926
auto status =
927927
process.GetTarget().EvaluateExpression(expression, &frame, result_sp);
928-
if (status != eExpressionCompleted || !result_sp)
928+
if (!result_sp)
929929
return llvm::createStringError(
930-
"expression evaluation failed. pass a string instead");
930+
"No result returned from expression. Exit status: %d", status);
931+
932+
if (status != eExpressionCompleted)
933+
return result_sp->GetError().ToError();
931934

932935
result_sp = result_sp->GetQualifiedRepresentationIfAvailable(
933936
result_sp->GetDynamicValueType(), /*synthValue=*/true);
@@ -1082,6 +1085,7 @@ class CommandObjectMemoryFind : public CommandObjectParsed {
10821085
m_memory_options.m_expr.GetValueAs<llvm::StringRef>().value_or(""),
10831086
m_exe_ctx.GetFrameRef(), *process);
10841087
if (!result_or_err) {
1088+
result.AppendError("Expression evaluation failed: ");
10851089
result.AppendError(llvm::toString(result_or_err.takeError()));
10861090
return;
10871091
}

lldb/test/API/functionalities/memory/find/TestMemoryFind.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ def test_memory_find(self):
5656
# Invalid expr is an error.
5757
self.expect(
5858
'memory find -e "not_a_symbol" `&bytedata[0]` `&bytedata[15]`',
59+
substrs=[
60+
"Expression evaluation failed:",
61+
"use of undeclared identifier 'not_a_symbol'",
62+
],
63+
error=True,
64+
)
65+
66+
self.expect(
67+
'memory find -e "" `&bytedata[0]` `&bytedata[2]`',
68+
substrs=[
69+
"Expression evaluation failed:",
70+
"No result returned from expression. Exit status: 1",
71+
],
5972
error=True,
60-
substrs=["error: expression evaluation failed. pass a string instead"],
6173
)
6274

75+
# Valid expressions/strings
6376
self.expect(
6477
'memory find -e "(uint8_t)0x22" `&bytedata[0]` `&bytedata[15]`',
6578
substrs=["data found at location: 0x", "22 33 44 55 66"],

0 commit comments

Comments
 (0)