LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB - PDBSymbol.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 61 91 67.0 %
Date: 2018-10-20 13:21:21 Functions: 11 18 61.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- PDBSymbol.cpp - base class for user-facing symbol types --*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/DebugInfo/PDB/PDBSymbol.h"
      11             : #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
      12             : #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
      13             : #include "llvm/DebugInfo/PDB/IPDBSession.h"
      14             : #include "llvm/DebugInfo/PDB/PDBExtras.h"
      15             : #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
      16             : #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
      17             : #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
      18             : #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
      19             : #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
      20             : #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
      21             : #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
      22             : #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
      23             : #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
      24             : #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
      25             : #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
      26             : #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
      27             : #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
      28             : #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
      29             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
      30             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
      31             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
      32             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
      33             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
      34             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
      35             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
      36             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
      37             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
      38             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
      39             : #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
      40             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
      41             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
      42             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
      43             : #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
      44             : #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
      45             : #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
      46             : #include "llvm/DebugInfo/PDB/PDBTypes.h"
      47             : #include <algorithm>
      48             : #include <memory>
      49             : 
      50             : using namespace llvm;
      51             : using namespace llvm::pdb;
      52             : 
      53        1906 : PDBSymbol::PDBSymbol(const IPDBSession &PDBSession) : Session(PDBSession) {}
      54             : 
      55           0 : PDBSymbol::PDBSymbol(PDBSymbol &&Other)
      56           0 :     : Session(Other.Session), RawSymbol(std::move(Other.RawSymbol)) {}
      57             : 
      58             : PDBSymbol::~PDBSymbol() = default;
      59             : 
      60             : #define FACTORY_SYMTAG_CASE(Tag, Type)                                         \
      61             :   case PDB_SymType::Tag:                                                       \
      62             :     return std::unique_ptr<PDBSymbol>(new Type(PDBSession));
      63             : 
      64             : std::unique_ptr<PDBSymbol>
      65         953 : PDBSymbol::createSymbol(const IPDBSession &PDBSession, PDB_SymType Tag) {
      66         953 :   switch (Tag) {
      67          20 :     FACTORY_SYMTAG_CASE(Exe, PDBSymbolExe)
      68          63 :     FACTORY_SYMTAG_CASE(Compiland, PDBSymbolCompiland)
      69           1 :     FACTORY_SYMTAG_CASE(CompilandDetails, PDBSymbolCompilandDetails)
      70           1 :     FACTORY_SYMTAG_CASE(CompilandEnv, PDBSymbolCompilandEnv)
      71           1 :     FACTORY_SYMTAG_CASE(Function, PDBSymbolFunc)
      72           1 :     FACTORY_SYMTAG_CASE(Block, PDBSymbolBlock)
      73         179 :     FACTORY_SYMTAG_CASE(Data, PDBSymbolData)
      74           1 :     FACTORY_SYMTAG_CASE(Annotation, PDBSymbolAnnotation)
      75           1 :     FACTORY_SYMTAG_CASE(Label, PDBSymbolLabel)
      76           1 :     FACTORY_SYMTAG_CASE(PublicSymbol, PDBSymbolPublicSymbol)
      77         128 :     FACTORY_SYMTAG_CASE(UDT, PDBSymbolTypeUDT)
      78          63 :     FACTORY_SYMTAG_CASE(Enum, PDBSymbolTypeEnum)
      79         120 :     FACTORY_SYMTAG_CASE(FunctionSig, PDBSymbolTypeFunctionSig)
      80         116 :     FACTORY_SYMTAG_CASE(PointerType, PDBSymbolTypePointer)
      81           2 :     FACTORY_SYMTAG_CASE(ArrayType, PDBSymbolTypeArray)
      82         182 :     FACTORY_SYMTAG_CASE(BuiltinType, PDBSymbolTypeBuiltin)
      83           7 :     FACTORY_SYMTAG_CASE(Typedef, PDBSymbolTypeTypedef)
      84           1 :     FACTORY_SYMTAG_CASE(BaseClass, PDBSymbolTypeBaseClass)
      85           1 :     FACTORY_SYMTAG_CASE(Friend, PDBSymbolTypeFriend)
      86          52 :     FACTORY_SYMTAG_CASE(FunctionArg, PDBSymbolTypeFunctionArg)
      87           1 :     FACTORY_SYMTAG_CASE(FuncDebugStart, PDBSymbolFuncDebugStart)
      88           1 :     FACTORY_SYMTAG_CASE(FuncDebugEnd, PDBSymbolFuncDebugEnd)
      89           1 :     FACTORY_SYMTAG_CASE(UsingNamespace, PDBSymbolUsingNamespace)
      90           1 :     FACTORY_SYMTAG_CASE(VTableShape, PDBSymbolTypeVTableShape)
      91           1 :     FACTORY_SYMTAG_CASE(VTable, PDBSymbolTypeVTable)
      92           1 :     FACTORY_SYMTAG_CASE(Custom, PDBSymbolCustom)
      93           1 :     FACTORY_SYMTAG_CASE(Thunk, PDBSymbolThunk)
      94           1 :     FACTORY_SYMTAG_CASE(CustomType, PDBSymbolTypeCustom)
      95           1 :     FACTORY_SYMTAG_CASE(ManagedType, PDBSymbolTypeManaged)
      96           1 :     FACTORY_SYMTAG_CASE(Dimension, PDBSymbolTypeDimension)
      97           2 :   default:
      98           2 :     return std::unique_ptr<PDBSymbol>(new PDBSymbolUnknown(PDBSession));
      99             :   }
     100             : }
     101             : 
     102             : std::unique_ptr<PDBSymbol>
     103          83 : PDBSymbol::create(const IPDBSession &PDBSession,
     104             :                   std::unique_ptr<IPDBRawSymbol> RawSymbol) {
     105          83 :   auto SymbolPtr = createSymbol(PDBSession, RawSymbol->getSymTag());
     106          83 :   SymbolPtr->RawSymbol = RawSymbol.get();
     107             :   SymbolPtr->OwnedRawSymbol = std::move(RawSymbol);
     108          83 :   return SymbolPtr;
     109             : }
     110             : 
     111         870 : std::unique_ptr<PDBSymbol> PDBSymbol::create(const IPDBSession &PDBSession,
     112             :                                              IPDBRawSymbol &RawSymbol) {
     113         870 :   auto SymbolPtr = createSymbol(PDBSession, RawSymbol.getSymTag());
     114         870 :   SymbolPtr->RawSymbol = &RawSymbol;
     115         870 :   return SymbolPtr;
     116             : }
     117             : 
     118         227 : void PDBSymbol::defaultDump(raw_ostream &OS, int Indent,
     119             :                             PdbSymbolIdField ShowFlags,
     120             :                             PdbSymbolIdField RecurseFlags) const {
     121         227 :   RawSymbol->dump(OS, Indent, ShowFlags, RecurseFlags);
     122         227 : }
     123             : 
     124           0 : void PDBSymbol::dumpProperties() const {
     125           0 :   outs() << "\n";
     126           0 :   defaultDump(outs(), 0, PdbSymbolIdField::All, PdbSymbolIdField::None);
     127           0 :   outs().flush();
     128           0 : }
     129             : 
     130           0 : void PDBSymbol::dumpChildStats() const {
     131             :   TagStats Stats;
     132           0 :   getChildStats(Stats);
     133           0 :   outs() << "\n";
     134           0 :   for (auto &Stat : Stats) {
     135           0 :     outs() << Stat.first << ": " << Stat.second << "\n";
     136             :   }
     137           0 :   outs().flush();
     138           0 : }
     139             : 
     140        1866 : PDB_SymType PDBSymbol::getSymTag() const { return RawSymbol->getSymTag(); }
     141          64 : uint32_t PDBSymbol::getSymIndexId() const { return RawSymbol->getSymIndexId(); }
     142             : 
     143          18 : std::unique_ptr<IPDBEnumSymbols> PDBSymbol::findAllChildren() const {
     144          18 :   return findAllChildren(PDB_SymType::None);
     145             : }
     146             : 
     147             : std::unique_ptr<IPDBEnumSymbols>
     148          24 : PDBSymbol::findAllChildren(PDB_SymType Type) const {
     149          24 :   return RawSymbol->findChildren(Type);
     150             : }
     151             : 
     152             : std::unique_ptr<IPDBEnumSymbols>
     153           0 : PDBSymbol::findChildren(PDB_SymType Type, StringRef Name,
     154             :                         PDB_NameSearchFlags Flags) const {
     155           0 :   return RawSymbol->findChildren(Type, Name, Flags);
     156             : }
     157             : 
     158             : std::unique_ptr<IPDBEnumSymbols>
     159           0 : PDBSymbol::findChildrenByRVA(PDB_SymType Type, StringRef Name,
     160             :                              PDB_NameSearchFlags Flags, uint32_t RVA) const {
     161           0 :   return RawSymbol->findChildrenByRVA(Type, Name, Flags, RVA);
     162             : }
     163             : 
     164             : std::unique_ptr<IPDBEnumSymbols>
     165           0 : PDBSymbol::findInlineFramesByRVA(uint32_t RVA) const {
     166           0 :   return RawSymbol->findInlineFramesByRVA(RVA);
     167             : }
     168             : 
     169             : std::unique_ptr<IPDBEnumSymbols>
     170           0 : PDBSymbol::getChildStats(TagStats &Stats) const {
     171           0 :   std::unique_ptr<IPDBEnumSymbols> Result(findAllChildren());
     172           0 :   if (!Result)
     173             :     return nullptr;
     174             :   Stats.clear();
     175           0 :   while (auto Child = Result->getNext()) {
     176           0 :     ++Stats[Child->getSymTag()];
     177             :   }
     178           0 :   Result->reset();
     179             :   return Result;
     180             : }
     181             : 
     182         196 : std::unique_ptr<PDBSymbol> PDBSymbol::getSymbolByIdHelper(uint32_t Id) const {
     183         196 :   return Session.getSymbolById(Id);
     184             : }
     185             : 
     186         752 : void llvm::pdb::dumpSymbolIdField(raw_ostream &OS, StringRef Name,
     187             :                                   SymIndexId Value, int Indent,
     188             :                                   const IPDBSession &Session,
     189             :                                   PdbSymbolIdField FieldId,
     190             :                                   PdbSymbolIdField ShowFlags,
     191             :                                   PdbSymbolIdField RecurseFlags) {
     192         752 :   if ((FieldId & ShowFlags) == PdbSymbolIdField::None)
     193         752 :     return;
     194             : 
     195         580 :   OS << "\n";
     196         580 :   OS.indent(Indent);
     197         580 :   OS << Name << ": " << Value;
     198             :   // Don't recurse unless the user requested it.
     199         580 :   if ((FieldId & RecurseFlags) == PdbSymbolIdField::None)
     200             :     return;
     201             :   // And obviously don't recurse on the symbol itself.
     202           0 :   if (FieldId == PdbSymbolIdField::SymIndexId)
     203             :     return;
     204             : 
     205           0 :   auto Child = Session.getSymbolById(Value);
     206             : 
     207             :   // It could have been a placeholder symbol for a type we don't yet support,
     208             :   // so just exit in that case.
     209           0 :   if (!Child)
     210             :     return;
     211             : 
     212             :   // Don't recurse more than once, so pass PdbSymbolIdField::None) for the
     213             :   // recurse flags.
     214           0 :   Child->defaultDump(OS, Indent + 2, ShowFlags, PdbSymbolIdField::None);
     215             : }

Generated by: LCOV version 1.13