blob: 59eaf3e8d4984213f31c3b5be60328e40af2858f [file] [log] [blame]
Adrian McCarthy4d93d662017-03-29 19:27:08 +00001//===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- 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/NativeExeSymbol.h"
11
Adrian McCarthy4aedc812017-06-22 18:57:51 +000012#include "llvm/ADT/STLExtras.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000013#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
14#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000015#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000016#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
17#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
Zachary Turner8ab7dd602018-09-07 00:12:34 +000018#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000019#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000020
Zachary Turner7999b4f2018-09-05 23:30:38 +000021using namespace llvm;
22using namespace llvm::pdb;
Adrian McCarthy4d93d662017-03-29 19:27:08 +000023
Zachary Turner8ab7dd602018-09-07 00:12:34 +000024static DbiStream *getDbiStreamPtr(NativeSession &Session) {
25 Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream();
26 if (DbiS)
27 return &DbiS.get();
28
29 consumeError(DbiS.takeError());
30 return nullptr;
31}
32
Adrian McCarthy8d090fc2017-07-12 19:38:11 +000033NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
Zachary Turner7999b4f2018-09-05 23:30:38 +000034 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
Zachary Turner8ab7dd602018-09-07 00:12:34 +000035 Dbi(getDbiStreamPtr(Session)) {}
Adrian McCarthy31bcb6f2017-06-22 18:43:18 +000036
37std::unique_ptr<NativeRawSymbol> NativeExeSymbol::clone() const {
Adrian McCarthy4aedc812017-06-22 18:57:51 +000038 return llvm::make_unique<NativeExeSymbol>(Session, SymbolId);
Adrian McCarthy31bcb6f2017-06-22 18:43:18 +000039}
Adrian McCarthy4d93d662017-03-29 19:27:08 +000040
41std::unique_ptr<IPDBEnumSymbols>
42NativeExeSymbol::findChildren(PDB_SymType Type) const {
43 switch (Type) {
44 case PDB_SymType::Compiland: {
Zachary Turner7999b4f2018-09-05 23:30:38 +000045 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
Adrian McCarthy4d93d662017-03-29 19:27:08 +000046 break;
47 }
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000048 case PDB_SymType::Enum:
Zachary Turner8ab7dd602018-09-07 00:12:34 +000049 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
Adrian McCarthy4d93d662017-03-29 19:27:08 +000050 default:
51 break;
52 }
53 return nullptr;
54}
55
56uint32_t NativeExeSymbol::getAge() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000057 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000058 if (IS)
59 return IS->getAge();
60 consumeError(IS.takeError());
61 return 0;
62}
63
64std::string NativeExeSymbol::getSymbolsFileName() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000065 return Session.getPDBFile().getFilePath();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000066}
67
Reid Kleckner67653ee2017-07-17 23:59:44 +000068codeview::GUID NativeExeSymbol::getGuid() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000069 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000070 if (IS)
71 return IS->getGuid();
72 consumeError(IS.takeError());
Reid Kleckner67653ee2017-07-17 23:59:44 +000073 return codeview::GUID{{0}};
Adrian McCarthy4d93d662017-03-29 19:27:08 +000074}
75
76bool NativeExeSymbol::hasCTypes() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000077 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000078 if (Dbi)
79 return Dbi->hasCTypes();
80 consumeError(Dbi.takeError());
81 return false;
82}
83
84bool NativeExeSymbol::hasPrivateSymbols() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000085 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000086 if (Dbi)
87 return !Dbi->isStripped();
88 consumeError(Dbi.takeError());
89 return false;
90}