Index: lit/SymbolFile/NativePDB/local-variables.cpp =================================================================== --- lit/SymbolFile/NativePDB/local-variables.cpp +++ lit/SymbolFile/NativePDB/local-variables.cpp @@ -156,6 +156,7 @@ // CHECK-NEXT: |-FunctionDecl {{.*}} main 'int (int, char **)' // CHECK-NEXT: | |-ParmVarDecl {{.*}} argc 'int' // CHECK-NEXT: | `-ParmVarDecl {{.*}} argv 'char **' +// CHECK-NEXT: |-FunctionDecl {{.*}} __scrt_common_main_seh 'int ()' static // CHECK-NEXT: `-FunctionDecl {{.*}} Function 'int (int, char)' // CHECK-NEXT: |-ParmVarDecl {{.*}} Param1 'int' // CHECK-NEXT: `-ParmVarDecl {{.*}} Param2 'char' Index: source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp =================================================================== --- source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp +++ source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp @@ -332,15 +332,6 @@ uint32_t SymbolFileNativePDB::GetNumCompileUnits() { const DbiModuleList &modules = m_index->dbi().modules(); uint32_t count = modules.getModuleCount(); - if (count == 0) - return count; - - // The linker can inject an additional "dummy" compilation unit into the - // PDB. Ignore this special compile unit for our purposes, if it is there. - // It is always the last one. - DbiModuleDescriptor last = modules.getModuleDescriptor(count - 1); - if (last.getModuleName() == "* Linker *") - --count; return count; } @@ -955,11 +946,9 @@ llvm::Optional modi = m_index->GetModuleIndexForVa(file_addr); if (!modi) return 0; - CompilandIndexItem *cci = m_index->compilands().GetCompiland(*modi); - if (!cci) - return 0; + CompilandIndexItem cci = m_index->compilands().GetOrCreateCompiland(*modi); - sc.comp_unit = GetOrCreateCompileUnit(*cci).get(); + sc.comp_unit = GetOrCreateCompileUnit(cci).get(); resolved_flags |= eSymbolContextCompUnit; } @@ -977,20 +966,58 @@ PdbCompilandSymId csid = match.uid.asCompilandSym(); CVSymbol cvs = m_index->ReadSymbolRecord(csid); PDB_SymType type = CVSymToPDBSym(cvs.kind()); - if (type != PDB_SymType::Function && type != PDB_SymType::Block) + if (type != PDB_SymType::Function && type != PDB_SymType::Block && + type != PDB_SymType::Thunk) continue; - if (type == PDB_SymType::Function) { - sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get(); - sc.block = sc.GetFunctionBlock(); - } - if (type == PDB_SymType::Block) { - sc.block = &GetOrCreateBlock(csid); - sc.function = sc.block->CalculateSymbolContextFunction(); + if (type == PDB_SymType::Thunk) { + auto symtab = m_obj_file->GetSymtab(); + if (!symtab) + continue; + + if (auto symbol = symtab->FindSymbolContainingFileAddress(file_addr)) { + sc.symbol = symbol; + resolved_flags |= eSymbolContextSymbol; + } else { + TrampolineSym tramp(static_cast(cvs.kind())); + cantFail( + SymbolDeserializer::deserializeAs(cvs, tramp)); + + auto section_list = m_obj_file->GetSectionList(); + if (!section_list) + continue; + auto section = section_list->FindSectionByID(tramp.ThunkSection); + + symtab->AddSymbol(Symbol(match.uid.toOpaqueId(), // symID + "IncrementalLinkThunk", // name + true, // name_is_mangled + eSymbolTypeTrampoline, + true, // external + false, // is_debug + true, // is_trampoline + false, // is_artificial + section, // section_sp + tramp.ThunkOffset, // value + tramp.Size, // size + tramp.Size != 0, // size_is_valid + false, // contains_linker_annotations + 0 // flags + )); + } + } else { + if (type == PDB_SymType::Function) { + sc.function = GetOrCreateFunction(csid, *sc.comp_unit).get(); + sc.block = sc.GetFunctionBlock(); + } + + if (type == PDB_SymType::Block) { + sc.block = &GetOrCreateBlock(csid); + sc.function = sc.block->CalculateSymbolContextFunction(); + } + resolved_flags |= eSymbolContextFunction; + resolved_flags |= eSymbolContextBlock; } - resolved_flags |= eSymbolContextFunction; - resolved_flags |= eSymbolContextBlock; - break; + break; } } @@ -1116,11 +1143,8 @@ } } - if (line_table->GetSize() == 0) - return false; - comp_unit.SetLineTable(line_table.release()); - return true; + return line_table->GetSize() > 0; } bool SymbolFileNativePDB::ParseDebugMacros(CompileUnit &comp_unit) { Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp =================================================================== --- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp +++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp @@ -206,16 +206,6 @@ // llvm::pdb::IPDBSession methods, such compilands will all be searched // automatically no matter whether we include them or not. m_cached_compile_unit_count = compilands->getChildCount(); - - // The linker can inject an additional "dummy" compilation unit into the - // PDB. Ignore this special compile unit for our purposes, if it is there. - // It is always the last one. - auto last_compiland_up = - compilands->getChildAtIndex(m_cached_compile_unit_count - 1); - lldbassert(last_compiland_up.get()); - std::string name = last_compiland_up->getName(); - if (name == "* Linker *") - --m_cached_compile_unit_count; } return m_cached_compile_unit_count; } Index: unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp =================================================================== --- unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp +++ unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp @@ -268,7 +268,7 @@ FileSpec header1("test-pdb.h"); FileSpec header2("test-pdb-nested.h"); uint32_t cus = symfile->GetNumCompileUnits(); - EXPECT_EQ(2u, cus); + EXPECT_EQ(3u, cus); SymbolContextList sc_list; lldb::SymbolContextItem scope = @@ -318,7 +318,7 @@ FileSpec header1("test-pdb.h"); FileSpec header2("test-pdb-nested.h"); uint32_t cus = symfile->GetNumCompileUnits(); - EXPECT_EQ(2u, cus); + EXPECT_EQ(3u, cus); SymbolContextList sc_list; lldb::SymbolContextItem scope =