blob: e86f836ee141a14b15f1757b280d99cfe34fedcc [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 Turner5c1873b2018-10-01 17:55:16 +000054 case PDB_SymType::VTableShape:
55 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE);
Zachary Turner6345e842018-09-21 22:36:28 +000056 case PDB_SymType::FunctionSig:
57 return Session.getSymbolCache().createTypeEnumerator(
58 {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
59
Adrian McCarthy4d93d662017-03-29 19:27:08 +000060 default:
61 break;
62 }
63 return nullptr;
64}
65
66uint32_t NativeExeSymbol::getAge() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000067 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000068 if (IS)
69 return IS->getAge();
70 consumeError(IS.takeError());
71 return 0;
72}
73
74std::string NativeExeSymbol::getSymbolsFileName() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000075 return Session.getPDBFile().getFilePath();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000076}
77
Reid Kleckner67653ee2017-07-17 23:59:44 +000078codeview::GUID NativeExeSymbol::getGuid() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000079 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000080 if (IS)
81 return IS->getGuid();
82 consumeError(IS.takeError());
Reid Kleckner67653ee2017-07-17 23:59:44 +000083 return codeview::GUID{{0}};
Adrian McCarthy4d93d662017-03-29 19:27:08 +000084}
85
86bool NativeExeSymbol::hasCTypes() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000087 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000088 if (Dbi)
89 return Dbi->hasCTypes();
90 consumeError(Dbi.takeError());
91 return false;
92}
93
94bool NativeExeSymbol::hasPrivateSymbols() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000095 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000096 if (Dbi)
97 return !Dbi->isStripped();
98 consumeError(Dbi.takeError());
99 return false;
100}