LCOV - code coverage report
Current view: top level - lib/DebugInfo/PDB - PDBSymbolCompiland.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 40 0.0 %
Date: 2018-10-20 13:21:21 Functions: 0 3 0.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           0 : void PDBSymbolCompiland::dump(PDBSymDumper &Dumper) const {
      26           0 :   Dumper.dump(*this);
      27           0 : }
      28             : 
      29           0 : std::string PDBSymbolCompiland::getSourceFileName() const {
      30           0 :   return sys::path::filename(getSourceFileFullPath()).str();
      31             : }
      32             : 
      33           0 : std::string PDBSymbolCompiland::getSourceFileFullPath() const {
      34             :   std::string SourceFileFullPath;
      35             : 
      36             :   // RecordedResult could be the basename, relative path or full path of the
      37             :   // source file. Usually it is retrieved and recorded from the command that
      38             :   // compiles this compiland.
      39             :   //
      40             :   //  cmd FileName          -> RecordedResult = .\\FileName
      41             :   //  cmd (Path)\\FileName  -> RecordedResult = (Path)\\FileName
      42             :   //
      43           0 :   std::string RecordedResult = RawSymbol->getSourceFileName();
      44             : 
      45           0 :   if (RecordedResult.empty()) {
      46           0 :     if (auto Envs = findAllChildren<PDBSymbolCompilandEnv>()) {
      47             :       std::string EnvWorkingDir, EnvSrc;
      48             : 
      49           0 :       while (auto Env = Envs->getNext()) {
      50           0 :         std::string Var = Env->getName();
      51           0 :         if (Var == "cwd") {
      52           0 :           EnvWorkingDir = Env->getValue();
      53           0 :           continue;
      54             :         }
      55           0 :         if (Var == "src") {
      56           0 :           EnvSrc = Env->getValue();
      57           0 :           if (sys::path::is_absolute(EnvSrc))
      58             :             return EnvSrc;
      59             :           RecordedResult = EnvSrc;
      60           0 :           continue;
      61             :         }
      62             :       }
      63           0 :       if (!EnvWorkingDir.empty() && !EnvSrc.empty()) {
      64             :         auto Len = EnvWorkingDir.length();
      65           0 :         if (EnvWorkingDir[Len - 1] != '/' && EnvWorkingDir[Len - 1] != '\\') {
      66           0 :           std::string Path = EnvWorkingDir + "\\" + EnvSrc;
      67             :           std::replace(Path.begin(), Path.end(), '/', '\\');
      68             :           // We will return it as full path if we can't find a better one.
      69           0 :           if (sys::path::is_absolute(Path))
      70             :             SourceFileFullPath = Path;
      71             :         }
      72             :       }
      73             :     }
      74             :   }
      75             : 
      76           0 :   if (!RecordedResult.empty()) {
      77           0 :     if (sys::path::is_absolute(RecordedResult))
      78           0 :       return RecordedResult;
      79             : 
      80             :     // This searches name that has same basename as the one in RecordedResult.
      81           0 :     auto OneSrcFile = Session.findOneSourceFile(
      82           0 :         this, RecordedResult, PDB_NameSearchFlags::NS_CaseInsensitive);
      83           0 :     if (OneSrcFile)
      84           0 :       return OneSrcFile->getFileName();
      85             :   }
      86             : 
      87             :   // At this point, we have to walk through all source files of this compiland,
      88             :   // and determine the right source file if any that is used to generate this
      89             :   // compiland based on language indicated in compilanddetails language field.
      90           0 :   auto Details = findOneChild<PDBSymbolCompilandDetails>();
      91           0 :   PDB_Lang Lang = Details ? Details->getLanguage() : PDB_Lang::Cpp;
      92           0 :   auto SrcFiles = Session.getSourceFilesForCompiland(*this);
      93           0 :   if (SrcFiles) {
      94           0 :     bool LangC = (Lang == PDB_Lang::Cpp || Lang == PDB_Lang::C);
      95           0 :     while (auto File = SrcFiles->getNext()) {
      96           0 :       std::string FileName = File->getFileName();
      97           0 :       auto file_extension = sys::path::extension(FileName);
      98           0 :       if (StringSwitch<bool>(file_extension.lower())
      99             :               .Case(".cpp", LangC)
     100             :               .Case(".c", LangC)
     101             :               .Case(".cc", LangC)
     102             :               .Case(".cxx", LangC)
     103           0 :               .Case(".asm", Lang == PDB_Lang::Masm)
     104             :               .Default(false))
     105           0 :         return File->getFileName();
     106             :     }
     107             :   }
     108             : 
     109             :   return SourceFileFullPath;
     110             : }

Generated by: LCOV version 1.13