Skip to content

Commit c4fb718

Browse files
authored
[lldb][NFC] Make the target's SectionLoadList private. (llvm#113278)
Lots of code around LLDB was directly accessing the target's section load list. This NFC patch makes the section load list private so the Target class can access it, but everyone else now uses accessor functions. This allows us to control the resolving of addresses and will allow for functionality in LLDB which can lazily resolve addresses in JIT plug-ins with a future patch.
1 parent 9ac6a55 commit c4fb718

35 files changed

+116
-106
lines changed

lldb/include/lldb/Target/SectionLoadHistory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SectionLoadHistory {
4545
const lldb::SectionSP &section_sp);
4646

4747
bool ResolveLoadAddress(uint32_t stop_id, lldb::addr_t load_addr,
48-
Address &so_addr);
48+
Address &so_addr, bool allow_section_end = false);
4949

5050
bool SetSectionLoadAddress(uint32_t stop_id,
5151
const lldb::SectionSP &section_sp,

lldb/include/lldb/Target/Target.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,13 @@ class Target : public std::enable_shared_from_this<Target>,
11511151
Address &pointer_addr,
11521152
bool force_live_memory = false);
11531153

1154-
SectionLoadList &GetSectionLoadList() {
1155-
return m_section_load_history.GetCurrentSectionLoadList();
1156-
}
1154+
bool HasLoadedSections();
1155+
1156+
lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP &section_sp);
1157+
1158+
void ClearSectionLoadList();
1159+
1160+
void DumpSectionLoadList(Stream &s);
11571161

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

12201224
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr,
1221-
uint32_t stop_id = SectionLoadHistory::eStopIDNow);
1225+
uint32_t stop_id = SectionLoadHistory::eStopIDNow,
1226+
bool allow_section_end = false);
12221227

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

16671672
Target(const Target &) = delete;
16681673
const Target &operator=(const Target &) = delete;
1674+
1675+
SectionLoadList &GetSectionLoadList() {
1676+
return m_section_load_history.GetCurrentSectionLoadList();
1677+
}
16691678
};
16701679

16711680
} // namespace lldb_private

