1 //===- NativeSession.cpp - Native 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/Native/NativeSession.h"
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/DebugInfo/MSF/ByteStream.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/Native/PDBFile.h"
18 #include "llvm/DebugInfo/PDB/Native/RawError.h"
19 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
21 #include "llvm/Support/Allocator.h"
22 #include "llvm/Support/Error.h"
23 #include "llvm/Support/ErrorOr.h"
24 #include "llvm/Support/MemoryBuffer.h"
25 #include <algorithm>
26 #include <memory>
27 
28 using namespace llvm;
29 using namespace llvm::msf;
30 using namespace llvm::pdb;
31 
32 NativeSession::NativeSession(std::unique_ptr<PDBFile> PdbFile,
33                              std::unique_ptr<BumpPtrAllocator> Allocator)
34     : Pdb(std::move(PdbFile)), Allocator(std::move(Allocator)) {}
35 
36 NativeSession::~NativeSession() = default;
37 
38 Error NativeSession::createFromPdb(StringRef Path,
39                                    std::unique_ptr<IPDBSession> &Session) {
40   ErrorOr<std::unique_ptr<MemoryBuffer>> ErrorOrBuffer =
41       MemoryBuffer::getFileOrSTDIN(Path, /*FileSize=*/-1,
42                                    /*RequiresNullTerminator=*/false);
43   if (!ErrorOrBuffer)
44     return make_error<GenericError>(generic_error_code::invalid_path);
45 
46   std::unique_ptr<MemoryBuffer> Buffer = std::move(*ErrorOrBuffer);
47   auto Stream = llvm::make_unique<MemoryBufferByteStream>(std::move(Buffer));
48 
49   auto Allocator = llvm::make_unique<BumpPtrAllocator>();
50   auto File = llvm::make_unique<PDBFile>(Path, std::move(Stream), *Allocator);
51   if (auto EC = File->parseFileHeaders())
52     return EC;
53   if (auto EC = File->parseStreamData())
54     return EC;
55 
56   Session =
57       llvm::make_unique<NativeSession>(std::move(File), std::move(Allocator));
58 
59   return Error::success();
60 }
61 
62 Error NativeSession::createFromExe(StringRef Path,
63                                    std::unique_ptr<IPDBSession> &Session) {
64   return make_error<RawError>(raw_error_code::feature_unsupported);
65 }
66 
67 uint64_t NativeSession::getLoadAddress() const { return 0; }
68 
69 void NativeSession::setLoadAddress(uint64_t Address) {}
70 
71 std::unique_ptr<PDBSymbolExe> NativeSession::getGlobalScope() const {
72   return nullptr;
73 }
74 
75 std::unique_ptr<PDBSymbol>
76 NativeSession::getSymbolById(uint32_t SymbolId) const {
77   return nullptr;
78 }
79 
80 std::unique_ptr<PDBSymbol>
81 NativeSession::findSymbolByAddress(uint64_t Address, PDB_SymType Type) const {
82   return nullptr;
83 }
84 
85 std::unique_ptr<IPDBEnumLineNumbers>
86 NativeSession::findLineNumbers(const PDBSymbolCompiland &Compiland,
87                                const IPDBSourceFile &File) const {
88   return nullptr;
89 }
90 
91 std::unique_ptr<IPDBEnumLineNumbers>
92 NativeSession::findLineNumbersByAddress(uint64_t Address,
93                                         uint32_t Length) const {
94   return nullptr;
95 }
96 
97 std::unique_ptr<IPDBEnumSourceFiles>
98 NativeSession::findSourceFiles(const PDBSymbolCompiland *Compiland,
99                                StringRef Pattern,
100                                PDB_NameSearchFlags Flags) const {
101   return nullptr;
102 }
103 
104 std::unique_ptr<IPDBSourceFile>
105 NativeSession::findOneSourceFile(const PDBSymbolCompiland *Compiland,
106                                  StringRef Pattern,
107                                  PDB_NameSearchFlags Flags) const {
108   return nullptr;
109 }
110 
111 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
112 NativeSession::findCompilandsForSourceFile(StringRef Pattern,
113                                            PDB_NameSearchFlags Flags) const {
114   return nullptr;
115 }
116 
117 std::unique_ptr<PDBSymbolCompiland>
118 NativeSession::findOneCompilandForSourceFile(StringRef Pattern,
119                                              PDB_NameSearchFlags Flags) const {
120   return nullptr;
121 }
122 
123 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getAllSourceFiles() const {
124   return nullptr;
125 }
126 
127 std::unique_ptr<IPDBEnumSourceFiles> NativeSession::getSourceFilesForCompiland(
128     const PDBSymbolCompiland &Compiland) const {
129   return nullptr;
130 }
131 
132 std::unique_ptr<IPDBSourceFile>
133 NativeSession::getSourceFileById(uint32_t FileId) const {
134   return nullptr;
135 }
136 
137 std::unique_ptr<IPDBEnumDataStreams> NativeSession::getDebugStreams() const {
138   return nullptr;
139 }
140