Skip to content

Commit 4ff41d0

Browse files
Merge pull request #5450 from adrian-prantl/poerror
Make sure Target::EvaluateExpression() passes up an error instead of …
2 parents 12b0007 + 08ab3aa commit 4ff41d0

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

lldb/source/Commands/CommandObjectExpression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ bool CommandObjectExpression::EvaluateExpression(llvm::StringRef expr,
494494
result.SetStatus(eReturnStatusFailed);
495495
}
496496
}
497+
} else {
498+
error_stream.Printf("error: unknown error\n");
497499
}
498500

499501
return (success != eExpressionSetupError &&

lldb/source/Target/Target.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "lldb/Core/StreamFile.h"
2727
#include "lldb/Core/StructuredDataImpl.h"
2828
#include "lldb/Core/ValueObject.h"
29+
#include "lldb/Core/ValueObjectConstResult.h"
2930
#include "lldb/Expression/DiagnosticManager.h"
3031
#include "lldb/Expression/ExpressionVariable.h"
3132
#include "lldb/Expression/REPL.h"
@@ -2862,6 +2863,10 @@ ExpressionResults Target::EvaluateExpression(
28622863
execution_results = UserExpression::Evaluate(exe_ctx, options, expr, prefix,
28632864
result_valobj_sp, error,
28642865
fixed_expression, ctx_obj);
2866+
// Pass up the error by wrapping it inside an error result.
2867+
if (error.Fail() && !result_valobj_sp)
2868+
result_valobj_sp = ValueObjectConstResult::Create(
2869+
exe_ctx.GetBestExecutionContextScope(), error);
28652870
}
28662871

28672872
if (execution_results == eExpressionCompleted)

lldb/test/API/commands/expression/context-object/TestContextObject.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_context_object(self):
6767

6868
# Test an expression evaluation
6969
value = obj_val.EvaluateExpression("1")
70-
self.assertFalse(value.IsValid())
70+
self.assertTrue(value.IsValid())
7171
self.assertFalse(value.GetError().Success())
7272

7373
#
@@ -79,7 +79,7 @@ def test_context_object(self):
7979

8080
# Test an expression evaluation
8181
value = obj_val.EvaluateExpression("1")
82-
self.assertFalse(value.IsValid())
82+
self.assertTrue(value.IsValid())
8383
self.assertFalse(value.GetError().Success())
8484

8585
# Test retrieveing of an element's field
@@ -97,7 +97,7 @@ def test_context_object(self):
9797

9898
# Test an expression evaluation
9999
value = obj_val.EvaluateExpression("1")
100-
self.assertFalse(value.IsValid())
100+
self.assertTrue(value.IsValid())
101101
self.assertFalse(value.GetError().Success())
102102

103103
# Test retrieveing of a dereferenced object's field
@@ -127,7 +127,7 @@ def test_context_object(self):
127127

128128
# Test an expression evaluation
129129
value = obj_val.EvaluateExpression("1")
130-
self.assertFalse(value.IsValid())
130+
self.assertTrue(value.IsValid())
131131
self.assertFalse(value.GetError().Success())
132132

133133
# Test retrieveing of a dereferenced object's field

lldb/test/API/commands/expression/fixits/TestFixIts.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def test_with_target(self):
4747
# The Fix-It changes "ptr.m" to "ptr->m".
4848
expr = "struct X { int m; }; X x; X *ptr = &x; int m = ptr.m;"
4949
value = frame.EvaluateExpression(expr, top_level_options)
50-
# A successfully parsed top-level expression will yield an error
51-
# that there is 'no value'. If a parsing error would have happened we
52-
# would get a different error kind, so let's check the error kind here.
53-
self.assertEquals(value.GetError().GetCString(), "error: No value")
50+
# A successfully parsed top-level expression will yield an
51+
# unknown error . If a parsing error would have happened we
52+
# would get a different error kind, so let's check the error
53+
# kind here.
54+
self.assertEquals(value.GetError().GetCString(), "unknown error")
5455

5556
# Try with two errors:
5657
two_error_expression = "my_pointer.second->a"
@@ -170,7 +171,7 @@ def test_with_multiple_retries(self):
170171
multiple_runs_options.SetRetriesWithFixIts(2)
171172
value = frame.EvaluateExpression(two_runs_expr, multiple_runs_options)
172173
# This error signals success for top level expressions.
173-
self.assertEquals(value.GetError().GetCString(), "error: No value")
174+
self.assertEquals(value.GetError().GetCString(), "unknown error")
174175

175176
# Test that the code above compiles to the right thing.
176177
self.expect_expr("test_X(1)", result_type="int", result_value="123")

0 commit comments

Comments
 (0)