LLVM  8.0.1
PDB.cpp
Go to the documentation of this file.
1 //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
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/PDB.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Config/config.h"
14 #if LLVM_ENABLE_DIA_SDK
16 #endif
18 #include "llvm/Support/Error.h"
20 
21 using namespace llvm;
22 using namespace llvm::pdb;
23 
25  std::unique_ptr<IPDBSession> &Session) {
26  // Create the correct concrete instance type based on the value of Type.
27  if (Type == PDB_ReaderType::Native) {
29  MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
30  /*RequiresNullTerminator=*/false);
31  if (!ErrorOrBuffer)
32  return errorCodeToError(ErrorOrBuffer.getError());
33 
34  return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session);
35  }
36 
37 #if LLVM_ENABLE_DIA_SDK
38  return DIASession::createFromPdb(Path, Session);
39 #else
40  return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
41 #endif
42 }
43 
45  std::unique_ptr<IPDBSession> &Session) {
46  // Create the correct concrete instance type based on the value of Type.
47  if (Type == PDB_ReaderType::Native)
48  return NativeSession::createFromExe(Path, Session);
49 
50 #if LLVM_ENABLE_DIA_SDK
51  return DIASession::createFromExe(Path, Session);
52 #else
53  return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
54 #endif
55 }
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Represents either an error or a value T.
Definition: ErrorOr.h:57
This class represents lattice values for constants.
Definition: AllocatorList.h:24
PDB_ReaderType
Specifies which PDB reader implementation is to be used.
Definition: PDBTypes.h:79
static Error createFromPdb(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: DIASession.cpp:96
Error loadDataForEXE(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:44
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:88
std::error_code getError() const
Definition: ErrorOr.h:160
Error loadDataForPDB(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:24
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: DIASession.cpp:122
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
static Error createFromPdb(std::unique_ptr< MemoryBuffer > MB, std::unique_ptr< IPDBSession > &Session)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49