Skip to content

[lldb] Change ValueObject::AddressOf() to return Expected (NFC) #106831

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class ValueObject {
/// (e.g. sythetic child provider).
virtual lldb::ValueObjectSP Clone(ConstString new_name);

virtual lldb::ValueObjectSP AddressOf(Status &error);
virtual llvm::Expected<lldb::ValueObjectSP> AddressOf(Status &error);

virtual lldb::addr_t GetLiveAddress() { return LLDB_INVALID_ADDRESS; }

Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObjectConstResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ValueObjectConstResult : public ValueObject {
uint32_t offset, const CompilerType &type, bool can_create,
ConstString name_const_str = ConstString()) override;

lldb::ValueObjectSP AddressOf(Status &error) override;
llvm::Expected<lldb::ValueObjectSP> AddressOf(Status &error) override;

lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
AddressType *address_type = nullptr) override;
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObjectConstResultCast.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ValueObjectConstResultCast : public ValueObjectCast {
uint32_t offset, const CompilerType &type, bool can_create,
ConstString name_const_str = ConstString()) override;

lldb::ValueObjectSP AddressOf(Status &error) override;
llvm::Expected<lldb::ValueObjectSP> AddressOf(Status &error) override;

size_t GetPointeeData(DataExtractor &data, uint32_t item_idx = 0,
uint32_t item_count = 1) override;
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObjectConstResultChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ValueObjectConstResultChild : public ValueObjectChild {
uint32_t offset, const CompilerType &type, bool can_create,
ConstString name_const_str = ConstString()) override;

lldb::ValueObjectSP AddressOf(Status &error) override;
llvm::Expected<lldb::ValueObjectSP> AddressOf(Status &error) override;

lldb::addr_t GetAddressOf(bool scalar_is_load_address = true,
AddressType *address_type = nullptr) override;
Expand Down
2 changes: 1 addition & 1 deletion lldb/include/lldb/Core/ValueObjectConstResultImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ValueObjectConstResultImpl {
bool can_create,
ConstString name_const_str = ConstString());

lldb::ValueObjectSP AddressOf(Status &error);
llvm::Expected<lldb::ValueObjectSP> AddressOf(Status &error);

lldb::addr_t GetLiveAddress() { return m_live_address; }

Expand Down
10 changes: 8 additions & 2 deletions lldb/source/API/SBValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,14 @@ lldb::SBValue SBValue::AddressOf() {
lldb::ValueObjectSP value_sp(GetSP(locker));
if (value_sp) {
Status error;
sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(),
GetPreferSyntheticValue());
auto address_of_valobj_sp_or_err = value_sp->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
sb_value.SetSP(*address_of_valobj_sp_or_err, GetPreferDynamicValue(),
GetPreferSyntheticValue());
}

