| 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" |
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/TypeMap.h" |
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/RegularExpression.h" |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 23 | |
| Pavel Labath | b8d8c62 | 2016-05-09 11:07:43 +0000 | [diff] [blame] | 24 | #include "llvm/DebugInfo/PDB/GenericError.h" |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 25 | #include "llvm/DebugInfo/PDB/IPDBDataStream.h" |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 26 | #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h" |
| 27 | #include "llvm/DebugInfo/PDB/IPDBLineNumber.h" |
| 28 | #include "llvm/DebugInfo/PDB/IPDBSourceFile.h" |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 29 | #include "llvm/DebugInfo/PDB/IPDBTable.h" |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 30 | #include "llvm/DebugInfo/PDB/PDBSymbol.h" |
| 31 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
| 32 | #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h" |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 33 | #include "llvm/DebugInfo/PDB/PDBSymbolData.h" |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 34 | #include "llvm/DebugInfo/PDB/PDBSymbolExe.h" |
| 35 | #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h" |
| 36 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h" |
| 37 | #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h" |
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 38 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h" |
| 39 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h" |
| 40 | #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h" |
| 41 | |
| 42 | #include "Plugins/SymbolFile/PDB/PDBASTParser.h" |
| 43 | |
| 44 | #include <regex> |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 45 | |
| 46 | using namespace lldb_private; |
| Zachary Turner | 54fd7ff | 2016-05-04 20:33:53 +0000 | [diff] [blame] | 47 | using namespace llvm::pdb; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 48 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | namespace { |
| 50 | lldb::LanguageType TranslateLanguage(PDB_Lang lang) { |
| 51 | switch (lang) { |
| 52 | case PDB_Lang::Cpp: |
| 53 | return lldb::LanguageType::eLanguageTypeC_plus_plus; |
| 54 | case PDB_Lang::C: |
| 55 | return lldb::LanguageType::eLanguageTypeC; |
| 56 | default: |
| 57 | return lldb::LanguageType::eLanguageTypeUnknown; |
| 58 | } |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | bool ShouldAddLine(uint32_t requested_line, uint32_t actual_line, |
| 62 | uint32_t addr_length) { |
| 63 | return ((requested_line == 0 || actual_line == requested_line) && |
| 64 | addr_length > 0); |
| 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 | void SymbolFilePDB::Initialize() { |
| 69 | PluginManager::RegisterPlugin(GetPluginNameStatic(), |
| 70 | GetPluginDescriptionStatic(), CreateInstance, |
| 71 | DebuggerInitialize); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | void SymbolFilePDB::Terminate() { |
| 75 | PluginManager::UnregisterPlugin(CreateInstance); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | void SymbolFilePDB::DebuggerInitialize(lldb_private::Debugger &debugger) {} |
| 79 | |
| 80 | lldb_private::ConstString SymbolFilePDB::GetPluginNameStatic() { |
| 81 | static ConstString g_name("pdb"); |
| 82 | return g_name; |
| 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 | const char *SymbolFilePDB::GetPluginDescriptionStatic() { |
| 86 | return "Microsoft PDB debug symbol file reader."; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | lldb_private::SymbolFile * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 90 | SymbolFilePDB::CreateInstance(lldb_private::ObjectFile *obj_file) { |
| 91 | return new SymbolFilePDB(obj_file); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | SymbolFilePDB::SymbolFilePDB(lldb_private::ObjectFile *object_file) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | : SymbolFile(object_file), m_cached_compile_unit_count(0) {} |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 96 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 97 | SymbolFilePDB::~SymbolFilePDB() {} |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 98 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | uint32_t SymbolFilePDB::CalculateAbilities() { |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 100 | uint32_t abilities = 0; |
| 101 | if (!m_obj_file) |
| 102 | return 0; |
| 103 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | if (!m_session_up) { |
| 105 | // Lazily load and match the PDB file, but only do this once. |
| 106 | std::string exePath = m_obj_file->GetFileSpec().GetPath(); |
| 107 | auto error = loadDataForEXE(PDB_ReaderType::DIA, llvm::StringRef(exePath), |
| 108 | m_session_up); |
| 109 | if (error) { |
| 110 | llvm::consumeError(std::move(error)); |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 111 | auto module_sp = m_obj_file->GetModule(); |
| 112 | if (!module_sp) |
| 113 | return 0; |
| 114 | // See if any symbol file is specified through `--symfile` option. |
| 115 | FileSpec symfile = module_sp->GetSymbolFileFileSpec(); |
| 116 | if (!symfile) |
| 117 | return 0; |
| 118 | error = loadDataForPDB(PDB_ReaderType::DIA, |
| 119 | llvm::StringRef(symfile.GetPath()), |
| 120 | m_session_up); |
| 121 | if (error) { |
| 122 | llvm::consumeError(std::move(error)); |
| 123 | return 0; |
| 124 | } |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 125 | } |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | } |
| Aaron Smith | 1f8552a | 2017-12-22 00:04:36 +0000 | [diff] [blame] | 127 | if (!m_session_up.get()) |
| 128 | return 0; |
| 129 | |
| 130 | auto enum_tables_up = m_session_up->getEnumTables(); |
| 131 | if (!enum_tables_up) |
| 132 | return 0; |
| 133 | while (auto table_up = enum_tables_up->getNext()) { |
| 134 | if (table_up->getItemCount() == 0) |
| 135 | continue; |
| 136 | auto type = table_up->getTableType(); |
| 137 | switch (type) { |
| 138 | case PDB_TableType::Symbols: |
| 139 | // This table represents a store of symbols with types listed in |
| 140 | // PDBSym_Type |
| 141 | abilities |= (CompileUnits | Functions | Blocks | |
| 142 | GlobalVariables | LocalVariables | VariableTypes); |
| 143 | break; |
| 144 | case PDB_TableType::LineNumbers: |
| 145 | abilities |= LineTables; |
| 146 | break; |
| 147 | default: break; |
| 148 | } |
| 149 | } |
| 150 | return abilities; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 153 | void SymbolFilePDB::InitializeObject() { |
| 154 | lldb::addr_t obj_load_address = m_obj_file->GetFileOffset(); |
| 155 | m_session_up->setLoadAddress(obj_load_address); |
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 156 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | TypeSystem *type_system = |
| 158 | GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); |
| 159 | ClangASTContext *clang_type_system = |
| 160 | llvm::dyn_cast_or_null<ClangASTContext>(type_system); |
| 161 | m_tu_decl_ctx_up = llvm::make_unique<CompilerDeclContext>( |
| 162 | type_system, clang_type_system->GetTranslationUnitDecl()); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | uint32_t SymbolFilePDB::GetNumCompileUnits() { |
| 166 | if (m_cached_compile_unit_count == 0) { |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 167 | auto global = m_session_up->getGlobalScope(); |
| Zachary Turner | 54fd7ff | 2016-05-04 20:33:53 +0000 | [diff] [blame] | 168 | auto compilands = global->findAllChildren<PDBSymbolCompiland>(); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 169 | m_cached_compile_unit_count = compilands->getChildCount(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 170 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 171 | // The linker can inject an additional "dummy" compilation unit into the |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 172 | // PDB. Ignore this special compile unit for our purposes, if it is there. |
| 173 | // It is always the last one. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | auto last_cu = compilands->getChildAtIndex(m_cached_compile_unit_count - 1); |
| 175 | std::string name = last_cu->getName(); |
| 176 | if (name == "* Linker *") |
| 177 | --m_cached_compile_unit_count; |
| 178 | } |
| 179 | return m_cached_compile_unit_count; |
| 180 | } |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 181 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitAtIndex(uint32_t index) { |
| 183 | auto global = m_session_up->getGlobalScope(); |
| 184 | auto compilands = global->findAllChildren<PDBSymbolCompiland>(); |
| 185 | auto cu = compilands->getChildAtIndex(index); |
| 186 | |
| 187 | uint32_t id = cu->getSymIndexId(); |
| 188 | |
| 189 | return ParseCompileUnitForSymIndex(id); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | lldb::LanguageType |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | SymbolFilePDB::ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) { |
| 194 | // What fields should I expect to be filled out on the SymbolContext? Is it |
| 195 | // safe to assume that `sc.comp_unit` is valid? |
| 196 | if (!sc.comp_unit) |
| 197 | return lldb::eLanguageTypeUnknown; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 198 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 199 | auto cu = m_session_up->getConcreteSymbolById<PDBSymbolCompiland>( |
| 200 | sc.comp_unit->GetID()); |
| 201 | if (!cu) |
| 202 | return lldb::eLanguageTypeUnknown; |
| 203 | auto details = cu->findOneChild<PDBSymbolCompilandDetails>(); |
| 204 | if (!details) |
| 205 | return lldb::eLanguageTypeUnknown; |
| 206 | return TranslateLanguage(details->getLanguage()); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | size_t SymbolFilePDB::ParseCompileUnitFunctions( |
| 210 | const lldb_private::SymbolContext &sc) { |
| 211 | // TODO: Implement this |
| 212 | return size_t(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 215 | bool SymbolFilePDB::ParseCompileUnitLineTable( |
| 216 | const lldb_private::SymbolContext &sc) { |
| 217 | return ParseCompileUnitLineTable(sc, 0); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | bool SymbolFilePDB::ParseCompileUnitDebugMacros( |
| 221 | const lldb_private::SymbolContext &sc) { |
| 222 | // PDB doesn't contain information about macros |
| 223 | return false; |
| 224 | } |
| 225 | |
| 226 | bool SymbolFilePDB::ParseCompileUnitSupportFiles( |
| 227 | const lldb_private::SymbolContext &sc, |
| 228 | lldb_private::FileSpecList &support_files) { |
| 229 | if (!sc.comp_unit) |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 230 | return false; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 231 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 232 | // 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] | 233 | // is easily (and quickly) accessible from DebugInfoPDB, so caching it a |
| 234 | // second time seems like a waste. Unfortunately, there's no good way around |
| 235 | // this short of a moderate refactor since SymbolVendor depends on being able |
| 236 | // to cache this list. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 237 | auto cu = m_session_up->getConcreteSymbolById<PDBSymbolCompiland>( |
| 238 | sc.comp_unit->GetID()); |
| 239 | if (!cu) |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 240 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | auto files = m_session_up->getSourceFilesForCompiland(*cu); |
| 242 | if (!files || files->getChildCount() == 0) |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 243 | return false; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 244 | |
| 245 | while (auto file = files->getNext()) { |
| 246 | FileSpec spec(file->getFileName(), false); |
| 247 | support_files.Append(spec); |
| 248 | } |
| 249 | return true; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 252 | bool SymbolFilePDB::ParseImportedModules( |
| 253 | const lldb_private::SymbolContext &sc, |
| 254 | std::vector<lldb_private::ConstString> &imported_modules) { |
| 255 | // PDB does not yet support module debug info |
| 256 | return false; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | size_t |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | SymbolFilePDB::ParseFunctionBlocks(const lldb_private::SymbolContext &sc) { |
| 261 | // TODO: Implement this |
| 262 | return size_t(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 265 | size_t SymbolFilePDB::ParseTypes(const lldb_private::SymbolContext &sc) { |
| 266 | // TODO: Implement this |
| 267 | return size_t(); |
| 268 | } |
| 269 | |
| 270 | size_t |
| 271 | SymbolFilePDB::ParseVariablesForContext(const lldb_private::SymbolContext &sc) { |
| 272 | // TODO: Implement this |
| 273 | return size_t(); |
| 274 | } |
| 275 | |
| 276 | lldb_private::Type *SymbolFilePDB::ResolveTypeUID(lldb::user_id_t type_uid) { |
| 277 | auto find_result = m_types.find(type_uid); |
| 278 | if (find_result != m_types.end()) |
| 279 | return find_result->second.get(); |
| 280 | |
| 281 | TypeSystem *type_system = |
| 282 | GetTypeSystemForLanguage(lldb::eLanguageTypeC_plus_plus); |
| 283 | ClangASTContext *clang_type_system = |
| 284 | llvm::dyn_cast_or_null<ClangASTContext>(type_system); |
| 285 | if (!clang_type_system) |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 286 | return nullptr; |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 287 | PDBASTParser *pdb = |
| 288 | llvm::dyn_cast<PDBASTParser>(clang_type_system->GetPDBParser()); |
| 289 | if (!pdb) |
| 290 | return nullptr; |
| 291 | |
| 292 | auto pdb_type = m_session_up->getSymbolById(type_uid); |
| 293 | if (pdb_type == nullptr) |
| 294 | return nullptr; |
| 295 | |
| 296 | lldb::TypeSP result = pdb->CreateLLDBTypeFromPDBType(*pdb_type); |
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 297 | if (result.get()) |
| 298 | m_types.insert(std::make_pair(type_uid, result)); |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 299 | return result.get(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 302 | bool SymbolFilePDB::CompleteType(lldb_private::CompilerType &compiler_type) { |
| 303 | // TODO: Implement this |
| 304 | return false; |
| 305 | } |
| 306 | |
| 307 | lldb_private::CompilerDecl SymbolFilePDB::GetDeclForUID(lldb::user_id_t uid) { |
| 308 | return lldb_private::CompilerDecl(); |
| 309 | } |
| 310 | |
| 311 | lldb_private::CompilerDeclContext |
| 312 | SymbolFilePDB::GetDeclContextForUID(lldb::user_id_t uid) { |
| 313 | // PDB always uses the translation unit decl context for everything. We can |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 314 | // improve this later but it's not easy because PDB doesn't provide a high |
| 315 | // enough level of type fidelity in this area. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 316 | return *m_tu_decl_ctx_up; |
| 317 | } |
| 318 | |
| 319 | lldb_private::CompilerDeclContext |
| 320 | SymbolFilePDB::GetDeclContextContainingUID(lldb::user_id_t uid) { |
| 321 | return *m_tu_decl_ctx_up; |
| 322 | } |
| 323 | |
| 324 | void SymbolFilePDB::ParseDeclsForContext( |
| 325 | lldb_private::CompilerDeclContext decl_ctx) {} |
| 326 | |
| 327 | uint32_t |
| 328 | SymbolFilePDB::ResolveSymbolContext(const lldb_private::Address &so_addr, |
| 329 | uint32_t resolve_scope, |
| 330 | lldb_private::SymbolContext &sc) { |
| 331 | return uint32_t(); |
| 332 | } |
| 333 | |
| 334 | uint32_t SymbolFilePDB::ResolveSymbolContext( |
| 335 | const lldb_private::FileSpec &file_spec, uint32_t line, bool check_inlines, |
| 336 | uint32_t resolve_scope, lldb_private::SymbolContextList &sc_list) { |
| 337 | if (resolve_scope & lldb::eSymbolContextCompUnit) { |
| 338 | // Locate all compilation units with line numbers referencing the specified |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 339 | // file. For example, if `file_spec` is <vector>, then this should return |
| 340 | // all source files and header files that reference <vector>, either |
| 341 | // directly or indirectly. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 342 | auto compilands = m_session_up->findCompilandsForSourceFile( |
| 343 | file_spec.GetPath(), PDB_NameSearchFlags::NS_CaseInsensitive); |
| 344 | |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 345 | // For each one, either find its previously parsed data or parse it afresh |
| 346 | // and add it to the symbol context list. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 347 | while (auto compiland = compilands->getNext()) { |
| 348 | // If we're not checking inlines, then don't add line information for this |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 349 | // file unless the FileSpec matches. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 350 | if (!check_inlines) { |
| 351 | // `getSourceFileName` returns the basename of the original source file |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 352 | // used to generate this compiland. It does not return the full path. |
| 353 | // Currently the only way to get that is to do a basename lookup to get |
| 354 | // the IPDBSourceFile, but this is ambiguous in the case of two source |
| 355 | // files with the same name contributing to the same compiland. This is |
| 356 | // a moderately extreme edge case, so we consider this OK for now, |
| 357 | // although we need to find a long-term solution. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 358 | std::string source_file = compiland->getSourceFileName(); |
| 359 | auto pdb_file = m_session_up->findOneSourceFile( |
| 360 | compiland.get(), source_file, |
| 361 | PDB_NameSearchFlags::NS_CaseInsensitive); |
| 362 | source_file = pdb_file->getFileName(); |
| 363 | FileSpec this_spec(source_file, false, FileSpec::ePathSyntaxWindows); |
| 364 | if (!file_spec.FileEquals(this_spec)) |
| 365 | continue; |
| 366 | } |
| 367 | |
| 368 | SymbolContext sc; |
| 369 | auto cu = ParseCompileUnitForSymIndex(compiland->getSymIndexId()); |
| 370 | sc.comp_unit = cu.get(); |
| 371 | sc.module_sp = cu->GetModule(); |
| 372 | sc_list.Append(sc); |
| 373 | |
| 374 | // 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] | 375 | // table that match the requested line (or all lines if `line` == 0). |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 376 | if (resolve_scope & lldb::eSymbolContextLineEntry) |
| 377 | ParseCompileUnitLineTable(sc, line); |
| 378 | } |
| 379 | } |
| 380 | return sc_list.GetSize(); |
| 381 | } |
| 382 | |
| 383 | uint32_t SymbolFilePDB::FindGlobalVariables( |
| 384 | const lldb_private::ConstString &name, |
| 385 | const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, |
| 386 | uint32_t max_matches, lldb_private::VariableList &variables) { |
| 387 | return uint32_t(); |
| 388 | } |
| 389 | |
| 390 | uint32_t |
| 391 | SymbolFilePDB::FindGlobalVariables(const lldb_private::RegularExpression ®ex, |
| 392 | bool append, uint32_t max_matches, |
| 393 | lldb_private::VariableList &variables) { |
| 394 | return uint32_t(); |
| 395 | } |
| 396 | |
| 397 | uint32_t SymbolFilePDB::FindFunctions( |
| 398 | const lldb_private::ConstString &name, |
| 399 | const lldb_private::CompilerDeclContext *parent_decl_ctx, |
| 400 | uint32_t name_type_mask, bool include_inlines, bool append, |
| 401 | lldb_private::SymbolContextList &sc_list) { |
| 402 | return uint32_t(); |
| 403 | } |
| 404 | |
| 405 | uint32_t |
| 406 | SymbolFilePDB::FindFunctions(const lldb_private::RegularExpression ®ex, |
| 407 | bool include_inlines, bool append, |
| 408 | lldb_private::SymbolContextList &sc_list) { |
| 409 | return uint32_t(); |
| 410 | } |
| 411 | |
| 412 | void SymbolFilePDB::GetMangledNamesForFunction( |
| 413 | const std::string &scope_qualified_name, |
| 414 | std::vector<lldb_private::ConstString> &mangled_names) {} |
| 415 | |
| 416 | uint32_t SymbolFilePDB::FindTypes( |
| 417 | const lldb_private::SymbolContext &sc, |
| 418 | const lldb_private::ConstString &name, |
| 419 | const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, |
| 420 | uint32_t max_matches, |
| 421 | llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, |
| 422 | lldb_private::TypeMap &types) { |
| 423 | if (!append) |
| 424 | types.Clear(); |
| 425 | if (!name) |
| 426 | return 0; |
| 427 | |
| 428 | searched_symbol_files.clear(); |
| 429 | searched_symbol_files.insert(this); |
| 430 | |
| 431 | std::string name_str = name.AsCString(); |
| 432 | |
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 433 | // There is an assumption 'name' is not a regex |
| 434 | FindTypesByName(name_str, max_matches, types); |
| 435 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 436 | return types.GetSize(); |
| 437 | } |
| 438 | |
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 439 | void |
| 440 | SymbolFilePDB::FindTypesByRegex(const lldb_private::RegularExpression ®ex, |
| 441 | uint32_t max_matches, |
| 442 | lldb_private::TypeMap &types) { |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 443 | // 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] | 444 | // space as much as possible since this searches EVERYTHING in the PDB, |
| 445 | // manually doing regex comparisons. PDB library isn't optimized for regex |
| 446 | // 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] | 447 | // 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] | 448 | // and do a regex comparison against each of them. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | PDB_SymType tags_to_search[] = {PDB_SymType::Enum, PDB_SymType::Typedef, |
| 450 | PDB_SymType::UDT}; |
| 451 | auto global = m_session_up->getGlobalScope(); |
| 452 | std::unique_ptr<IPDBEnumSymbols> results; |
| 453 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 454 | uint32_t matches = 0; |
| 455 | |
| 456 | for (auto tag : tags_to_search) { |
| 457 | results = global->findAllChildren(tag); |
| 458 | while (auto result = results->getNext()) { |
| 459 | if (max_matches > 0 && matches >= max_matches) |
| 460 | break; |
| 461 | |
| 462 | std::string type_name; |
| 463 | if (auto enum_type = llvm::dyn_cast<PDBSymbolTypeEnum>(result.get())) |
| 464 | type_name = enum_type->getName(); |
| 465 | else if (auto typedef_type = |
| 466 | llvm::dyn_cast<PDBSymbolTypeTypedef>(result.get())) |
| 467 | type_name = typedef_type->getName(); |
| 468 | else if (auto class_type = llvm::dyn_cast<PDBSymbolTypeUDT>(result.get())) |
| 469 | type_name = class_type->getName(); |
| 470 | else { |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 471 | // We're looking only for types that have names. Skip symbols, as well |
| 472 | // as unnamed types such as arrays, pointers, etc. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 473 | continue; |
| 474 | } |
| 475 | |
| Aaron Smith | 86e9434 | 2017-12-22 05:26:50 +0000 | [diff] [blame] | 476 | if (!regex.Execute(type_name)) |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 477 | continue; |
| 478 | |
| 479 | // This should cause the type to get cached and stored in the `m_types` |
| 480 | // lookup. |
| 481 | if (!ResolveTypeUID(result->getSymIndexId())) |
| 482 | continue; |
| 483 | |
| 484 | auto iter = m_types.find(result->getSymIndexId()); |
| 485 | if (iter == m_types.end()) |
| 486 | continue; |
| 487 | types.Insert(iter->second); |
| 488 | ++matches; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | void SymbolFilePDB::FindTypesByName(const std::string &name, |
| 494 | uint32_t max_matches, |
| 495 | lldb_private::TypeMap &types) { |
| 496 | auto global = m_session_up->getGlobalScope(); |
| 497 | std::unique_ptr<IPDBEnumSymbols> results; |
| Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 498 | results = global->findChildren(PDB_SymType::None, name, |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 499 | PDB_NameSearchFlags::NS_Default); |
| 500 | |
| 501 | uint32_t matches = 0; |
| 502 | |
| 503 | while (auto result = results->getNext()) { |
| 504 | if (max_matches > 0 && matches >= max_matches) |
| 505 | break; |
| 506 | switch (result->getSymTag()) { |
| 507 | case PDB_SymType::Enum: |
| 508 | case PDB_SymType::UDT: |
| 509 | case PDB_SymType::Typedef: |
| 510 | break; |
| 511 | default: |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 512 | // We're looking only for types that have names. Skip symbols, as well as |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | // unnamed types such as arrays, pointers, etc. |
| 514 | continue; |
| 515 | } |
| 516 | |
| 517 | // This should cause the type to get cached and stored in the `m_types` |
| 518 | // lookup. |
| 519 | if (!ResolveTypeUID(result->getSymIndexId())) |
| 520 | continue; |
| 521 | |
| 522 | auto iter = m_types.find(result->getSymIndexId()); |
| 523 | if (iter == m_types.end()) |
| 524 | continue; |
| 525 | types.Insert(iter->second); |
| 526 | ++matches; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | size_t SymbolFilePDB::FindTypes( |
| 531 | const std::vector<lldb_private::CompilerContext> &contexts, bool append, |
| 532 | lldb_private::TypeMap &types) { |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | lldb_private::TypeList *SymbolFilePDB::GetTypeList() { return nullptr; } |
| 537 | |
| 538 | size_t SymbolFilePDB::GetTypes(lldb_private::SymbolContextScope *sc_scope, |
| 539 | uint32_t type_mask, |
| 540 | lldb_private::TypeList &type_list) { |
| 541 | return size_t(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | lldb_private::TypeSystem * |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 545 | SymbolFilePDB::GetTypeSystemForLanguage(lldb::LanguageType language) { |
| 546 | auto type_system = |
| 547 | m_obj_file->GetModule()->GetTypeSystemForLanguage(language); |
| 548 | if (type_system) |
| 549 | type_system->SetSymbolFile(this); |
| 550 | return type_system; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 553 | lldb_private::CompilerDeclContext SymbolFilePDB::FindNamespace( |
| 554 | const lldb_private::SymbolContext &sc, |
| 555 | const lldb_private::ConstString &name, |
| 556 | const lldb_private::CompilerDeclContext *parent_decl_ctx) { |
| 557 | return lldb_private::CompilerDeclContext(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 560 | lldb_private::ConstString SymbolFilePDB::GetPluginName() { |
| 561 | static ConstString g_name("pdb"); |
| 562 | return g_name; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 565 | uint32_t SymbolFilePDB::GetPluginVersion() { return 1; } |
| 566 | |
| 567 | IPDBSession &SymbolFilePDB::GetPDBSession() { return *m_session_up; } |
| 568 | |
| 569 | const IPDBSession &SymbolFilePDB::GetPDBSession() const { |
| 570 | return *m_session_up; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | lldb::CompUnitSP SymbolFilePDB::ParseCompileUnitForSymIndex(uint32_t id) { |
| 574 | auto found_cu = m_comp_units.find(id); |
| 575 | if (found_cu != m_comp_units.end()) |
| 576 | return found_cu->second; |
| 577 | |
| 578 | auto cu = m_session_up->getConcreteSymbolById<PDBSymbolCompiland>(id); |
| 579 | |
| 580 | // `getSourceFileName` returns the basename of the original source file used |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 581 | // to generate this compiland. It does not return the full path. Currently |
| 582 | // the only way to get that is to do a basename lookup to get the |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 583 | // IPDBSourceFile, but this is ambiguous in the case of two source files with |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 584 | // the same name contributing to the same compiland. This is a moderately |
| 585 | // extreme edge case, so we consider this OK for now, although we need to find |
| 586 | // a long-term solution. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | auto file = |
| 588 | m_session_up->findOneSourceFile(cu.get(), cu->getSourceFileName(), |
| 589 | PDB_NameSearchFlags::NS_CaseInsensitive); |
| 590 | std::string path = file->getFileName(); |
| 591 | |
| 592 | lldb::LanguageType lang; |
| 593 | auto details = cu->findOneChild<PDBSymbolCompilandDetails>(); |
| 594 | if (!details) |
| 595 | lang = lldb::eLanguageTypeC_plus_plus; |
| 596 | else |
| 597 | lang = TranslateLanguage(details->getLanguage()); |
| 598 | |
| 599 | // Don't support optimized code for now, DebugInfoPDB does not return this |
| 600 | // information. |
| 601 | LazyBool optimized = eLazyBoolNo; |
| 602 | auto result = std::make_shared<CompileUnit>( |
| 603 | m_obj_file->GetModule(), nullptr, path.c_str(), id, lang, optimized); |
| 604 | m_comp_units.insert(std::make_pair(id, result)); |
| 605 | return result; |
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 608 | bool SymbolFilePDB::ParseCompileUnitLineTable( |
| 609 | const lldb_private::SymbolContext &sc, uint32_t match_line) { |
| 610 | auto global = m_session_up->getGlobalScope(); |
| 611 | auto cu = m_session_up->getConcreteSymbolById<PDBSymbolCompiland>( |
| 612 | sc.comp_unit->GetID()); |
| Zachary Turner | 42dff79 | 2016-04-15 00:21:26 +0000 | [diff] [blame] | 613 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 614 | // 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] | 615 | // returned by ParseCompileUnitSupportFiles. But the underlying SDK gives us |
| 616 | // a globally unique idenfitifier in the namespace of the PDB. So, we have to |
| 617 | // do a mapping so that we can hand out indices. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 618 | llvm::DenseMap<uint32_t, uint32_t> index_map; |
| 619 | BuildSupportFileIdToSupportFileIndexMap(*cu, index_map); |
| 620 | auto line_table = llvm::make_unique<LineTable>(sc.comp_unit); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 621 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 622 | // Find contributions to `cu` from all source and header files. |
| 623 | std::string path = sc.comp_unit->GetPath(); |
| 624 | auto files = m_session_up->getSourceFilesForCompiland(*cu); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 625 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 626 | // For each source and header file, create a LineSequence for contributions to |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 627 | // the cu from that file, and add the sequence. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 628 | while (auto file = files->getNext()) { |
| 629 | std::unique_ptr<LineSequence> sequence( |
| 630 | line_table->CreateLineSequenceContainer()); |
| 631 | auto lines = m_session_up->findLineNumbers(*cu, *file); |
| 632 | int entry_count = lines->getChildCount(); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 633 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 634 | uint64_t prev_addr; |
| 635 | uint32_t prev_length; |
| 636 | uint32_t prev_line; |
| 637 | uint32_t prev_source_idx; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 638 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | for (int i = 0; i < entry_count; ++i) { |
| 640 | auto line = lines->getChildAtIndex(i); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 641 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | uint64_t lno = line->getLineNumber(); |
| 643 | uint64_t addr = line->getVirtualAddress(); |
| 644 | uint32_t length = line->getLength(); |
| 645 | uint32_t source_id = line->getSourceFileId(); |
| 646 | uint32_t col = line->getColumnNumber(); |
| 647 | uint32_t source_idx = index_map[source_id]; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 648 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 649 | // There was a gap between the current entry and the previous entry if the |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 650 | // addresses don't perfectly line up. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 651 | bool is_gap = (i > 0) && (prev_addr + prev_length < addr); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 652 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 653 | // Before inserting the current entry, insert a terminal entry at the end |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 654 | // of the previous entry's address range if the current entry resulted in |
| 655 | // a gap from the previous entry. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 656 | if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) { |
| 657 | line_table->AppendLineEntryToSequence( |
| 658 | sequence.get(), prev_addr + prev_length, prev_line, 0, |
| 659 | prev_source_idx, false, false, false, false, true); |
| 660 | } |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 661 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 662 | if (ShouldAddLine(match_line, lno, length)) { |
| 663 | bool is_statement = line->isStatement(); |
| 664 | bool is_prologue = false; |
| 665 | bool is_epilogue = false; |
| 666 | auto func = |
| 667 | m_session_up->findSymbolByAddress(addr, PDB_SymType::Function); |
| 668 | if (func) { |
| 669 | auto prologue = func->findOneChild<PDBSymbolFuncDebugStart>(); |
| 670 | is_prologue = (addr == prologue->getVirtualAddress()); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 671 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 672 | auto epilogue = func->findOneChild<PDBSymbolFuncDebugEnd>(); |
| 673 | is_epilogue = (addr == epilogue->getVirtualAddress()); |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 674 | } |
| Zachary Turner | 7e8c7be | 2016-03-10 00:06:26 +0000 | [diff] [blame] | 675 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 676 | line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col, |
| 677 | source_idx, is_statement, false, |
| 678 | is_prologue, is_epilogue, false); |
| 679 | } |
| Zachary Turner | 7e8c7be | 2016-03-10 00:06:26 +0000 | [diff] [blame] | 680 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 681 | prev_addr = addr; |
| 682 | prev_length = length; |
| 683 | prev_line = lno; |
| 684 | prev_source_idx = source_idx; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 687 | if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) { |
| 688 | // The end is always a terminal entry, so insert it regardless. |
| 689 | line_table->AppendLineEntryToSequence( |
| 690 | sequence.get(), prev_addr + prev_length, prev_line, 0, |
| 691 | prev_source_idx, false, false, false, false, true); |
| 692 | } |
| 693 | |
| 694 | line_table->InsertSequence(sequence.release()); |
| 695 | } |
| 696 | |
| 697 | sc.comp_unit->SetLineTable(line_table.release()); |
| 698 | return true; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 701 | void SymbolFilePDB::BuildSupportFileIdToSupportFileIndexMap( |
| 702 | const PDBSymbolCompiland &cu, |
| 703 | llvm::DenseMap<uint32_t, uint32_t> &index_map) const { |
| 704 | // This is a hack, but we need to convert the source id into an index into the |
| Adrian McCarthy | 9d0eb996 | 2017-01-27 21:42:28 +0000 | [diff] [blame] | 705 | // support files array. We don't want to do path comparisons to avoid |
| 706 | // basename / full path issues that may or may not even be a problem, so we |
| 707 | // use the globally unique source file identifiers. Ideally we could use the |
| 708 | // global identifiers everywhere, but LineEntry currently assumes indices. |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 709 | auto source_files = m_session_up->getSourceFilesForCompiland(cu); |
| 710 | int index = 0; |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 711 | |
| Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 712 | while (auto file = source_files->getNext()) { |
| 713 | uint32_t source_id = file->getUniqueId(); |
| 714 | index_map[source_id] = index++; |
| 715 | } |
| Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 716 | } |