blob: 6249524eddde5aa84c816d2c25e2315529b65d14 [file] [log] [blame]
Rui Ueyama0fcd8262016-05-20 19:55:17 +00001//===- SymbolStream.cpp - PDB Symbol Stream Access ------------------------===//
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/SymbolStream.h"
11
12#include "llvm/DebugInfo/CodeView/CodeView.h"
13#include "llvm/DebugInfo/CodeView/TypeRecord.h"
Zachary Turner9e33e6f2016-05-24 18:55:14 +000014#include "llvm/DebugInfo/PDB/Raw/ByteStream.h"
Rui Ueyama0fcd8262016-05-20 19:55:17 +000015#include "llvm/DebugInfo/PDB/Raw/MappedBlockStream.h"
16#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
17#include "llvm/DebugInfo/PDB/Raw/RawError.h"
18#include "llvm/DebugInfo/PDB/Raw/StreamReader.h"
19
20#include "llvm/Support/Endian.h"
21
22using namespace llvm;
23using namespace llvm::support;
24using namespace llvm::pdb;
25
Rui Ueyama0fcd8262016-05-20 19:55:17 +000026SymbolStream::SymbolStream(PDBFile &File, uint32_t StreamNum)
Zachary Turner9e33e6f2016-05-24 18:55:14 +000027 : MappedStream(StreamNum, File) {}
Rui Ueyama0fcd8262016-05-20 19:55:17 +000028
29SymbolStream::~SymbolStream() {}
30
Zachary Turner9e33e6f2016-05-24 18:55:14 +000031Error SymbolStream::reload() {
32 StreamReader Reader(MappedStream);
Rui Ueyama0fcd8262016-05-20 19:55:17 +000033
Zachary Turner9e33e6f2016-05-24 18:55:14 +000034 if (Stream.initialize(Reader, MappedStream.getLength()))
Rui Ueyama0fcd8262016-05-20 19:55:17 +000035 return make_error<RawError>(raw_error_code::corrupt_file,
Zachary Turner9e33e6f2016-05-24 18:55:14 +000036 "Could not load symbol stream.");
Rui Ueyama0fcd8262016-05-20 19:55:17 +000037
Rui Ueyama0fcd8262016-05-20 19:55:17 +000038 return Error::success();
39}
Zachary Turner9e33e6f2016-05-24 18:55:14 +000040
41iterator_range<codeview::SymbolIterator> SymbolStream::getSymbols() const {
42 using codeview::SymbolIterator;
43 ArrayRef<uint8_t> Data;
44 if (auto Error = Stream.getArrayRef(0, Data, Stream.getLength())) {
45 consumeError(std::move(Error));
46 return iterator_range<SymbolIterator>(SymbolIterator(), SymbolIterator());
47 }
48
49 return codeview::makeSymbolRange(Data, nullptr);
50}