mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
[lldb] Add SymbolContext::GetFunctionOrSymbolAddress (#123340)
Many uses of SC::GetAddressRange were not interested in the range, but in the address of the function/symbol contained inside the symbol context. They were getting that by calling the GetBaseAddress on the returned range, which worked well enough so far, but isn't compatible with discontinuous functions, whose address (entry point) may not be the lowest address in the range. To resolve this problem, this PR creates a new function whose purpose is return the address of the function or symbol inside the symbol context. It also changes all of the callers of GetAddressRange which do not actually care about the range to call this function instead.
This commit is contained in:
@@ -165,8 +165,8 @@ public:
|
||||
/// eSymbolContextSymbol is set in \a scope
|
||||
///
|
||||
/// \param[in] scope
|
||||
/// A mask of symbol context bits telling this function which
|
||||
/// address ranges it can use when trying to extract one from
|
||||
/// A mask bits from the \b SymbolContextItem enum telling this function
|
||||
/// which address ranges it can use when trying to extract one from
|
||||
/// the valid (non-nullptr) symbol context classes.
|
||||
///
|
||||
/// \param[in] range_idx
|
||||
@@ -192,6 +192,13 @@ public:
|
||||
bool GetAddressRange(uint32_t scope, uint32_t range_idx,
|
||||
bool use_inline_block_range, AddressRange &range) const;
|
||||
|
||||
/// Get the address of the function or symbol represented by this symbol
|
||||
/// context.
|
||||
///
|
||||
/// If both fields are present, the address of the function is returned. If
|
||||
/// both are empty, the result is an invalid address.
|
||||
Address GetFunctionOrSymbolAddress() const;
|
||||
|
||||
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line,
|
||||
AddressRange &range);
|
||||
|
||||
|
||||
@@ -1621,12 +1621,15 @@ static void DumpSymbolContextList(
|
||||
if (!first_module)
|
||||
strm.EOL();
|
||||
|
||||
AddressRange range;
|
||||
Address addr;
|
||||
if (sc.line_entry.IsValid())
|
||||
addr = sc.line_entry.range.GetBaseAddress();
|
||||
else if (sc.block && sc.block->GetContainingInlinedBlock())
|
||||
sc.block->GetContainingInlinedBlock()->GetStartAddress(addr);
|
||||
else
|
||||
addr = sc.GetFunctionOrSymbolAddress();
|
||||
|
||||
sc.GetAddressRange(eSymbolContextEverything, 0, true, range);
|
||||
|
||||
DumpAddress(exe_scope, range.GetBaseAddress(), verbose, all_ranges, strm,
|
||||
settings);
|
||||
DumpAddress(exe_scope, addr, verbose, all_ranges, strm, settings);
|
||||
first_module = false;
|
||||
}
|
||||
strm.IndentLess();
|
||||
@@ -3570,16 +3573,13 @@ protected:
|
||||
continue;
|
||||
if (!sc.module_sp || sc.module_sp->GetObjectFile() == nullptr)
|
||||
continue;
|
||||
AddressRange range;
|
||||
if (!sc.GetAddressRange(eSymbolContextFunction | eSymbolContextSymbol, 0,
|
||||
false, range))
|
||||
continue;
|
||||
if (!range.GetBaseAddress().IsValid())
|
||||
Address addr = sc.GetFunctionOrSymbolAddress();
|
||||
if (!addr.IsValid())
|
||||
continue;
|
||||
ConstString funcname(sc.GetFunctionName());
|
||||
if (funcname.IsEmpty())
|
||||
continue;
|
||||
addr_t start_addr = range.GetBaseAddress().GetLoadAddress(target);
|
||||
addr_t start_addr = addr.GetLoadAddress(target);
|
||||
if (abi)
|
||||
start_addr = abi->FixCodeAddress(start_addr);
|
||||
|
||||
|
||||
@@ -426,9 +426,7 @@ DynamicLoaderHexagonDYLD::GetStepThroughTrampolinePlan(Thread &thread,
|
||||
typedef std::vector<lldb::addr_t> AddressVector;
|
||||
AddressVector addrs;
|
||||
for (const SymbolContext &context : target_symbols) {
|
||||
AddressRange range;
|
||||
context.GetAddressRange(eSymbolContextEverything, 0, false, range);
|
||||
lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
|
||||
addr_t addr = context.GetFunctionOrSymbolAddress().GetLoadAddress(&target);
|
||||
if (addr != LLDB_INVALID_ADDRESS)
|
||||
addrs.push_back(addr);
|
||||
}
|
||||
|
||||
@@ -939,13 +939,10 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
|
||||
images.FindSymbolsWithNameAndType(trampoline_name, eSymbolTypeCode,
|
||||
code_symbols);
|
||||
for (const SymbolContext &context : code_symbols) {
|
||||
AddressRange addr_range;
|
||||
context.GetAddressRange(eSymbolContextEverything, 0, false,
|
||||
addr_range);
|
||||
addresses.push_back(addr_range.GetBaseAddress());
|
||||
Address addr = context.GetFunctionOrSymbolAddress();
|
||||
addresses.push_back(addr);
|
||||
if (log) {
|
||||
addr_t load_addr =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
|
||||
addr_t load_addr = addr.GetLoadAddress(target_sp.get());
|
||||
|
||||
LLDB_LOGF(log, "Found a trampoline target symbol at 0x%" PRIx64 ".",
|
||||
load_addr);
|
||||
@@ -980,13 +977,10 @@ DynamicLoaderDarwin::GetStepThroughTrampolinePlan(Thread &thread,
|
||||
indirect_symbols);
|
||||
|
||||
for (const SymbolContext &context : indirect_symbols) {
|
||||
AddressRange addr_range;
|
||||
context.GetAddressRange(eSymbolContextEverything, 0, false,
|
||||
addr_range);
|
||||
addresses.push_back(addr_range.GetBaseAddress());
|
||||
Address addr = context.GetFunctionOrSymbolAddress();
|
||||
addresses.push_back(addr);
|
||||
if (log) {
|
||||
addr_t load_addr =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(target_sp.get());
|
||||
addr_t load_addr = addr.GetLoadAddress(target_sp.get());
|
||||
|
||||
LLDB_LOGF(log, "Found an indirect target symbol at 0x%" PRIx64 ".",
|
||||
load_addr);
|
||||
|
||||
@@ -512,9 +512,7 @@ DynamicLoaderPOSIXDYLD::GetStepThroughTrampolinePlan(Thread &thread,
|
||||
typedef std::vector<lldb::addr_t> AddressVector;
|
||||
AddressVector addrs;
|
||||
for (const SymbolContext &context : target_symbols) {
|
||||
AddressRange range;
|
||||
context.GetAddressRange(eSymbolContextEverything, 0, false, range);
|
||||
lldb::addr_t addr = range.GetBaseAddress().GetLoadAddress(&target);
|
||||
addr_t addr = context.GetFunctionOrSymbolAddress().GetLoadAddress(&target);
|
||||
if (addr != LLDB_INVALID_ADDRESS)
|
||||
addrs.push_back(addr);
|
||||
}
|
||||
|
||||
@@ -142,10 +142,7 @@ line_entry_helper(Target &target, const SymbolContext &sc, Symbol *symbol,
|
||||
|
||||
CPPLanguageRuntime::LibCppStdFunctionCallableInfo optional_info;
|
||||
|
||||
AddressRange range;
|
||||
sc.GetAddressRange(eSymbolContextEverything, 0, false, range);
|
||||
|
||||
Address address = range.GetBaseAddress();
|
||||
Address address = sc.GetFunctionOrSymbolAddress();
|
||||
|
||||
Address addr;
|
||||
if (target.ResolveLoadAddress(address.GetCallableLoadAddress(&target),
|
||||
|
||||
@@ -52,9 +52,6 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
|
||||
if (count > 0) {
|
||||
SymbolContext sc;
|
||||
if (sc_list.GetContextAtIndex(0, sc)) {
|
||||
const uint32_t range_scope =
|
||||
eSymbolContextFunction | eSymbolContextSymbol;
|
||||
const bool use_inline_block_range = false;
|
||||
EvaluateExpressionOptions options;
|
||||
options.SetStopOthers(true);
|
||||
options.SetUnwindOnError(true);
|
||||
@@ -77,9 +74,8 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
|
||||
prot_arg |= PROT_WRITE;
|
||||
}
|
||||
|
||||
AddressRange mmap_range;
|
||||
if (sc.GetAddressRange(range_scope, 0, use_inline_block_range,
|
||||
mmap_range)) {
|
||||
Address mmap_addr = sc.GetFunctionOrSymbolAddress();
|
||||
if (mmap_addr.IsValid()) {
|
||||
auto type_system_or_err =
|
||||
process->GetTarget().GetScratchTypeSystemForLanguage(
|
||||
eLanguageTypeC);
|
||||
@@ -96,9 +92,8 @@ bool lldb_private::InferiorCallMmap(Process *process, addr_t &allocated_addr,
|
||||
MmapArgList args =
|
||||
process->GetTarget().GetPlatform()->GetMmapArgumentList(
|
||||
arch, addr, length, prot_arg, flags, fd, offset);
|
||||
lldb::ThreadPlanSP call_plan_sp(
|
||||
new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(),
|
||||
void_ptr_type, args, options));
|
||||
lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallFunction(
|
||||
*thread, mmap_addr, void_ptr_type, args, options));
|
||||
if (call_plan_sp) {
|
||||
DiagnosticManager diagnostics;
|
||||
|
||||
@@ -149,9 +144,6 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
|
||||
if (count > 0) {
|
||||
SymbolContext sc;
|
||||
if (sc_list.GetContextAtIndex(0, sc)) {
|
||||
const uint32_t range_scope =
|
||||
eSymbolContextFunction | eSymbolContextSymbol;
|
||||
const bool use_inline_block_range = false;
|
||||
EvaluateExpressionOptions options;
|
||||
options.SetStopOthers(true);
|
||||
options.SetUnwindOnError(true);
|
||||
@@ -161,13 +153,11 @@ bool lldb_private::InferiorCallMunmap(Process *process, addr_t addr,
|
||||
options.SetTimeout(process->GetUtilityExpressionTimeout());
|
||||
options.SetTrapExceptions(false);
|
||||
|
||||
AddressRange munmap_range;
|
||||
if (sc.GetAddressRange(range_scope, 0, use_inline_block_range,
|
||||
munmap_range)) {
|
||||
Address munmap_addr = sc.GetFunctionOrSymbolAddress();
|
||||
if (munmap_addr.IsValid()) {
|
||||
lldb::addr_t args[] = {addr, length};
|
||||
lldb::ThreadPlanSP call_plan_sp(
|
||||
new ThreadPlanCallFunction(*thread, munmap_range.GetBaseAddress(),
|
||||
CompilerType(), args, options));
|
||||
lldb::ThreadPlanSP call_plan_sp(new ThreadPlanCallFunction(
|
||||
*thread, munmap_addr, CompilerType(), args, options));
|
||||
if (call_plan_sp) {
|
||||
DiagnosticManager diagnostics;
|
||||
|
||||
|
||||
@@ -632,10 +632,8 @@ bool SystemRuntimeMacOSX::BacktraceRecordingHeadersInitialized() {
|
||||
if (!sc_list.IsEmpty()) {
|
||||
SymbolContext sc;
|
||||
sc_list.GetContextAtIndex(0, sc);
|
||||
AddressRange addr_range;
|
||||
sc.GetAddressRange(eSymbolContextSymbol, 0, false, addr_range);
|
||||
queue_info_version_address =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(&target);
|
||||
Address addr = sc.GetFunctionOrSymbolAddress();
|
||||
queue_info_version_address = addr.GetLoadAddress(&target);
|
||||
}
|
||||
sc_list.Clear();
|
||||
|
||||
@@ -646,10 +644,8 @@ bool SystemRuntimeMacOSX::BacktraceRecordingHeadersInitialized() {
|
||||
if (!sc_list.IsEmpty()) {
|
||||
SymbolContext sc;
|
||||
sc_list.GetContextAtIndex(0, sc);
|
||||
AddressRange addr_range;
|
||||
sc.GetAddressRange(eSymbolContextSymbol, 0, false, addr_range);
|
||||
queue_info_data_offset_address =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(&target);
|
||||
Address addr = sc.GetFunctionOrSymbolAddress();
|
||||
queue_info_data_offset_address = addr.GetLoadAddress(&target);
|
||||
}
|
||||
sc_list.Clear();
|
||||
|
||||
@@ -660,10 +656,8 @@ bool SystemRuntimeMacOSX::BacktraceRecordingHeadersInitialized() {
|
||||
if (!sc_list.IsEmpty()) {
|
||||
SymbolContext sc;
|
||||
sc_list.GetContextAtIndex(0, sc);
|
||||
AddressRange addr_range;
|
||||
sc.GetAddressRange(eSymbolContextSymbol, 0, false, addr_range);
|
||||
item_info_version_address =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(&target);
|
||||
Address addr = sc.GetFunctionOrSymbolAddress();
|
||||
item_info_version_address = addr.GetLoadAddress(&target);
|
||||
}
|
||||
sc_list.Clear();
|
||||
|
||||
@@ -674,10 +668,8 @@ bool SystemRuntimeMacOSX::BacktraceRecordingHeadersInitialized() {
|
||||
if (!sc_list.IsEmpty()) {
|
||||
SymbolContext sc;
|
||||
sc_list.GetContextAtIndex(0, sc);
|
||||
AddressRange addr_range;
|
||||
sc.GetAddressRange(eSymbolContextSymbol, 0, false, addr_range);
|
||||
item_info_data_offset_address =
|
||||
addr_range.GetBaseAddress().GetLoadAddress(&target);
|
||||
Address addr = sc.GetFunctionOrSymbolAddress();
|
||||
item_info_data_offset_address = addr.GetLoadAddress(&target);
|
||||
}
|
||||
|
||||
if (queue_info_version_address != LLDB_INVALID_ADDRESS &&
|
||||
|
||||
@@ -370,6 +370,16 @@ bool SymbolContext::GetAddressRange(uint32_t scope, uint32_t range_idx,
|
||||
return false;
|
||||
}
|
||||
|
||||
Address SymbolContext::GetFunctionOrSymbolAddress() const {
|
||||
if (function)
|
||||
return function->GetAddress();
|
||||
|
||||
if (symbol)
|
||||
return symbol->GetAddress();
|
||||
|
||||
return Address();
|
||||
}
|
||||
|
||||
LanguageType SymbolContext::GetLanguage() const {
|
||||
LanguageType lang;
|
||||
if (function && (lang = function->GetLanguage()) != eLanguageTypeUnknown) {
|
||||
|
||||
Reference in New Issue
Block a user