[llvm] r356829 - [DebugInfo] follow up for "add SectionedAddress to DebugInfo interfaces"
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 23 01:08:40 PDT 2019
Author: avl
Date: Sat Mar 23 01:08:40 2019
New Revision: 356829
URL: http://llvm.org/viewvc/llvm-project?rev=356829&view=rev
Log:
[DebugInfo] follow up for "add SectionedAddress to DebugInfo interfaces"
[Symbolizer] Add getModuleSectionIndexForAddress() helper routine
The https://reviews.llvm.org/D58194 patch changed symbolizer interface.
Particularily it requires not only Address but SectionIndex also.
Note object::SectionedAddress parameter:
Expected<DILineInfo> symbolizeCode(const std::string &ModuleName,
object::SectionedAddress ModuleOffset,
StringRef DWPName = "");
There are callers of symbolizer which do not know particular section index.
That patch creates getModuleSectionIndexForAddress() routine which
will detect section index for the specified address. Thus if caller
set ModuleOffset.SectionIndex into object::SectionedAddress::UndefSection
state then symbolizer would detect section index using
getModuleSectionIndexForAddress routine.
Differential Revision: https://reviews.llvm.org/D58848
Modified:
llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h
llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
Modified: llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp?rev=356829&r1=356828&r2=356829&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp Sat Mar 23 01:08:40 2019
@@ -227,6 +227,11 @@ SymbolizableObjectFile::symbolizeCode(ob
FunctionNameKind FNKind,
bool UseSymbolTable) const {
DILineInfo LineInfo;
+
+ if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
+ ModuleOffset.SectionIndex =
+ getModuleSectionIndexForAddress(ModuleOffset.Address);
+
if (DebugInfoContext) {
LineInfo = DebugInfoContext->getLineInfoForAddress(
ModuleOffset, getDILineInfoSpecifier(FNKind));
@@ -248,6 +253,10 @@ DIInliningInfo SymbolizableObjectFile::s
bool UseSymbolTable) const {
DIInliningInfo InlinedContext;
+ if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection)
+ ModuleOffset.SectionIndex =
+ getModuleSectionIndexForAddress(ModuleOffset.Address);
+
if (DebugInfoContext)
InlinedContext = DebugInfoContext->getInliningInfoForAddress(
ModuleOffset, getDILineInfoSpecifier(FNKind));
@@ -276,3 +285,20 @@ DIGlobal SymbolizableObjectFile::symboli
Res.Start, Res.Size);
return Res;
}
+
+/// Search for the first occurence of specified Address in ObjectFile.
+uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress(
+ uint64_t Address) const {
+
+ for (SectionRef Sec : Module->sections()) {
+ if (!Sec.isText() || Sec.isVirtual())
+ continue;
+
+ if (Address >= Sec.getAddress() &&
+ Address <= Sec.getAddress() + Sec.getSize()) {
+ return Sec.getIndex();
+ }
+ }
+
+ return object::SectionedAddress::UndefSection;
+}
Modified: llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h?rev=356829&r1=356828&r2=356829&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h Sat Mar 23 01:08:40 2019
@@ -63,6 +63,9 @@ private:
uint64_t OpdAddress = 0);
std::error_code addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
+ /// Search for the first occurence of specified Address in ObjectFile.
+ uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
+
object::ObjectFile *Module;
std::unique_ptr<DIContext> DebugInfoContext;
Modified: llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp?rev=356829&r1=356828&r2=356829&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp Sat Mar 23 01:08:40 2019
@@ -194,48 +194,6 @@ static bool parseCommand(StringRef Input
return !StringRef(pos, offset_length).getAsInteger(0, ModuleOffset);
}
-// This routine returns section index for an address.
-// Assumption: would work ambiguously for object files which have sections not
-// assigned to an address(since the same address could belong to various
-// sections).
-static uint64_t getModuleSectionIndexForAddress(const std::string &ModuleName,
- uint64_t Address) {
-
- // following ModuleName processing was copied from
- // LLVMSymbolizer::getOrCreateModuleInfo().
- // it needs to be refactored to avoid code duplication.
- std::string BinaryName = ModuleName;
- size_t ColonPos = ModuleName.find_last_of(':');
- // Verify that substring after colon form a valid arch name.
- if (ColonPos != std::string::npos) {
- std::string ArchStr = ModuleName.substr(ColonPos + 1);
- if (Triple(ArchStr).getArch() != Triple::UnknownArch) {
- BinaryName = ModuleName.substr(0, ColonPos);
- }
- }
-
- Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(BinaryName);
-
- if (error(BinaryOrErr))
- return object::SectionedAddress::UndefSection;
-
- Binary &Binary = *BinaryOrErr->getBinary();
-
- if (ObjectFile *O = dyn_cast<ObjectFile>(&Binary)) {
- for (SectionRef Sec : O->sections()) {
- if (!Sec.isText() || Sec.isVirtual())
- continue;
-
- if (Address >= Sec.getAddress() &&
- Address <= Sec.getAddress() + Sec.getSize()) {
- return Sec.getIndex();
- }
- }
- }
-
- return object::SectionedAddress::UndefSection;
-}
-
static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer,
DIPrinter &Printer) {
bool IsData = false;
@@ -253,18 +211,19 @@ static void symbolizeInput(StringRef Inp
outs() << Delimiter;
}
Offset -= ClAdjustVMA;
- object::SectionedAddress ModuleOffset = {
- Offset, getModuleSectionIndexForAddress(ModuleName, Offset)};
if (IsData) {
- auto ResOrErr = Symbolizer.symbolizeData(ModuleName, ModuleOffset);
+ auto ResOrErr = Symbolizer.symbolizeData(
+ ModuleName, {Offset, object::SectionedAddress::UndefSection});
Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get());
} else if (ClPrintInlining) {
- auto ResOrErr =
- Symbolizer.symbolizeInlinedCode(ModuleName, ModuleOffset, ClDwpName);
+ auto ResOrErr = Symbolizer.symbolizeInlinedCode(
+ ModuleName, {Offset, object::SectionedAddress::UndefSection},
+ ClDwpName);
Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get());
} else {
- auto ResOrErr =
- Symbolizer.symbolizeCode(ModuleName, ModuleOffset, ClDwpName);
+ auto ResOrErr = Symbolizer.symbolizeCode(
+ ModuleName, {Offset, object::SectionedAddress::UndefSection},
+ ClDwpName);
Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get());
}
outs() << "\n";
More information about the llvm-commits
mailing list