-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[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
Michael137
merged 1 commit into
llvm:main
from
Michael137:lldb/memory-find-expression-1
Jun 13, 2025
Merged
[lldb] CommandObjectMemoryFind: Improve expression evaluation error messages #144036
Michael137
merged 1 commit into
llvm:main
from
Michael137:lldb/memory-find-expression-1
Jun 13, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…essages 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 | ^~~~~~~ ```
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesWe 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:
After:
Full diff: https://github.com/llvm/llvm-project/pull/144036.diff 2 Files Affected:
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"],
|
labath
approved these changes
Jun 13, 2025
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
…essages (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 | ^~~~~~~ ```
akuhlens
pushed a commit
to akuhlens/llvm-project
that referenced
this pull request
Jun 24, 2025
…essages (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 | ^~~~~~~ ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
After: