Skip to content

[lldb] Add Function::GetAddress and redirect some uses #115836

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 1 commit into from
Jan 10, 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
8 changes: 8 additions & 0 deletions lldb/include/lldb/Symbol/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ class Function : public UserID, public SymbolContextScope {

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

/// Return the address of the function (its entry point). This address is also
/// used as a base address for relocation of function-scope entities (blocks
/// and variables).
const Address &GetAddress() const { return m_address; }

lldb::LanguageType GetLanguage() const;
/// Find the file and line number of the source location of the start of the
/// function. This will use the declaration if present and fall back on the
Expand Down Expand Up @@ -658,6 +663,9 @@ class Function : public UserID, public SymbolContextScope {
/// include addresses belonging to other functions.
AddressRange m_range;

/// The address (entry point) of the function.
Address m_address;

/// The frame base expression for variables that are relative to the frame
/// pointer.
DWARFExpressionList m_frame_base;
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/API/SBBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ bool SBBlock::GetDescription(SBStream &description) {
m_opaque_ptr->CalculateSymbolContext(&sc);
if (sc.function) {
m_opaque_ptr->DumpAddressRanges(
&strm,
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
&strm, sc.function->GetAddress().GetFileAddress());
}
} else
strm.PutCString("No value");
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/API/SBFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ SBInstructionList SBFunction::GetInstructions(SBTarget target,
if (m_opaque_ptr) {
TargetSP target_sp(target.GetSP());
std::unique_lock<std::recursive_mutex> lock;
ModuleSP module_sp(
m_opaque_ptr->GetAddressRange().GetBaseAddress().GetModule());
ModuleSP module_sp(m_opaque_ptr->GetAddress().GetModule());
if (target_sp && module_sp) {
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
const bool force_live_memory = true;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void BreakpointResolver::AddLocation(SearchFilter &filter,
// If the line number is before the prologue end, move it there...
bool skipped_prologue = false;
if (skip_prologue && sc.function) {
Address prologue_addr(sc.function->GetAddressRange().GetBaseAddress());
Address prologue_addr = sc.function->GetAddress();
if (prologue_addr.IsValid() && (line_start == prologue_addr)) {
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
if (prologue_byte_size) {
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/BreakpointResolverName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ BreakpointResolverName::SearchCallback(SearchFilter &filter,
if (!sc.block->GetStartAddress(break_addr))
break_addr.Clear();
} else if (sc.function) {
break_addr = sc.function->GetAddressRange().GetBaseAddress();
break_addr = sc.function->GetAddress();
if (m_skip_prologue && break_addr.IsValid()) {
const uint32_t prologue_byte_size = sc.function->GetPrologueByteSize();
if (prologue_byte_size)
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Core/SearchFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool SearchFilter::FunctionPasses(Function &function) {
// This is a slightly cheesy job, but since we don't have finer grained
// filters yet, just checking that the start address passes is probably
// good enough for the base class behavior.
Address addr = function.GetAddressRange().GetBaseAddress();
Address addr = function.GetAddress();
return AddressPasses(addr);
}

Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Expression/DWARFExpressionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ bool DWARFExpressionList::MatchesOperand(
if (!sc.function)
return false;

addr_t load_function_start =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t load_function_start = sc.function->GetAddress().GetFileAddress();
if (load_function_start == LLDB_INVALID_ADDRESS)
return false;

Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Expression/IRExecutionUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,7 @@ class LoadAddressResolver {

// If that didn't work, try the function.
if (load_address == LLDB_INVALID_ADDRESS && candidate_sc.function) {
Address addr =
candidate_sc.function->GetAddressRange().GetBaseAddress();
Address addr = candidate_sc.function->GetAddress();
load_address = m_target->GetProcessSP() ? addr.GetLoadAddress(m_target)
: addr.GetFileAddress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ lldb::addr_t ArchitectureMips::GetBreakableLoadAddress(lldb::addr_t addr,
resolve_scope, sc);
Address sym_addr;
if (sc.function)
sym_addr = sc.function->GetAddressRange().GetBaseAddress();
sym_addr = sc.function->GetAddress();
else if (sc.symbol)
sym_addr = sc.symbol->GetAddress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,8 @@ bool DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(SymbolContext &sym_ctx) {
if (sym_ctx.symbol) {
module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
}
if (module_sp.get() == nullptr && sym_ctx.function) {
module_sp =
sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
}
if (module_sp.get() == nullptr && sym_ctx.function)
module_sp = sym_ctx.function->GetAddress().GetModule();
if (module_sp.get() == nullptr)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,7 @@ bool DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(
if (sym_ctx.symbol)
module_sp = sym_ctx.symbol->GetAddressRef().GetModule();
if (!module_sp && sym_ctx.function)
module_sp =
sym_ctx.function->GetAddressRange().GetBaseAddress().GetModule();
module_sp = sym_ctx.function->GetAddress().GetModule();
if (!module_sp)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,7 @@ void ClangExpressionDeclMap::AddOneFunction(NameSearchContext &context,
return;
}

fun_address = function->GetAddressRange().GetBaseAddress();
fun_address = function->GetAddress();

CompilerType copied_function_type = GuardedCopyType(function_clang_type);
if (copied_function_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ size_t SymbolFileBreakpad::ParseBlocksRecursive(Function &func) {
blocks.push_back(&func.GetBlock(false));

size_t blocks_added = 0;
addr_t func_base = func.GetAddressRange().GetBaseAddress().GetOffset();
addr_t func_base = func.GetAddress().GetOffset();
CompUnitData &data = m_cu_data->GetEntryRef(comp_unit->GetID()).data;
LineIterator It(*m_objfile_sp, Record::Func, data.bookmark),
End(*m_objfile_sp);
Expand Down Expand Up @@ -396,7 +396,7 @@ SymbolFileBreakpad::ResolveSymbolContext(const Address &so_addr,
Block &block = func_sp->GetBlock(true);
sc.block = block.FindInnermostBlockByOffset(
so_addr.GetFileAddress() -
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
sc.function->GetAddress().GetFileAddress());
if (sc.block)
result |= eSymbolContextBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,7 @@ static void RemoveFunctionsWithModuleNotEqualTo(const ModuleSP &module_sp,
SymbolContext sc;
sc_list.GetContextAtIndex(i, sc);
if (sc.function) {
const SectionSP section_sp(
sc.function->GetAddressRange().GetBaseAddress().GetSection());
const SectionSP section_sp = sc.function->GetAddress().GetSection();
if (section_sp->GetModule() != module_sp) {
sc_list.RemoveContextAtIndex(i);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ Block *SymbolFileNativePDB::CreateBlock(PdbCompilandSymId block_id) {
lldbassert(func);
lldb::addr_t block_base =
m_index->MakeVirtualAddress(block.Segment, block.CodeOffset);
lldb::addr_t func_base =
func->GetAddressRange().GetBaseAddress().GetFileAddress();
lldb::addr_t func_base = func->GetAddress().GetFileAddress();
BlockSP child_block = parent_block->CreateChild(opaque_block_uid);
if (block_base >= func_base)
child_block->AddRange(Block::Range(block_base - func_base, block.CodeSize));
Expand Down Expand Up @@ -1113,8 +1112,7 @@ uint32_t SymbolFileNativePDB::ResolveSymbolContext(
sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get();
if (sc.function) {
Block &block = sc.function->GetBlock(true);
addr_t func_base =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t func_base = sc.function->GetAddress().GetFileAddress();
addr_t offset = file_addr - func_base;
sc.block = block.FindInnermostBlockByOffset(offset);
}
Expand All @@ -1127,8 +1125,7 @@ uint32_t SymbolFileNativePDB::ResolveSymbolContext(
sc.function = block->CalculateSymbolContextFunction();
if (sc.function) {
sc.function->GetBlock(true);
addr_t func_base =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t func_base = sc.function->GetAddress().GetFileAddress();
addr_t offset = file_addr - func_base;
sc.block = block->FindInnermostBlockByOffset(offset);
}
Expand Down Expand Up @@ -1857,8 +1854,7 @@ VariableSP SymbolFileNativePDB::CreateLocalVariable(PdbCompilandSymId scope_id,
// when lookuping local variables in this scope.
if (!var_info.location.IsValid())
var_info.location = DWARFExpressionList(module, DWARFExpression(), nullptr);
var_info.location.SetFuncFileAddress(
func->GetAddressRange().GetBaseAddress().GetFileAddress());
var_info.location.SetFuncFileAddress(func->GetAddress().GetFileAddress());
CompilandIndexItem *cii = m_index->compilands().GetCompiland(var_id.modi);
CompUnitSP comp_unit_sp = GetOrCreateCompileUnit(*cii);
TypeSP type_sp = GetOrCreateType(var_info.type);
Expand Down
14 changes: 6 additions & 8 deletions lldb/source/Symbol/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ void Block::GetDescription(Stream *s, Function *function,

addr_t base_addr = LLDB_INVALID_ADDRESS;
if (target)
base_addr =
function->GetAddressRange().GetBaseAddress().GetLoadAddress(target);
base_addr = function->GetAddress().GetLoadAddress(target);
if (base_addr == LLDB_INVALID_ADDRESS)
base_addr = function->GetAddressRange().GetBaseAddress().GetFileAddress();
base_addr = function->GetAddress().GetFileAddress();

s->Printf(", range%s = ", num_ranges > 1 ? "s" : "");
for (size_t i = 0; i < num_ranges; ++i) {
Expand Down Expand Up @@ -299,7 +298,7 @@ bool Block::GetRangeAtIndex(uint32_t range_idx, AddressRange &range) {
Function *function = CalculateSymbolContextFunction();
if (function) {
const Range &vm_range = m_ranges.GetEntryRef(range_idx);
range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress();
range.GetBaseAddress() = function->GetAddress();
range.GetBaseAddress().Slide(vm_range.GetRangeBase());
range.SetByteSize(vm_range.GetByteSize());
return true;
Expand All @@ -317,7 +316,7 @@ AddressRanges Block::GetRanges() {
ranges.emplace_back();
auto &range = ranges.back();
const Range &vm_range = m_ranges.GetEntryRef(i);
range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress();
range.GetBaseAddress() = function->GetAddress();
range.GetBaseAddress().Slide(vm_range.GetRangeBase());
range.SetByteSize(vm_range.GetByteSize());
}
Expand All @@ -330,7 +329,7 @@ bool Block::GetStartAddress(Address &addr) {

Function *function = CalculateSymbolContextFunction();
if (function) {
addr = function->GetAddressRange().GetBaseAddress();
addr = function->GetAddress();
addr.Slide(m_ranges.GetEntryRef(0).GetRangeBase());
return true;
}
Expand All @@ -349,8 +348,7 @@ void Block::AddRange(const Range &range) {
if (log) {
ModuleSP module_sp(m_parent_scope.CalculateSymbolContextModule());
Function *function = m_parent_scope.CalculateSymbolContextFunction();
const addr_t function_file_addr =
function->GetAddressRange().GetBaseAddress().GetFileAddress();
const addr_t function_file_addr = function->GetAddress().GetFileAddress();
const addr_t block_start_addr = function_file_addr + range.GetRangeBase();
const addr_t block_end_addr = function_file_addr + range.GetRangeEnd();
Type *func_type = function->GetType();
Expand Down
15 changes: 7 additions & 8 deletions lldb/source/Symbol/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ lldb::addr_t CallEdge::GetLoadAddress(lldb::addr_t unresolved_pc,
Function &caller, Target &target) {
Log *log = GetLog(LLDBLog::Step);

const Address &caller_start_addr = caller.GetAddressRange().GetBaseAddress();
const Address &caller_start_addr = caller.GetAddress();

ModuleSP caller_module_sp = caller_start_addr.GetModule();
if (!caller_module_sp) {
Expand Down Expand Up @@ -279,9 +279,10 @@ Function::Function(CompileUnit *comp_unit, lldb::user_id_t func_uid,
AddressRanges ranges)
: UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
m_type(type), m_mangled(mangled), m_block(*this, func_uid),
m_range(CollapseRanges(ranges)), m_prologue_byte_size(0) {
m_range(CollapseRanges(ranges)), m_address(m_range.GetBaseAddress()),
m_prologue_byte_size(0) {
assert(comp_unit != nullptr);
lldb::addr_t base_file_addr = m_range.GetBaseAddress().GetFileAddress();
lldb::addr_t base_file_addr = m_address.GetFileAddress();
for (const AddressRange &range : ranges)
m_block.AddRange(
Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
Expand Down Expand Up @@ -312,8 +313,7 @@ void Function::GetStartLineSourceInfo(SupportFileSP &source_file_sp,
return;

LineEntry line_entry;
if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
line_entry, nullptr)) {
if (line_table->FindLineEntryByAddress(GetAddress(), line_entry, nullptr)) {
line_no = line_entry.line;
source_file_sp = line_entry.file_sp;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ Function *Function::CalculateSymbolContextFunction() { return this; }
lldb::DisassemblerSP Function::GetInstructions(const ExecutionContext &exe_ctx,
const char *flavor,
bool prefer_file_cache) {
ModuleSP module_sp(GetAddressRange().GetBaseAddress().GetModule());
ModuleSP module_sp = GetAddress().GetModule();
if (module_sp && exe_ctx.HasTargetScope()) {
return Disassembler::DisassembleRange(
module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
Expand Down Expand Up @@ -601,8 +601,7 @@ uint32_t Function::GetPrologueByteSize() {
if (line_table) {
LineEntry first_line_entry;
uint32_t first_line_entry_idx = UINT32_MAX;
if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
first_line_entry,
if (line_table->FindLineEntryByAddress(GetAddress(), first_line_entry,
&first_line_entry_idx)) {
// Make sure the first line entry isn't already the end of the prologue
addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
Expand Down
10 changes: 3 additions & 7 deletions lldb/source/Symbol/SymbolContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ bool SymbolContext::DumpStopContext(
if (addr_t file_addr = addr.GetFileAddress();
file_addr != LLDB_INVALID_ADDRESS) {
const addr_t function_offset =
file_addr -
function->GetAddressRange().GetBaseAddress().GetFileAddress();
file_addr - function->GetAddress().GetFileAddress();
if (!show_function_name) {
// Print +offset even if offset is 0
dumped_something = true;
Expand Down Expand Up @@ -700,9 +699,7 @@ LineEntry SymbolContext::GetFunctionStartLineEntry() const {
}

if (function) {
if (function->GetAddressRange()
.GetBaseAddress()
.CalculateSymbolContextLineEntry(line_entry))
if (function->GetAddress().CalculateSymbolContextLineEntry(line_entry))
return line_entry;
}
return LineEntry();
Expand Down Expand Up @@ -1228,8 +1225,7 @@ bool SymbolContextList::AppendIfUnique(const SymbolContext &sc,
continue;

if (pos->function) {
if (pos->function->GetAddressRange().GetBaseAddress() ==
sc.symbol->GetAddressRef()) {
if (pos->function->GetAddress() == sc.symbol->GetAddressRef()) {
// Do we already have a function with this symbol?
if (pos->symbol == sc.symbol)
return false;
Expand Down
8 changes: 3 additions & 5 deletions lldb/source/Symbol/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ bool Variable::LocationIsValidForFrame(StackFrame *frame) {
TargetSP target_sp(frame->CalculateTarget());

addr_t loclist_base_load_addr =
function->GetAddressRange().GetBaseAddress().GetLoadAddress(
target_sp.get());
function->GetAddress().GetLoadAddress(target_sp.get());
if (loclist_base_load_addr == LLDB_INVALID_ADDRESS)
return false;
// It is a location list. We just need to tell if the location list
Expand Down Expand Up @@ -259,7 +258,7 @@ bool Variable::LocationIsValidForAddress(const Address &address) {

if (sc.function) {
addr_t loclist_base_file_addr =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
sc.function->GetAddress().GetFileAddress();
if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
return false;
// It is a location list. We just need to tell if the location list
Expand Down Expand Up @@ -450,8 +449,7 @@ bool Variable::DumpLocations(Stream *s, const Address &address) {

const addr_t file_addr = address.GetFileAddress();
if (sc.function) {
addr_t loclist_base_file_addr =
sc.function->GetAddressRange().GetBaseAddress().GetFileAddress();
addr_t loclist_base_file_addr = sc.function->GetAddress().GetFileAddress();
if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
return false;
return m_location_list.DumpLocations(s, eDescriptionLevelBrief,
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/Target/StackFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,7 @@ llvm::Error StackFrame::GetFrameBaseValue(Scalar &frame_base) {
addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
if (!m_sc.function->GetFrameBaseExpression().IsAlwaysValidSingleExpr())
loclist_base_addr =
m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(
exe_ctx.GetTargetPtr());
m_sc.function->GetAddress().GetLoadAddress(exe_ctx.GetTargetPtr());

llvm::Expected<Value> expr_value =
m_sc.function->GetFrameBaseExpression().Evaluate(
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/ThreadPlanStepInRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ bool ThreadPlanStepInRange::ShouldStop(Event *event_ptr) {
eSymbolContextSymbol);

if (sc.function) {
func_start_address = sc.function->GetAddressRange().GetBaseAddress();
func_start_address = sc.function->GetAddress();
if (curr_addr == func_start_address.GetLoadAddress(&GetTarget()))
bytes_to_skip = sc.function->GetPrologueByteSize();
} else if (sc.symbol) {
Expand Down
3 changes: 1 addition & 2 deletions lldb/source/ValueObject/ValueObjectVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ bool ValueObjectVariable::UpdateValue() {
variable->CalculateSymbolContext(&sc);
if (sc.function)
loclist_base_load_addr =
sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(
target);
sc.function->GetAddress().GetLoadAddress(target);
}
Value old_value(m_value);
llvm::Expected<Value> maybe_value = expr_list.Evaluate(
Expand Down
Loading