Skip to content

[lldb] CommandObjectMemoryFind: Improve expression evaluation error messages #144036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lldb/source/Commands/CommandObjectMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion lldb/test/API/functionalities/memory/find/TestMemoryFind.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Loading