diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h --- a/lldb/include/lldb/Utility/FileSpec.h +++ b/lldb/include/lldb/Utility/FileSpec.h @@ -70,8 +70,12 @@ /// \param[in] style /// The style of the path /// + /// \param[in] normalize + /// Whether or not to cleanup the filepath or not. + /// /// \see FileSpec::SetFile (const char *path) - explicit FileSpec(llvm::StringRef path, Style style = Style::native); + explicit FileSpec(llvm::StringRef path, Style style = Style::native, + bool normalize = true); explicit FileSpec(llvm::StringRef path, const llvm::Triple &triple); @@ -348,7 +352,10 @@ /// /// \param[in] style /// The style for the given path. - void SetFile(llvm::StringRef path, Style style); + /// + /// \param[in] normalize + /// Whether or not to cleanup the filepath or not. + void SetFile(llvm::StringRef path, Style style, bool normalize = true); /// Change the file specified with a new path. /// @@ -363,6 +370,10 @@ /// The triple which is used to set the Path style. void SetFile(llvm::StringRef path, const llvm::Triple &triple); + /// \returns \c true if the normalized FileSpec is the same as this; otherwise + /// \c false is returned. + bool IsNormalized() const; + bool IsResolved() const { return m_is_resolved; } /// Set if the file path has been resolved or not. diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -213,7 +213,7 @@ remapped_file = std::move(*file_path); // Unconditionally add an entry, so the indices match up. - support_files.EmplaceBack(remapped_file, style); + support_files.EmplaceBack(remapped_file, style, false); } return support_files; diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -68,8 +68,9 @@ FileSpec::FileSpec() : m_style(GetNativeStyle()) {} // Default constructor that can take an optional full path to a file on disk. -FileSpec::FileSpec(llvm::StringRef path, Style style) : m_style(style) { - SetFile(path, style); +FileSpec::FileSpec(llvm::StringRef path, Style style, bool normalize) + : m_style(style) { + SetFile(path, style, normalize); } FileSpec::FileSpec(llvm::StringRef path, const llvm::Triple &triple) @@ -171,7 +172,7 @@ // Update the contents of this object with a new path. The path will be split // up into a directory and filename and stored as uniqued string values for // quick comparison and efficient memory usage. -void FileSpec::SetFile(llvm::StringRef pathname, Style style) { +void FileSpec::SetFile(llvm::StringRef pathname, Style style, bool normalize) { m_filename.Clear(); m_directory.Clear(); m_is_resolved = false; @@ -183,11 +184,11 @@ llvm::SmallString<128> resolved(pathname); // Normalize the path by removing ".", ".." and other redundant components. - if (needsNormalization(resolved)) + if (normalize && needsNormalization(resolved)) llvm::sys::path::remove_dots(resolved, true, m_style); // Normalize back slashes to forward slashes - if (m_style == Style::windows) + if (normalize && m_style == Style::windows) std::replace(resolved.begin(), resolved.end(), '\\', '/'); if (resolved.empty()) { @@ -213,6 +214,10 @@ return SetFile(path, triple.isOSWindows() ? Style::windows : Style::posix); } +bool FileSpec::IsNormalized() const { + return *this == FileSpec(GetPath(), m_style, true); +} + // Convert to pointer operator. This allows code to check any FileSpec objects // to see if they contain anything valid using code such as: //