LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB - PDBSymbolCompiland.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 4 43 9.3 %
Date: 2018-06-17 00:07:59 Functions: 1 4 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- PDBSymbolCompiland.cpp - compiland details ---------------*- 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/IPDBSession.h"
      11             : #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
      12             : 
      13             : #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
      14             : #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
      15             : #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
      16             : #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
      17             : 
      18             : #include "llvm/ADT/StringSwitch.h"
      19             : #include "llvm/Support/Path.h"
      20             : #include <utility>
      21             : 
      22             : using namespace llvm;
      23             : using namespace llvm::pdb;
      24             : 
      25          51 : PDBSymbolCompiland::PDBSymbolCompiland(const IPDBSession &PDBSession,
      26          51 :                                        std::unique_ptr<IPDBRawSymbol> Symbol)
      27         153 :     : PDBSymbol(PDBSession, std::move(Symbol)) {
      28             :   assert(RawSymbol->getSymTag() == PDB_SymType::Compiland);
      29          51 : }
      30             : 
      31           0 : void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const {
      32           0 :   Dumper.dump(*this);
      33           0 : }
      34             : 
      35           0 : std::string PDBSymbolCompiland::getSourceFileName() const {
      36           0 :   return sys::path::filename(getSourceFileFullPath()).str();
      37             : }
      38             : 
      39           0 : std::string PDBSymbolCompiland::getSourceFileFullPath() const {
      40             :   std::string SourceFileFullPath;
      41             : 
      42             :   // RecordedResult could be the basename, relative path or full path of the
      43             :   // source file. Usually it is retrieved and recorded from the command that
      44             :   // compiles this compiland.
      45             :   //
      46             :   //  cmd FileName          -> RecordedResult = .\\FileName
      47             :   //  cmd (Path)\\FileName  -> RecordedResult = (Path)\\FileName
      48             :   //
      49           0 :   std::string RecordedResult = RawSymbol->getSourceFileName();
      50             : 
      51           0 :   if (RecordedResult.empty()) {
      52           0 :     if (auto Envs = findAllChildren<PDBSymbolCompilandEnv>()) {
      53             :       std::string EnvWorkingDir, EnvSrc;
      54             : 
      55           0 :       while (auto Env = Envs->getNext()) {
      56             :         std::string Var = Env->getName();
      57           0 :         if (Var == "cwd") {
      58           0 :           EnvWorkingDir = Env->getValue();
      59           0 :           continue;
      60             :         }
      61           0 :         if (Var == "src") {
      62           0 :           EnvSrc = Env->getValue();
      63           0 :           if (sys::path::is_absolute(EnvSrc))
      64             :             return EnvSrc;
      65             :           RecordedResult = EnvSrc;
      66           0 :           continue;
      67             :         }
      68             :       }
      69           0 :       if (!EnvWorkingDir.empty() && !EnvSrc.empty()) {
      70             :         auto Len = EnvWorkingDir.length();
      71           0 :         if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
      72           0 :           std::string Path = EnvWorkingDir + "\\" + EnvSrc;
      73             :           std::replace(Path.begin(), Path.end(), '/', '\\');
      74             :           // We will return it as full path if we can't find a better one.
      75           0 :           if (sys::path::is_absolute(Path))
      76             :             SourceFileFullPath = Path;
      77             :         }
      78             :       }
      79             :     }
      80             :   }
      81             : 
      82           0 :   if (!RecordedResult.empty()) {
      83           0 :     if (sys::path::is_absolute(RecordedResult))
      84           0 :       return RecordedResult;
      85             : 
      86             :     // This searches name that has same basename as the one in RecordedResult.
      87           0 :     auto OneSrcFile = Session.findOneSourceFile(
      88           0 :         this, RecordedResult, PDB_NameSearchFlags::NS_CaseInsensitive);
      89           0 :     if (OneSrcFile)
      90           0 :       return OneSrcFile->getFileName();
      91             :   }
      92             : 
      93             :   // At this point, we have to walk through all source files of this compiland,
      94             :   // and determine the right source file if any that is used to generate this
      95             :   // compiland based on language indicated in compilanddetails language field.
      96           0 :   auto Details = findOneChild<PDBSymbolCompilandDetails>();
      97           0 :   PDB_Lang Lang = Details ? Details->getLanguage() : PDB_Lang::Cpp;
      98           0 :   auto SrcFiles = Session.getSourceFilesForCompiland(*this);
      99           0 :   if (SrcFiles) {
     100           0 :     bool LangC = (Lang == PDB_Lang::Cpp || Lang == PDB_Lang::C);
     101           0 :     while (auto File = SrcFiles->getNext()) {
     102           0 :       std::string FileName = File->getFileName();
     103           0 :       auto file_extension = sys::path::extension(FileName);
     104           0 :       if (StringSwitch<bool>(file_extension.lower())
     105             :               .Case(".cpp", LangC)
     106             :               .Case(".c", LangC)
     107             :               .Case(".cc", LangC)
     108             :               .Case(".cxx", LangC)
     109           0 :               .Case(".asm", Lang == PDB_Lang::Masm)
     110             :               .Default(false))
     111           0 :         return File->getFileName();
     112             :     }
     113             :   }
     114             : 
     115             :   return SourceFileFullPath;
     116             : }

Generated by: LCOV version 1.13