Index: source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp +++ source/Plugins/SymbolFile/DWARF/DWARFDebugLine.cpp @@ -465,12 +465,21 @@ FileSpec file_spec; std::string remapped_file; + bool deduplicate = (prologue_start != stmt_list); + // File index is only used for fetching information and not stored in the + // file spec entries. So we don't need to unify it over multiple prologues + // of the compile unit. for (uint32_t file_idx = 1; prologue.GetFile(file_idx, cu_comp_dir, file_spec); ++file_idx) { if (module_sp->RemapSourceFile(file_spec.GetPath(), remapped_file)) file_spec.SetFile(remapped_file, false, FileSpec::Style::native); - support_files.Append(file_spec); + + // Avoid adding duplicate file specs from subsequent prologues. + if (deduplicate) + support_files.AppendIfUnique(file_spec); + else + support_files.Append(file_spec); } // Only parse the prologue and skip the statement table. Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -992,6 +992,7 @@ LineTable *line_table; std::unique_ptr sequence_ap; lldb::addr_t addr_mask; + const FileSpecList &support_files; }; //---------------------------------------------------------------------- @@ -1014,9 +1015,28 @@ info->sequence_ap.reset(line_table->CreateLineSequenceContainer()); assert(info->sequence_ap.get()); } + + // If this is a compile unit with multiple prologues, figure out the + // file's index in the aggregated list of support files. + uint16_t file_idx = state.file; + if (file_idx > 0 && file_idx <= state.prologue->file_names.size()) { + const char *name = state.prologue->file_names[file_idx - 1].name; + FileSpec file_spec(name, false); + uint32_t promoted_idx = + info->support_files.FindFileIndex(0, file_spec, false); + + if (promoted_idx != UINT32_MAX && promoted_idx < UINT16_MAX) { + llvm::dbgs() << "Promoted " << file_idx << " -> "; + llvm::dbgs() << promoted_idx << " (" << name << ")\n"; + file_idx = promoted_idx; + } else { + llvm::dbgs() << "Unpromoted " << file_idx << " (" << name << ")\n"; + } + } + line_table->AppendLineEntryToSequence( info->sequence_ap.get(), state.address & info->addr_mask, state.line, - state.column, state.file, state.is_stmt, state.basic_block, + state.column, file_idx, state.is_stmt, state.basic_block, state.prologue_end, state.epilogue_begin, state.end_sequence); if (state.end_sequence) { // First, put the current sequence into the line table. @@ -1042,8 +1062,9 @@ if (cu_line_offset != DW_INVALID_OFFSET) { std::unique_ptr line_table_ap(new LineTable(sc.comp_unit)); if (line_table_ap.get()) { - ParseDWARFLineTableCallbackInfo info; - info.line_table = line_table_ap.get(); + const FileSpecList &support_files = sc.comp_unit->GetSupportFiles(); + ParseDWARFLineTableCallbackInfo info{line_table_ap.get(), nullptr, 0, + support_files}; /* * MIPS: @@ -1067,10 +1088,15 @@ break; } + const DWARFDataExtractor &debug_line_data = get_debug_line_data(); + lldb::offset_t data_end = debug_line_data.GetByteSize(); lldb::offset_t offset = cu_line_offset; - DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, - ParseDWARFLineTableCallback, - &info); + + do { + DWARFDebugLine::ParseStatementTable( + debug_line_data, &offset, ParseDWARFLineTableCallback, &info); + } while (offset < data_end); + SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile(); if (debug_map_symfile) { // We have an object file that has a line table with addresses that