Skip to content

[lldb][NFC] Make the target's SectionLoadList private. #113278

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

Merged
merged 4 commits into from
Jan 15, 2025
Merged
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/Target/SectionLoadHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SectionLoadHistory {
const lldb::SectionSP &section_sp);

bool ResolveLoadAddress(uint32_t stop_id, lldb::addr_t load_addr,
Address &so_addr);
Address &so_addr, bool allow_section_end = false);

bool SetSectionLoadAddress(uint32_t stop_id,
const lldb::SectionSP &section_sp,
Expand Down
17 changes: 13 additions & 4 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -1151,9 +1151,13 @@ class Target : public std::enable_shared_from_this<Target>,
Address &pointer_addr,
bool force_live_memory = false);

SectionLoadList &GetSectionLoadList() {
return m_section_load_history.GetCurrentSectionLoadList();
}
bool HasLoadedSections();

lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP &section_sp);

void ClearSectionLoadList();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like nobody but dynamic loaders should be calling these two. Is there some way to express that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetSectionLoadAddress(...) is called all over the place, but ClearSectionLoadList() is called only by DynamicLoaderMacOS, but it should be able to be called by any dynamic loader, so I wouldn't want to limit the ability to call it. And we can't tie it to a dynamic loader as I could see us wanting to add a command that would call this function for symbolication purposes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.


void DumpSectionLoadList(Stream &s);

static Target *GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr,
const SymbolContext *sc_ptr);
Expand Down Expand Up @@ -1218,7 +1222,8 @@ class Target : public std::enable_shared_from_this<Target>,
bool ResolveFileAddress(lldb::addr_t load_addr, Address &so_addr);

bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr,
uint32_t stop_id = SectionLoadHistory::eStopIDNow);
uint32_t stop_id = SectionLoadHistory::eStopIDNow,
bool allow_section_end = false);

