Skip to content

Commit 52d43e1

Browse files
committed
[lldb/interpreter] Improve REPL init file compatibility
This patch changes the command interpreter sourcing logic for the REPL init file. Instead of looking for a arbitrary file name, it standardizes the REPL init file name to match to following scheme: `.lldbinit-<language>-repl` This will make the naming more homogenous and the sourcing logic future-proof. rdar://65836048 Differential Revision: https://reviews.llvm.org/D86987 Signed-off-by: Med Ismail Bennani <[email protected]>
1 parent 9c4d83f commit 52d43e1

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

lldb/docs/man/lldb.rst

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

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

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 7 additions & 7 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"
@@ -2095,17 +2096,16 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file,
20952096

20962097
static void GetHomeREPLInitFile(llvm::SmallVectorImpl<char> &init_file,
20972098
LanguageType language) {
2098-
std::string init_file_name;
2099-
2100-
switch (language) {
2101-
// TODO: Add support for a language used with a REPL.
2102-
default:
2099+
if (language == LanguageType::eLanguageTypeUnknown)
21032100
return;
2104-
}
21052101

2102+
std::string init_file_name =
2103+
(llvm::Twine(".lldbinit-") +
2104+
llvm::Twine(Language::GetNameForLanguageType(language)) +
2105+
llvm::Twine("-repl"))
2106+
.str();
21062107
FileSystem::Instance().GetHomeDirectory(init_file);
21072108
llvm::sys::path::append(init_file, init_file_name);
2108-
21092109
FileSystem::Instance().Resolve(init_file);
21102110
}
21112111

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)