forked from OSchip/llvm-project
Let the users of LLVMSymbolizer decide whether they want to symbolize inlined frames.
Introduce LLVMSymbolizer::symbolizeInlinedCode() instead of switching on PrintInlining option passed to the constructor. This will be needed once we retrun structured data (instead of std::string) from LLVMSymbolizer and move printing logic out. llvm-svn: 251675
This commit is contained in:
parent
e31e67719c
commit
46c1ce6ff5
|
@ -34,18 +34,16 @@ public:
|
|||
struct Options {
|
||||
FunctionNameKind PrintFunctions;
|
||||
bool UseSymbolTable : 1;
|
||||
bool PrintInlining : 1;
|
||||
bool Demangle : 1;
|
||||
bool RelativeAddresses : 1;
|
||||
std::string DefaultArch;
|
||||
std::vector<std::string> DsymHints;
|
||||
Options(FunctionNameKind PrintFunctions = FunctionNameKind::LinkageName,
|
||||
bool UseSymbolTable = true, bool PrintInlining = true,
|
||||
bool Demangle = true, bool RelativeAddresses = false,
|
||||
std::string DefaultArch = "")
|
||||
bool UseSymbolTable = true, bool Demangle = true,
|
||||
bool RelativeAddresses = false, std::string DefaultArch = "")
|
||||
: PrintFunctions(PrintFunctions), UseSymbolTable(UseSymbolTable),
|
||||
PrintInlining(PrintInlining), Demangle(Demangle),
|
||||
RelativeAddresses(RelativeAddresses), DefaultArch(DefaultArch) {}
|
||||
Demangle(Demangle), RelativeAddresses(RelativeAddresses),
|
||||
DefaultArch(DefaultArch) {}
|
||||
};
|
||||
|
||||
LLVMSymbolizer(const Options &Opts = Options()) : Opts(Opts) {}
|
||||
|
@ -57,6 +55,8 @@ public:
|
|||
// a string (possibly containing newlines).
|
||||
std::string
|
||||
symbolizeCode(const std::string &ModuleName, uint64_t ModuleOffset);
|
||||
std::string symbolizeInlinedCode(const std::string &ModuleName,
|
||||
uint64_t ModuleOffset);
|
||||
std::string
|
||||
symbolizeData(const std::string &ModuleName, uint64_t ModuleOffset);
|
||||
void flush();
|
||||
|
@ -80,6 +80,8 @@ private:
|
|||
|
||||
std::string printDILineInfo(DILineInfo LineInfo,
|
||||
const SymbolizableModule *ModInfo) const;
|
||||
std::string printDIInliningInfo(DIInliningInfo InlinedContext,
|
||||
const SymbolizableModule *ModInfo) const;
|
||||
std::string printDIGlobal(DIGlobal Global,
|
||||
const SymbolizableModule *ModInfo) const;
|
||||
|
||||
|
|
|
@ -73,23 +73,27 @@ std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
|
|||
if (Opts.RelativeAddresses)
|
||||
ModuleOffset += Info->getModulePreferredBase();
|
||||
|
||||
if (Opts.PrintInlining) {
|
||||
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
|
||||
ModuleOffset, Opts.PrintFunctions, Opts.UseSymbolTable);
|
||||
uint32_t FramesNum = InlinedContext.getNumberOfFrames();
|
||||
assert(FramesNum > 0);
|
||||
std::string Result;
|
||||
for (uint32_t i = 0; i < FramesNum; i++) {
|
||||
DILineInfo LineInfo = InlinedContext.getFrame(i);
|
||||
Result += printDILineInfo(LineInfo, Info);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
DILineInfo LineInfo = Info->symbolizeCode(ModuleOffset, Opts.PrintFunctions,
|
||||
Opts.UseSymbolTable);
|
||||
return printDILineInfo(LineInfo, Info);
|
||||
}
|
||||
|
||||
std::string LLVMSymbolizer::symbolizeInlinedCode(const std::string &ModuleName,
|
||||
uint64_t ModuleOffset) {
|
||||
SymbolizableModule *Info = getOrCreateModuleInfo(ModuleName);
|
||||
if (!Info)
|
||||
return printDIInliningInfo(DIInliningInfo(), nullptr);
|
||||
|
||||
// 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();
|
||||
|
||||
DIInliningInfo InlinedContext = Info->symbolizeInlinedCode(
|
||||
ModuleOffset, Opts.PrintFunctions, Opts.UseSymbolTable);
|
||||
return printDIInliningInfo(InlinedContext, Info);
|
||||
}
|
||||
|
||||
std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
|
||||
uint64_t ModuleOffset) {
|
||||
if (Opts.UseSymbolTable) {
|
||||
|
@ -374,6 +378,20 @@ LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
|
|||
return Result.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
LLVMSymbolizer::printDIInliningInfo(DIInliningInfo InlinedContext,
|
||||
const SymbolizableModule *ModInfo) const {
|
||||
uint32_t FramesNum = InlinedContext.getNumberOfFrames();
|
||||
if (FramesNum == 0)
|
||||
return printDILineInfo(DILineInfo(), ModInfo);
|
||||
std::string Result;
|
||||
for (uint32_t i = 0; i < FramesNum; i++) {
|
||||
DILineInfo LineInfo = InlinedContext.getFrame(i);
|
||||
Result += printDILineInfo(LineInfo, ModInfo);
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
std::string
|
||||
LLVMSymbolizer::printDIGlobal(DIGlobal Global,
|
||||
const SymbolizableModule *ModInfo) const {
|
||||
|
|
|
@ -133,8 +133,7 @@ int main(int argc, char **argv) {
|
|||
llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
|
||||
|
||||
cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n");
|
||||
LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable,
|
||||
ClPrintInlining, ClDemangle,
|
||||
LLVMSymbolizer::Options Opts(ClPrintFunctions, ClUseSymbolTable, ClDemangle,
|
||||
ClUseRelativeAddress, ClDefaultArch);
|
||||
for (const auto &hint : ClDsymHint) {
|
||||
if (sys::path::extension(hint) == ".dSYM") {
|
||||
|
@ -152,7 +151,9 @@ int main(int argc, char **argv) {
|
|||
while (parseCommand(IsData, ModuleName, ModuleOffset)) {
|
||||
std::string Result =
|
||||
IsData ? Symbolizer.symbolizeData(ModuleName, ModuleOffset)
|
||||
: Symbolizer.symbolizeCode(ModuleName, ModuleOffset);
|
||||
: ClPrintInlining
|
||||
? Symbolizer.symbolizeInlinedCode(ModuleName, ModuleOffset)
|
||||
: Symbolizer.symbolizeCode(ModuleName, ModuleOffset);
|
||||
if (ClPrintAddress) {
|
||||
outs() << "0x";
|
||||
outs().write_hex(ModuleOffset);
|
||||
|
|
Loading…
Reference in New Issue