blob: 14a0fb4c93a4dd406c0240f4298e476b40fe2afc [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
Adrian McCarthy4d93d662017-03-29 19:27:08 +000037std::unique_ptr<IPDBEnumSymbols>
38NativeExeSymbol::findChildren(PDB_SymType Type) const {
39 switch (Type) {
40 case PDB_SymType::Compiland: {
Zachary Turner7999b4f2018-09-05 23:30:38 +000041 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
Adrian McCarthy4d93d662017-03-29 19:27:08 +000042 break;
43 }
Zachary Turner518cb2d2018-09-30 16:19:18 +000044 case PDB_SymType::ArrayType:
45 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY);
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000046 case PDB_SymType::Enum:
Zachary Turner8ab7dd602018-09-07 00:12:34 +000047 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
Zachary Turnerda4b63a2018-09-07 23:21:33 +000048 case PDB_SymType::PointerType:
49 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER);
Zachary Turner355ffb02018-09-21 22:36:04 +000050 case PDB_SymType::UDT:
51 return Session.getSymbolCache().createTypeEnumerator(
52 {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION,
53 codeview::LF_INTERFACE});
Zachary Turner6345e842018-09-21 22:36:28 +000054 case PDB_SymType::FunctionSig:
55 return Session.getSymbolCache().createTypeEnumerator(
56 {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
57
Adrian McCarthy4d93d662017-03-29 19:27:08 +000058 default:
59 break;
60 }
61 return nullptr;
62}
63
64uint32_t NativeExeSymbol::getAge() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000065 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000066 if (IS)
67 return IS->getAge();
68 consumeError(IS.takeError());
69 return 0;
70}
71
72std::string NativeExeSymbol::getSymbolsFileName() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000073 return Session.getPDBFile().getFilePath();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000074}
75
Reid Kleckner67653ee2017-07-17 23:59:44 +000076codeview::GUID NativeExeSymbol::getGuid() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000077 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000078 if (IS)
79 return IS->getGuid();
80 consumeError(IS.takeError());
Reid Kleckner67653ee2017-07-17 23:59:44 +000081 return codeview::GUID{{0}};
Adrian McCarthy4d93d662017-03-29 19:27:08 +000082}
83
84bool NativeExeSymbol::hasCTypes() 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->hasCTypes();
88 consumeError(Dbi.takeError());
89 return false;
90}
91
92bool NativeExeSymbol::hasPrivateSymbols() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000093 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000094 if (Dbi)
95 return !Dbi->isStripped();
96 consumeError(Dbi.takeError());
97 return false;
98}