diff options
author | Greg Clayton <gclayton@apple.com> | 2018-05-21 14:14:36 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2018-05-21 14:14:36 +0000 |
commit | 86188d8a404093c37b7b63515aaf223d5aa4d113 (patch) | |
tree | ba2070245f06c3270faca61c6ca6c9b1dafc6223 /lldb/source/Utility/FileSpec.cpp | |
parent | b13f033818ca7fa3b37afd5708ae3b87114e2f39 (diff) | |
download | bcm5719-llvm-86188d8a404093c37b7b63515aaf223d5aa4d113.tar.gz bcm5719-llvm-86188d8a404093c37b7b63515aaf223d5aa4d113.zip |
Fix PathMappingList for relative and empty paths after recent FileSpec normalization changes
PathMappingList was broken for relative and empty paths after normalization changes in FileSpec. There were also no tests for PathMappingList so I added those.
Changes include:
Change PathMappingList::ReverseRemapPath() to take FileSpec objects instead of ConstString. The only client of this was doing work to convert to and from ConstString objects for no reason.
Normalize all paths prefix and replacements that are added to the PathMappingList vector so they match the paths that have been already normalized in the debug info
Unify code in the two forms of PathMappingList::RemapPath() so only one contains the actual functionality. Prior to this, there were two versions of this code.
Use FileSpec::AppendPathComponent() and remove a long standing TODO so paths are correctly appended to each other.
Added tests for absolute, relative and empty paths.
Differential Revision: https://reviews.llvm.org/D47021
llvm-svn: 332842
Diffstat (limited to 'lldb/source/Utility/FileSpec.cpp')
-rw-r--r-- | lldb/source/Utility/FileSpec.cpp | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index 944f01d9000..ac404cea435 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -67,6 +67,31 @@ void Denormalize(llvm::SmallVectorImpl<char> &path, FileSpec::Style style) { std::replace(path.begin(), path.end(), '/', '\\'); } + +bool PathIsRelative(llvm::StringRef path, FileSpec::Style style) { + + if (path.empty()) + return false; + + if (PathStyleIsPosix(style)) { + // If the path doesn't start with '/' or '~', return true + switch (path[0]) { + case '/': + case '~': + return false; + default: + return true; + } + } else { + if (path.size() >= 2 && path[1] == ':') + return false; + if (path[0] == '/') + return false; + return true; + } + return false; +} + } // end anonymous namespace void FileSpec::Resolve(llvm::SmallVectorImpl<char> &path) { @@ -814,31 +839,10 @@ bool FileSpec::IsSourceImplementationFile() const { } bool FileSpec::IsRelative() const { - const char *dir = m_directory.GetCString(); - llvm::StringRef directory(dir ? dir : ""); - - if (directory.size() > 0) { - if (PathStyleIsPosix(m_style)) { - // If the path doesn't start with '/' or '~', return true - switch (directory[0]) { - case '/': - case '~': - return false; - default: - return true; - } - } else { - if (directory.size() >= 2 && directory[1] == ':') - return false; - if (directory[0] == '/') - return false; - return true; - } - } else if (m_filename) { - // No directory, just a basename, return true - return true; - } - return false; + if (m_directory) + return PathIsRelative(m_directory.GetStringRef(), m_style); + else + return PathIsRelative(m_filename.GetStringRef(), m_style); } bool FileSpec::IsAbsolute() const { return !FileSpec::IsRelative(); } |