Skip to content

Commit dad1a60

Browse files
authored
Merge pull request #1736 from medismailben/apple/stable/20200714
[lldb/interpreter] Improve REPL init file compatibility
2 parents 1d103b6 + 040f52c commit dad1a60

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

lldb/docs/man/lldb.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,11 @@ program. This would be ~/.lldbinit-lldb for the command line :program:`lldb`
311311
and ~/.lldbinit-Xcode for Xcode. If there is no application specific init
312312
file, :program:`lldb` will look for an init file in the home directory.
313313
If launched with a `REPL`_ option, it will first look for a REPL configuration
314-
file, specific to the REPL language. If this file doesn't exist, or :program:`lldb`
315-
wasn't launch with `REPL`_, meaning there is neither a REPL init file nor an
316-
application specific init file, `lldb` will fallback to the global ~/.lldbinit.
314+
file, specific to the REPL language. The init file should be named as follow:
315+
`.lldbinit-<language>-repl` (i.e. `.lldbinit-swift-repl`). If this file doesn't
316+
exist, or :program:`lldb` wasn't launch with `REPL`_, meaning there is neither
317+
a REPL init file nor an application specific init file, `lldb` will fallback to
318+
the global ~/.lldbinit.
317319

318320
Secondly, it will look for an .lldbinit file in the current working directory.
319321
For security reasons, :program:`lldb` will print a warning and not source this

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "lldb/Interpreter/Property.h"
6868
#include "lldb/Utility/Args.h"
6969

70+
#include "lldb/Target/Language.h"
7071
#include "lldb/Target/Process.h"
7172
#include "lldb/Target/StopInfo.h"
7273
#include "lldb/Target/TargetList.h"
@@ -2090,17 +2091,16 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file,
20902091

20912092
static void GetHomeREPLInitFile(llvm::SmallVectorImpl<char> &init_file,
20922093
LanguageType language) {
2093-
std::string init_file_name;
2094-
2095-
switch (language) {
2096-
// TODO: Add support for a language used with a REPL.
2097-
default:
2094+
if (language == LanguageType::eLanguageTypeUnknown)
20982095
return;
2099-
}
21002096

2101-
llvm::sys::path::home_directory(init_file);
2097+
std::string init_file_name =
2098+
(llvm::Twine(".lldbinit-") +
2099+
llvm::Twine(Language::GetNameForLanguageType(language)) +
2100+
llvm::Twine("-repl"))
2101+
.str();
2102+
FileSystem::Instance().GetHomeDirectory(init_file);
21022103
llvm::sys::path::append(init_file, init_file_name);
2103-
21042104
FileSystem::Instance().Resolve(init_file);
21052105
}
21062106

lldb/tools/driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ int Driver::MainLoop() {
491491
SBCommandInterpreter sb_interpreter = m_debugger.GetCommandInterpreter();
492492

493493
// Before we handle any options from the command line, we parse the
494-
// .lldbinit file in the user's home directory.
494+
// REPL init file or the default file in the user's home directory.
495495
SBCommandReturnObject result;
496496
sb_interpreter.SourceInitFileInHomeDirectory(result, m_option_data.m_repl);
497497
if (m_option_data.m_debug_mode) {

0 commit comments

Comments
 (0)