Skip to content

[lldb] Fix a off-by-one error in ParseSupportFilesFromPrologue #71984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,24 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
FileSpec::Style style,
llvm::StringRef compile_dir = {}) {
FileSpecList support_files;
size_t first_file = 0;
if (prologue.getVersion() <= 4) {
// File index 0 is not valid before DWARF v5. Add a dummy entry to ensure
// support file list indices match those we get from the debug info and line
// tables.

// Handle the case where there are no files first to avoid having to special
// case this later.
if (prologue.FileNames.empty())
return support_files;

// Before DWARF v5, the line table indexes were one based.
const bool is_one_based = prologue.getVersion() < 5;
const size_t file_names = prologue.FileNames.size();
const size_t first_file_idx = is_one_based ? 1 : 0;
const size_t last_file_idx = is_one_based ? file_names : file_names - 1;

// Add a dummy entry to ensure the support file list indices match those we
// get from the debug info and line tables.
if (is_one_based)
support_files.Append(FileSpec());
first_file = 1;
}

const size_t number_of_files = prologue.FileNames.size();
for (size_t idx = first_file; idx <= number_of_files; ++idx) {
for (size_t idx = first_file_idx; idx <= last_file_idx; ++idx) {
std::string remapped_file;
if (auto file_path = GetFileByIndex(prologue, idx, compile_dir, style)) {
if (auto remapped = module->RemapSourceFile(llvm::StringRef(*file_path)))
Expand Down