diff --git a/lldb/source/Utility/TildeExpressionResolver.cpp b/lldb/source/Utility/TildeExpressionResolver.cpp --- a/lldb/source/Utility/TildeExpressionResolver.cpp +++ b/lldb/source/Utility/TildeExpressionResolver.cpp @@ -11,6 +11,7 @@ #include #include +#include "lldb/Utility/ConstString.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/FileSystem.h" @@ -75,6 +76,7 @@ bool TildeExpressionResolver::ResolveFullPath( StringRef Expr, llvm::SmallVectorImpl &Output) { + static std::vector> g_tildes_expanded; if (!Expr.startswith("~")) { Output.assign(Expr.begin(), Expr.end()); return false; @@ -84,11 +86,27 @@ StringRef Left = Expr.take_until([](char c) { return path::is_separator(c); }); - if (!ResolveExact(Left, Output)) { - Output.assign(Expr.begin(), Expr.end()); - return false; + ConstString tilde_name(Left); + std::string expanded_path; + for (const auto &it : g_tildes_expanded) { + if (std::get<0>(it) == tilde_name) { + expanded_path = std::get<1>(it); + break; + } } - Output.append(Expr.begin() + Left.size(), Expr.end()); + if (expanded_path.empty()) { + if (!ResolveExact(Left, Output)) { + Output.assign(Expr.begin(), Expr.end()); + return false; + } + expanded_path = std::string(Output.data(), Output.size()); + g_tildes_expanded.push_back( + std::tuple(tilde_name, expanded_path)); + } else { + StringRef expanded_strref(expanded_path); + Output.assign(expanded_path.begin(), expanded_path.end()); + } + Output.append(Expr.begin() + tilde_name.GetLength(), Expr.end()); return true; }