blob: 3f393409129b105608a4db430dd9a98ebc4e37e2 [file] [log] [blame]
Adrian McCarthy4d93d662017-03-29 19:27:08 +00001//===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Adrian McCarthy4d93d662017-03-29 19:27:08 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
10
Adrian McCarthy4aedc812017-06-22 18:57:51 +000011#include "llvm/ADT/STLExtras.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000012#include "llvm/DebugInfo/PDB/Native/DbiStream.h"
13#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000014#include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000015#include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
16#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
Zachary Turner8ab7dd602018-09-07 00:12:34 +000017#include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
Zachary Turner7999b4f2018-09-05 23:30:38 +000018#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Adrian McCarthy4d93d662017-03-29 19:27:08 +000019
Zachary Turner7999b4f2018-09-05 23:30:38 +000020using namespace llvm;
21using namespace llvm::pdb;
Adrian McCarthy4d93d662017-03-29 19:27:08 +000022
Zachary Turner8ab7dd602018-09-07 00:12:34 +000023static DbiStream *getDbiStreamPtr(NativeSession &Session) {
24 Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream();
25 if (DbiS)
26 return &DbiS.get();
27
28 consumeError(DbiS.takeError());
29 return nullptr;
30}
31
Adrian McCarthy8d090fc2017-07-12 19:38:11 +000032NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
Zachary Turner7999b4f2018-09-05 23:30:38 +000033 : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
Zachary Turner8ab7dd602018-09-07 00:12:34 +000034 Dbi(getDbiStreamPtr(Session)) {}
Adrian McCarthy31bcb6f2017-06-22 18:43:18 +000035
Adrian McCarthy4d93d662017-03-29 19:27:08 +000036std::unique_ptr<IPDBEnumSymbols>
37NativeExeSymbol::findChildren(PDB_SymType Type) const {
38 switch (Type) {
39 case PDB_SymType::Compiland: {
Zachary Turner7999b4f2018-09-05 23:30:38 +000040 return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
Adrian McCarthy4d93d662017-03-29 19:27:08 +000041 break;
42 }
Zachary Turner518cb2d2018-09-30 16:19:18 +000043 case PDB_SymType::ArrayType:
44 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY);
Adrian McCarthyb41f03e2017-08-04 22:37:58 +000045 case PDB_SymType::Enum:
Zachary Turner8ab7dd602018-09-07 00:12:34 +000046 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
Zachary Turnerda4b63a2018-09-07 23:21:33 +000047 case PDB_SymType::PointerType:
48 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER);
Zachary Turner355ffb02018-09-21 22:36:04 +000049 case PDB_SymType::UDT:
50 return Session.getSymbolCache().createTypeEnumerator(
51 {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION,
52 codeview::LF_INTERFACE});
Zachary Turner5c1873b2018-10-01 17:55:16 +000053 case PDB_SymType::VTableShape:
54 return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE);
Zachary Turner6345e842018-09-21 22:36:28 +000055 case PDB_SymType::FunctionSig:
56 return Session.getSymbolCache().createTypeEnumerator(
57 {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
Zachary Turnera5e3e022018-10-01 17:55:38 +000058 case PDB_SymType::Typedef:
59 return Session.getSymbolCache().createGlobalsEnumerator(codeview::S_UDT);
Zachary Turner6345e842018-09-21 22:36:28 +000060
Adrian McCarthy4d93d662017-03-29 19:27:08 +000061 default:
62 break;
63 }
64 return nullptr;
65}
66
67uint32_t NativeExeSymbol::getAge() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000068 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000069 if (IS)
70 return IS->getAge();
71 consumeError(IS.takeError());
72 return 0;
73}
74
75std::string NativeExeSymbol::getSymbolsFileName() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000076 return Session.getPDBFile().getFilePath();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000077}
78
Reid Kleckner67653ee2017-07-17 23:59:44 +000079codeview::GUID NativeExeSymbol::getGuid() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000080 auto IS = Session.getPDBFile().getPDBInfoStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000081 if (IS)
82 return IS->getGuid();
83 consumeError(IS.takeError());
Reid Kleckner67653ee2017-07-17 23:59:44 +000084 return codeview::GUID{{0}};
Adrian McCarthy4d93d662017-03-29 19:27:08 +000085}
86
87bool NativeExeSymbol::hasCTypes() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000088 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000089 if (Dbi)
90 return Dbi->hasCTypes();
91 consumeError(Dbi.takeError());
92 return false;
93}
94
95bool NativeExeSymbol::hasPrivateSymbols() const {
Zachary Turner8ab7dd602018-09-07 00:12:34 +000096 auto Dbi = Session.getPDBFile().getPDBDbiStream();
Adrian McCarthy4d93d662017-03-29 19:27:08 +000097 if (Dbi)
98 return !Dbi->isStripped();
99 consumeError(Dbi.takeError());
100 return false;
101}