Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 1 | //===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // 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 McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h" |
| 10 | |
Adrian McCarthy | 4aedc81 | 2017-06-22 18:57:51 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/STLExtras.h" |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" |
| 13 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 14 | #include "llvm/DebugInfo/PDB/Native/NativeCompilandSymbol.h" |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h" |
| 16 | #include "llvm/DebugInfo/PDB/Native/PDBFile.h" |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 17 | #include "llvm/DebugInfo/PDB/Native/SymbolCache.h" |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 18 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 19 | |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | using namespace llvm::pdb; |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 22 | |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 23 | static 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 McCarthy | 8d090fc | 2017-07-12 19:38:11 +0000 | [diff] [blame] | 32 | NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId) |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 33 | : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId), |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 34 | Dbi(getDbiStreamPtr(Session)) {} |
Adrian McCarthy | 31bcb6f | 2017-06-22 18:43:18 +0000 | [diff] [blame] | 35 | |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 36 | std::unique_ptr<IPDBEnumSymbols> |
| 37 | NativeExeSymbol::findChildren(PDB_SymType Type) const { |
| 38 | switch (Type) { |
| 39 | case PDB_SymType::Compiland: { |
Zachary Turner | 7999b4f | 2018-09-05 23:30:38 +0000 | [diff] [blame] | 40 | return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session)); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 41 | break; |
| 42 | } |
Zachary Turner | 518cb2d | 2018-09-30 16:19:18 +0000 | [diff] [blame] | 43 | case PDB_SymType::ArrayType: |
| 44 | return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY); |
Adrian McCarthy | b41f03e | 2017-08-04 22:37:58 +0000 | [diff] [blame] | 45 | case PDB_SymType::Enum: |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 46 | return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM); |
Zachary Turner | da4b63a | 2018-09-07 23:21:33 +0000 | [diff] [blame] | 47 | case PDB_SymType::PointerType: |
| 48 | return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER); |
Zachary Turner | 355ffb0 | 2018-09-21 22:36:04 +0000 | [diff] [blame] | 49 | case PDB_SymType::UDT: |
| 50 | return Session.getSymbolCache().createTypeEnumerator( |
| 51 | {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION, |
| 52 | codeview::LF_INTERFACE}); |
Zachary Turner | 5c1873b | 2018-10-01 17:55:16 +0000 | [diff] [blame] | 53 | case PDB_SymType::VTableShape: |
| 54 | return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE); |
Zachary Turner | 6345e84 | 2018-09-21 22:36:28 +0000 | [diff] [blame] | 55 | case PDB_SymType::FunctionSig: |
| 56 | return Session.getSymbolCache().createTypeEnumerator( |
| 57 | {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION}); |
Zachary Turner | a5e3e02 | 2018-10-01 17:55:38 +0000 | [diff] [blame] | 58 | case PDB_SymType::Typedef: |
| 59 | return Session.getSymbolCache().createGlobalsEnumerator(codeview::S_UDT); |
Zachary Turner | 6345e84 | 2018-09-21 22:36:28 +0000 | [diff] [blame] | 60 | |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 61 | default: |
| 62 | break; |
| 63 | } |
| 64 | return nullptr; |
| 65 | } |
| 66 | |
| 67 | uint32_t NativeExeSymbol::getAge() const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 68 | auto IS = Session.getPDBFile().getPDBInfoStream(); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 69 | if (IS) |
| 70 | return IS->getAge(); |
| 71 | consumeError(IS.takeError()); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | std::string NativeExeSymbol::getSymbolsFileName() const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 76 | return Session.getPDBFile().getFilePath(); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Reid Kleckner | 67653ee | 2017-07-17 23:59:44 +0000 | [diff] [blame] | 79 | codeview::GUID NativeExeSymbol::getGuid() const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 80 | auto IS = Session.getPDBFile().getPDBInfoStream(); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 81 | if (IS) |
| 82 | return IS->getGuid(); |
| 83 | consumeError(IS.takeError()); |
Reid Kleckner | 67653ee | 2017-07-17 23:59:44 +0000 | [diff] [blame] | 84 | return codeview::GUID{{0}}; |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | bool NativeExeSymbol::hasCTypes() const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 88 | auto Dbi = Session.getPDBFile().getPDBDbiStream(); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 89 | if (Dbi) |
| 90 | return Dbi->hasCTypes(); |
| 91 | consumeError(Dbi.takeError()); |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | bool NativeExeSymbol::hasPrivateSymbols() const { |
Zachary Turner | 8ab7dd60 | 2018-09-07 00:12:34 +0000 | [diff] [blame] | 96 | auto Dbi = Session.getPDBFile().getPDBDbiStream(); |
Adrian McCarthy | 4d93d66 | 2017-03-29 19:27:08 +0000 | [diff] [blame] | 97 | if (Dbi) |
| 98 | return !Dbi->isStripped(); |
| 99 | consumeError(Dbi.takeError()); |
| 100 | return false; |
| 101 | } |