[lldb] Add Function::GetAddress and redirect some uses (#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.
This commit is contained in:
parent
86b1b0671c
commit
66a88f62cd
@ -449,6 +449,11 @@ public:
|
||||
|
||||
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
|
||||
@ -658,6 +663,9 @@ protected:
|
||||
/// 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;
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -731,8 +731,7 @@ public:
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
|
@ -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) {
|
||||
@ -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;
|
||||
@ -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());
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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();
|
||||
|
@ -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) {
|
||||
@ -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,
|
||||
@ -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;
|
||||
}
|
||||
@ -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,
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
@ -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();
|
||||
@ -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;
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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,
|
||||
|
@ -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(
|
||||
|
@ -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) {
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user