diff options
author | Med Ismail Bennani <medismail.bennani@gmail.com> | 2020-08-19 22:04:35 +0200 |
---|---|---|
committer | Med Ismail Bennani <medismail.bennani@gmail.com> | 2020-08-20 00:36:32 +0200 |
commit | 868b45b5b31d1203cab09ae0306f4c47e6070f68 (patch) | |
tree | 1b88ba2908e420de8fe11a187da6b5250b41af9d /lldb/source/Interpreter/CommandInterpreter.cpp | |
parent | 428bebaf10e177db5e42206ca8f871f0bcbef058 (diff) | |
download | llvm-868b45b5b31d1203cab09ae0306f4c47e6070f68.zip llvm-868b45b5b31d1203cab09ae0306f4c47e6070f68.tar.gz llvm-868b45b5b31d1203cab09ae0306f4c47e6070f68.tar.bz2 |
[lldb/interpreter] Add REPL-specific init file
This patch adds the infrastructure to have language specific REPL init
files. It's the foundation work to a following patch that will introduce
Swift REPL init file.
When lldb is launched with the `--repl` option, it will look for a REPL
init file in the home directory and source it. This overrides the
default `~/.lldbinit`, which content might make the REPL behave
unexpectedly. If the REPL init file doesn't exists, lldb will fall back
to the default init file.
rdar://65836048
Differential Revision: https://reviews.llvm.org/D86242
Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
Diffstat (limited to 'lldb/source/Interpreter/CommandInterpreter.cpp')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index ec82efb..6a355cb 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -2090,6 +2090,22 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file, FileSystem::Instance().Resolve(init_file); } +static void GetHomeREPLInitFile(llvm::SmallVectorImpl<char> &init_file, + LanguageType language) { + std::string init_file_name; + + switch (language) { + // TODO: Add support for a language used with a REPL. + default: + return; + } + + llvm::sys::path::home_directory(init_file); + llvm::sys::path::append(init_file, init_file_name); + + FileSystem::Instance().Resolve(init_file); +} + static void GetCwdInitFile(llvm::SmallVectorImpl<char> &init_file) { llvm::StringRef s = ".lldbinit"; init_file.assign(s.begin(), s.end()); @@ -2164,15 +2180,27 @@ void CommandInterpreter::SourceInitFileCwd(CommandReturnObject &result) { /// We will first see if there is an application specific ".lldbinit" file /// whose name is "~/.lldbinit" followed by a "-" and the name of the program. -/// If this file doesn't exist, we fall back to just the "~/.lldbinit" file. -void CommandInterpreter::SourceInitFileHome(CommandReturnObject &result) { +/// If this file doesn't exist, we fall back to the REPL init file or the +/// default home init file in "~/.lldbinit". +void CommandInterpreter::SourceInitFileHome(CommandReturnObject &result, + bool is_repl) { if (m_skip_lldbinit_files) { result.SetStatus(eReturnStatusSuccessFinishNoResult); return; } llvm::SmallString<128> init_file; - GetHomeInitFile(init_file); + + if (is_repl) { + LanguageType language = {}; + TargetSP target_sp = GetDebugger().GetSelectedTarget(); + if (target_sp) + language = target_sp->GetLanguage(); + GetHomeREPLInitFile(init_file, language); + } + + if (init_file.empty()) + GetHomeInitFile(init_file); if (!m_skip_app_init_files) { llvm::StringRef program_name = |