Skip to content

Commit 9169133

Browse files
committed
Respond to user feedback:
- Rename Target::SectionLoadListIsEmpty() to Target::HasLoadedSections() and invert all call sites - Change Target::HasLoadedSections() to not be const and avoid the const cast.
1 parent dab763a commit 9169133

File tree

20 files changed

+32
-33
lines changed

20 files changed

+32
-33
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,7 @@ class Target : public std::enable_shared_from_this<Target>,
11511151
Address &pointer_addr,
11521152
bool force_live_memory = false);
11531153

1154-
1155-
bool SectionLoadListIsEmpty() const;
1154+
bool HasLoadedSections();
11561155

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

lldb/source/Commands/CommandObjectDisassemble.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ CommandObjectDisassemble::GetContainingAddressRanges() {
269269
};
270270

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

lldb/source/Commands/CommandObjectRegister.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ 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().ResolveLoadAddress(reg_addr,
98+
if (exe_ctx.GetTargetRef().ResolveLoadAddress(reg_addr,
9999
so_reg_addr)) {
100100
strm.PutCString(" ");
101101
so_reg_addr.Dump(&strm, exe_ctx.GetBestExecutionContextScope(),

lldb/source/Commands/CommandObjectSource.cpp

Lines changed: 2 additions & 2 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.SectionLoadListIsEmpty()) {
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();
@@ -959,7 +959,7 @@ class CommandObjectSourceList : public CommandObjectParsed {
959959
StreamString error_strm;
960960
SymbolContextList sc_list;
961961

962-
if (target.SectionLoadListIsEmpty()) {
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();

lldb/source/Commands/CommandObjectTarget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ static bool LookupAddressInModule(CommandInterpreter &interpreter, Stream &strm,
15221522
Address so_addr;
15231523
SymbolContext sc;
15241524
Target *target = interpreter.GetExecutionContext().GetTargetPtr();
1525-
if (target && !target->SectionLoadListIsEmpty()) {
1525+
if (target && target->HasLoadedSections()) {
15261526
if (!target->ResolveLoadAddress(addr, so_addr))
15271527
return false;
15281528
else if (so_addr.GetModule().get() != module)
@@ -2974,7 +2974,7 @@ class CommandObjectTargetModulesLoad
29742974
sect_name);
29752975
break;
29762976
} else {
2977-
if (target.SetSectionLoadAddress(section_sp,
2977+
if (target.SetSectionLoadAddress(section_sp,
29782978
load_addr))
29792979
changed = true;
29802980
result.AppendMessageWithFormat(
@@ -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.SectionLoadListIsEmpty()) {
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,

lldb/source/Core/Address.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ 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->SectionLoadListIsEmpty()) {
141+
if (target && target->HasLoadedSections()) {
142142
if (target->ResolveLoadAddress(deref_addr, deref_so_addr))
143143
return true;
144144
} else {

lldb/source/Core/Disassembler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +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.SectionLoadListIsEmpty() ? target.GetImages().ResolveFileAddress(addr.GetOffset(), resolved_addr) : target.ResolveLoadAddress(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);
111115

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

lldb/source/Core/DumpDataExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ static lldb::offset_t DumpInstructions(const DataExtractor &DE, Stream *s,
139139
if (target_sp->ResolveLoadAddress(addr, so_addr)) {
140140
data_from_file = false;
141141
} else {
142-
if (target_sp->SectionLoadListIsEmpty() ||
142+
if (!target_sp->HasLoadedSections() ||
143143
!target_sp->GetImages().ResolveFileAddress(addr, so_addr))
144144
so_addr.SetRawAddress(addr);
145145
}

lldb/source/Core/FormatEntity.cpp

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,7 @@ bool SectionList::ContainsSection(user_id_t sect_id) const {
637637

638638
void SectionList::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
639639
bool show_header, uint32_t depth) const {
640-
bool target_has_loaded_sections =
641-
target && !target->SectionLoadListIsEmpty();
640+
bool target_has_loaded_sections = target && target->HasLoadedSections();
642641
if (show_header && !m_sections.empty()) {
643642
s.indent(indent);
644643
s << llvm::formatv(

lldb/source/Core/Value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ 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-
if (!target->SectionLoadListIsEmpty()) {
367+
if (target->HasLoadedSections()) {
368368
address = m_value.ULongLong(LLDB_INVALID_ADDRESS);
369369
if (target->ResolveLoadAddress(address, file_so_addr)) {
370370
address_type = eAddressTypeLoad;

lldb/source/DataFormatters/CXXFunctionPointer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool lldb_private::formatters::CXXFunctionPointerSummaryProvider(
3939

4040
Address so_addr;
4141
Target *target = exe_ctx.GetTargetPtr();
42-
if (target && !target->SectionLoadListIsEmpty()) {
42+
if (target && target->HasLoadedSections()) {
4343
target->ResolveLoadAddress(func_ptr_address, so_addr);
4444
if (so_addr.GetSection() == nullptr) {
4545
// If we have an address that doesn't correspond to any symbol,

lldb/source/Expression/ObjectFileJIT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ 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.SetSectionLoadAddress(section_sp,
181+
if (target.SetSectionLoadAddress(section_sp,
182182
section_sp->GetFileAddress() + value))
183183
++num_loaded_sections;
184184
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,
7676

7777
Address resolved_addr;
7878

79-
if (target.SectionLoadListIsEmpty())
79+
if (!target.HasLoadedSections())
8080
// No sections are loaded, so we must assume we are not running yet and
8181
// need to operate only on file address.
8282
target.ResolveFileAddress(addr, resolved_addr);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ 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->SectionLoadListIsEmpty()) {
1790+
} else if (target && target->HasLoadedSections()) {
17911791
target->ResolveLoadAddress(value, value_so_addr);
17921792
target->ResolveLoadAddress(pc, pc_so_addr);
17931793
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ 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.GetSectionLoadAddress(section_sp) !=
106+
if (target.GetSectionLoadAddress(section_sp) !=
107107
LLDB_INVALID_ADDRESS) {
108108
no_load_addresses = false;
109109
break;

lldb/source/Plugins/LanguageRuntime/CPlusPlus/CPPLanguageRuntime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ CPPLanguageRuntime::FindLibCppStdFunctionCallableInfo(
266266

267267
Target &target = process->GetTarget();
268268

269-
if (target.SectionLoadListIsEmpty())
269+
if (!target.HasLoadedSections())
270270
return optional_info;
271271

272272
Address vtable_first_entry_resolved;
273273

274-
if (!target.ResolveLoadAddress(vtable_address_first_entry,
274+
if (!target.ResolveLoadAddress(vtable_address_first_entry,
275275
vtable_first_entry_resolved))
276276
return optional_info;
277277

@@ -321,7 +321,7 @@ CPPLanguageRuntime::FindLibCppStdFunctionCallableInfo(
321321
// Setup for cases 2, 4 and 5 we have a pointer to a function after the
322322
// vtable. We will use a process of elimination to drop through each case
323323
// and obtain the data we need.
324-
if (target.ResolveLoadAddress(possible_function_address,
324+
if (target.ResolveLoadAddress(possible_function_address,
325325
function_address_resolved)) {
326326
target.GetImages().ResolveSymbolContextForAddress(
327327
function_address_resolved, eSymbolContextEverything, sc);
@@ -417,7 +417,7 @@ CPPLanguageRuntime::GetStepThroughTrampolinePlan(Thread &thread,
417417

418418
TargetSP target_sp(thread.CalculateTarget());
419419

420-
if (target_sp->SectionLoadListIsEmpty())
420+
if (!target_sp->HasLoadedSections())
421421
return ret_plan_sp;
422422

423423
Address pc_addr_resolved;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6245,7 +6245,7 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
62456245
"0x%" PRIx64,
62466246
section_sp->GetName().AsCString(),
62476247
section_sp->GetFileAddress() + value);
6248-
if (target.SetSectionLoadAddress(section_sp,
6248+
if (target.SetSectionLoadAddress(section_sp,
62496249
section_sp->GetFileAddress() + value,
62506250
warn_multiple))
62516251
++num_loaded_sections;
@@ -6268,7 +6268,7 @@ bool ObjectFileMachO::SetLoadAddress(Target &target, lldb::addr_t value,
62686268
"ObjectFileMachO::SetLoadAddress segment '%s' load addr is "
62696269
"0x%" PRIx64,
62706270
section_sp->GetName().AsCString(), section_load_addr);
6271-
if (target.SetSectionLoadAddress(section_sp, section_load_addr,
6271+
if (target.SetSectionLoadAddress(section_sp, section_load_addr,
62726272
warn_multiple))
62736273
++num_loaded_sections;
62746274
}

lldb/source/Plugins/Trace/intel-pt/TraceIntelPTBundleSaver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ BuildModulesSection(Process &process, FileSpec directory) {
263263

264264
lldb::addr_t load_addr = LLDB_INVALID_ADDRESS;
265265
Address base_addr(objfile->GetBaseAddress());
266-
if (base_addr.IsValid() &&
267-
!process.GetTarget().SectionLoadListIsEmpty())
266+
if (base_addr.IsValid() && process.GetTarget().HasLoadedSections())
268267
load_addr = base_addr.GetLoadAddress(&process.GetTarget());
269268

270269
if (load_addr == LLDB_INVALID_ADDRESS)

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5147,9 +5147,7 @@ Target::ReportStatistics(const lldb_private::StatisticsOptions &options) {
51475147

51485148
void Target::ResetStatistics() { m_stats.Reset(*this); }
51495149

5150-
bool Target::SectionLoadListIsEmpty() const {
5151-
return const_cast<Target *>(this)->GetSectionLoadList().IsEmpty();
5152-
}
5150+
bool Target::HasLoadedSections() { return !GetSectionLoadList().IsEmpty(); }
51535151

51545152
lldb::addr_t Target::GetSectionLoadAddress(const lldb::SectionSP &section_sp) {
51555153
return GetSectionLoadList().GetSectionLoadAddress(section_sp);

0 commit comments

Comments
 (0)