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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 7 additions & 8 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 5 additions & 5 deletions
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())

0 commit comments

Comments
 (0)