[llvm] r251669 - [LLVMSymbolize] Move printing the description of a global into a separate function. NFC.

Alexey Samsonov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 29 16:49:20 PDT 2015


Author: samsonov
Date: Thu Oct 29 18:49:19 2015
New Revision: 251669

URL: http://llvm.org/viewvc/llvm-project?rev=251669&view=rev
Log:
[LLVMSymbolize] Move printing the description of a global into a separate function. NFC.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DIContext.h
    llvm/trunk/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h
    llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
    llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
    llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h
    llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Thu Oct 29 18:49:19 2015
@@ -65,6 +65,15 @@ class DIInliningInfo {
   }
 };
 
+/// DIGlobal - container for description of a global variable.
+struct DIGlobal {
+  std::string Name;
+  uint64_t Start;
+  uint64_t Size;
+
+  DIGlobal() : Name("<invalid>"), Start(0), Size(0) {}
+};
+
 /// A DINameKind is passed to name search methods to specify a
 /// preference regarding the type of name resolution the caller wants.
 enum class DINameKind { None, ShortName, LinkageName };

Modified: llvm/trunk/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h Thu Oct 29 18:49:19 2015
@@ -37,8 +37,7 @@ public:
   virtual DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
                                               FunctionNameKind FNKind,
                                               bool UseSymbolTable) const = 0;
-  virtual bool symbolizeData(uint64_t ModuleOffset, std::string &Name,
-                             uint64_t &Start, uint64_t &Size) const = 0;
+  virtual DIGlobal symbolizeData(uint64_t ModuleOffset) const = 0;
 
   // Return true if this is a 32-bit x86 PE COFF module.
   virtual bool isWin32Module() const = 0;

Modified: llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/Symbolize/Symbolize.h Thu Oct 29 18:49:19 2015
@@ -80,6 +80,8 @@ private:
 
   std::string printDILineInfo(DILineInfo LineInfo,
                               const SymbolizableModule *ModInfo) const;
+  std::string printDIGlobal(DIGlobal Global,
+                            const SymbolizableModule *ModInfo) const;
 
   // Owns all the parsed binaries and object files.
   SmallVector<std::unique_ptr<Binary>, 4> ParsedBinariesAndObjects;

Modified: llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp Thu Oct 29 18:49:19 2015
@@ -239,11 +239,11 @@ DIInliningInfo SymbolizableObjectFile::s
   return PatchedInlinedContext;
 }
 
-bool SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset,
-                                           std::string &Name, uint64_t &Start,
-                                           uint64_t &Size) const {
-  return getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset, Name, Start,
-                                Size);
+DIGlobal SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset) const {
+  DIGlobal Res;
+  getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset, Res.Name, Res.Start,
+                         Res.Size);
+  return Res;
 }
 
 }  // namespace symbolize

Modified: llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h Thu Oct 29 18:49:19 2015
@@ -33,8 +33,7 @@ public:
   DIInliningInfo symbolizeInlinedCode(uint64_t ModuleOffset,
                                       FunctionNameKind FNKind,
                                       bool UseSymbolTable) const override;
-  bool symbolizeData(uint64_t ModuleOffset, std::string &Name, uint64_t &Start,
-                     uint64_t &Size) const override;
+  DIGlobal symbolizeData(uint64_t ModuleOffset) const override;
 
   // Return true if this is a 32-bit x86 PE COFF module.
   bool isWin32Module() const override;

Modified: llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp?rev=251669&r1=251668&r2=251669&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/Symbolize.cpp Thu Oct 29 18:49:19 2015
@@ -56,6 +56,10 @@ static bool error(std::error_code ec) {
 }
 
 
+// By default, DILineInfo contains "<invalid>" for function/filename it
+// cannot fetch. We replace it to "??" to make our output closer to addr2line.
+static const char kDILineInfoBadString[] = "<invalid>";
+
 const char LLVMSymbolizer::kBadString[] = "??";
 
 std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
@@ -88,9 +92,6 @@ std::string LLVMSymbolizer::symbolizeCod
 
 std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
                                           uint64_t ModuleOffset) {
-  std::string Name = kBadString;
-  uint64_t Start = 0;
-  uint64_t Size = 0;
   if (Opts.UseSymbolTable) {
     if (SymbolizableModule *Info = getOrCreateModuleInfo(ModuleName)) {
       // If the user is giving us relative addresses, add the preferred base of
@@ -98,13 +99,11 @@ std::string LLVMSymbolizer::symbolizeDat
       // expects.
       if (Opts.RelativeAddresses)
         ModuleOffset += Info->getModulePreferredBase();
-      if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
-        Name = DemangleName(Name, Info);
+      DIGlobal Global = Info->symbolizeData(ModuleOffset);
+      return printDIGlobal(Global, Info);
     }
   }
-  std::stringstream ss;
-  ss << Name << "\n" << Start << " " << Size << "\n";
-  return ss.str();
+  return printDIGlobal(DIGlobal(), nullptr);
 }
 
 void LLVMSymbolizer::flush() {
@@ -359,9 +358,6 @@ LLVMSymbolizer::getOrCreateModuleInfo(co
 std::string
 LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo,
                                 const SymbolizableModule *ModInfo) const {
-  // By default, DILineInfo contains "<invalid>" for function/filename it
-  // cannot fetch. We replace it to "??" to make our output closer to addr2line.
-  static const std::string kDILineInfoBadString = "<invalid>";
   std::stringstream Result;
   if (Opts.PrintFunctions != FunctionNameKind::None) {
     std::string FunctionName = LineInfo.FunctionName;
@@ -378,6 +374,20 @@ LLVMSymbolizer::printDILineInfo(DILineIn
   return Result.str();
 }
 
+std::string
+LLVMSymbolizer::printDIGlobal(DIGlobal Global,
+                              const SymbolizableModule *ModInfo) const {
+  std::stringstream Result;
+  std::string Name = Global.Name;
+  if (Name == kDILineInfoBadString)
+    Name = kBadString;
+  else if (Opts.Demangle)
+    Name = DemangleName(Name, ModInfo);
+  Result << Name << "\n";
+  Result << Global.Start << " " << Global.Size << "\n";
+  return Result.str();
+}
+
 // Undo these various manglings for Win32 extern "C" functions:
 // cdecl       - _foo
 // stdcall     - _foo at 12
@@ -442,7 +452,7 @@ std::string LLVMSymbolizer::DemangleName
     return (result == 0) ? Name : std::string(DemangledName);
   }
 #endif
-  if (ModInfo->isWin32Module())
+  if (ModInfo && ModInfo->isWin32Module())
     return std::string(demanglePE32ExternCFunc(Name));
   return Name;
 }




More information about the llvm-commits mailing list