diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-05-22 17:46:59 +0000 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-05-22 17:46:59 +0000 |
| commit | fb9b3011953cf89f70b1c4e802396a6656dfc9b3 (patch) | |
| tree | 4d94869706b9680624740b426bb11d17f094a2e9 /lldb/source/Host/common/Editline.cpp | |
| parent | b417513a506f2dfbe478fa499d75e6a625a361a5 (diff) | |
| download | bcm5719-llvm-fb9b3011953cf89f70b1c4e802396a6656dfc9b3.tar.gz bcm5719-llvm-fb9b3011953cf89f70b1c4e802396a6656dfc9b3.zip | |
[EditLine] Rewrite GetHistoryFilePath
Rewrite the GetHistoryFilePath implementation without relying on
FileSpec in the spirit of our discussion in D61994.
It changes LLDBs behavior in two ways:
1. We now only use the -widehistory suffix when LLDB is built with wchar
support, instead of as the fallback from when the ~/.lldb directory
isn't writable.
2. When the ~/.lldb directory isn't writable, we don't write any history
files at all. Previously we would write them to the user's home
directory (with the incorrect wide suffix), polluting ~ with a
different file for every IO handler.
Differential revision: https://reviews.llvm.org/D62216
llvm-svn: 361412
Diffstat (limited to 'lldb/source/Host/common/Editline.cpp')
| -rw-r--r-- | lldb/source/Host/common/Editline.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index aa52b4ca4f0..febb1e512ea 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -171,23 +171,28 @@ private: } const char *GetHistoryFilePath() { + // Compute the history path lazily. if (m_path.empty() && m_history && !m_prefix.empty()) { - FileSpec parent_path("~/.lldb"); - FileSystem::Instance().Resolve(parent_path); - char history_path[PATH_MAX]; - if (!llvm::sys::fs::create_directory(parent_path.GetPath())) { - snprintf(history_path, sizeof(history_path), "~/.lldb/%s-history", - m_prefix.c_str()); - } else { - snprintf(history_path, sizeof(history_path), "~/%s-widehistory", - m_prefix.c_str()); + llvm::SmallString<128> lldb_history_file; + llvm::sys::path::home_directory(lldb_history_file); + llvm::sys::path::append(lldb_history_file, ".lldb"); + + // LLDB stores its history in ~/.lldb/. If for some reason this directory + // isn't writable or cannot be created, history won't be available. + if (!llvm::sys::fs::create_directory(lldb_history_file)) { +#if LLDB_EDITLINE_USE_WCHAR + std::string filename = m_prefix + "-widehistory"; +#else + std::string filename = m_prefix + "-history"; +#endif + llvm::sys::path::append(lldb_history_file, filename); + m_path = lldb_history_file.str(); } - auto file_spec = FileSpec(history_path); - FileSystem::Instance().Resolve(file_spec); - m_path = file_spec.GetPath(); } + if (m_path.empty()) - return NULL; + return nullptr; + return m_path.c_str(); } |