bool SetSectionLoadAddress(const lldb::SectionSP &section,
lldb::addr_t load_addr,
Expand Down Expand Up @@ -1666,6 +1671,10 @@ class Target : public std::enable_shared_from_this<Target>,

Target(const Target &) = delete;
const Target &operator=(const Target &) = delete;

SectionLoadList &GetSectionLoadList() {
return m_section_load_history.GetCurrentSectionLoadList();
}
};

} // namespace lldb_private
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/API/SBBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
bkpt_sp->GetTarget().GetAPIMutex());
Address address;
Target &target = bkpt_sp->GetTarget();
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
if (!target.ResolveLoadAddress(vm_addr, address)) {
address.SetRawAddress(vm_addr);
}
sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
Expand All @@ -157,7 +157,7 @@ break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
bkpt_sp->GetTarget().GetAPIMutex());
Address address;
Target &target = bkpt_sp->GetTarget();
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
if (!target.ResolveLoadAddress(vm_addr, address)) {
address.SetRawAddress(vm_addr);
}
break_id = bkpt_sp->FindLocationIDByAddress(address);
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Breakpoint/BreakpointLocationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ BreakpointLocationList::FindByAddress(const Address &addr) const {
so_addr = addr;
} else {
// Try and resolve as a load address if possible.
m_owner.GetTarget().GetSectionLoadList().ResolveLoadAddress(
addr.GetOffset(), so_addr);
m_owner.GetTarget().ResolveLoadAddress(addr.GetOffset(), so_addr);
if (!so_addr.IsValid()) {
// The address didn't resolve, so just set to passed in addr.
so_addr = addr;
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Commands/CommandObjectDisassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
};

Target &target = GetTarget();
if (!target.GetSectionLoadList().IsEmpty()) {
if (target.HasLoadedSections()) {
Address symbol_containing_address;
if (target.GetSectionLoadList().ResolveLoadAddress(
m_options.symbol_containing_addr, symbol_containing_address)) {
if (target.ResolveLoadAddress(m_options.symbol_containing_addr,
symbol_containing_address)) {
get_range(symbol_containing_address);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Commands/CommandObjectRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
if (reg_addr != LLDB_INVALID_ADDRESS) {
Address so_reg_addr;
if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(
reg_addr, so_reg_addr)) {
if (exe_ctx.GetTargetRef().ResolveLoadAddress(reg_addr,
so_reg_addr)) {
strm.PutCString(" ");
so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
Address::DumpStyleResolvedDescription);
Expand Down
9 changes: 4 additions & 5 deletions lldb/source/Commands/CommandObjectSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
size_t num_matches = 0;
assert(module_list.GetSize() > 0);
Target &target = GetTarget();
if (target.GetSectionLoadList().IsEmpty()) {
if (!target.HasLoadedSections()) {
// The target isn't loaded yet, we need to lookup the file address in all
// modules. Note: the module list option does not apply to addresses.
const size_t num_modules = module_list.GetSize();
Expand All @@ -328,7 +328,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
} else {
// The target has some things loaded, resolve this address to a compile
// unit + file + line and display
if (target.GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
if (target.ResolveLoadAddress(addr, so_addr)) {
ModuleSP module_sp(so_addr.GetModule());
// Check to make sure this module is in our list.
if (module_sp && module_list.GetIndexForModule(module_sp.get()) !=
Expand Down Expand Up @@ -959,7 +959,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
StreamString error_strm;
SymbolContextList sc_list;

if (target.GetSectionLoadList().IsEmpty()) {
if (!target.HasLoadedSections()) {
// The target isn't loaded yet, we need to lookup the file address in
// all modules
const ModuleList &module_list = target.GetImages();
Expand Down Expand Up @@ -987,8 +987,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
} else {
// The target has some things loaded, resolve this address to a compile
// unit + file + line and display
if (target.GetSectionLoadList().ResolveLoadAddress(m_options.address,
so_addr)) {
if (target.ResolveLoadAddress(m_options.address, so_addr)) {
ModuleSP module_sp(so_addr.GetModule());
if (module_sp) {
SymbolContext sc;
Expand Down
15 changes: 7 additions & 8 deletions lldb/source/Commands/CommandObjectTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,8 +1522,8 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
Address so_addr;
SymbolContext sc;
Target *target = interpreter.GetExecutionContext().GetTargetPtr();
if (target && !target->GetSectionLoadList().IsEmpty()) {
if (!target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr))
if (target && target->HasLoadedSections()) {
if (!target->ResolveLoadAddress(addr, so_addr))
return false;
else if (so_addr.GetModule().get() != module)
return false;
Expand Down Expand Up @@ -2974,8 +2974,8 @@ class CommandObjectTargetModulesLoad
sect_name);
break;
} else {
if (target.GetSectionLoadList().SetSectionLoadAddress(
section_sp, load_addr))
if (target.SetSectionLoadAddress(section_sp,
load_addr))
changed = true;
result.AppendMessageWithFormat(
"section '%s' loaded at 0x%" PRIx64 "\n",
Expand Down Expand Up @@ -3329,7 +3329,7 @@ class CommandObjectTargetModulesList : public CommandObjectParsed {
if (objfile) {
Address base_addr(objfile->GetBaseAddress());
if (base_addr.IsValid()) {
if (!target.GetSectionLoadList().IsEmpty()) {
if (target.HasLoadedSections()) {
lldb::addr_t load_addr = base_addr.GetLoadAddress(&target);
if (load_addr == LLDB_INVALID_ADDRESS) {
base_addr.Dump(&strm, &target,
Expand Down Expand Up @@ -3544,8 +3544,7 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
function_options, sc_list);
} else if (m_options.m_type == eLookupTypeAddress && target) {
Address addr;
if (target->GetSectionLoadList().ResolveLoadAddress(m_options.m_addr,
addr)) {
if (target->ResolveLoadAddress(m_options.m_addr, addr)) {
SymbolContext sc;
ModuleSP module_sp(addr.GetModule());
module_sp->ResolveSymbolContextForAddress(addr,
Expand Down Expand Up @@ -5270,7 +5269,7 @@ class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
protected:
void DoExecute(Args &command, CommandReturnObject &result) override {
Target &target = GetTarget();
target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
target.DumpSectionLoadList(result.GetOutputStream());
result.SetStatus(eReturnStatusSuccessFinishResult);
}
};
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Core/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ static bool ReadAddress(ExecutionContextScope *exe_scope,
// If we have any sections that are loaded, try and resolve using the
// section load list
Target *target = exe_ctx.GetTargetPtr();
if (target && !target->GetSectionLoadList().IsEmpty()) {
if (target->GetSectionLoadList().ResolveLoadAddress(deref_addr,
deref_so_addr))
if (target && target->HasLoadedSections()) {
if (target->ResolveLoadAddress(deref_addr, deref_so_addr))
return true;
} else {
// If we were not running, yet able to read an integer, we must have a
Expand Down Expand Up @@ -1046,8 +1045,9 @@ AddressClass Address::GetAddressClass() const {

bool Address::SetLoadAddress(lldb::addr_t load_addr, Target *target,
bool allow_section_end) {
if (target && target->GetSectionLoadList().ResolveLoadAddress(
load_addr, *this, allow_section_end))
if (target && target->ResolveLoadAddress(load_addr, *this,
SectionLoadHistory::eStopIDNow,
allow_section_end))
return true;
m_section_wp.reset();
m_offset = load_addr;
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Core/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ static Address ResolveAddress(Target &target, const Address &addr) {
Address resolved_addr;
// If we weren't passed in a section offset address range, try and resolve
// it to something
bool is_resolved = target.GetSectionLoadList().IsEmpty()
? target.GetImages().ResolveFileAddress(
addr.GetOffset(), resolved_addr)
: target.GetSectionLoadList().ResolveLoadAddress(
addr.GetOffset(), resolved_addr);
bool is_resolved =
target.HasLoadedSections()
? target.ResolveLoadAddress(addr.GetOffset(), resolved_addr)
: target.GetImages().ResolveFileAddress(addr.GetOffset(),
resolved_addr);

// We weren't able to resolve the address, just treat it as a raw address
if (is_resolved && resolved_addr.IsValid())
Expand Down
10 changes: 4 additions & 6 deletions lldb/source/Core/DumpDataExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s,
lldb::addr_t addr = base_addr + start_offset;
lldb_private::Address so_addr;
bool data_from_file = true;
if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
if (target_sp->ResolveLoadAddress(addr, so_addr)) {
data_from_file = false;
} else {
if (target_sp->GetSectionLoadList().IsEmpty() ||
if (!target_sp->HasLoadedSections() ||
!target_sp->GetImages().ResolveFileAddress(addr, so_addr))
so_addr.SetRawAddress(addr);
}
Expand Down Expand Up @@ -707,8 +707,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
TargetSP target_sp(exe_scope->CalculateTarget());
lldb_private::Address so_addr;
if (target_sp) {
if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr,
so_addr)) {
if (target_sp->ResolveLoadAddress(addr, so_addr)) {
s->PutChar(' ');
so_addr.Dump(s, exe_scope, Address::DumpStyleResolvedDescription,
Address::DumpStyleModuleWithFileAddress);
Expand All @@ -719,8 +718,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
if (ProcessSP process_sp = exe_scope->CalculateProcess()) {
if (ABISP abi_sp = process_sp->GetABI()) {
addr_t addr_fixed = abi_sp->FixCodeAddress(addr);
if (target_sp->GetSectionLoadList().ResolveLoadAddress(
addr_fixed, so_addr)) {
if (target_sp->ResolveLoadAddress(addr_fixed, so_addr)) {
s->PutChar(' ');
s->Printf("(0x%*.*" PRIx64 ")", (int)(2 * item_byte_size),
(int)(2 * item_byte_size), addr_fixed);
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/FormatEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc,
Target *target = Target::GetTargetFromContexts(exe_ctx, sc);

addr_t vaddr = LLDB_INVALID_ADDRESS;
if (target && !target->GetSectionLoadList().IsEmpty())
if (target && target->HasLoadedSections())
vaddr = addr.GetLoadAddress(target);
if (vaddr == LLDB_INVALID_ADDRESS)
vaddr = addr.GetFileAddress();
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Core/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ addr_t Section::GetLoadBaseAddress(Target *target) const {
load_base_addr += GetOffset();
}
if (load_base_addr == LLDB_INVALID_ADDRESS) {
load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress(
load_base_addr = target->GetSectionLoadAddress(
const_cast<Section *>(this)->shared_from_this());
}
return load_base_addr;
Expand Down Expand Up @@ -637,8 +637,7 @@ bool SectionList::ContainsSection(user_id_t sect_id) const {

void SectionList::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
bool show_header, uint32_t depth) const {
bool target_has_loaded_sections =
target && !target->GetSectionLoadList().IsEmpty();
bool target_has_loaded_sections = target && target->HasLoadedSections();
if (show_header && !m_sections.empty()) {
s.indent(indent);
s << llvm::formatv(
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/Core/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,9 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
// memory sections loaded. This allows you to use "target modules
// load" to load your executable and any shared libraries, then
// execute commands where you can look at types in data sections.
const SectionLoadList &target_sections = target->GetSectionLoadList();
if (!target_sections.IsEmpty()) {
if (target->HasLoadedSections()) {
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
if (target_sections.ResolveLoadAddress(address, file_so_addr)) {
if (target->ResolveLoadAddress(address, file_so_addr)) {
address_type = eAddressTypeLoad;
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
data.SetAddressByteSize(
Expand Down
5 changes: 2 additions & 3 deletions lldb/source/DataFormatters/CXXFunctionPointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(

Address so_addr;
Target *target = exe_ctx.GetTargetPtr();
if (target && !target->GetSectionLoadList().IsEmpty()) {
target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
so_addr);
if (target && target->HasLoadedSections()) {
target->ResolveLoadAddress(func_ptr_address, so_addr);
if (so_addr.GetSection() == nullptr) {
// If we have an address that doesn't correspond to any symbol,
// it might have authentication bits. Strip them & see if it
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Expression/ObjectFileJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ bool ObjectFileJIT::SetLoadAddress(Target &target, lldb::addr_t value,
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
if (section_sp && section_sp->GetFileSize() > 0 &&
!section_sp->IsThreadSpecific()) {
if (target.GetSectionLoadList().SetSectionLoadAddress(
section_sp, section_sp->GetFileAddress() + value))
if (target.SetSectionLoadAddress(section_sp,
section_sp->GetFileAddress() + value))
++num_loaded_sections;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,

Address resolved_addr;

SectionLoadList &section_load_list = target.GetSectionLoadList();
if (section_load_list.IsEmpty())
if (!target.HasLoadedSections())
// No sections are loaded, so we must assume we are not running yet and
// need to operate only on file address.
target.ResolveFileAddress(addr, resolved_addr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1787,9 +1787,9 @@ const char *DisassemblerLLVMC::SymbolLookup(uint64_t value, uint64_t *type_ptr,
module_sp->ResolveFileAddress(value, value_so_addr);
module_sp->ResolveFileAddress(pc, pc_so_addr);
}
} else if (target && !target->GetSectionLoadList().IsEmpty()) {
target->GetSectionLoadList().ResolveLoadAddress(value, value_so_addr);
target->GetSectionLoadList().ResolveLoadAddress(pc, pc_so_addr);
} else if (target && target->HasLoadedSections()) {
target->ResolveLoadAddress(value, value_so_addr);
target->ResolveLoadAddress(pc, pc_so_addr);
}

SymbolContext sym_ctx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
dyld_instance->UnloadAllImages();
dyld_instance->ClearDYLDModule();
process->GetTarget().GetImages().Clear();
process->GetTarget().GetSectionLoadList().Clear();
process->GetTarget().ClearSectionLoadList();

addr_t all_image_infos = process->GetImageInfoAddress();
int addr_size =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void DynamicLoaderStatic::LoadAllImagesAtFileAddresses() {
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
if (section_sp) {
if (target.GetSectionLoadList().GetSectionLoadAddress(
section_sp) != LLDB_INVALID_ADDRESS) {
if (target.GetSectionLoadAddress(section_sp) !=
LLDB_INVALID_ADDRESS) {
no_load_addresses = false;
break;
}
Expand Down
Loading
Loading