Skip to content

Commit 66a88f6

Browse files
authored
[lldb] Add Function::GetAddress and redirect some uses (llvm#115836)
Many calls to Function::GetAddressRange() were not interested in the range itself. Instead they wanted to find the address of the function (its entry point) or the base address for relocation of function-scoped entities (technically, the two don't need to be the same, but there's isn't good reason for them not to be). This PR creates a separate function for retrieving this, and changes the existing (non-controversial) uses to call that instead.
1 parent 86b1b06 commit 66a88f6

File tree

22 files changed

+49
-64
lines changed

22 files changed

+49
-64
lines changed

lldb/include/lldb/Symbol/Function.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ class Function : public UserID, public SymbolContextScope {
449449

450450
AddressRanges GetAddressRanges() { return m_block.GetRanges(); }
451451

452+
/// Return the address of the function (its entry point). This address is also
453+
/// used as a base address for relocation of function-scope entities (blocks
454+
/// and variables).
455+
const Address &GetAddress() const { return m_address; }
456+
452457
lldb::LanguageType GetLanguage() const;
453458
/// Find the file and line number of the source location of the start of the
454459
/// function. This will use the declaration if present and fall back on the
@@ -658,6 +663,9 @@ class Function : public UserID, public SymbolContextScope {
658663
/// include addresses belonging to other functions.
659664
AddressRange m_range;
660665

666+
/// The address (entry point) of the function.
667+
Address m_address;
668+
661669
/// The frame base expression for variables that are relative to the frame
662670
/// pointer.
663671
DWARFExpressionList m_frame_base;

lldb/source/API/SBBlock.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ bool SBBlock::GetDescription(SBStream &description) {
176176
m_opaque_ptr->CalculateSymbolContext(&sc);
177177
if (sc.function) {
178178
m_opaque_ptr->DumpAddressRanges(
179-
&strm,
180-
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
179+
&strm, sc.function->GetAddress().GetFileAddress());
181180
}
182181
} else
183182
strm.PutCString("No value");

lldb/source/API/SBFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ SBInstructionList SBFunction::GetInstructions(SBTarget target,
120120
if (m_opaque_ptr) {
121121
TargetSP target_sp(target.GetSP());
122122
std::unique_lock<std::recursive_mutex> lock;
123-
ModuleSP module_sp(
124-
m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
123+
ModuleSP module_sp(m_opaque_ptr->GetAddress().GetModule());
125124
if (target_sp && module_sp) {
126125
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
127126
const bool force_live_memory = true;

lldb/source/Breakpoint/BreakpointResolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
325325
// If the line number is before the prologue end, move it there...
326326
bool skipped_prologue = false;
327327
if (skip_prologue && sc.function) {
328-
Address prologue_addr(sc.function->GetAddressRange().GetBaseAddress());
328+
Address prologue_addr = sc.function->GetAddress();
329329
if (prologue_addr.IsValid() && (line_start == prologue_addr)) {
330330
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
331331
if (prologue_byte_size) {

lldb/source/Breakpoint/BreakpointResolverName.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
339339
if (!sc.block->GetStartAddress(break_addr))
340340
break_addr.Clear();
341341
} else if (sc.function) {
342-
break_addr = sc.function->GetAddressRange().GetBaseAddress();
342+
break_addr = sc.function->GetAddress();
343343
if (m_skip_prologue && break_addr.IsValid()) {
344344
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
345345
if (prologue_byte_size)

lldb/source/Core/SearchFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bool SearchFilter::FunctionPasses(Function &function) {
152152
// This is a slightly cheesy job, but since we don't have finer grained
153153
// filters yet, just checking that the start address passes is probably
154154
// good enough for the base class behavior.
155-
Address addr = function.GetAddressRange().GetBaseAddress();
155+
Address addr = function.GetAddress();
156156
return AddressPasses(addr);
157157
}
158158

lldb/source/Expression/DWARFExpressionList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ bool DWARFExpressionList::MatchesOperand(
126126
if (!sc.function)
127127
return false;
128128

129-
addr_t load_function_start =
130-
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
129+
addr_t load_function_start = sc.function->GetAddress().GetFileAddress();
131130
if (load_function_start == LLDB_INVALID_ADDRESS)
132131
return false;
133132

lldb/source/Expression/IRExecutionUnit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ class LoadAddressResolver {
731731

732732
// If that didn't work, try the function.
733733
if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
734-
Address addr =
735-
candidate_sc.function->GetAddressRange().GetBaseAddress();
734+
Address addr = candidate_sc.function->GetAddress();
736735
load_address = m_target->GetProcessSP() ? addr.GetLoadAddress(m_target)
737736
: addr.GetFileAddress();
738737
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,
9797
resolve_scope, sc);
9898
Address sym_addr;
9999
if (sc.function)
100-
sym_addr = sc.function->GetAddressRange().GetBaseAddress();
100+
sym_addr = sc.function->GetAddress();
101101
else if (sc.symbol)
102102
sym_addr = sc.symbol->GetAddress();
103103

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,10 +796,8 @@ bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) {
796796
if (sym_ctx.symbol) {
797797
module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
798798
}
799-
if (module_sp.get() == nullptr && sym_ctx.function) {
800-
module_sp =
801-
sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
802-
}
799+
if (module_sp.get() == nullptr && sym_ctx.function)
800+
module_sp = sym_ctx.function->GetAddress().GetModule();
803801
if (module_sp.get() == nullptr)
804802
return false;
805803

0 commit comments

Comments
 (0)