Home | History | Annotate | Download | only in Raw
      1 //===- RawSession.cpp - Raw implementation of IPDBSession -------*- 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/Raw/RawSession.h"
     11 
     12 #include "llvm/DebugInfo/CodeView/ByteStream.h"
     13 #include "llvm/DebugInfo/CodeView/StreamInterface.h"
     14 #include "llvm/DebugInfo/PDB/GenericError.h"
     15 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
     16 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
     17 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
     18 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
     19 #include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
     20 #include "llvm/DebugInfo/PDB/Raw/RawError.h"
     21 
     22 #include "llvm/Support/ErrorOr.h"
     23 #include "llvm/Support/MemoryBuffer.h"
     24 
     25 using namespace llvm;
     26 using namespace llvm::pdb;
     27 
     28 namespace {
     29 // We need a class which behaves like an immutable ByteStream, but whose data
     30 // is backed by an llvm::MemoryBuffer.  It also needs to own the underlying
     31 // MemoryBuffer, so this simple adapter is a good way to achieve that.
     32 class InputByteStream : public codeview::ByteStream<false> {
     33 public:
     34   explicit InputByteStream(std::unique_ptr<MemoryBuffer> Buffer)
     35       : ByteStream(ArrayRef<uint8_t>(Buffer->getBuffer().bytes_begin(),
     36                                      Buffer->getBuffer().bytes_end())),
     37         MemBuffer(std::move(Buffer)) {}
     38 
     39   std::unique_ptr<MemoryBuffer> MemBuffer;
     40 };
     41 }
     42 
     43 RawSession::RawSession(std::unique_ptr<PDBFile> PdbFile)
     44     : Pdb(std::move(PdbFile)) {}
     45 
     46 RawSession::~RawSession() {}
     47 
     48 Error RawSession::createFromPdb(StringRef Path,
     49                                 std::unique_ptr<IPDBSession> &Session) {
     50 
     51   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
     52       MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
     53                                    /*RequiresNullTerminator=*/false);
     54   if (!ErrorOrBuffer)
     55     return llvm::make_error<GenericError>(generic_error_code::invalid_path);
     56 
     57   std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
     58   auto Stream = llvm::make_unique<InputByteStream>(std::move(Buffer));
     59 
     60   std::unique_ptr<PDBFile> File(new PDBFile(std::move(Stream)));
     61   if (auto EC = File->parseFileHeaders())
     62     return EC;
     63   if (auto EC = File->parseStreamData())
     64     return EC;
     65 
     66   Session.reset(new RawSession(std::move(File)));
     67 
     68   return Error::success();
     69 }
     70 
     71 Error RawSession::createFromExe(StringRef Path,
     72                                 std::unique_ptr<IPDBSession> &Session) {
     73   return llvm::make_error<RawError>(raw_error_code::feature_unsupported);
     74 }
     75 
     76 uint64_t RawSession::getLoadAddress() const { return 0; }
     77 
     78 void RawSession::setLoadAddress(uint64_t Address) {}
     79 
     80 std::unique_ptr<PDBSymbolExe> RawSession::getGlobalScope() const {
     81   return nullptr;
     82 }
     83 
     84 std::unique_ptr<PDBSymbol> RawSession::getSymbolById(uint32_t SymbolId) const {
     85   return nullptr;
     86 }
     87 
     88 std::unique_ptr<PDBSymbol>
     89 RawSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
     90   return nullptr;
     91 }
     92 
     93 std::unique_ptr<IPDBEnumLineNumbers>
     94 RawSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
     95                             const IPDBSourceFile &File) const {
     96   return nullptr;
     97 }
     98 
     99 std::unique_ptr<IPDBEnumLineNumbers>
    100 RawSession::findLineNumbersByAddress(uint64_t Address, uint32_t Length) const {
    101   return nullptr;
    102 }
    103 
    104 std::unique_ptr<IPDBEnumSourceFiles>
    105 RawSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
    106                             llvm::StringRef Pattern,
    107                             PDB_NameSearchFlags Flags) const {
    108   return nullptr;
    109 }
    110 
    111 std::unique_ptr<IPDBSourceFile>
    112 RawSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
    113                               llvm::StringRef Pattern,
    114                               PDB_NameSearchFlags Flags) const {
    115   return nullptr;
    116 }
    117 
    118 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
    119 RawSession::findCompilandsForSourceFile(llvm::StringRef Pattern,
    120                                         PDB_NameSearchFlags Flags) const {
    121   return nullptr;
    122 }
    123 
    124 std::unique_ptr<PDBSymbolCompiland>
    125 RawSession::findOneCompilandForSourceFile(llvm::StringRef Pattern,
    126                                           PDB_NameSearchFlags Flags) const {
    127   return nullptr;
    128 }
    129 
    130 std::unique_ptr<IPDBEnumSourceFiles> RawSession::getAllSourceFiles() const {
    131   return nullptr;
    132 }
    133 
    134 std::unique_ptr<IPDBEnumSourceFiles> RawSession::getSourceFilesForCompiland(
    135     const PDBSymbolCompiland &Compiland) const {
    136   return nullptr;
    137 }
    138 
    139 std::unique_ptr<IPDBSourceFile>
    140 RawSession::getSourceFileById(uint32_t FileId) const {
    141   return nullptr;
    142 }
    143 
    144 std::unique_ptr<IPDBEnumDataStreams> RawSession::getDebugStreams() const {
    145   return nullptr;
    146 }
    147