diff options
| author | Reid Kleckner <rnk@google.com> | 2015-10-09 00:15:01 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2015-10-09 00:15:01 +0000 |
| commit | e94fef7b3d2efbdbd22098e4ead372033bf731ab (patch) | |
| tree | 61d9953f625179af720486c1f6508f0616d3d1fc /llvm/tools | |
| parent | d837cd044fd21ba182d4af49d3885dcd59a5d6a4 (diff) | |
| download | bcm5719-llvm-e94fef7b3d2efbdbd22098e4ead372033bf731ab.tar.gz bcm5719-llvm-e94fef7b3d2efbdbd22098e4ead372033bf731ab.zip | |
[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
llvm-svn: 249784
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp | 20 | ||||
| -rw-r--r-- | llvm/tools/llvm-symbolizer/LLVMSymbolize.h | 4 |
2 files changed, 22 insertions, 2 deletions
diff --git a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp index 497207ed4ca..cbfbdda08c9 100644 --- a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/llvm/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/llvm/tools/llvm-symbolizer/LLVMSymbolize.h b/llvm/tools/llvm-symbolizer/LLVMSymbolize.h index b52c76036e1..00a3860eacb 100644 --- a/llvm/tools/llvm-symbolizer/LLVMSymbolize.h +++ b/llvm/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, |

