[lldb] Make single-argument Address constructor explicit (NFC) (#189035)

This is to highlight places where we (probably unintentionally)
construct an `Address` object from an already resolved address, making
it unresolved again.
See the changes in `DynamicLoaderDarwin.cpp` for a quick example.

Also, use this constructor instead of `Address(lldb::addr_t file_addr,
const SectionList *section_list)` when `section_list` is `nullptr`.
This commit is contained in:
Sergei Barannikov 2026-03-27 20:22:48 +03:00 committed by GitHub
parent 9e44babdaf
commit 22cfe6f39d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 59 additions and 61 deletions

View File

@ -406,9 +406,9 @@ public:
private:
// Data members:
bool m_should_resolve_indirect_functions;
bool m_is_reexported;
bool m_is_indirect;
bool m_should_resolve_indirect_functions = false;
bool m_is_reexported = false;
bool m_is_indirect = false;
///< The address defining this location.
Address m_address;
///< The breakpoint that produced this object.
@ -424,7 +424,7 @@ private:
/// by multiple processes.
std::mutex m_condition_mutex;
///< For testing whether the condition source code changed.
size_t m_condition_hash;
size_t m_condition_hash = 0;
///< Breakpoint location ID.
lldb::break_id_t m_loc_id;
///< Number of times this breakpoint location has been hit.

View File

@ -160,7 +160,7 @@ public:
/// A list of sections, one of which may contain the \a file_addr.
Address(lldb::addr_t file_addr, const SectionList *section_list);
Address(lldb::addr_t abs_addr);
explicit Address(lldb::addr_t abs_addr);
/// Assignment operator.
///

View File

@ -34,9 +34,7 @@ using namespace lldb_private;
BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
const Address &addr, lldb::tid_t tid,
bool check_for_resolver)
: m_should_resolve_indirect_functions(false), m_is_reexported(false),
m_is_indirect(false), m_address(addr), m_owner(owner),
m_condition_hash(0), m_loc_id(loc_id), m_hit_counter() {
: m_address(addr), m_owner(owner), m_loc_id(loc_id) {
if (check_for_resolver) {
const Symbol *symbol = m_address.CalculateSymbolContextSymbol();
if (symbol && symbol->IsIndirect()) {
@ -48,9 +46,7 @@ BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
}
BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner)
: m_should_resolve_indirect_functions(false), m_is_reexported(false),
m_is_indirect(false), m_address(LLDB_INVALID_ADDRESS), m_owner(owner),
m_condition_hash(0), m_loc_id(loc_id), m_hit_counter() {
: m_owner(owner), m_loc_id(loc_id) {
SetThreadIDInternal(LLDB_INVALID_THREAD_ID);
}

View File

@ -655,7 +655,7 @@ protected:
return;
}
Address address(addr, nullptr);
Address address(addr);
bytes_read = target->ReadMemory(address, data_sp->GetBytes(),
data_sp->GetByteSize(), error, true);
if (bytes_read == 0) {
@ -703,8 +703,8 @@ protected:
std::string buffer;
buffer.resize(item_byte_size + 1, 0);
Status error;
size_t read = target->ReadCStringFromMemory(data_addr, &buffer[0],
item_byte_size + 1, error);
size_t read = target->ReadCStringFromMemory(
Address(data_addr), &buffer[0], item_byte_size + 1, error);
if (error.Fail()) {
result.AppendErrorWithFormat(
"failed to read memory from 0x%" PRIx64 ".\n", addr);

View File

@ -3632,9 +3632,10 @@ protected:
UnwindTable &uw_table = sc.module_sp->GetUnwindTable();
FuncUnwindersSP func_unwinders_sp =
m_options.m_cached
? uw_table.GetFuncUnwindersContainingAddress(start_addr, sc)
: uw_table.GetUncachedFuncUnwindersContainingAddress(start_addr,
sc);
? uw_table.GetFuncUnwindersContainingAddress(Address(start_addr),
sc)
: uw_table.GetUncachedFuncUnwindersContainingAddress(
Address(start_addr), sc);
if (!func_unwinders_sp)
continue;

View File

@ -748,7 +748,7 @@ bool Address::Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style,
DumpAddressRange(s->AsRawOstream(), range->GetRangeBase(),
range->GetRangeEnd(), addr_size);
s->PutCString(", location = ");
var_sp->DumpLocations(s, all_ranges ? LLDB_INVALID_ADDRESS : *this);
var_sp->DumpLocations(s, all_ranges ? Address() : *this);
s->PutCString(", decl = ");
var_sp->GetDeclaration().DumpStopContext(s, false);
s->EOL();

View File

@ -125,7 +125,7 @@ lldb_private::formatters::GetArrayAddressOrPointerValue(ValueObject &valobj) {
data_addr.type == eAddressTypeFile)
return Address(data_addr.address, valobj.GetModule()->GetSectionList());
return data_addr.address;
return Address(data_addr.address);
}
void lldb_private::formatters::DumpCxxSmartPtrPointerSummary(

View File

@ -404,8 +404,7 @@ static bool ReadEncodedBufferAndDumpToStream(
if (!options.GetStream())
return false;
if (options.GetLocation() == 0 ||
options.GetLocation() == LLDB_INVALID_ADDRESS)
if (options.GetLocation() == Address(0) || options.GetLocation() == Address())
return false;
lldb::TargetSP target_sp = options.GetTargetSP();

View File

@ -1899,10 +1899,10 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
case Value::ValueType::LoadAddress: {
if (target) {
if (curr_piece.ResizeData(piece_byte_size) == piece_byte_size) {
if (target->ReadMemory(addr, curr_piece.GetBuffer().GetBytes(),
piece_byte_size, error,
/*force_live_memory=*/false) !=
piece_byte_size) {
if (target->ReadMemory(
Address(addr), curr_piece.GetBuffer().GetBytes(),
piece_byte_size, error,
/*force_live_memory=*/false) != piece_byte_size) {
const char *addr_type = (curr_piece_source_value_type ==
Value::ValueType::LoadAddress)
? "load"

View File

@ -847,7 +847,7 @@ ValueObjectSP ABISysV_mips::GetReturnValueObjectImpl(
reg_ctx->GetRegisterInfoByName("r2", 0), 0);
// We have got the address. Create a memory object out of it
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(mem_address, nullptr), return_compiler_type);
&thread, "", Address(mem_address), return_compiler_type);
return return_valobj_sp;
} else if (return_compiler_type.IsRealFloatingPointType()) {
if (IsSoftFloat(fp_flag)) {

View File

@ -1121,7 +1121,7 @@ ValueObjectSP ABISysV_mips64::GetReturnValueObjectImpl(
// We have got the address. Create a memory object out of it
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(mem_address, nullptr), return_compiler_type);
&thread, "", Address(mem_address), return_compiler_type);
}
return return_valobj_sp;
}

View File

@ -843,7 +843,7 @@ ValueObjectSP ABISysV_ppc::GetReturnValueObjectImpl(
(uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r3_id,
0);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
}

View File

@ -605,7 +605,7 @@ ValueObjectSP ABISysV_s390x::GetReturnValueObjectImpl(
lldb::addr_t storage_addr =
(uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(r2_id, 0);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
return return_valobj_sp;

View File

@ -505,7 +505,7 @@ ValueObjectSP ABISysV_i386::GetReturnValueObjectSimple(
thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
0xffffffff);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
} else // Neither 'Integral' nor 'Floating Point'
{
@ -614,7 +614,7 @@ ValueObjectSP ABISysV_i386::GetReturnValueObjectImpl(
thread.GetRegisterContext()->ReadRegisterAsUnsigned(eax_id, 0) &
0xffffffff);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
return return_valobj_sp;

View File

@ -841,7 +841,7 @@ ValueObjectSP ABISysV_x86_64::GetReturnValueObjectImpl(
(uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
0);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
}

View File

@ -724,7 +724,7 @@ ValueObjectSP ABIWindows_x86_64::GetReturnValueObjectImpl(
(uint64_t)thread.GetRegisterContext()->ReadRegisterAsUnsigned(rax_id,
0);
return_valobj_sp = ValueObjectMemory::Create(
&thread, "", Address(storage_addr, nullptr), return_compiler_type);
&thread, "", Address(storage_addr), return_compiler_type);
}
return return_valobj_sp;
}

View File

@ -113,7 +113,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,
if (current_offset == 0)
return addr;
auto insn = GetInstructionAtAddress(target, current_offset, addr);
auto insn = GetInstructionAtAddress(target, Address(current_offset), addr);
if (nullptr == insn || !insn->HasDelaySlot())
return addr;

View File

@ -255,8 +255,6 @@ void DynamicLoaderFreeBSDKernel::DebuggerInit(
DynamicLoaderFreeBSDKernel::DynamicLoaderFreeBSDKernel(Process *process,
addr_t kernel_address)
: DynamicLoader(process), m_process(process),
m_linker_file_list_struct_addr(LLDB_INVALID_ADDRESS),
m_linker_file_head_addr(LLDB_INVALID_ADDRESS),
m_kernel_load_address(kernel_address), m_mutex() {
process->SetCanRunCode(false);
}

View File

@ -289,7 +289,7 @@ bool DynamicLoaderHexagonDYLD::SetRendezvousBreakpoint() {
// Make sure our breakpoint is at the right address.
assert(target.GetBreakpointByID(m_dyld_bid)
->FindLocationByAddress(break_addr)
->FindLocationByAddress(Address(break_addr))
->GetBreakpoint()
.GetID() == m_dyld_bid);

View File

@ -1037,7 +1037,8 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
current_symbol->GetName().GetCString(),
actual_symbol->GetName().GetCString(),
target_addr.GetLoadAddress(target_sp.get()));
addresses.push_back(target_addr.GetLoadAddress(target_sp.get()));
addresses.push_back(
Address(target_addr.GetLoadAddress(target_sp.get())));
}
}
}

View File

@ -103,7 +103,7 @@ InstrumentationRuntimeMainThreadChecker::RetrieveReportData(
std::string apiName;
Status read_error;
target.ReadCStringFromMemory(apiname_ptr, apiName, read_error);
target.ReadCStringFromMemory(Address(apiname_ptr), apiName, read_error);
if (read_error.Fail())
return StructuredData::ObjectSP();

View File

@ -6,7 +6,7 @@ using namespace lldb;
using namespace lldb_private;
bool CFBasicHash::IsValid() const {
if (m_address != LLDB_INVALID_ADDRESS) {
if (m_address != Address()) {
if (m_ptr_size == 4 && m_ht_32)
return true;
else if (m_ptr_size == 8 && m_ht_64)
@ -21,7 +21,7 @@ bool CFBasicHash::Update(addr_t addr, ExecutionContextRef exe_ctx_rf) {
if (addr == LLDB_INVALID_ADDRESS || !addr)
return false;
m_address = addr;
m_address = Address(addr);
m_exe_ctx_ref = exe_ctx_rf;
m_ptr_size =
m_exe_ctx_ref.GetTargetSP()->GetArchitecture().GetAddressByteSize();

View File

@ -62,7 +62,7 @@ private:
uint32_t m_ptr_size = UINT32_MAX;
lldb::ByteOrder m_byte_order = lldb::eByteOrderInvalid;
Address m_address = LLDB_INVALID_ADDRESS;
Address m_address;
std::unique_ptr<__CFBasicHash<uint32_t>> m_ht_32 = nullptr;
std::unique_ptr<__CFBasicHash<uint64_t>> m_ht_64 = nullptr;
ExecutionContextRef m_exe_ctx_ref;

View File

@ -145,7 +145,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
if (error.Fail())
return false;
if (has_explicit_length && is_unicode) {
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetQuote('"');
@ -158,7 +158,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
return StringPrinter::ReadStringAndDumpToStream<
StringPrinter::StringElementType::UTF16>(options);
} else {
options.SetLocation(location + 1);
options.SetLocation(Address(location + 1));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetSourceSize(explicit_length);
@ -174,7 +174,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
!is_path_store && !is_mutable) {
uint64_t location = 3 * ptr_size + valobj_addr;
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetQuote('"');
@ -196,7 +196,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
if (error.Fail())
return false;
}
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetQuote('"');
@ -222,7 +222,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
explicit_length = length_valobj_sp->GetValueAsUnsigned(0) >> 20;
lldb::addr_t location = valobj.GetValueAsUnsigned(0) + ptr_size + 4;
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetQuote('"');
@ -245,7 +245,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
has_explicit_length = !(error.Fail() || explicit_length == 0);
location++;
}
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetSourceSize(explicit_length);
@ -268,7 +268,7 @@ bool lldb_private::formatters::NSStringSummaryProvider(
if (has_explicit_length && !has_null)
explicit_length++; // account for the fact that there is no NULL and we
// need to have one added
options.SetLocation(location);
options.SetLocation(Address(location));
options.SetTargetSP(valobj.GetTargetSP());
options.SetStream(&stream);
options.SetSourceSize(explicit_length);

View File

@ -307,7 +307,7 @@ bool ItaniumABIRuntime::GetDynamicTypeAndAddress(
return false;
Status error;
const int64_t offset_to_top = target.ReadSignedIntegerFromMemory(
offset_to_top_location, addr_byte_size, INT64_MIN, error);
Address(offset_to_top_location), addr_byte_size, INT64_MIN, error);
if (offset_to_top == INT64_MIN)
return false;

View File

@ -978,7 +978,8 @@ Address ObjectFileELF::GetImageInfoAddress(Target *target) {
if (symbol.d_tag == DT_MIPS_RLD_MAP) {
// DT_MIPS_RLD_MAP tag stores an absolute address of the debug pointer.
Address addr;
if (target->ReadPointerFromMemory(d_load_addr, error, addr, true))
if (target->ReadPointerFromMemory(Address(d_load_addr), error, addr,
true))
return addr;
}
if (symbol.d_tag == DT_MIPS_RLD_MAP_REL) {
@ -986,7 +987,8 @@ Address ObjectFileELF::GetImageInfoAddress(Target *target) {
// relative to the address of the tag.
uint64_t rel_offset;
rel_offset = target->ReadUnsignedIntegerFromMemory(
d_load_addr, GetAddressByteSize(), UINT64_MAX, error, true);
Address(d_load_addr), GetAddressByteSize(), UINT64_MAX, error,
true);
if (error.Success() && rel_offset != UINT64_MAX) {
Address addr;
addr_t debug_ptr_address =
@ -1025,7 +1027,7 @@ Address ObjectFileELF::GetBaseAddress() {
if (header.sh_flags & SHF_ALLOC)
return Address(GetSectionList()->FindSectionByID(SectionIndex(I)), 0);
}
return LLDB_INVALID_ADDRESS;
return Address();
}
for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
@ -1036,7 +1038,7 @@ Address ObjectFileELF::GetBaseAddress() {
return Address(
GetSectionList()->FindSectionByID(SegmentID(EnumPHdr.index())), 0);
}
return LLDB_INVALID_ADDRESS;
return Address();
}
size_t ObjectFileELF::ParseDependentModules() {

View File

@ -959,7 +959,8 @@ uint32_t SymbolFileCTF::ResolveSymbolContext(const Address &so_addr,
// Resolve variables.
if (resolve_scope & eSymbolContextVariable) {
for (VariableSP variable_sp : m_variables) {
if (variable_sp->LocationIsValidForAddress(so_addr.GetFileAddress())) {
if (variable_sp->LocationIsValidForAddress(
Address(so_addr.GetFileAddress()))) {
sc.variable = variable_sp.get();
break;
}

View File

@ -1826,7 +1826,7 @@ void SymbolFileNativePDB::ParseInlineSite(PdbCompilandSymId id,
S_INLINESITE) {
// Its parent is another inline site, lookup parent site's range vector
// for callsite line.
ParseInlineSite(parent_id, func_base);
ParseInlineSite(parent_id, Address(func_base));
std::shared_ptr<InlineSite> parent_site =
m_inline_sites[toOpaqueUid(parent_id)];
FileSpec &parent_decl_file =

View File

@ -1113,7 +1113,7 @@ bool SymbolContextSpecifier::AddressMatches(lldb::addr_t addr) {
if (m_type & eAddressRangeSpecified) {
} else {
Address match_address(addr, nullptr);
Address match_address(addr);
SymbolContext sc;
m_target_sp->GetImages().ResolveSymbolContextForAddress(
match_address, eSymbolContextEverything, sc);

View File

@ -65,7 +65,7 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
: m_thread_wp(thread_sp), m_frame_index(frame_idx),
m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(),
m_id(pc, cfa, nullptr, thread_sp->GetProcess().get()),
m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
m_frame_code_addr(Address(pc)), m_sc(), m_flags(), m_frame_base(),
m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
m_stack_frame_kind(kind), m_artificial(artificial),
m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
@ -93,7 +93,7 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
m_concrete_frame_index(unwind_frame_index),
m_reg_context_sp(reg_context_sp),
m_id(pc, cfa, nullptr, thread_sp->GetProcess().get()),
m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
m_frame_code_addr(Address(pc)), m_sc(), m_flags(), m_frame_base(),
m_frame_base_error(), m_cfa_is_valid(true),
m_stack_frame_kind(StackFrame::Kind::Regular), m_artificial(false),
m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),

View File

@ -582,7 +582,7 @@ Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal,
std::make_shared<SearchFilterForUnconstrainedSearches>(
shared_from_this());
BreakpointResolverSP resolver_sp =
std::make_shared<BreakpointResolverAddress>(nullptr, file_addr,
std::make_shared<BreakpointResolverAddress>(nullptr, Address(file_addr),
file_spec);
return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware,
false);

View File

@ -255,7 +255,7 @@ bool ValueObjectDynamicValue::UpdateValue() {
}
m_value.GetScalar() = (uint64_t)local_buffer.data();
m_address = LLDB_INVALID_ADDRESS;
m_address = Address();
} else {
// Otherwise we have a legitimate address on the target. Point to the load
// address.