Skip to content

Commit 539b72f

Browse files
authored
[lldb] Return an llvm::Expected from DWARFExpression::Evaluate (NFCI) (#94420)
Change the signature of `DWARFExpression::Evaluate` and `DWARFExpressionList::Evaluate` to return an `llvm::Expected` instead of a boolean. This eliminates the `Status` output parameter and generally improves error handling.
1 parent 4e0d937 commit 539b72f

File tree

13 files changed

+403
-584
lines changed

13 files changed

+403
-584
lines changed

lldb/include/lldb/Expression/DWARFExpression.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ class DWARFExpression {
132132
/// \return
133133
/// True on success; false otherwise. If error_ptr is non-NULL,
134134
/// details of the failure are provided through it.
135-
static bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
136-
lldb::ModuleSP module_sp, const DataExtractor &opcodes,
137-
const plugin::dwarf::DWARFUnit *dwarf_cu,
138-
const lldb::RegisterKind reg_set,
139-
const Value *initial_value_ptr,
140-
const Value *object_address_ptr, Value &result,
141-
Status *error_ptr);
135+
static llvm::Expected<Value>
136+
Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
137+
lldb::ModuleSP module_sp, const DataExtractor &opcodes,
138+
const plugin::dwarf::DWARFUnit *dwarf_cu,
139+
const lldb::RegisterKind reg_set, const Value *initial_value_ptr,
140+
const Value *object_address_ptr);
142141

143142
static bool ParseDWARFLocationList(const plugin::dwarf::DWARFUnit *dwarf_cu,
144143
const DataExtractor &data,

lldb/include/lldb/Expression/DWARFExpressionList.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
1010
#define LLDB_EXPRESSION_DWARFEXPRESSIONLIST_H
1111

12+
#include "lldb/Core/Value.h"
1213
#include "lldb/Expression/DWARFExpression.h"
1314
#include "lldb/Utility/RangeMap.h"
1415
#include "lldb/lldb-private.h"
@@ -113,10 +114,11 @@ class DWARFExpressionList {
113114

114115
void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
115116

116-
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx,
117-
lldb::addr_t func_load_addr, const Value *initial_value_ptr,
118-
const Value *object_address_ptr, Value &result,
119-
Status *error_ptr) const;
117+
llvm::Expected<Value> Evaluate(ExecutionContext *exe_ctx,
118+
RegisterContext *reg_ctx,
119+
lldb::addr_t func_load_addr,
120+
const Value *initial_value_ptr,
121+
const Value *object_address_ptr) const;
120122

121123
private:
122124
// RangeDataVector requires a comparator for DWARFExpression, but it doesn't

lldb/source/Core/ValueObjectVariable.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,11 @@ bool ValueObjectVariable::UpdateValue() {
164164
target);
165165
}
166166
Value old_value(m_value);
167-
if (expr_list.Evaluate(&exe_ctx, nullptr, loclist_base_load_addr, nullptr,
168-
nullptr, m_value, &m_error)) {
167+
llvm::Expected<Value> maybe_value = expr_list.Evaluate(
168+
&exe_ctx, nullptr, loclist_base_load_addr, nullptr, nullptr);
169+
170+
if (maybe_value) {
171+
m_value = *maybe_value;
169172
m_resolved_value = m_value;
170173
m_value.SetContext(Value::ContextType::Variable, variable);
171174

@@ -246,6 +249,7 @@ bool ValueObjectVariable::UpdateValue() {
246249

247250
SetValueIsValid(m_error.Success());
248251
} else {
252+
m_error = maybe_value.takeError();
249253
// could not find location, won't allow editing
250254
m_resolved_value.SetContext(Value::ContextType::Invalid, nullptr);
251255
}

0 commit comments

Comments
 (0)