Skip to content

Commit 69b0b7e

Browse files
authored
[lldb] Return an llvm::Error from GetFrameBaseValue (#111882)
This fixes the following assertion: "Cannot create Expected<T> from Error success value." The problem was that GetFrameBaseValue return false without updating the Status argument. This patch eliminates the opportunity for mistakes by returning an llvm:Error.
1 parent 942fefe commit 69b0b7e

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

lldb/include/lldb/Target/StackFrame.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,10 @@ class StackFrame : public ExecutionContextScope,
195195
/// \param [out] value
196196
/// The address of the CFA for this frame, if available.
197197
///
198-
/// \param [out] error_ptr
199-
/// If there is an error determining the CFA address, this may contain a
200-
/// string explaining the failure.
201-
///
202198
/// \return
203-
/// Returns true if the CFA value was successfully set in value. Some
204-
/// frames may be unable to provide this value; they will return false.
205-
bool GetFrameBaseValue(Scalar &value, Status *error_ptr);
199+
/// If there is an error determining the CFA address, return an error
200+
/// explaining the failure. Success otherwise.
201+
llvm::Error GetFrameBaseValue(Scalar &value);
206202

207203
/// Get the DWARFExpressionList corresponding to the Canonical Frame Address.
208204
///

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,14 +1780,12 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
17801780
if (exe_ctx) {
17811781
if (frame) {
17821782
Scalar value;
1783-
Status fb_err;
1784-
if (frame->GetFrameBaseValue(value, &fb_err)) {
1785-
int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
1786-
value += fbreg_offset;
1787-
stack.push_back(value);
1788-
stack.back().SetValueType(Value::ValueType::LoadAddress);
1789-
} else
1790-
return fb_err.ToError();
1783+
if (llvm::Error err = frame->GetFrameBaseValue(value))
1784+
return err;
1785+
int64_t fbreg_offset = opcodes.GetSLEB128(&offset);
1786+
value += fbreg_offset;
1787+
stack.push_back(value);
1788+
stack.back().SetValueType(Value::ValueType::LoadAddress);
17911789
} else {
17921790
return llvm::createStringError(
17931791
"invalid stack frame in context for DW_OP_fbreg opcode");

lldb/source/Target/StackFrame.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,12 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
10791079
return valobj_sp;
10801080
}
10811081

1082-
bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
1082+
llvm::Error StackFrame::GetFrameBaseValue(Scalar &frame_base) {
10831083
std::lock_guard<std::recursive_mutex> guard(m_mutex);
10841084
if (!m_cfa_is_valid) {
10851085
m_frame_base_error = Status::FromErrorString(
10861086
"No frame base available for this historical stack frame.");
1087-
return false;
1087+
return m_frame_base_error.ToError();
10881088
}
10891089

10901090
if (m_flags.IsClear(GOT_FRAME_BASE)) {
@@ -1113,12 +1113,11 @@ bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
11131113
}
11141114
}
11151115

1116-
if (m_frame_base_error.Success())
1117-
frame_base = m_frame_base;
1116+
if (m_frame_base_error.Fail())
1117+
return m_frame_base_error.ToError();
11181118

1119-
if (error_ptr)
1120-
*error_ptr = m_frame_base_error.Clone();
1121-
return m_frame_base_error.Success();
1119+
frame_base = m_frame_base;
1120+
return llvm::Error::success();
11221121
}
11231122

11241123
DWARFExpressionList *StackFrame::GetFrameBaseExpression(Status *error_ptr) {

0 commit comments

Comments
 (0)