OSDN Git Service

Let the users of LLVMSymbolizer decide whether they want to symbolize inlined frames.
authorAlexey Samsonov <vonosmas@gmail.com>
Fri, 30 Oct 2015 00:40:20 +0000 (00:40 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Fri, 30 Oct 2015 00:40:20 +0000 (00:40 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251675 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/Symbolize/Symbolize.h
lib/DebugInfo/Symbolize/Symbolize.cpp
tools/llvm-symbolizer/llvm-symbolizer.cpp

index 98e0b19..9574a48 100644 (file)
@@ -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;
 
index 87f76ed..2e6f604 100644 (file)
@@ -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) {
@@ -375,6 +379,20 @@ LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
 }
 
 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 {
   std::stringstream Result;
index 5784e6b..b75f1bc 100644 (file)
@@ -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);