lldb/source/API/SBBreakpoint.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) {
137137
bkpt_sp->GetTarget().GetAPIMutex());
138138
Address address;
139139
Target &target = bkpt_sp->GetTarget();
140-
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
140+
if (!target.ResolveLoadAddress(vm_addr, address)) {
141141
address.SetRawAddress(vm_addr);
142142
}
143143
sb_bp_location.SetLocation(bkpt_sp->FindLocationByAddress(address));
@@ -157,7 +157,7 @@ break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) {
157157
bkpt_sp->GetTarget().GetAPIMutex());
158158
Address address;
159159
Target &target = bkpt_sp->GetTarget();
160-
if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) {
160+
if (!target.ResolveLoadAddress(vm_addr, address)) {
161161
address.SetRawAddress(vm_addr);
162162
}
163163
break_id = bkpt_sp->FindLocationIDByAddress(address);

lldb/source/Breakpoint/BreakpointLocationList.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ BreakpointLocationList::FindByAddress(const Address &addr) const {
103103
so_addr = addr;
104104
} else {
105105
// Try and resolve as a load address if possible.
106-
m_owner.GetTarget().GetSectionLoadList().ResolveLoadAddress(
107-
addr.GetOffset(), so_addr);
106+
m_owner.GetTarget().ResolveLoadAddress(addr.GetOffset(), so_addr);
108107
if (!so_addr.IsValid()) {
109108
// The address didn't resolve, so just set to passed in addr.
110109
so_addr = addr;

lldb/source/Commands/CommandObjectDisassemble.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
269269
};
270270

271271
Target &target = GetTarget();
272-
if (!target.GetSectionLoadList().IsEmpty()) {
272+
if (target.HasLoadedSections()) {
273273
Address symbol_containing_address;
274-
if (target.GetSectionLoadList().ResolveLoadAddress(
275-
m_options.symbol_containing_addr, symbol_containing_address)) {
274+
if (target.ResolveLoadAddress(m_options.symbol_containing_addr,
275+
symbol_containing_address)) {
276276
get_range(symbol_containing_address);
277277
}
278278
} else {

lldb/source/Commands/CommandObjectRegister.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ class CommandObjectRegisterRead : public CommandObjectParsed {
9595
addr_t reg_addr = reg_value.GetAsUInt64(LLDB_INVALID_ADDRESS);
9696
if (reg_addr != LLDB_INVALID_ADDRESS) {
9797
Address so_reg_addr;
98-
if (exe_ctx.GetTargetRef().GetSectionLoadList().ResolveLoadAddress(
99-
reg_addr, so_reg_addr)) {
98+
if (exe_ctx.GetTargetRef().ResolveLoadAddress(reg_addr,
99+
so_reg_addr)) {
100100
strm.PutCString(" ");
101101
so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),
102102
Address::DumpStyleResolvedDescription);

lldb/source/Commands/CommandObjectSource.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
302302
size_t num_matches = 0;
303303
assert(module_list.GetSize() > 0);
304304
Target &target = GetTarget();
305-
if (target.GetSectionLoadList().IsEmpty()) {
305+
if (!target.HasLoadedSections()) {
306306
// The target isn't loaded yet, we need to lookup the file address in all
307307
// modules. Note: the module list option does not apply to addresses.
308308
const size_t num_modules = module_list.GetSize();
@@ -328,7 +328,7 @@ class CommandObjectSourceInfo : public CommandObjectParsed {
328328
} else {
329329
// The target has some things loaded, resolve this address to a compile
330330
// unit + file + line and display
331-
if (target.GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
331+
if (target.ResolveLoadAddress(addr, so_addr)) {
332332
ModuleSP module_sp(so_addr.GetModule());
333333
// Check to make sure this module is in our list.
334334
if (module_sp && module_list.GetIndexForModule(module_sp.get()) !=
@@ -959,7 +959,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
959959
StreamString error_strm;
960960
SymbolContextList sc_list;
961961

962-
if (target.GetSectionLoadList().IsEmpty()) {
962+
if (!target.HasLoadedSections()) {
963963
// The target isn't loaded yet, we need to lookup the file address in
964964
// all modules
965965
const ModuleList &module_list = target.GetImages();
@@ -987,8 +987,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
987987
} else {
988988
// The target has some things loaded, resolve this address to a compile
989989
// unit + file + line and display
990-
if (target.GetSectionLoadList().ResolveLoadAddress(m_options.address,
991-
so_addr)) {
990+
if (target.ResolveLoadAddress(m_options.address, so_addr)) {
992991
ModuleSP module_sp(so_addr.GetModule());
993992
if (module_sp) {
994993
SymbolContext sc;

lldb/source/Commands/CommandObjectTarget.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -1522,8 +1522,8 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
15221522
Address so_addr;
15231523
SymbolContext sc;
15241524
Target *target = interpreter.GetExecutionContext().GetTargetPtr();
1525-
if (target && !target->GetSectionLoadList().IsEmpty()) {
1526-
if (!target->GetSectionLoadList().ResolveLoadAddress(addr, so_addr))
1525+
if (target && target->HasLoadedSections()) {
1526+
if (!target->ResolveLoadAddress(addr, so_addr))
15271527
return false;
15281528
else if (so_addr.GetModule().get() != module)
15291529
return false;
@@ -2974,8 +2974,8 @@ class CommandObjectTargetModulesLoad
29742974
sect_name);
29752975
break;
29762976
} else {
2977-
if (target.GetSectionLoadList().SetSectionLoadAddress(
2978-
section_sp, load_addr))
2977+
if (target.SetSectionLoadAddress(section_sp,
2978+
load_addr))
29792979
changed = true;
29802980
result.AppendMessageWithFormat(
29812981
"section '%s' loaded at 0x%" PRIx64 "\n",
@@ -3329,7 +3329,7 @@ class CommandObjectTargetModulesList : public CommandObjectParsed {
33293329
if (objfile) {
33303330
Address base_addr(objfile->GetBaseAddress());
33313331
if (base_addr.IsValid()) {
3332-
if (!target.GetSectionLoadList().IsEmpty()) {
3332+
if (target.HasLoadedSections()) {
33333333
lldb::addr_t load_addr = base_addr.GetLoadAddress(&target);
33343334
if (load_addr == LLDB_INVALID_ADDRESS) {
33353335
base_addr.Dump(&strm, &target,
@@ -3544,8 +3544,7 @@ class CommandObjectTargetModulesShowUnwind : public CommandObjectParsed {
35443544
function_options, sc_list);
35453545
} else if (m_options.m_type == eLookupTypeAddress && target) {
35463546
Address addr;
3547-
if (target->GetSectionLoadList().ResolveLoadAddress(m_options.m_addr,
3548-
addr)) {
3547+
if (target->ResolveLoadAddress(m_options.m_addr, addr)) {
35493548
SymbolContext sc;
35503549
ModuleSP module_sp(addr.GetModule());
35513550
module_sp->ResolveSymbolContextForAddress(addr,
@@ -5270,7 +5269,7 @@ class CommandObjectTargetDumpSectionLoadList : public CommandObjectParsed {
52705269
protected:
52715270
void DoExecute(Args &command, CommandReturnObject &result) override {
52725271
Target &target = GetTarget();
5273-
target.GetSectionLoadList().Dump(result.GetOutputStream(), &target);
5272+
target.DumpSectionLoadList(result.GetOutputStream());
52745273
result.SetStatus(eReturnStatusSuccessFinishResult);
52755274
}
52765275
};

lldb/source/Core/Address.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,8 @@ static bool ReadAddress(ExecutionContextScope *exe_scope,
138138
// If we have any sections that are loaded, try and resolve using the
139139
// section load list
140140
Target *target = exe_ctx.GetTargetPtr();
141-
if (target && !target->GetSectionLoadList().IsEmpty()) {
142-
if (target->GetSectionLoadList().ResolveLoadAddress(deref_addr,
143-
deref_so_addr))
141+
if (target && target->HasLoadedSections()) {
142+
if (target->ResolveLoadAddress(deref_addr, deref_so_addr))
144143
return true;
145144
} else {
146145
// If we were not running, yet able to read an integer, we must have a
@@ -1046,8 +1045,9 @@ AddressClass Address::GetAddressClass() const {
10461045

10471046
bool Address::SetLoadAddress(lldb::addr_t load_addr, Target *target,
10481047
bool allow_section_end) {
1049-
if (target && target->GetSectionLoadList().ResolveLoadAddress(
1050-
load_addr, *this, allow_section_end))
1048+
if (target && target->ResolveLoadAddress(load_addr, *this,
1049+
SectionLoadHistory::eStopIDNow,
1050+
allow_section_end))
10511051
return true;
10521052
m_section_wp.reset();
10531053
m_offset = load_addr;

lldb/source/Core/Disassembler.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ static Address ResolveAddress(Target &target, const Address &addr) {
107107
Address resolved_addr;
108108
// If we weren't passed in a section offset address range, try and resolve
109109
// it to something
110-
bool is_resolved = target.GetSectionLoadList().IsEmpty()
111-
? target.GetImages().ResolveFileAddress(
112-
addr.GetOffset(), resolved_addr)
113-
: target.GetSectionLoadList().ResolveLoadAddress(
114-
addr.GetOffset(), resolved_addr);
110+
bool is_resolved =
111+
target.HasLoadedSections()
112+
? target.ResolveLoadAddress(addr.GetOffset(), resolved_addr)
113+
: target.GetImages().ResolveFileAddress(addr.GetOffset(),
114+
resolved_addr);
115115

116116
// We weren't able to resolve the address, just treat it as a raw address
117117
if (is_resolved && resolved_addr.IsValid())

lldb/source/Core/DumpDataExtractor.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s,
136136
lldb::addr_t addr = base_addr + start_offset;
137137
lldb_private::Address so_addr;
138138
bool data_from_file = true;
139-
if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr, so_addr)) {
139+
if (target_sp->ResolveLoadAddress(addr, so_addr)) {
140140
data_from_file = false;
141141
} else {
142-
if (target_sp->GetSectionLoadList().IsEmpty() ||
142+
if (!target_sp->HasLoadedSections() ||
143143
!target_sp->GetImages().ResolveFileAddress(addr, so_addr))
144144
so_addr.SetRawAddress(addr);
145145
}
@@ -707,8 +707,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
707707
TargetSP target_sp(exe_scope->CalculateTarget());
708708
lldb_private::Address so_addr;
709709
if (target_sp) {
710-
if (target_sp->GetSectionLoadList().ResolveLoadAddress(addr,
711-
so_addr)) {
710+
if (target_sp->ResolveLoadAddress(addr, so_addr)) {
712711
s->PutChar(' ');
713712
so_addr.Dump(s, exe_scope, Address::DumpStyleResolvedDescription,
714713
Address::DumpStyleModuleWithFileAddress);
@@ -719,8 +718,7 @@ lldb::offset_t lldb_private::DumpDataExtractor(
719718
if (ProcessSP process_sp = exe_scope->CalculateProcess()) {
720719
if (ABISP abi_sp = process_sp->GetABI()) {
721720
addr_t addr_fixed = abi_sp->FixCodeAddress(addr);
722-
if (target_sp->GetSectionLoadList().ResolveLoadAddress(
723-
addr_fixed, so_addr)) {
721+
if (target_sp->ResolveLoadAddress(addr_fixed, so_addr)) {
724722
s->PutChar(' ');
725723
s->Printf("(0x%*.*" PRIx64 ")", (int)(2 * item_byte_size),
726724
(int)(2 * item_byte_size), addr_fixed);

lldb/source/Core/FormatEntity.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static bool DumpAddressAndContent(Stream &s, const SymbolContext *sc,
412412
Target *target = Target::GetTargetFromContexts(exe_ctx, sc);
413413

414414
addr_t vaddr = LLDB_INVALID_ADDRESS;
415-
if (target && !target->GetSectionLoadList().IsEmpty())
415+
if (target && target->HasLoadedSections())
416416
vaddr = addr.GetLoadAddress(target);
417417
if (vaddr == LLDB_INVALID_ADDRESS)
418418
vaddr = addr.GetFileAddress();

lldb/source/Core/Section.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ addr_t Section::GetLoadBaseAddress(Target *target) const {
238238
load_base_addr += GetOffset();
239239
}
240240
if (load_base_addr == LLDB_INVALID_ADDRESS) {
241-
load_base_addr = target->GetSectionLoadList().GetSectionLoadAddress(
241+
load_base_addr = target->GetSectionLoadAddress(
242242
const_cast<Section *>(this)->shared_from_this());
243243
}
244244
return load_base_addr;
@@ -643,8 +643,7 @@ bool SectionList::ContainsSection(user_id_t sect_id) const {
643643

644644
void SectionList::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
645645
bool show_header, uint32_t depth) const {
646-
bool target_has_loaded_sections =
647-
target && !target->GetSectionLoadList().IsEmpty();
646+
bool target_has_loaded_sections = target && target->HasLoadedSections();
648647
if (show_header && !m_sections.empty()) {
649648
s.indent(indent);
650649
s << llvm::formatv(

lldb/source/Core/Value.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,9 @@ Status Value::GetValueAsData(ExecutionContext *exe_ctx, DataExtractor &data,
364364
// memory sections loaded. This allows you to use "target modules
365365
// load" to load your executable and any shared libraries, then
366366
// execute commands where you can look at types in data sections.
367-
const SectionLoadList &target_sections = target->GetSectionLoadList();
368-
if (!target_sections.IsEmpty()) {
367+
if (target->HasLoadedSections()) {
369368
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
370-
if (target_sections.ResolveLoadAddress(address, file_so_addr)) {
369+
if (target->ResolveLoadAddress(address, file_so_addr)) {
371370
address_type = eAddressTypeLoad;
372371
data.SetByteOrder(target->GetArchitecture().GetByteOrder());
373372
data.SetAddressByteSize(

lldb/source/DataFormatters/CXXFunctionPointer.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
3939

4040
Address so_addr;
4141
Target *target = exe_ctx.GetTargetPtr();
42-
if (target && !target->GetSectionLoadList().IsEmpty()) {
43-
target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address,
44-
so_addr);
42+
if (target && target->HasLoadedSections()) {
43+
target->ResolveLoadAddress(func_ptr_address, so_addr);
4544
if (so_addr.GetSection() == nullptr) {
4645
// If we have an address that doesn't correspond to any symbol,
4746
// it might have authentication bits. Strip them & see if it

lldb/source/Expression/ObjectFileJIT.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ bool ObjectFileJIT::SetLoadAddress(Target &target, lldb::addr_t value,
178178
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
179179
if (section_sp && section_sp->GetFileSize() > 0 &&
180180
!section_sp->IsThreadSpecific()) {
181-
if (target.GetSectionLoadList().SetSectionLoadAddress(
182-
section_sp, section_sp->GetFileAddress() + value))
181+
if (target.SetSectionLoadAddress(section_sp,
182+
section_sp->GetFileAddress() + value))
183183
++num_loaded_sections;
184184
}
185185
}

lldb/source/Plugins/Architecture/Mips/ArchitectureMips.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,
7676

7777
Address resolved_addr;
7878

79-
SectionLoadList &section_load_list = target.GetSectionLoadList();
80-
if (section_load_list.IsEmpty())
79+
if (!target.HasLoadedSections())
8180
// No sections are loaded, so we must assume we are not running yet and
8281
// need to operate only on file address.
8382
target.ResolveFileAddress(addr, resolved_addr);

lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1787,9 +1787,9 @@ const char *DisassemblerLLVMC::SymbolLookup(uint64_t value, uint64_t *type_ptr,
17871787
module_sp->ResolveFileAddress(value, value_so_addr);
17881788
module_sp->ResolveFileAddress(pc, pc_so_addr);
17891789
}
1790-
} else if (target && !target->GetSectionLoadList().IsEmpty()) {
1791-
target->GetSectionLoadList().ResolveLoadAddress(value, value_so_addr);
1792-
target->GetSectionLoadList().ResolveLoadAddress(pc, pc_so_addr);
1790+
} else if (target && target->HasLoadedSections()) {
1791+
target->ResolveLoadAddress(value, value_so_addr);
1792+
target->ResolveLoadAddress(pc, pc_so_addr);
17931793
}
17941794

17951795
SymbolContext sym_ctx;

lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOS.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
368368
dyld_instance->UnloadAllImages();
369369
dyld_instance->ClearDYLDModule();
370370
process->GetTarget().GetImages().Clear();
371-
process->GetTarget().GetSectionLoadList().Clear();
371+
process->GetTarget().ClearSectionLoadList();
372372

373373
addr_t all_image_infos = process->GetImageInfoAddress();
374374
int addr_size =

lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ void DynamicLoaderStatic::LoadAllImagesAtFileAddresses() {
103103
for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) {
104104
SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx));
105105
if (section_sp) {
106-
if (target.GetSectionLoadList().GetSectionLoadAddress(
107-
section_sp) != LLDB_INVALID_ADDRESS) {
106+
if (target.GetSectionLoadAddress(section_sp) !=
107+
LLDB_INVALID_ADDRESS) {
108108
no_load_addresses = false;
109109
break;
110110
}

0 commit comments

Comments
 (0)