aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-symbolizer
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-10-09 00:15:01 +0000
committerReid Kleckner <rnk@google.com>2015-10-09 00:15:01 +0000
commit27a9e1dbcf5d0fdf2457c10fecd089a8c02cdec5 (patch)
treeb899e2bbb7645d6f2a6a7d135bd71558733d3654 /tools/llvm-symbolizer
parent4100fc009b56a849ea878b6e0375caa5992ba91b (diff)
[llvm-symbolizer] Make --relative-address work with DWARF contexts
Summary: Previously the relative address flag only affected PDB debug info. Now both DIContext implementations always expect to be passed virtual addresses. llvm-symbolizer is now responsible for adding ImageBase to module offsets when --relative-offset is passed. Reviewers: zturner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12883 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249784 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-symbolizer')
-rw-r--r--tools/llvm-symbolizer/LLVMSymbolize.cpp20
-rw-r--r--tools/llvm-symbolizer/LLVMSymbolize.h4
2 files changed, 22 insertions, 2 deletions
diff --git a/tools/llvm-symbolizer/LLVMSymbolize.cpp b/tools/llvm-symbolizer/LLVMSymbolize.cpp
index 497207ed4ca..cbfbdda08c9 100644
--- a/tools/llvm-symbolizer/LLVMSymbolize.cpp
+++ b/tools/llvm-symbolizer/LLVMSymbolize.cpp
@@ -126,6 +126,13 @@ bool ModuleInfo::isWin32Module() const {
return CoffObject && CoffObject->getMachine() == COFF::IMAGE_FILE_MACHINE_I386;
}
+uint64_t ModuleInfo::getModulePreferredBase() const {
+ if (auto *CoffObject = dyn_cast<COFFObjectFile>(Module))
+ if (auto Base = CoffObject->getImageBase())
+ return Base.get();
+ return 0;
+}
+
bool ModuleInfo::getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
std::string &Name, uint64_t &Addr,
uint64_t &Size) const {
@@ -210,6 +217,12 @@ std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
ModuleInfo *Info = getOrCreateModuleInfo(ModuleName);
if (!Info)
return printDILineInfo(DILineInfo(), Info);
+
+ // If the user is giving us relative addresses, add the preferred base of the
+ // object to the offset before we do the query. It's what DIContext expects.
+ if (Opts.RelativeAddresses)
+ ModuleOffset += Info->getModulePreferredBase();
+
if (Opts.PrintInlining) {
DIInliningInfo InlinedContext =
Info->symbolizeInlinedCode(ModuleOffset, Opts);
@@ -233,6 +246,10 @@ std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
uint64_t Size = 0;
if (Opts.UseSymbolTable) {
if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) {
+ // If the user is giving us relative addresses, add the preferred base of the
+ // object to the offset before we do the query. It's what DIContext expects.
+ if (Opts.RelativeAddresses)
+ ModuleOffset += Info->getModulePreferredBase();
if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
Name = DemangleName(Name, Info);
}
@@ -474,8 +491,7 @@ LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
PDB_ErrorCode Error = loadDataForEXE(PDB_ReaderType::DIA,
Objects.first->getFileName(), Session);
if (Error == PDB_ErrorCode::Success) {
- Context = new PDBContext(*CoffObject, std::move(Session),
- Opts.RelativeAddresses);
+ Context = new PDBContext(*CoffObject, std::move(Session));
}
}
if (!Context)
diff --git a/tools/llvm-symbolizer/LLVMSymbolize.h b/tools/llvm-symbolizer/LLVMSymbolize.h
index b52c76036e1..00a3860eacb 100644
--- a/tools/llvm-symbolizer/LLVMSymbolize.h
+++ b/tools/llvm-symbolizer/LLVMSymbolize.h
@@ -117,6 +117,10 @@ public:
// Return true if this is a 32-bit x86 PE COFF module.
bool isWin32Module() const;
+ // Returns the preferred base of the module, i.e. where the loader would place
+ // it in memory assuming there were no conflicts.
+ uint64_t getModulePreferredBase() const;
+
private:
bool getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
std::string &Name, uint64_t &Addr,