return sb_value;
Expand Down
11 changes: 9 additions & 2 deletions lldb/source/Core/ValueObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,14 @@ ValueObjectSP ValueObject::GetValueForExpressionPath(
if (*final_task_on_target ==
ValueObject::eExpressionPathAftermathTakeAddress) {
Status error;
ValueObjectSP final_value = ret_val->AddressOf(error);
ValueObjectSP final_value;
auto address_of_valobj_sp_or_err = ret_val->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
final_value = *address_of_valobj_sp_or_err;
if (error.Fail() || !final_value.get()) {
if (reason_to_stop)
*reason_to_stop =
Expand Down Expand Up @@ -2895,7 +2902,7 @@ ValueObjectSP ValueObject::Dereference(Status &error) {
}
}

ValueObjectSP ValueObject::AddressOf(Status &error) {
llvm::Expected<lldb::ValueObjectSP> ValueObject::AddressOf(Status &error) {
if (m_addr_of_valobj_sp)
return m_addr_of_valobj_sp;

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/ValueObjectConstResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ lldb::ValueObjectSP ValueObjectConstResult::GetSyntheticChildAtOffset(
name_const_str);
}

lldb::ValueObjectSP ValueObjectConstResult::AddressOf(Status &error) {
llvm::Expected<lldb::ValueObjectSP>
ValueObjectConstResult::AddressOf(Status &error) {
return m_impl.AddressOf(error);
}

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/ValueObjectConstResultCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ lldb::ValueObjectSP ValueObjectConstResultCast::GetSyntheticChildAtOffset(
name_const_str);
}

lldb::ValueObjectSP ValueObjectConstResultCast::AddressOf(Status &error) {
llvm::Expected<lldb::ValueObjectSP>
ValueObjectConstResultCast::AddressOf(Status &error) {
return m_impl.AddressOf(error);
}

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/ValueObjectConstResultChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ lldb::ValueObjectSP ValueObjectConstResultChild::GetSyntheticChildAtOffset(
name_const_str);
}

lldb::ValueObjectSP ValueObjectConstResultChild::AddressOf(Status &error) {
llvm::Expected<lldb::ValueObjectSP>
ValueObjectConstResultChild::AddressOf(Status &error) {
return m_impl.AddressOf(error);
}

Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Core/ValueObjectConstResultImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ lldb::ValueObjectSP ValueObjectConstResultImpl::GetSyntheticChildAtOffset(
offset, type, can_create, name_const_str);
}

lldb::ValueObjectSP ValueObjectConstResultImpl::AddressOf(Status &error) {
llvm::Expected<lldb::ValueObjectSP>
ValueObjectConstResultImpl::AddressOf(Status &error) {
if (m_address_of_backend.get() != nullptr)
return m_address_of_backend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,14 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context) {

if (m_ctx_obj) {
Status status;
lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status);
lldb::ValueObjectSP ctx_obj_ptr;
auto address_of_valobj_sp_or_err = m_ctx_obj->AddressOf(status);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
ctx_obj_ptr = *address_of_valobj_sp_or_err;
if (!ctx_obj_ptr || status.Fail())
return;

Expand Down Expand Up @@ -888,7 +895,14 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context) {

if (m_ctx_obj) {
Status status;
lldb::ValueObjectSP ctx_obj_ptr = m_ctx_obj->AddressOf(status);
lldb::ValueObjectSP ctx_obj_ptr;
auto address_of_valobj_sp_or_err = m_ctx_obj->AddressOf(status);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
ctx_obj_ptr = *address_of_valobj_sp_or_err;
if (!ctx_obj_ptr || status.Fail())
return;

Expand Down
9 changes: 8 additions & 1 deletion lldb/source/Plugins/Language/CPlusPlus/Coroutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ lldb_private::formatters::StdlibCoroutineHandleSyntheticFrontEnd::Update() {
lldb::ValueObjectSP promise = CreateValueObjectFromAddress(
"promise", frame_ptr_addr + 2 * ptr_size, exe_ctx, promise_type);
Status error;
lldb::ValueObjectSP promisePtr = promise->AddressOf(error);
lldb::ValueObjectSP promisePtr;
auto address_of_valobj_sp_or_err = promise->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
promisePtr = *address_of_valobj_sp_or_err;
if (error.Success())
m_promise_ptr_sp = promisePtr->Clone(ConstString("promise"));

Expand Down
18 changes: 16 additions & 2 deletions lldb/source/Plugins/Language/CPlusPlus/LibCxxList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ lldb::ChildCacheState ForwardListFrontEnd::Update() {
AbstractListFrontEnd::Update();

Status err;
ValueObjectSP backend_addr(m_backend.AddressOf(err));
ValueObjectSP backend_addr;
auto address_of_valobj_sp_or_err = m_backend.AddressOf(err);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
backend_addr = *address_of_valobj_sp_or_err;
if (err.Fail() || !backend_addr)
return lldb::ChildCacheState::eRefetch;

Expand Down Expand Up @@ -400,7 +407,14 @@ lldb::ChildCacheState ListFrontEnd::Update() {
m_node_address = 0;

Status err;
ValueObjectSP backend_addr(m_backend.AddressOf(err));
ValueObjectSP backend_addr;
auto address_of_valobj_sp_or_err = m_backend.AddressOf(err);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
backend_addr = *address_of_valobj_sp_or_err;
if (err.Fail() || !backend_addr)
return lldb::ChildCacheState::eRefetch;
m_node_address = backend_addr->GetValueAsUnsigned(0);
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Language/ObjC/NSArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@ lldb_private::formatters::NSArraySyntheticFrontEndCreator(

if (flags.IsClear(eTypeIsPointer)) {
Status error;
valobj_sp = valobj_sp->AddressOf(error);
auto address_of_valobj_sp_or_err = valobj_sp->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
valobj_sp = *address_of_valobj_sp_or_err;
if (error.Fail() || !valobj_sp)
return nullptr;
}
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Language/ObjC/NSDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,13 @@ lldb_private::formatters::NSDictionarySyntheticFrontEndCreator(

if (flags.IsClear(eTypeIsPointer)) {
Status error;
valobj_sp = valobj_sp->AddressOf(error);
auto address_of_valobj_sp_or_err = valobj_sp->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
valobj_sp = *address_of_valobj_sp_or_err;
if (error.Fail() || !valobj_sp)
return nullptr;
}
Expand Down
8 changes: 7 additions & 1 deletion lldb/source/Plugins/Language/ObjC/NSSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,13 @@ lldb_private::formatters::NSSetSyntheticFrontEndCreator(

if (flags.IsClear(eTypeIsPointer)) {
Status error;
valobj_sp = valobj_sp->AddressOf(error);
auto address_of_valobj_sp_or_err = valobj_sp->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
valobj_sp = *address_of_valobj_sp_or_err;
if (error.Fail() || !valobj_sp)
return nullptr;
}
Expand Down
11 changes: 9 additions & 2 deletions lldb/source/Symbol/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,15 @@ Status Variable::GetValuesForVariableExpressionPath(
if (error.Success()) {
for (uint32_t i = 0; i < valobj_list.GetSize();) {
Status tmp_error;
ValueObjectSP valobj_sp(
valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
ValueObjectSP valobj_sp;
auto address_of_valobj_sp_or_err =
valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
valobj_sp = *address_of_valobj_sp_or_err;
if (tmp_error.Fail()) {
variable_list.RemoveVariableAtIndex(i);
valobj_list.RemoveValueObjectAtIndex(i);
Expand Down
9 changes: 8 additions & 1 deletion lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,14 @@ ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error));
valobj_sp = deref_valobj_sp;
} else if (address_of) {
ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error));
ValueObjectSP address_of_valobj_sp;
auto address_of_valobj_sp_or_err = valobj_sp->AddressOf(error);
if (!address_of_valobj_sp_or_err)
LLDB_LOG_ERROR(GetLog(LLDBLog::Object),
address_of_valobj_sp_or_err.takeError(),
"unable to get the address of the value object");
else
address_of_valobj_sp = *address_of_valobj_sp_or_err;
valobj_sp = address_of_valobj_sp;
}
}
Expand Down
Loading