LLVM  9.0.0svn
PDB.cpp
Go to the documentation of this file.
1 //===- PDB.cpp - base header file for creating a PDB reader ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/Config/config.h"
13 #if LLVM_ENABLE_DIA_SDK
15 #endif
17 #include "llvm/Support/Error.h"
19 
20 using namespace llvm;
21 using namespace llvm::pdb;
22 
24  std::unique_ptr<IPDBSession> &Session) {
25  // Create the correct concrete instance type based on the value of Type.
26  if (Type == PDB_ReaderType::Native) {
28  MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
29  /*RequiresNullTerminator=*/false);
30  if (!ErrorOrBuffer)
31  return errorCodeToError(ErrorOrBuffer.getError());
32 
33  return NativeSession::createFromPdb(std::move(*ErrorOrBuffer), Session);
34  }
35 
36 #if LLVM_ENABLE_DIA_SDK
37  return DIASession::createFromPdb(Path, Session);
38 #else
39  return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
40 #endif
41 }
42 
44  std::unique_ptr<IPDBSession> &Session) {
45  // Create the correct concrete instance type based on the value of Type.
46  if (Type == PDB_ReaderType::Native)
47  return NativeSession::createFromExe(Path, Session);
48 
49 #if LLVM_ENABLE_DIA_SDK
50  return DIASession::createFromExe(Path, Session);
51 #else
52  return make_error<PDBError>(pdb_error_code::dia_sdk_not_present);
53 #endif
54 }
static Error createFromExe(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Represents either an error or a value T.
Definition: ErrorOr.h:56
This class represents lattice values for constants.
Definition: AllocatorList.h:23
PDB_ReaderType
Specifies which PDB reader implementation is to be used.
Definition: PDBTypes.h:78
static Error createFromPdb(StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: DIASession.cpp:95
Error loadDataForEXE(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:43
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
std::error_code getError() const
Definition: ErrorOr.h:159
Error loadDataForPDB(PDB_ReaderType Type, StringRef Path, std::unique_ptr< IPDBSession > &Session)
Definition: PDB.cpp:23
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:121
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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:48