| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1 | //===-- SymbolFilePDB.cpp ---------------------------------------*- 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 "SymbolFilePDB.h" | 
|  | 11 |  | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 12 | #include "clang/Lex/Lexer.h" | 
|  | 13 |  | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" | 
|  | 15 | #include "lldb/Core/PluginManager.h" | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/ClangASTContext.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 17 | #include "lldb/Symbol/CompileUnit.h" | 
|  | 18 | #include "lldb/Symbol/LineTable.h" | 
|  | 19 | #include "lldb/Symbol/ObjectFile.h" | 
|  | 20 | #include "lldb/Symbol/SymbolContext.h" | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolVendor.h" | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 22 | #include "lldb/Symbol/TypeList.h" | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/TypeMap.h" | 
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 24 | #include "lldb/Utility/RegularExpression.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 25 |  | 
| Pavel Labath | b8d8c62 | 2016-05-09 11:07:43 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/PDB/GenericError.h" | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 27 | #include "llvm/DebugInfo/PDB/IPDBDataStream.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 28 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" | 
|  | 29 | #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 30 | #include "llvm/DebugInfo/PDB/IPDBSectionContrib.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 31 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 32 | #include "llvm/DebugInfo/PDB/IPDBTable.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 34 | #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 35 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" | 
|  | 36 | #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 37 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 38 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" | 
|  | 39 | #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" | 
|  | 40 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" | 
|  | 41 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 42 | #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h" | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 43 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" | 
|  | 44 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" | 
|  | 45 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" | 
|  | 46 |  | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 47 | #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h" | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 48 | #include "Plugins/SymbolFile/PDB/PDBASTParser.h" | 
|  | 49 |  | 
|  | 50 | #include <regex> | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 51 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 52 | using namespace lldb; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 53 | using namespace lldb_private; | 
| Zachary Turner | 54fd7ff | 2016-05-04 20:33:53 +0000 | [diff] [blame] | 54 | using namespace llvm::pdb; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 55 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | namespace { | 
|  | 57 | lldb::LanguageType TranslateLanguage(PDB_Lang lang) { | 
|  | 58 | switch (lang) { | 
|  | 59 | case PDB_Lang::Cpp: | 
|  | 60 | return lldb::LanguageType::eLanguageTypeC_plus_plus; | 
|  | 61 | case PDB_Lang::C: | 
|  | 62 | return lldb::LanguageType::eLanguageTypeC; | 
|  | 63 | default: | 
|  | 64 | return lldb::LanguageType::eLanguageTypeUnknown; | 
|  | 65 | } | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 66 | } | 
|  | 67 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line, | 
|  | 69 | uint32_t addr_length) { | 
|  | 70 | return ((requested_line == 0 || actual_line == requested_line) && | 
|  | 71 | addr_length > 0); | 
|  | 72 | } | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 73 | } // namespace | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 74 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | void SymbolFilePDB::Initialize() { | 
|  | 76 | PluginManager::RegisterPlugin(GetPluginNameStatic(), | 
|  | 77 | GetPluginDescriptionStatic(), CreateInstance, | 
|  | 78 | DebuggerInitialize); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 79 | } | 
|  | 80 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | void SymbolFilePDB::Terminate() { | 
|  | 82 | PluginManager::UnregisterPlugin(CreateInstance); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | void SymbolFilePDB::DebuggerInitialize(lldb_private::Debugger &debugger) {} | 
|  | 86 |  | 
|  | 87 | lldb_private::ConstString SymbolFilePDB::GetPluginNameStatic() { | 
|  | 88 | static ConstString g_name("pdb"); | 
|  | 89 | return g_name; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 90 | } | 
|  | 91 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | const char *SymbolFilePDB::GetPluginDescriptionStatic() { | 
|  | 93 | return "Microsoft PDB debug symbol file reader."; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 94 | } | 
|  | 95 |  | 
|  | 96 | lldb_private::SymbolFile * | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | SymbolFilePDB::CreateInstance(lldb_private::ObjectFile *obj_file) { | 
|  | 98 | return new SymbolFilePDB(obj_file); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file) | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 102 | : SymbolFile(object_file), m_session_up(), m_global_scope_up(), | 
|  | 103 | m_cached_compile_unit_count(0), m_tu_decl_ctx_up() {} | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 104 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | SymbolFilePDB::~SymbolFilePDB() {} | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 106 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | uint32_t SymbolFilePDB::CalculateAbilities() { | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 108 | uint32_t abilities = 0; | 
|  | 109 | if (!m_obj_file) | 
|  | 110 | return 0; | 
|  | 111 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | if (!m_session_up) { | 
|  | 113 | // Lazily load and match the PDB file, but only do this once. | 
|  | 114 | std::string exePath = m_obj_file->GetFileSpec().GetPath(); | 
|  | 115 | auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath), | 
|  | 116 | m_session_up); | 
|  | 117 | if (error) { | 
|  | 118 | llvm::consumeError(std::move(error)); | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 119 | auto module_sp = m_obj_file->GetModule(); | 
|  | 120 | if (!module_sp) | 
|  | 121 | return 0; | 
|  | 122 | // See if any symbol file is specified through `--symfile` option. | 
|  | 123 | FileSpec symfile = module_sp->GetSymbolFileFileSpec(); | 
|  | 124 | if (!symfile) | 
|  | 125 | return 0; | 
|  | 126 | error = loadDataForPDB(PDB_ReaderType::DIA, | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 127 | llvm::StringRef(symfile.GetPath()), m_session_up); | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 128 | if (error) { | 
|  | 129 | llvm::consumeError(std::move(error)); | 
|  | 130 | return 0; | 
|  | 131 | } | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 132 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | } | 
| Aaron Smith | d5a925f | 2018-03-22 19:21:34 +0000 | [diff] [blame] | 134 | if (!m_session_up) | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 135 | return 0; | 
|  | 136 |  | 
|  | 137 | auto enum_tables_up = m_session_up->getEnumTables(); | 
|  | 138 | if (!enum_tables_up) | 
|  | 139 | return 0; | 
|  | 140 | while (auto table_up = enum_tables_up->getNext()) { | 
|  | 141 | if (table_up->getItemCount() == 0) | 
|  | 142 | continue; | 
|  | 143 | auto type = table_up->getTableType(); | 
|  | 144 | switch (type) { | 
|  | 145 | case PDB_TableType::Symbols: | 
|  | 146 | // This table represents a store of symbols with types listed in | 
|  | 147 | // PDBSym_Type | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 148 | abilities |= (CompileUnits | Functions | Blocks | GlobalVariables | | 
|  | 149 | LocalVariables | VariableTypes); | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 150 | break; | 
|  | 151 | case PDB_TableType::LineNumbers: | 
|  | 152 | abilities |= LineTables; | 
|  | 153 | break; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 154 | default: | 
|  | 155 | break; | 
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 156 | } | 
|  | 157 | } | 
|  | 158 | return abilities; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | void SymbolFilePDB::InitializeObject() { | 
|  | 162 | lldb::addr_t obj_load_address = m_obj_file->GetFileOffset(); | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 163 | lldbassert(obj_load_address && obj_load_address != LLDB_INVALID_ADDRESS); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 164 | m_session_up->setLoadAddress(obj_load_address); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 165 | if (!m_global_scope_up) | 
|  | 166 | m_global_scope_up = m_session_up->getGlobalScope(); | 
|  | 167 | lldbassert(m_global_scope_up.get()); | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 168 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | TypeSystem *type_system = | 
|  | 170 | GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); | 
|  | 171 | ClangASTContext *clang_type_system = | 
|  | 172 | llvm::dyn_cast_or_null<ClangASTContext>(type_system); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 173 | lldbassert(clang_type_system); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | m_tu_decl_ctx_up = llvm::make_unique<CompilerDeclContext>( | 
|  | 175 | type_system, clang_type_system->GetTranslationUnitDecl()); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 176 | } | 
|  | 177 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | uint32_t SymbolFilePDB::GetNumCompileUnits() { | 
|  | 179 | if (m_cached_compile_unit_count == 0) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 180 | auto compilands = m_global_scope_up->findAllChildren<PDBSymbolCompiland>(); | 
|  | 181 | if (!compilands) | 
|  | 182 | return 0; | 
|  | 183 |  | 
|  | 184 | // The linker could link *.dll (compiland language = LINK), or import | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 185 | // *.dll. For example, a compiland with name `Import:KERNEL32.dll` could be | 
|  | 186 | // found as a child of the global scope (PDB executable). Usually, such | 
|  | 187 | // compilands contain `thunk` symbols in which we are not interested for | 
|  | 188 | // now. However we still count them in the compiland list. If we perform | 
|  | 189 | // any compiland related activity, like finding symbols through | 
|  | 190 | // llvm::pdb::IPDBSession methods, such compilands will all be searched | 
|  | 191 | // automatically no matter whether we include them or not. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 192 | m_cached_compile_unit_count = compilands->getChildCount(); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 193 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 194 | // The linker can inject an additional "dummy" compilation unit into the | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 195 | // PDB. Ignore this special compile unit for our purposes, if it is there. | 
|  | 196 | // It is always the last one. | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 197 | auto last_compiland_up = | 
|  | 198 | compilands->getChildAtIndex(m_cached_compile_unit_count - 1); | 
|  | 199 | lldbassert(last_compiland_up.get()); | 
|  | 200 | std::string name = last_compiland_up->getName(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | if (name == "* Linker *") | 
|  | 202 | --m_cached_compile_unit_count; | 
|  | 203 | } | 
|  | 204 | return m_cached_compile_unit_count; | 
|  | 205 | } | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 206 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 207 | void SymbolFilePDB::GetCompileUnitIndex( | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 208 | const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 209 | auto results_up = m_global_scope_up->findAllChildren<PDBSymbolCompiland>(); | 
|  | 210 | if (!results_up) | 
|  | 211 | return; | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 212 | auto uid = pdb_compiland.getSymIndexId(); | 
| Raphael Isemann | fbdf0b9 | 2018-01-22 06:56:09 +0000 | [diff] [blame] | 213 | for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 214 | auto compiland_up = results_up->getChildAtIndex(cu_idx); | 
|  | 215 | if (!compiland_up) | 
|  | 216 | continue; | 
|  | 217 | if (compiland_up->getSymIndexId() == uid) { | 
|  | 218 | index = cu_idx; | 
|  | 219 | return; | 
|  | 220 | } | 
|  | 221 | } | 
|  | 222 | index = UINT32_MAX; | 
|  | 223 | return; | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | std::unique_ptr<llvm::pdb::PDBSymbolCompiland> | 
|  | 227 | SymbolFilePDB::GetPDBCompilandByUID(uint32_t uid) { | 
|  | 228 | return m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(uid); | 
|  | 229 | } | 
|  | 230 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 231 | lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitAtIndex(uint32_t index) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 232 | if (index >= GetNumCompileUnits()) | 
|  | 233 | return CompUnitSP(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 234 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 235 | // Assuming we always retrieve same compilands listed in same order through | 
|  | 236 | // `PDBSymbolExe::findAllChildren` method, otherwise using `index` to get a | 
|  | 237 | // compile unit makes no sense. | 
|  | 238 | auto results = m_global_scope_up->findAllChildren<PDBSymbolCompiland>(); | 
|  | 239 | if (!results) | 
|  | 240 | return CompUnitSP(); | 
|  | 241 | auto compiland_up = results->getChildAtIndex(index); | 
|  | 242 | if (!compiland_up) | 
|  | 243 | return CompUnitSP(); | 
|  | 244 | return ParseCompileUnitForUID(compiland_up->getSymIndexId(), index); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 245 | } | 
|  | 246 |  | 
|  | 247 | lldb::LanguageType | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | SymbolFilePDB::ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) { | 
|  | 249 | // What fields should I expect to be filled out on the SymbolContext?  Is it | 
|  | 250 | // safe to assume that `sc.comp_unit` is valid? | 
|  | 251 | if (!sc.comp_unit) | 
|  | 252 | return lldb::eLanguageTypeUnknown; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 253 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 254 | auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID()); | 
|  | 255 | if (!compiland_up) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 256 | return lldb::eLanguageTypeUnknown; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 257 | auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 258 | if (!details) | 
|  | 259 | return lldb::eLanguageTypeUnknown; | 
|  | 260 | return TranslateLanguage(details->getLanguage()); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 261 | } | 
|  | 262 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 263 | lldb_private::Function *SymbolFilePDB::ParseCompileUnitFunctionForPDBFunc( | 
|  | 264 | const PDBSymbolFunc &pdb_func, const lldb_private::SymbolContext &sc) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 265 | lldbassert(sc.comp_unit && sc.module_sp.get()); | 
|  | 266 |  | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 267 | auto file_vm_addr = pdb_func.getVirtualAddress(); | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 268 | if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0) | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 269 | return nullptr; | 
|  | 270 |  | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 271 | auto func_length = pdb_func.getLength(); | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 272 | AddressRange func_range = | 
|  | 273 | AddressRange(file_vm_addr, func_length, sc.module_sp->GetSectionList()); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 274 | if (!func_range.GetBaseAddress().IsValid()) | 
|  | 275 | return nullptr; | 
|  | 276 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 277 | lldb_private::Type *func_type = ResolveTypeUID(pdb_func.getSymIndexId()); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 278 | if (!func_type) | 
|  | 279 | return nullptr; | 
|  | 280 |  | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 281 | user_id_t func_type_uid = pdb_func.getSignatureId(); | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 282 |  | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 283 | Mangled mangled = GetMangledForPDBFunc(pdb_func); | 
|  | 284 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 285 | FunctionSP func_sp = | 
|  | 286 | std::make_shared<Function>(sc.comp_unit, pdb_func.getSymIndexId(), | 
|  | 287 | func_type_uid, mangled, func_type, func_range); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 288 |  | 
|  | 289 | sc.comp_unit->AddFunction(func_sp); | 
|  | 290 | return func_sp.get(); | 
|  | 291 | } | 
|  | 292 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 293 | size_t SymbolFilePDB::ParseCompileUnitFunctions( | 
|  | 294 | const lldb_private::SymbolContext &sc) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 295 | lldbassert(sc.comp_unit); | 
|  | 296 | size_t func_added = 0; | 
|  | 297 | auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID()); | 
|  | 298 | if (!compiland_up) | 
|  | 299 | return 0; | 
|  | 300 | auto results_up = compiland_up->findAllChildren<PDBSymbolFunc>(); | 
|  | 301 | if (!results_up) | 
|  | 302 | return 0; | 
|  | 303 | while (auto pdb_func_up = results_up->getNext()) { | 
|  | 304 | auto func_sp = | 
|  | 305 | sc.comp_unit->FindFunctionByUID(pdb_func_up->getSymIndexId()); | 
|  | 306 | if (!func_sp) { | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 307 | if (ParseCompileUnitFunctionForPDBFunc(*pdb_func_up, sc)) | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 308 | ++func_added; | 
|  | 309 | } | 
|  | 310 | } | 
|  | 311 | return func_added; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 312 | } | 
|  | 313 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 314 | bool SymbolFilePDB::ParseCompileUnitLineTable( | 
|  | 315 | const lldb_private::SymbolContext &sc) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 316 | lldbassert(sc.comp_unit); | 
|  | 317 | if (sc.comp_unit->GetLineTable()) | 
|  | 318 | return true; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | return ParseCompileUnitLineTable(sc, 0); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 322 | bool SymbolFilePDB::ParseCompileUnitDebugMacros( | 
|  | 323 | const lldb_private::SymbolContext &sc) { | 
|  | 324 | // PDB doesn't contain information about macros | 
|  | 325 | return false; | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | bool SymbolFilePDB::ParseCompileUnitSupportFiles( | 
|  | 329 | const lldb_private::SymbolContext &sc, | 
|  | 330 | lldb_private::FileSpecList &support_files) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 331 | lldbassert(sc.comp_unit); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 332 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 333 | // In theory this is unnecessary work for us, because all of this information | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 334 | // is easily (and quickly) accessible from DebugInfoPDB, so caching it a | 
|  | 335 | // second time seems like a waste.  Unfortunately, there's no good way around | 
|  | 336 | // this short of a moderate refactor since SymbolVendor depends on being able | 
|  | 337 | // to cache this list. | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 338 | auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID()); | 
|  | 339 | if (!compiland_up) | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 340 | return false; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 341 | auto files = m_session_up->getSourceFilesForCompiland(*compiland_up); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | if (!files || files->getChildCount() == 0) | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 343 | return false; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 344 |  | 
|  | 345 | while (auto file = files->getNext()) { | 
| Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 346 | FileSpec spec(file->getFileName(), false, FileSpec::Style::windows); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 347 | support_files.AppendIfUnique(spec); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | } | 
|  | 349 | return true; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 350 | } | 
|  | 351 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | bool SymbolFilePDB::ParseImportedModules( | 
|  | 353 | const lldb_private::SymbolContext &sc, | 
|  | 354 | std::vector<lldb_private::ConstString> &imported_modules) { | 
|  | 355 | // PDB does not yet support module debug info | 
|  | 356 | return false; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 357 | } | 
|  | 358 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 359 | static size_t ParseFunctionBlocksForPDBSymbol( | 
|  | 360 | const lldb_private::SymbolContext &sc, uint64_t func_file_vm_addr, | 
|  | 361 | const llvm::pdb::PDBSymbol *pdb_symbol, lldb_private::Block *parent_block, | 
|  | 362 | bool is_top_parent) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 363 | assert(pdb_symbol && parent_block); | 
|  | 364 |  | 
|  | 365 | size_t num_added = 0; | 
|  | 366 | switch (pdb_symbol->getSymTag()) { | 
|  | 367 | case PDB_SymType::Block: | 
|  | 368 | case PDB_SymType::Function: { | 
|  | 369 | Block *block = nullptr; | 
|  | 370 | auto &raw_sym = pdb_symbol->getRawSymbol(); | 
|  | 371 | if (auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(pdb_symbol)) { | 
|  | 372 | if (pdb_func->hasNoInlineAttribute()) | 
|  | 373 | break; | 
|  | 374 | if (is_top_parent) | 
|  | 375 | block = parent_block; | 
|  | 376 | else | 
|  | 377 | break; | 
|  | 378 | } else if (llvm::dyn_cast<PDBSymbolBlock>(pdb_symbol)) { | 
|  | 379 | auto uid = pdb_symbol->getSymIndexId(); | 
|  | 380 | if (parent_block->FindBlockByID(uid)) | 
|  | 381 | break; | 
|  | 382 | if (raw_sym.getVirtualAddress() < func_file_vm_addr) | 
|  | 383 | break; | 
|  | 384 |  | 
|  | 385 | auto block_sp = std::make_shared<Block>(pdb_symbol->getSymIndexId()); | 
|  | 386 | parent_block->AddChild(block_sp); | 
|  | 387 | block = block_sp.get(); | 
|  | 388 | } else | 
|  | 389 | llvm_unreachable("Unexpected PDB symbol!"); | 
|  | 390 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 391 | block->AddRange(Block::Range( | 
|  | 392 | raw_sym.getVirtualAddress() - func_file_vm_addr, raw_sym.getLength())); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 393 | block->FinalizeRanges(); | 
|  | 394 | ++num_added; | 
|  | 395 |  | 
|  | 396 | auto results_up = pdb_symbol->findAllChildren(); | 
|  | 397 | if (!results_up) | 
|  | 398 | break; | 
|  | 399 | while (auto symbol_up = results_up->getNext()) { | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 400 | num_added += ParseFunctionBlocksForPDBSymbol( | 
|  | 401 | sc, func_file_vm_addr, symbol_up.get(), block, false); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 402 | } | 
|  | 403 | } break; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 404 | default: | 
|  | 405 | break; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 406 | } | 
|  | 407 | return num_added; | 
|  | 408 | } | 
|  | 409 |  | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 410 | size_t | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 411 | SymbolFilePDB::ParseFunctionBlocks(const lldb_private::SymbolContext &sc) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 412 | lldbassert(sc.comp_unit && sc.function); | 
|  | 413 | size_t num_added = 0; | 
|  | 414 | auto uid = sc.function->GetID(); | 
|  | 415 | auto pdb_func_up = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid); | 
|  | 416 | if (!pdb_func_up) | 
|  | 417 | return 0; | 
|  | 418 | Block &parent_block = sc.function->GetBlock(false); | 
|  | 419 | num_added = | 
|  | 420 | ParseFunctionBlocksForPDBSymbol(sc, pdb_func_up->getVirtualAddress(), | 
|  | 421 | pdb_func_up.get(), &parent_block, true); | 
|  | 422 | return num_added; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 423 | } | 
|  | 424 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 425 | size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) { | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 426 | lldbassert(sc.module_sp.get()); | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 427 | if (!sc.comp_unit) | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 428 | return 0; | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 429 |  | 
|  | 430 | size_t num_added = 0; | 
|  | 431 | auto compiland = GetPDBCompilandByUID(sc.comp_unit->GetID()); | 
|  | 432 | if (!compiland) | 
|  | 433 | return 0; | 
|  | 434 |  | 
|  | 435 | auto ParseTypesByTagFn = [&num_added, this](const PDBSymbol &raw_sym) { | 
|  | 436 | std::unique_ptr<IPDBEnumSymbols> results; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 437 | PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef, | 
|  | 438 | PDB_SymType::UDT}; | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 439 | for (auto tag : tags_to_search) { | 
|  | 440 | results = raw_sym.findAllChildren(tag); | 
|  | 441 | if (!results || results->getChildCount() == 0) | 
|  | 442 | continue; | 
|  | 443 | while (auto symbol = results->getNext()) { | 
|  | 444 | switch (symbol->getSymTag()) { | 
|  | 445 | case PDB_SymType::Enum: | 
|  | 446 | case PDB_SymType::UDT: | 
|  | 447 | case PDB_SymType::Typedef: | 
|  | 448 | break; | 
|  | 449 | default: | 
|  | 450 | continue; | 
|  | 451 | } | 
|  | 452 |  | 
|  | 453 | // This should cause the type to get cached and stored in the `m_types` | 
|  | 454 | // lookup. | 
|  | 455 | if (!ResolveTypeUID(symbol->getSymIndexId())) | 
|  | 456 | continue; | 
|  | 457 |  | 
|  | 458 | ++num_added; | 
|  | 459 | } | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 460 | } | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 461 | }; | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 462 |  | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 463 | if (sc.function) { | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 464 | auto pdb_func = m_session_up->getConcreteSymbolById<PDBSymbolFunc>( | 
|  | 465 | sc.function->GetID()); | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 466 | if (!pdb_func) | 
|  | 467 | return 0; | 
|  | 468 | ParseTypesByTagFn(*pdb_func); | 
|  | 469 | } else { | 
|  | 470 | ParseTypesByTagFn(*compiland); | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 471 |  | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 472 | // Also parse global types particularly coming from this compiland. | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 473 | // Unfortunately, PDB has no compiland information for each global type. We | 
|  | 474 | // have to parse them all. But ensure we only do this once. | 
| Aaron Smith | 66b8407 | 2018-03-14 04:05:27 +0000 | [diff] [blame] | 475 | static bool parse_all_global_types = false; | 
|  | 476 | if (!parse_all_global_types) { | 
|  | 477 | ParseTypesByTagFn(*m_global_scope_up); | 
|  | 478 | parse_all_global_types = true; | 
|  | 479 | } | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 480 | } | 
|  | 481 | return num_added; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | } | 
|  | 483 |  | 
|  | 484 | size_t | 
|  | 485 | SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) { | 
|  | 486 | // TODO: Implement this | 
|  | 487 | return size_t(); | 
|  | 488 | } | 
|  | 489 |  | 
|  | 490 | lldb_private::Type *SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) { | 
|  | 491 | auto find_result = m_types.find(type_uid); | 
|  | 492 | if (find_result != m_types.end()) | 
|  | 493 | return find_result->second.get(); | 
|  | 494 |  | 
|  | 495 | TypeSystem *type_system = | 
|  | 496 | GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); | 
|  | 497 | ClangASTContext *clang_type_system = | 
|  | 498 | llvm::dyn_cast_or_null<ClangASTContext>(type_system); | 
|  | 499 | if (!clang_type_system) | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 500 | return nullptr; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 501 | PDBASTParser *pdb = | 
|  | 502 | llvm::dyn_cast<PDBASTParser>(clang_type_system->GetPDBParser()); | 
|  | 503 | if (!pdb) | 
|  | 504 | return nullptr; | 
|  | 505 |  | 
|  | 506 | auto pdb_type = m_session_up->getSymbolById(type_uid); | 
|  | 507 | if (pdb_type == nullptr) | 
|  | 508 | return nullptr; | 
|  | 509 |  | 
|  | 510 | lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type); | 
| Aaron Smith | d5a925f | 2018-03-22 19:21:34 +0000 | [diff] [blame] | 511 | if (result) { | 
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 512 | m_types.insert(std::make_pair(type_uid, result)); | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 513 | auto type_list = GetTypeList(); | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 514 | if (type_list) | 
|  | 515 | type_list->Insert(result); | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 516 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 517 | return result.get(); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 518 | } | 
|  | 519 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 520 | bool SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) { | 
|  | 521 | // TODO: Implement this | 
|  | 522 | return false; | 
|  | 523 | } | 
|  | 524 |  | 
|  | 525 | lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) { | 
|  | 526 | return lldb_private::CompilerDecl(); | 
|  | 527 | } | 
|  | 528 |  | 
|  | 529 | lldb_private::CompilerDeclContext | 
|  | 530 | SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) { | 
|  | 531 | // PDB always uses the translation unit decl context for everything.  We can | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 532 | // improve this later but it's not easy because PDB doesn't provide a high | 
|  | 533 | // enough level of type fidelity in this area. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | return *m_tu_decl_ctx_up; | 
|  | 535 | } | 
|  | 536 |  | 
|  | 537 | lldb_private::CompilerDeclContext | 
|  | 538 | SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { | 
|  | 539 | return *m_tu_decl_ctx_up; | 
|  | 540 | } | 
|  | 541 |  | 
|  | 542 | void SymbolFilePDB::ParseDeclsForContext( | 
|  | 543 | lldb_private::CompilerDeclContext decl_ctx) {} | 
|  | 544 |  | 
|  | 545 | uint32_t | 
|  | 546 | SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, | 
|  | 547 | uint32_t resolve_scope, | 
|  | 548 | lldb_private::SymbolContext &sc) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 549 | uint32_t resolved_flags = 0; | 
| Pavel Labath | 4d4d63e | 2018-02-09 11:37:01 +0000 | [diff] [blame] | 550 | if (resolve_scope & eSymbolContextCompUnit || | 
|  | 551 | resolve_scope & eSymbolContextVariable || | 
|  | 552 | resolve_scope & eSymbolContextFunction || | 
|  | 553 | resolve_scope & eSymbolContextBlock || | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 554 | resolve_scope & eSymbolContextLineEntry) { | 
|  | 555 | addr_t file_vm_addr = so_addr.GetFileAddress(); | 
|  | 556 | auto symbol_up = | 
|  | 557 | m_session_up->findSymbolByAddress(file_vm_addr, PDB_SymType::None); | 
|  | 558 | if (!symbol_up) | 
|  | 559 | return 0; | 
|  | 560 |  | 
|  | 561 | auto cu_sp = GetCompileUnitContainsAddress(so_addr); | 
|  | 562 | if (!cu_sp) { | 
|  | 563 | if (resolved_flags | eSymbolContextVariable) { | 
|  | 564 | // TODO: Resolve variables | 
|  | 565 | } | 
|  | 566 | return 0; | 
|  | 567 | } | 
|  | 568 | sc.comp_unit = cu_sp.get(); | 
|  | 569 | resolved_flags |= eSymbolContextCompUnit; | 
|  | 570 | lldbassert(sc.module_sp == cu_sp->GetModule()); | 
|  | 571 |  | 
|  | 572 | switch (symbol_up->getSymTag()) { | 
|  | 573 | case PDB_SymType::Function: | 
|  | 574 | if (resolve_scope & eSymbolContextFunction) { | 
|  | 575 | auto *pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get()); | 
|  | 576 | assert(pdb_func); | 
|  | 577 | auto func_uid = pdb_func->getSymIndexId(); | 
|  | 578 | sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get(); | 
|  | 579 | if (sc.function == nullptr) | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 580 | sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 581 | if (sc.function) { | 
|  | 582 | resolved_flags |= eSymbolContextFunction; | 
|  | 583 | if (resolve_scope & eSymbolContextBlock) { | 
|  | 584 | Block &block = sc.function->GetBlock(true); | 
|  | 585 | sc.block = block.FindBlockByID(sc.function->GetID()); | 
|  | 586 | if (sc.block) | 
|  | 587 | resolved_flags |= eSymbolContextBlock; | 
|  | 588 | } | 
|  | 589 | } | 
|  | 590 | } | 
|  | 591 | break; | 
|  | 592 | default: | 
|  | 593 | break; | 
|  | 594 | } | 
|  | 595 |  | 
|  | 596 | if (resolve_scope & eSymbolContextLineEntry) { | 
|  | 597 | if (auto *line_table = sc.comp_unit->GetLineTable()) { | 
|  | 598 | Address addr(so_addr); | 
|  | 599 | if (line_table->FindLineEntryByAddress(addr, sc.line_entry)) | 
|  | 600 | resolved_flags |= eSymbolContextLineEntry; | 
|  | 601 | } | 
|  | 602 | } | 
|  | 603 | } | 
|  | 604 | return resolved_flags; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | } | 
|  | 606 |  | 
|  | 607 | uint32_t SymbolFilePDB::ResolveSymbolContext( | 
|  | 608 | const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines, | 
|  | 609 | uint32_t resolve_scope, lldb_private::SymbolContextList &sc_list) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 610 | const size_t old_size = sc_list.GetSize(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 611 | if (resolve_scope & lldb::eSymbolContextCompUnit) { | 
|  | 612 | // Locate all compilation units with line numbers referencing the specified | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 613 | // file.  For example, if `file_spec` is <vector>, then this should return | 
|  | 614 | // all source files and header files that reference <vector>, either | 
|  | 615 | // directly or indirectly. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 616 | auto compilands = m_session_up->findCompilandsForSourceFile( | 
|  | 617 | file_spec.GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive); | 
|  | 618 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 619 | if (!compilands) | 
|  | 620 | return 0; | 
|  | 621 |  | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 622 | // For each one, either find its previously parsed data or parse it afresh | 
|  | 623 | // and add it to the symbol context list. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 624 | while (auto compiland = compilands->getNext()) { | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 625 | // If we're not checking inlines, then don't add line information for | 
|  | 626 | // this file unless the FileSpec matches. For inline functions, we don't | 
|  | 627 | // have to match the FileSpec since they could be defined in headers | 
|  | 628 | // other than file specified in FileSpec. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 629 | if (!check_inlines) { | 
| Aaron Smith | 487b0c6 | 2018-03-20 00:18:22 +0000 | [diff] [blame] | 630 | std::string source_file = compiland->getSourceFileFullPath(); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 631 | if (source_file.empty()) | 
|  | 632 | continue; | 
| Pavel Labath | 2cb7cf8 | 2018-05-14 14:52:47 +0000 | [diff] [blame] | 633 | FileSpec this_spec(source_file, false, FileSpec::Style::windows); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 634 | bool need_full_match = !file_spec.GetDirectory().IsEmpty(); | 
|  | 635 | if (FileSpec::Compare(file_spec, this_spec, need_full_match) != 0) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 636 | continue; | 
|  | 637 | } | 
|  | 638 |  | 
|  | 639 | SymbolContext sc; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 640 | auto cu = ParseCompileUnitForUID(compiland->getSymIndexId()); | 
| Aaron Smith | d5a925f | 2018-03-22 19:21:34 +0000 | [diff] [blame] | 641 | if (!cu) | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 642 | continue; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | sc.comp_unit = cu.get(); | 
|  | 644 | sc.module_sp = cu->GetModule(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 645 |  | 
|  | 646 | // If we were asked to resolve line entries, add all entries to the line | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 647 | // table that match the requested line (or all lines if `line` == 0). | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 648 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock | | 
|  | 649 | eSymbolContextLineEntry)) { | 
|  | 650 | bool has_line_table = ParseCompileUnitLineTable(sc, line); | 
|  | 651 |  | 
|  | 652 | if ((resolve_scope & eSymbolContextLineEntry) && !has_line_table) { | 
|  | 653 | // The query asks for line entries, but we can't get them for the | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 654 | // compile unit. This is not normal for `line` = 0. So just assert | 
|  | 655 | // it. | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 656 | assert(line && "Couldn't get all line entries!\n"); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 657 |  | 
|  | 658 | // Current compiland does not have the requested line. Search next. | 
|  | 659 | continue; | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 | if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock)) { | 
|  | 663 | if (!has_line_table) | 
|  | 664 | continue; | 
|  | 665 |  | 
|  | 666 | auto *line_table = sc.comp_unit->GetLineTable(); | 
|  | 667 | lldbassert(line_table); | 
|  | 668 |  | 
|  | 669 | uint32_t num_line_entries = line_table->GetSize(); | 
|  | 670 | // Skip the terminal line entry. | 
|  | 671 | --num_line_entries; | 
|  | 672 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 673 | // If `line `!= 0, see if we can resolve function for each line entry | 
|  | 674 | // in the line table. | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 675 | for (uint32_t line_idx = 0; line && line_idx < num_line_entries; | 
|  | 676 | ++line_idx) { | 
|  | 677 | if (!line_table->GetLineEntryAtIndex(line_idx, sc.line_entry)) | 
|  | 678 | continue; | 
|  | 679 |  | 
|  | 680 | auto file_vm_addr = | 
|  | 681 | sc.line_entry.range.GetBaseAddress().GetFileAddress(); | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 682 | if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0) | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 683 | continue; | 
|  | 684 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 685 | auto symbol_up = m_session_up->findSymbolByAddress( | 
|  | 686 | file_vm_addr, PDB_SymType::Function); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 687 | if (symbol_up) { | 
|  | 688 | auto func_uid = symbol_up->getSymIndexId(); | 
|  | 689 | sc.function = sc.comp_unit->FindFunctionByUID(func_uid).get(); | 
|  | 690 | if (sc.function == nullptr) { | 
|  | 691 | auto pdb_func = llvm::dyn_cast<PDBSymbolFunc>(symbol_up.get()); | 
|  | 692 | assert(pdb_func); | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 693 | sc.function = ParseCompileUnitFunctionForPDBFunc(*pdb_func, sc); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 694 | } | 
|  | 695 | if (sc.function && (resolve_scope & eSymbolContextBlock)) { | 
|  | 696 | Block &block = sc.function->GetBlock(true); | 
|  | 697 | sc.block = block.FindBlockByID(sc.function->GetID()); | 
|  | 698 | } | 
|  | 699 | } | 
|  | 700 | sc_list.Append(sc); | 
|  | 701 | } | 
|  | 702 | } else if (has_line_table) { | 
|  | 703 | // We can parse line table for the compile unit. But no query to | 
|  | 704 | // resolve function or block. We append `sc` to the list anyway. | 
|  | 705 | sc_list.Append(sc); | 
|  | 706 | } | 
|  | 707 | } else { | 
|  | 708 | // No query for line entry, function or block. But we have a valid | 
|  | 709 | // compile unit, append `sc` to the list. | 
|  | 710 | sc_list.Append(sc); | 
|  | 711 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | } | 
|  | 713 | } | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 714 | return sc_list.GetSize() - old_size; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 715 | } | 
|  | 716 |  | 
|  | 717 | uint32_t SymbolFilePDB::FindGlobalVariables( | 
|  | 718 | const lldb_private::ConstString &name, | 
|  | 719 | const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, | 
|  | 720 | uint32_t max_matches, lldb_private::VariableList &variables) { | 
|  | 721 | return uint32_t(); | 
|  | 722 | } | 
|  | 723 |  | 
|  | 724 | uint32_t | 
|  | 725 | SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, | 
|  | 726 | bool append, uint32_t max_matches, | 
|  | 727 | lldb_private::VariableList &variables) { | 
|  | 728 | return uint32_t(); | 
|  | 729 | } | 
|  | 730 |  | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 731 | bool SymbolFilePDB::ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 732 | bool include_inlines, | 
|  | 733 | lldb_private::SymbolContextList &sc_list) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 734 | lldb_private::SymbolContext sc; | 
| Aaron Smith | a3a8cc8 | 2018-03-20 00:34:18 +0000 | [diff] [blame] | 735 | sc.comp_unit = ParseCompileUnitForUID(pdb_func.getCompilandId()).get(); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 736 | if (!sc.comp_unit) | 
|  | 737 | return false; | 
|  | 738 | sc.module_sp = sc.comp_unit->GetModule(); | 
| Aaron Smith | a3a8cc8 | 2018-03-20 00:34:18 +0000 | [diff] [blame] | 739 | sc.function = ParseCompileUnitFunctionForPDBFunc(pdb_func, sc); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 740 | if (!sc.function) | 
|  | 741 | return false; | 
|  | 742 |  | 
|  | 743 | sc_list.Append(sc); | 
|  | 744 | return true; | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | bool SymbolFilePDB::ResolveFunction(uint32_t uid, bool include_inlines, | 
|  | 748 | lldb_private::SymbolContextList &sc_list) { | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 749 | auto pdb_func_up = m_session_up->getConcreteSymbolById<PDBSymbolFunc>(uid); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 750 | if (!pdb_func_up && !(include_inlines && pdb_func_up->hasInlineAttribute())) | 
|  | 751 | return false; | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 752 | return ResolveFunction(*pdb_func_up, include_inlines, sc_list); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 753 | } | 
|  | 754 |  | 
|  | 755 | void SymbolFilePDB::CacheFunctionNames() { | 
|  | 756 | if (!m_func_full_names.IsEmpty()) | 
|  | 757 | return; | 
|  | 758 |  | 
|  | 759 | std::map<uint64_t, uint32_t> addr_ids; | 
|  | 760 |  | 
|  | 761 | if (auto results_up = m_global_scope_up->findAllChildren<PDBSymbolFunc>()) { | 
|  | 762 | while (auto pdb_func_up = results_up->getNext()) { | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 763 | if (pdb_func_up->isCompilerGenerated()) | 
|  | 764 | continue; | 
|  | 765 |  | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 766 | auto name = pdb_func_up->getName(); | 
|  | 767 | auto demangled_name = pdb_func_up->getUndecoratedName(); | 
|  | 768 | if (name.empty() && demangled_name.empty()) | 
|  | 769 | continue; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 770 |  | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 771 | auto uid = pdb_func_up->getSymIndexId(); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 772 | if (!demangled_name.empty() && pdb_func_up->getVirtualAddress()) | 
|  | 773 | addr_ids.insert(std::make_pair(pdb_func_up->getVirtualAddress(), uid)); | 
|  | 774 |  | 
|  | 775 | if (auto parent = pdb_func_up->getClassParent()) { | 
|  | 776 |  | 
|  | 777 | // PDB have symbols for class/struct methods or static methods in Enum | 
|  | 778 | // Class. We won't bother to check if the parent is UDT or Enum here. | 
|  | 779 | m_func_method_names.Append(ConstString(name), uid); | 
|  | 780 |  | 
|  | 781 | ConstString cstr_name(name); | 
|  | 782 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 783 | // To search a method name, like NS::Class:MemberFunc, LLDB searches | 
|  | 784 | // its base name, i.e. MemberFunc by default. Since PDBSymbolFunc does | 
|  | 785 | // not have inforamtion of this, we extract base names and cache them | 
|  | 786 | // by our own effort. | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 787 | llvm::StringRef basename; | 
|  | 788 | CPlusPlusLanguage::MethodName cpp_method(cstr_name); | 
|  | 789 | if (cpp_method.IsValid()) { | 
|  | 790 | llvm::StringRef context; | 
|  | 791 | basename = cpp_method.GetBasename(); | 
|  | 792 | if (basename.empty()) | 
|  | 793 | CPlusPlusLanguage::ExtractContextAndIdentifier(name.c_str(), | 
|  | 794 | context, basename); | 
|  | 795 | } | 
|  | 796 |  | 
|  | 797 | if (!basename.empty()) | 
|  | 798 | m_func_base_names.Append(ConstString(basename), uid); | 
|  | 799 | else { | 
|  | 800 | m_func_base_names.Append(ConstString(name), uid); | 
|  | 801 | } | 
|  | 802 |  | 
|  | 803 | if (!demangled_name.empty()) | 
|  | 804 | m_func_full_names.Append(ConstString(demangled_name), uid); | 
|  | 805 |  | 
|  | 806 | } else { | 
|  | 807 | // Handle not-method symbols. | 
|  | 808 |  | 
|  | 809 | // The function name might contain namespace, or its lexical scope. It | 
|  | 810 | // is not safe to get its base name by applying same scheme as we deal | 
|  | 811 | // with the method names. | 
|  | 812 | // FIXME: Remove namespace if function is static in a scope. | 
|  | 813 | m_func_base_names.Append(ConstString(name), uid); | 
|  | 814 |  | 
|  | 815 | if (name == "main") { | 
|  | 816 | m_func_full_names.Append(ConstString(name), uid); | 
|  | 817 |  | 
|  | 818 | if (!demangled_name.empty() && name != demangled_name) { | 
|  | 819 | m_func_full_names.Append(ConstString(demangled_name), uid); | 
|  | 820 | m_func_base_names.Append(ConstString(demangled_name), uid); | 
|  | 821 | } | 
|  | 822 | } else if (!demangled_name.empty()) { | 
|  | 823 | m_func_full_names.Append(ConstString(demangled_name), uid); | 
|  | 824 | } else { | 
|  | 825 | m_func_full_names.Append(ConstString(name), uid); | 
|  | 826 | } | 
|  | 827 | } | 
|  | 828 | } | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | if (auto results_up = | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 832 | m_global_scope_up->findAllChildren<PDBSymbolPublicSymbol>()) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 833 | while (auto pub_sym_up = results_up->getNext()) { | 
|  | 834 | if (!pub_sym_up->isFunction()) | 
|  | 835 | continue; | 
|  | 836 | auto name = pub_sym_up->getName(); | 
|  | 837 | if (name.empty()) | 
|  | 838 | continue; | 
|  | 839 |  | 
|  | 840 | if (CPlusPlusLanguage::IsCPPMangledName(name.c_str())) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 841 | auto vm_addr = pub_sym_up->getVirtualAddress(); | 
|  | 842 |  | 
|  | 843 | // PDB public symbol has mangled name for its associated function. | 
|  | 844 | if (vm_addr && addr_ids.find(vm_addr) != addr_ids.end()) { | 
|  | 845 | // Cache mangled name. | 
|  | 846 | m_func_full_names.Append(ConstString(name), addr_ids[vm_addr]); | 
|  | 847 | } | 
|  | 848 | } | 
|  | 849 | } | 
|  | 850 | } | 
|  | 851 | // Sort them before value searching is working properly | 
|  | 852 | m_func_full_names.Sort(); | 
|  | 853 | m_func_full_names.SizeToFit(); | 
|  | 854 | m_func_method_names.Sort(); | 
|  | 855 | m_func_method_names.SizeToFit(); | 
|  | 856 | m_func_base_names.Sort(); | 
|  | 857 | m_func_base_names.SizeToFit(); | 
|  | 858 | } | 
|  | 859 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 860 | uint32_t SymbolFilePDB::FindFunctions( | 
|  | 861 | const lldb_private::ConstString &name, | 
|  | 862 | const lldb_private::CompilerDeclContext *parent_decl_ctx, | 
|  | 863 | uint32_t name_type_mask, bool include_inlines, bool append, | 
|  | 864 | lldb_private::SymbolContextList &sc_list) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 865 | if (!append) | 
|  | 866 | sc_list.Clear(); | 
|  | 867 | lldbassert((name_type_mask & eFunctionNameTypeAuto) == 0); | 
|  | 868 |  | 
|  | 869 | if (name_type_mask == eFunctionNameTypeNone) | 
|  | 870 | return 0; | 
|  | 871 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) | 
|  | 872 | return 0; | 
|  | 873 | if (name.IsEmpty()) | 
|  | 874 | return 0; | 
|  | 875 |  | 
|  | 876 | auto old_size = sc_list.GetSize(); | 
| Pavel Labath | 4d4d63e | 2018-02-09 11:37:01 +0000 | [diff] [blame] | 877 | if (name_type_mask & eFunctionNameTypeFull || | 
|  | 878 | name_type_mask & eFunctionNameTypeBase || | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 879 | name_type_mask & eFunctionNameTypeMethod) { | 
|  | 880 | CacheFunctionNames(); | 
|  | 881 |  | 
|  | 882 | std::set<uint32_t> resolved_ids; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 883 | auto ResolveFn = [include_inlines, &name, &sc_list, &resolved_ids, | 
|  | 884 | this](UniqueCStringMap<uint32_t> &Names) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 885 | std::vector<uint32_t> ids; | 
|  | 886 | if (Names.GetValues(name, ids)) { | 
|  | 887 | for (auto id : ids) { | 
|  | 888 | if (resolved_ids.find(id) == resolved_ids.end()) { | 
|  | 889 | if (ResolveFunction(id, include_inlines, sc_list)) | 
|  | 890 | resolved_ids.insert(id); | 
|  | 891 | } | 
|  | 892 | } | 
|  | 893 | } | 
|  | 894 | }; | 
|  | 895 | if (name_type_mask & eFunctionNameTypeFull) { | 
|  | 896 | ResolveFn(m_func_full_names); | 
|  | 897 | } | 
|  | 898 | if (name_type_mask & eFunctionNameTypeBase) { | 
|  | 899 | ResolveFn(m_func_base_names); | 
|  | 900 | } | 
|  | 901 | if (name_type_mask & eFunctionNameTypeMethod) { | 
|  | 902 | ResolveFn(m_func_method_names); | 
|  | 903 | } | 
|  | 904 | } | 
|  | 905 | return sc_list.GetSize() - old_size; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 906 | } | 
|  | 907 |  | 
|  | 908 | uint32_t | 
|  | 909 | SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, | 
|  | 910 | bool include_inlines, bool append, | 
|  | 911 | lldb_private::SymbolContextList &sc_list) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 912 | if (!append) | 
|  | 913 | sc_list.Clear(); | 
|  | 914 | if (!regex.IsValid()) | 
|  | 915 | return 0; | 
|  | 916 |  | 
|  | 917 | auto old_size = sc_list.GetSize(); | 
|  | 918 | CacheFunctionNames(); | 
|  | 919 |  | 
|  | 920 | std::set<uint32_t> resolved_ids; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 921 | auto ResolveFn = [®ex, include_inlines, &sc_list, &resolved_ids, | 
|  | 922 | this](UniqueCStringMap<uint32_t> &Names) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 923 | std::vector<uint32_t> ids; | 
|  | 924 | if (Names.GetValues(regex, ids)) { | 
|  | 925 | for (auto id : ids) { | 
|  | 926 | if (resolved_ids.find(id) == resolved_ids.end()) | 
|  | 927 | if (ResolveFunction(id, include_inlines, sc_list)) | 
|  | 928 | resolved_ids.insert(id); | 
|  | 929 | } | 
|  | 930 | } | 
|  | 931 | }; | 
|  | 932 | ResolveFn(m_func_full_names); | 
|  | 933 | ResolveFn(m_func_base_names); | 
|  | 934 |  | 
|  | 935 | return sc_list.GetSize() - old_size; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 936 | } | 
|  | 937 |  | 
|  | 938 | void SymbolFilePDB::GetMangledNamesForFunction( | 
|  | 939 | const std::string &scope_qualified_name, | 
|  | 940 | std::vector<lldb_private::ConstString> &mangled_names) {} | 
|  | 941 |  | 
|  | 942 | uint32_t SymbolFilePDB::FindTypes( | 
|  | 943 | const lldb_private::SymbolContext &sc, | 
|  | 944 | const lldb_private::ConstString &name, | 
|  | 945 | const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, | 
|  | 946 | uint32_t max_matches, | 
|  | 947 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, | 
|  | 948 | lldb_private::TypeMap &types) { | 
|  | 949 | if (!append) | 
|  | 950 | types.Clear(); | 
|  | 951 | if (!name) | 
|  | 952 | return 0; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 953 | if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx)) | 
|  | 954 | return 0; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 |  | 
|  | 956 | searched_symbol_files.clear(); | 
|  | 957 | searched_symbol_files.insert(this); | 
|  | 958 |  | 
|  | 959 | std::string name_str = name.AsCString(); | 
|  | 960 |  | 
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 961 | // There is an assumption 'name' is not a regex | 
|  | 962 | FindTypesByName(name_str, max_matches, types); | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 963 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 964 | return types.GetSize(); | 
|  | 965 | } | 
|  | 966 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 967 | void SymbolFilePDB::FindTypesByRegex( | 
|  | 968 | const lldb_private::RegularExpression ®ex, uint32_t max_matches, | 
|  | 969 | lldb_private::TypeMap &types) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 970 | // When searching by regex, we need to go out of our way to limit the search | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 971 | // space as much as possible since this searches EVERYTHING in the PDB, | 
|  | 972 | // manually doing regex comparisons.  PDB library isn't optimized for regex | 
|  | 973 | // searches or searches across multiple symbol types at the same time, so the | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 974 | // best we can do is to search enums, then typedefs, then classes one by one, | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 975 | // and do a regex comparison against each of them. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 976 | PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef, | 
|  | 977 | PDB_SymType::UDT}; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 978 | std::unique_ptr<IPDBEnumSymbols> results; | 
|  | 979 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 980 | uint32_t matches = 0; | 
|  | 981 |  | 
|  | 982 | for (auto tag : tags_to_search) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 983 | results = m_global_scope_up->findAllChildren(tag); | 
|  | 984 | if (!results) | 
|  | 985 | continue; | 
|  | 986 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 987 | while (auto result = results->getNext()) { | 
|  | 988 | if (max_matches > 0 && matches >= max_matches) | 
|  | 989 | break; | 
|  | 990 |  | 
|  | 991 | std::string type_name; | 
|  | 992 | if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get())) | 
|  | 993 | type_name = enum_type->getName(); | 
|  | 994 | else if (auto typedef_type = | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 995 | llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get())) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 996 | type_name = typedef_type->getName(); | 
|  | 997 | else if (auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get())) | 
|  | 998 | type_name = class_type->getName(); | 
|  | 999 | else { | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 1000 | // We're looking only for types that have names.  Skip symbols, as well | 
|  | 1001 | // as unnamed types such as arrays, pointers, etc. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1002 | continue; | 
|  | 1003 | } | 
|  | 1004 |  | 
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 1005 | if (!regex.Execute(type_name)) | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1006 | continue; | 
|  | 1007 |  | 
|  | 1008 | // This should cause the type to get cached and stored in the `m_types` | 
|  | 1009 | // lookup. | 
|  | 1010 | if (!ResolveTypeUID(result->getSymIndexId())) | 
|  | 1011 | continue; | 
|  | 1012 |  | 
|  | 1013 | auto iter = m_types.find(result->getSymIndexId()); | 
|  | 1014 | if (iter == m_types.end()) | 
|  | 1015 | continue; | 
|  | 1016 | types.Insert(iter->second); | 
|  | 1017 | ++matches; | 
|  | 1018 | } | 
|  | 1019 | } | 
|  | 1020 | } | 
|  | 1021 |  | 
|  | 1022 | void SymbolFilePDB::FindTypesByName(const std::string &name, | 
|  | 1023 | uint32_t max_matches, | 
|  | 1024 | lldb_private::TypeMap &types) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1025 | std::unique_ptr<IPDBEnumSymbols> results; | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 1026 | if (name.empty()) | 
|  | 1027 | return; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1028 | results = m_global_scope_up->findChildren(PDB_SymType::None, name, | 
|  | 1029 | PDB_NameSearchFlags::NS_Default); | 
|  | 1030 | if (!results) | 
|  | 1031 | return; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1032 |  | 
|  | 1033 | uint32_t matches = 0; | 
|  | 1034 |  | 
|  | 1035 | while (auto result = results->getNext()) { | 
|  | 1036 | if (max_matches > 0 && matches >= max_matches) | 
|  | 1037 | break; | 
|  | 1038 | switch (result->getSymTag()) { | 
|  | 1039 | case PDB_SymType::Enum: | 
|  | 1040 | case PDB_SymType::UDT: | 
|  | 1041 | case PDB_SymType::Typedef: | 
|  | 1042 | break; | 
|  | 1043 | default: | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1044 | // We're looking only for types that have names.  Skip symbols, as well | 
|  | 1045 | // as unnamed types such as arrays, pointers, etc. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1046 | continue; | 
|  | 1047 | } | 
|  | 1048 |  | 
|  | 1049 | // This should cause the type to get cached and stored in the `m_types` | 
|  | 1050 | // lookup. | 
|  | 1051 | if (!ResolveTypeUID(result->getSymIndexId())) | 
|  | 1052 | continue; | 
|  | 1053 |  | 
|  | 1054 | auto iter = m_types.find(result->getSymIndexId()); | 
|  | 1055 | if (iter == m_types.end()) | 
|  | 1056 | continue; | 
|  | 1057 | types.Insert(iter->second); | 
|  | 1058 | ++matches; | 
|  | 1059 | } | 
|  | 1060 | } | 
|  | 1061 |  | 
|  | 1062 | size_t SymbolFilePDB::FindTypes( | 
|  | 1063 | const std::vector<lldb_private::CompilerContext> &contexts, bool append, | 
|  | 1064 | lldb_private::TypeMap &types) { | 
|  | 1065 | return 0; | 
|  | 1066 | } | 
|  | 1067 |  | 
| Aaron Smith | ec40f81 | 2018-01-23 20:35:19 +0000 | [diff] [blame] | 1068 | lldb_private::TypeList *SymbolFilePDB::GetTypeList() { | 
|  | 1069 | return m_obj_file->GetModule()->GetTypeList(); | 
|  | 1070 | } | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1071 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1072 | void SymbolFilePDB::GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, | 
|  | 1073 | uint32_t type_mask, | 
|  | 1074 | TypeCollection &type_collection) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1075 | bool can_parse = false; | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1076 | switch (pdb_symbol.getSymTag()) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1077 | case PDB_SymType::ArrayType: | 
|  | 1078 | can_parse = ((type_mask & eTypeClassArray) != 0); | 
|  | 1079 | break; | 
|  | 1080 | case PDB_SymType::BuiltinType: | 
|  | 1081 | can_parse = ((type_mask & eTypeClassBuiltin) != 0); | 
|  | 1082 | break; | 
|  | 1083 | case PDB_SymType::Enum: | 
|  | 1084 | can_parse = ((type_mask & eTypeClassEnumeration) != 0); | 
|  | 1085 | break; | 
|  | 1086 | case PDB_SymType::Function: | 
|  | 1087 | case PDB_SymType::FunctionSig: | 
|  | 1088 | can_parse = ((type_mask & eTypeClassFunction) != 0); | 
|  | 1089 | break; | 
|  | 1090 | case PDB_SymType::PointerType: | 
|  | 1091 | can_parse = ((type_mask & (eTypeClassPointer | eTypeClassBlockPointer | | 
|  | 1092 | eTypeClassMemberPointer)) != 0); | 
|  | 1093 | break; | 
|  | 1094 | case PDB_SymType::Typedef: | 
|  | 1095 | can_parse = ((type_mask & eTypeClassTypedef) != 0); | 
|  | 1096 | break; | 
|  | 1097 | case PDB_SymType::UDT: { | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1098 | auto *udt = llvm::dyn_cast<PDBSymbolTypeUDT>(&pdb_symbol); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1099 | assert(udt); | 
|  | 1100 | can_parse = (udt->getUdtKind() != PDB_UdtType::Interface && | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1101 | ((type_mask & (eTypeClassClass | eTypeClassStruct | | 
|  | 1102 | eTypeClassUnion)) != 0)); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1103 | } break; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1104 | default: | 
|  | 1105 | break; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1106 | } | 
|  | 1107 |  | 
|  | 1108 | if (can_parse) { | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1109 | if (auto *type = ResolveTypeUID(pdb_symbol.getSymIndexId())) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1110 | auto result = | 
|  | 1111 | std::find(type_collection.begin(), type_collection.end(), type); | 
|  | 1112 | if (result == type_collection.end()) | 
|  | 1113 | type_collection.push_back(type); | 
|  | 1114 | } | 
|  | 1115 | } | 
|  | 1116 |  | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1117 | auto results_up = pdb_symbol.findAllChildren(); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1118 | while (auto symbol_up = results_up->getNext()) | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1119 | GetTypesForPDBSymbol(*symbol_up, type_mask, type_collection); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1120 | } | 
|  | 1121 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1122 | size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, | 
|  | 1123 | uint32_t type_mask, | 
|  | 1124 | lldb_private::TypeList &type_list) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1125 | TypeCollection type_collection; | 
|  | 1126 | uint32_t old_size = type_list.GetSize(); | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1127 | CompileUnit *cu = | 
|  | 1128 | sc_scope ? sc_scope->CalculateSymbolContextCompileUnit() : nullptr; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1129 | if (cu) { | 
|  | 1130 | auto compiland_up = GetPDBCompilandByUID(cu->GetID()); | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1131 | if (!compiland_up) | 
|  | 1132 | return 0; | 
|  | 1133 | GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1134 | } else { | 
|  | 1135 | for (uint32_t cu_idx = 0; cu_idx < GetNumCompileUnits(); ++cu_idx) { | 
|  | 1136 | auto cu_sp = ParseCompileUnitAtIndex(cu_idx); | 
| Aaron Smith | d5a925f | 2018-03-22 19:21:34 +0000 | [diff] [blame] | 1137 | if (cu_sp) { | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1138 | if (auto compiland_up = GetPDBCompilandByUID(cu_sp->GetID())) | 
|  | 1139 | GetTypesForPDBSymbol(*compiland_up, type_mask, type_collection); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1140 | } | 
|  | 1141 | } | 
|  | 1142 | } | 
|  | 1143 |  | 
|  | 1144 | for (auto type : type_collection) { | 
|  | 1145 | type->GetForwardCompilerType(); | 
|  | 1146 | type_list.Insert(type->shared_from_this()); | 
|  | 1147 | } | 
|  | 1148 | return type_list.GetSize() - old_size; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1149 | } | 
|  | 1150 |  | 
|  | 1151 | lldb_private::TypeSystem * | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1152 | SymbolFilePDB::GetTypeSystemForLanguage(lldb::LanguageType language) { | 
|  | 1153 | auto type_system = | 
|  | 1154 | m_obj_file->GetModule()->GetTypeSystemForLanguage(language); | 
|  | 1155 | if (type_system) | 
|  | 1156 | type_system->SetSymbolFile(this); | 
|  | 1157 | return type_system; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1158 | } | 
|  | 1159 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1160 | lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace( | 
|  | 1161 | const lldb_private::SymbolContext &sc, | 
|  | 1162 | const lldb_private::ConstString &name, | 
|  | 1163 | const lldb_private::CompilerDeclContext *parent_decl_ctx) { | 
|  | 1164 | return lldb_private::CompilerDeclContext(); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1165 | } | 
|  | 1166 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1167 | lldb_private::ConstString SymbolFilePDB::GetPluginName() { | 
|  | 1168 | static ConstString g_name("pdb"); | 
|  | 1169 | return g_name; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1170 | } | 
|  | 1171 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1172 | uint32_t SymbolFilePDB::GetPluginVersion() { return 1; } | 
|  | 1173 |  | 
|  | 1174 | IPDBSession &SymbolFilePDB::GetPDBSession() { return *m_session_up; } | 
|  | 1175 |  | 
|  | 1176 | const IPDBSession &SymbolFilePDB::GetPDBSession() const { | 
|  | 1177 | return *m_session_up; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1178 | } | 
|  | 1179 |  | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1180 | lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitForUID(uint32_t id, | 
|  | 1181 | uint32_t index) { | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1182 | auto found_cu = m_comp_units.find(id); | 
|  | 1183 | if (found_cu != m_comp_units.end()) | 
|  | 1184 | return found_cu->second; | 
|  | 1185 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1186 | auto compiland_up = GetPDBCompilandByUID(id); | 
|  | 1187 | if (!compiland_up) | 
|  | 1188 | return CompUnitSP(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1189 |  | 
|  | 1190 | lldb::LanguageType lang; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1191 | auto details = compiland_up->findOneChild<PDBSymbolCompilandDetails>(); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1192 | if (!details) | 
|  | 1193 | lang = lldb::eLanguageTypeC_plus_plus; | 
|  | 1194 | else | 
|  | 1195 | lang = TranslateLanguage(details->getLanguage()); | 
|  | 1196 |  | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 1197 | if (lang == lldb::LanguageType::eLanguageTypeUnknown) | 
|  | 1198 | return CompUnitSP(); | 
|  | 1199 |  | 
| Aaron Smith | 487b0c6 | 2018-03-20 00:18:22 +0000 | [diff] [blame] | 1200 | std::string path = compiland_up->getSourceFileFullPath(); | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 1201 | if (path.empty()) | 
|  | 1202 | return CompUnitSP(); | 
|  | 1203 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1204 | // Don't support optimized code for now, DebugInfoPDB does not return this | 
|  | 1205 | // information. | 
|  | 1206 | LazyBool optimized = eLazyBoolNo; | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1207 | auto cu_sp = std::make_shared<CompileUnit>(m_obj_file->GetModule(), nullptr, | 
|  | 1208 | path.c_str(), id, lang, optimized); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1209 |  | 
|  | 1210 | if (!cu_sp) | 
|  | 1211 | return CompUnitSP(); | 
|  | 1212 |  | 
|  | 1213 | m_comp_units.insert(std::make_pair(id, cu_sp)); | 
|  | 1214 | if (index == UINT32_MAX) | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1215 | GetCompileUnitIndex(*compiland_up, index); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1216 | lldbassert(index != UINT32_MAX); | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1217 | m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(index, | 
|  | 1218 | cu_sp); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1219 | return cu_sp; | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 1220 | } | 
|  | 1221 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1222 | bool SymbolFilePDB::ParseCompileUnitLineTable( | 
|  | 1223 | const lldb_private::SymbolContext &sc, uint32_t match_line) { | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1224 | lldbassert(sc.comp_unit); | 
|  | 1225 |  | 
|  | 1226 | auto compiland_up = GetPDBCompilandByUID(sc.comp_unit->GetID()); | 
|  | 1227 | if (!compiland_up) | 
|  | 1228 | return false; | 
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 1229 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1230 | // LineEntry needs the *index* of the file into the list of support files | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 1231 | // returned by ParseCompileUnitSupportFiles.  But the underlying SDK gives us | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1232 | // a globally unique idenfitifier in the namespace of the PDB.  So, we have | 
|  | 1233 | // to do a mapping so that we can hand out indices. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1234 | llvm::DenseMap<uint32_t, uint32_t> index_map; | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1235 | BuildSupportFileIdToSupportFileIndexMap(*compiland_up, index_map); | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1236 | auto line_table = llvm::make_unique<LineTable>(sc.comp_unit); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1237 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1238 | // Find contributions to `compiland` from all source and header files. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1239 | std::string path = sc.comp_unit->GetPath(); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1240 | auto files = m_session_up->getSourceFilesForCompiland(*compiland_up); | 
|  | 1241 | if (!files) | 
|  | 1242 | return false; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1243 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1244 | // For each source and header file, create a LineSequence for contributions | 
|  | 1245 | // to the compiland from that file, and add the sequence. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1246 | while (auto file = files->getNext()) { | 
|  | 1247 | std::unique_ptr<LineSequence> sequence( | 
|  | 1248 | line_table->CreateLineSequenceContainer()); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1249 | auto lines = m_session_up->findLineNumbers(*compiland_up, *file); | 
|  | 1250 | if (!lines) | 
|  | 1251 | continue; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1252 | int entry_count = lines->getChildCount(); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1253 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1254 | uint64_t prev_addr; | 
|  | 1255 | uint32_t prev_length; | 
|  | 1256 | uint32_t prev_line; | 
|  | 1257 | uint32_t prev_source_idx; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1258 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1259 | for (int i = 0; i < entry_count; ++i) { | 
|  | 1260 | auto line = lines->getChildAtIndex(i); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1261 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1262 | uint64_t lno = line->getLineNumber(); | 
|  | 1263 | uint64_t addr = line->getVirtualAddress(); | 
|  | 1264 | uint32_t length = line->getLength(); | 
|  | 1265 | uint32_t source_id = line->getSourceFileId(); | 
|  | 1266 | uint32_t col = line->getColumnNumber(); | 
|  | 1267 | uint32_t source_idx = index_map[source_id]; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1268 |  | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1269 | // There was a gap between the current entry and the previous entry if | 
|  | 1270 | // the addresses don't perfectly line up. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1271 | bool is_gap = (i > 0) && (prev_addr + prev_length < addr); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1272 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1273 | // Before inserting the current entry, insert a terminal entry at the end | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 1274 | // of the previous entry's address range if the current entry resulted in | 
|  | 1275 | // a gap from the previous entry. | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1276 | if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) { | 
|  | 1277 | line_table->AppendLineEntryToSequence( | 
|  | 1278 | sequence.get(), prev_addr + prev_length, prev_line, 0, | 
|  | 1279 | prev_source_idx, false, false, false, false, true); | 
|  | 1280 | } | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1281 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1282 | if (ShouldAddLine(match_line, lno, length)) { | 
|  | 1283 | bool is_statement = line->isStatement(); | 
|  | 1284 | bool is_prologue = false; | 
|  | 1285 | bool is_epilogue = false; | 
|  | 1286 | auto func = | 
|  | 1287 | m_session_up->findSymbolByAddress(addr, PDB_SymType::Function); | 
|  | 1288 | if (func) { | 
|  | 1289 | auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>(); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1290 | if (prologue) | 
|  | 1291 | is_prologue = (addr == prologue->getVirtualAddress()); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1292 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1293 | auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>(); | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1294 | if (epilogue) | 
|  | 1295 | is_epilogue = (addr == epilogue->getVirtualAddress()); | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1296 | } | 
| Zachary Turner | 7e8c7be | 2016-03-10 00:06:26 +0000 | [diff] [blame] | 1297 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1298 | line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col, | 
|  | 1299 | source_idx, is_statement, false, | 
|  | 1300 | is_prologue, is_epilogue, false); | 
|  | 1301 | } | 
| Zachary Turner | 7e8c7be | 2016-03-10 00:06:26 +0000 | [diff] [blame] | 1302 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1303 | prev_addr = addr; | 
|  | 1304 | prev_length = length; | 
|  | 1305 | prev_line = lno; | 
|  | 1306 | prev_source_idx = source_idx; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1307 | } | 
|  | 1308 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1309 | if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) { | 
|  | 1310 | // The end is always a terminal entry, so insert it regardless. | 
|  | 1311 | line_table->AppendLineEntryToSequence( | 
|  | 1312 | sequence.get(), prev_addr + prev_length, prev_line, 0, | 
|  | 1313 | prev_source_idx, false, false, false, false, true); | 
|  | 1314 | } | 
|  | 1315 |  | 
|  | 1316 | line_table->InsertSequence(sequence.release()); | 
|  | 1317 | } | 
|  | 1318 |  | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1319 | if (line_table->GetSize()) { | 
|  | 1320 | sc.comp_unit->SetLineTable(line_table.release()); | 
|  | 1321 | return true; | 
|  | 1322 | } | 
|  | 1323 | return false; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1324 | } | 
|  | 1325 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1326 | void SymbolFilePDB::BuildSupportFileIdToSupportFileIndexMap( | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1327 | const PDBSymbolCompiland &compiland, | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1328 | llvm::DenseMap<uint32_t, uint32_t> &index_map) const { | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1329 | // This is a hack, but we need to convert the source id into an index into | 
|  | 1330 | // the support files array.  We don't want to do path comparisons to avoid | 
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 1331 | // basename / full path issues that may or may not even be a problem, so we | 
|  | 1332 | // use the globally unique source file identifiers.  Ideally we could use the | 
|  | 1333 | // global identifiers everywhere, but LineEntry currently assumes indices. | 
| Aaron Smith | 10a0257 | 2018-01-13 06:58:18 +0000 | [diff] [blame] | 1334 | auto source_files = m_session_up->getSourceFilesForCompiland(compiland); | 
|  | 1335 | if (!source_files) | 
|  | 1336 | return; | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1337 | int index = 0; | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1338 |  | 
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1339 | while (auto file = source_files->getNext()) { | 
|  | 1340 | uint32_t source_id = file->getUniqueId(); | 
|  | 1341 | index_map[source_id] = index++; | 
|  | 1342 | } | 
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 1343 | } | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1344 |  | 
|  | 1345 | lldb::CompUnitSP SymbolFilePDB::GetCompileUnitContainsAddress( | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 1346 | const lldb_private::Address &so_addr) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1347 | lldb::addr_t file_vm_addr = so_addr.GetFileAddress(); | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 1348 | if (file_vm_addr == LLDB_INVALID_ADDRESS || file_vm_addr == 0) | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1349 | return nullptr; | 
|  | 1350 |  | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 1351 | // If it is a PDB function's vm addr, this is the first sure bet. | 
|  | 1352 | if (auto lines = | 
|  | 1353 | m_session_up->findLineNumbersByAddress(file_vm_addr, /*Length=*/1)) { | 
|  | 1354 | if (auto first_line = lines->getNext()) | 
|  | 1355 | return ParseCompileUnitForUID(first_line->getCompilandId()); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1356 | } | 
|  | 1357 |  | 
| Aaron Smith | 308e39c | 2018-03-22 19:26:33 +0000 | [diff] [blame] | 1358 | // Otherwise we resort to section contributions. | 
|  | 1359 | if (auto sec_contribs = m_session_up->getSectionContribs()) { | 
|  | 1360 | while (auto section = sec_contribs->getNext()) { | 
|  | 1361 | auto va = section->getVirtualAddress(); | 
|  | 1362 | if (file_vm_addr >= va && file_vm_addr < va + section->getLength()) | 
|  | 1363 | return ParseCompileUnitForUID(section->getCompilandId()); | 
|  | 1364 | } | 
|  | 1365 | } | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1366 | return nullptr; | 
|  | 1367 | } | 
|  | 1368 |  | 
|  | 1369 | Mangled | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1370 | SymbolFilePDB::GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1371 | Mangled mangled; | 
| Aaron Smith | e664b5d | 2018-03-19 21:14:19 +0000 | [diff] [blame] | 1372 | auto func_name = pdb_func.getName(); | 
|  | 1373 | auto func_undecorated_name = pdb_func.getUndecoratedName(); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1374 | std::string func_decorated_name; | 
|  | 1375 |  | 
|  | 1376 | // Seek from public symbols for non-static function's decorated name if any. | 
|  | 1377 | // For static functions, they don't have undecorated names and aren't exposed | 
|  | 1378 | // in Public Symbols either. | 
|  | 1379 | if (!func_undecorated_name.empty()) { | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1380 | auto result_up = m_global_scope_up->findChildren( | 
|  | 1381 | PDB_SymType::PublicSymbol, func_undecorated_name, | 
|  | 1382 | PDB_NameSearchFlags::NS_UndecoratedName); | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1383 | if (result_up) { | 
|  | 1384 | while (auto symbol_up = result_up->getNext()) { | 
|  | 1385 | // For a public symbol, it is unique. | 
|  | 1386 | lldbassert(result_up->getChildCount() == 1); | 
|  | 1387 | if (auto *pdb_public_sym = | 
| Aaron Smith | c8316ed | 2018-03-22 03:44:51 +0000 | [diff] [blame] | 1388 | llvm::dyn_cast_or_null<PDBSymbolPublicSymbol>( | 
|  | 1389 | symbol_up.get())) { | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1390 | if (pdb_public_sym->isFunction()) { | 
|  | 1391 | func_decorated_name = pdb_public_sym->getName(); | 
| Aaron Smith | f76fe68 | 2018-03-07 03:16:50 +0000 | [diff] [blame] | 1392 | break; | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1393 | } | 
|  | 1394 | } | 
|  | 1395 | } | 
|  | 1396 | } | 
|  | 1397 | } | 
|  | 1398 | if (!func_decorated_name.empty()) { | 
|  | 1399 | mangled.SetMangledName(ConstString(func_decorated_name)); | 
|  | 1400 |  | 
|  | 1401 | // For MSVC, format of C funciton's decorated name depends on calling | 
|  | 1402 | // conventon. Unfortunately none of the format is recognized by current | 
|  | 1403 | // LLDB. For example, `_purecall` is a __cdecl C function. From PDB, | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1404 | // `__purecall` is retrieved as both its decorated and undecorated name | 
|  | 1405 | // (using PDBSymbolFunc::getUndecoratedName method). However `__purecall` | 
|  | 1406 | // string is not treated as mangled in LLDB (neither `?` nor `_Z` prefix). | 
|  | 1407 | // Mangled::GetDemangledName method will fail internally and caches an | 
|  | 1408 | // empty string as its undecorated name. So we will face a contradition | 
|  | 1409 | // here for the same symbol: | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1410 | //   non-empty undecorated name from PDB | 
|  | 1411 | //   empty undecorated name from LLDB | 
|  | 1412 | if (!func_undecorated_name.empty() && | 
|  | 1413 | mangled.GetDemangledName(mangled.GuessLanguage()).IsEmpty()) | 
|  | 1414 | mangled.SetDemangledName(ConstString(func_undecorated_name)); | 
|  | 1415 |  | 
|  | 1416 | // LLDB uses several flags to control how a C++ decorated name is | 
| Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1417 | // undecorated for MSVC. See `safeUndecorateName` in Class Mangled. So the | 
|  | 1418 | // yielded name could be different from what we retrieve from | 
| Aaron Smith | 7ac1c78 | 2018-02-09 05:31:28 +0000 | [diff] [blame] | 1419 | // PDB source unless we also apply same flags in getting undecorated | 
|  | 1420 | // name through PDBSymbolFunc::getUndecoratedNameEx method. | 
|  | 1421 | if (!func_undecorated_name.empty() && | 
|  | 1422 | mangled.GetDemangledName(mangled.GuessLanguage()) != | 
|  | 1423 | ConstString(func_undecorated_name)) | 
|  | 1424 | mangled.SetDemangledName(ConstString(func_undecorated_name)); | 
|  | 1425 | } else if (!func_undecorated_name.empty()) { | 
|  | 1426 | mangled.SetDemangledName(ConstString(func_undecorated_name)); | 
|  | 1427 | } else if (!func_name.empty()) | 
|  | 1428 | mangled.SetValue(ConstString(func_name), false); | 
|  | 1429 |  | 
|  | 1430 | return mangled; | 
|  | 1431 | } | 
|  | 1432 |  | 
|  | 1433 | bool SymbolFilePDB::DeclContextMatchesThisSymbolFile( | 
|  | 1434 | const lldb_private::CompilerDeclContext *decl_ctx) { | 
|  | 1435 | if (decl_ctx == nullptr || !decl_ctx->IsValid()) | 
|  | 1436 | return true; | 
|  | 1437 |  | 
|  | 1438 | TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem(); | 
|  | 1439 | if (!decl_ctx_type_system) | 
|  | 1440 | return false; | 
|  | 1441 | TypeSystem *type_system = GetTypeSystemForLanguage( | 
|  | 1442 | decl_ctx_type_system->GetMinimumLanguage(nullptr)); | 
|  | 1443 | if (decl_ctx_type_system == type_system) | 
|  | 1444 | return true; // The type systems match, return true | 
|  | 1445 |  | 
|  | 1446 | return false; | 
|  | 1447 | } |