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) {}
// 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();
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;
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) {
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 {
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") {
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);