Skip to content

Commit

Permalink
[DebugLine] Don't try to guess the path style
Browse files Browse the repository at this point in the history
In r368879 I made an attempt to guess the path style from the files in
the line table. After some consideration I now think this is a poor
idea. This patch undoes that behavior and instead adds an optional
argument to specify the path style. This allows us to make that decision
elsewhere where we have more information. In case of LLDB based on the
Unit.

llvm-svn: 369072
  • Loading branch information
JDevlieghere committed Aug 15, 2019
1 parent 4660ea9 commit de0ce98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 45 deletions.
29 changes: 12 additions & 17 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,10 @@ ParseLLVMLineTable(lldb_private::DWARFContext &context,
return *line_table;
}

static FileSpecList
ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
const llvm::DWARFDebugLine::Prologue &prologue,
llvm::StringRef compile_dir = {},
FileSpec first_file = {}) {
static FileSpecList ParseSupportFilesFromPrologue(
const lldb::ModuleSP &module,
const llvm::DWARFDebugLine::Prologue &prologue, FileSpec::Style style,
llvm::StringRef compile_dir = {}, FileSpec first_file = {}) {
FileSpecList support_files;
support_files.Append(first_file);

Expand All @@ -191,8 +190,8 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
std::string original_file;
if (!prologue.getFileNameByIndex(
idx, compile_dir,
llvm::DILineInfoSpecifier::FileLineInfoKind::Default,
original_file)) {
llvm::DILineInfoSpecifier::FileLineInfoKind::Default, original_file,
style)) {
// Always add an entry so the indexes remain correct.
support_files.EmplaceBack();
continue;
Expand All @@ -202,18 +201,14 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
if (!prologue.getFileNameByIndex(
idx, compile_dir,
llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
remapped_file)) {
remapped_file, style)) {
// Always add an entry so the indexes remain correct.
support_files.EmplaceBack(original_file,
FileSpec::GuessPathStyle(original_file)
.getValueOr(FileSpec::Style::native));
support_files.EmplaceBack(original_file, style);
continue;
}

module->RemapSourceFile(llvm::StringRef(original_file), remapped_file);
support_files.EmplaceBack(remapped_file,
FileSpec::GuessPathStyle(remapped_file)
.getValueOr(FileSpec::Style::native));
support_files.EmplaceBack(remapped_file, style);
}

return support_files;
Expand Down Expand Up @@ -893,8 +888,8 @@ SymbolFileDWARF::GetTypeUnitSupportFiles(DWARFTypeUnit &tu) {
"SymbolFileDWARF::GetTypeUnitSupportFiles failed to parse "
"the line table prologue");
} else {
list =
ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(), prologue);
list = ParseSupportFilesFromPrologue(GetObjectFile()->GetModule(),
prologue, tu.GetPathStyle());
}
}
return list;
Expand Down Expand Up @@ -1013,7 +1008,7 @@ bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
}

comp_unit.SetSupportFiles(ParseSupportFilesFromPrologue(
comp_unit.GetModule(), line_table->Prologue,
comp_unit.GetModule(), line_table->Prologue, dwarf_cu->GetPathStyle(),
dwarf_cu->GetCompilationDirectory().GetCString(), FileSpec(comp_unit)));

return true;
Expand Down
9 changes: 6 additions & 3 deletions llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Path.h"
#include <cstdint>
#include <map>
#include <string>
Expand Down Expand Up @@ -128,9 +129,11 @@ class DWARFDebugLine {

bool hasFileAtIndex(uint64_t FileIndex) const;

bool getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
std::string &Result) const;
bool
getFileNameByIndex(uint64_t FileIndex, StringRef CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
std::string &Result,
sys::path::Style Style = sys::path::Style::native) const;

void clear();
void dump(raw_ostream &OS, DIDumpOptions DumpOptions) const;
Expand Down
30 changes: 5 additions & 25 deletions llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
Expand Down Expand Up @@ -1041,28 +1040,9 @@ static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
sys::path::is_absolute(Path, sys::path::Style::windows);
}

/// If given an absolute path, guess the path style.
static sys::path::Style GuessPathStyle(StringRef Path) {
bool Posix = sys::path::is_absolute(Path, sys::path::Style::posix);
bool Windows = sys::path::is_absolute(Path, sys::path::Style::windows);
// This is a relative path.
if (!Posix && !Windows)
return sys::path::Style::native;
// This is a valid absolute path for both Windows and Posix.
if (Posix && Windows)
return sys::path::Style::native;
if (Posix)
return sys::path::Style::posix;
if (Windows)
return sys::path::Style::windows;

llvm_unreachable("All combinations should have been handled.");
}

bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
StringRef CompDir,
FileLineInfoKind Kind,
std::string &Result) const {
bool DWARFDebugLine::Prologue::getFileNameByIndex(
uint64_t FileIndex, StringRef CompDir, FileLineInfoKind Kind,
std::string &Result, sys::path::Style Style) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return false;
const FileNameEntry &Entry = getFileNameEntry(FileIndex);
Expand All @@ -1088,11 +1068,11 @@ bool DWARFDebugLine::Prologue::getFileNameByIndex(uint64_t FileIndex,
// We know that FileName is not absolute, the only way to have an
// absolute path at this point would be if IncludeDir is absolute.
if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
sys::path::append(FilePath, GuessPathStyle(CompDir), CompDir);
sys::path::append(FilePath, Style, CompDir);
}

// sys::path::append skips empty strings.
sys::path::append(FilePath, GuessPathStyle(IncludeDir), IncludeDir, FileName);
sys::path::append(FilePath, Style, IncludeDir, FileName);
Result = FilePath.str();
return true;
}
Expand Down

0 comments on commit de0ce98

Please sign in to comment.