Skip to content

[lldb/interpreter] Improve REPL init file compatibility #1736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lldb/docs/man/lldb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ program. This would be ~/.lldbinit-lldb for the command line :program:`lldb`
and ~/.lldbinit-Xcode for Xcode. If there is no application specific init
file, :program:`lldb` will look for an init file in the home directory.
If launched with a `REPL`_ option, it will first look for a REPL configuration
file, specific to the REPL language. If this file doesn't exist, or :program:`lldb`
wasn't launch with `REPL`_, meaning there is neither a REPL init file nor an
application specific init file, `lldb` will fallback to the global ~/.lldbinit.
file, specific to the REPL language. The init file should be named as follow:
`.lldbinit-<language>-repl` (i.e. `.lldbinit-swift-repl`). If this file doesn't
exist, or :program:`lldb` wasn't launch with `REPL`_, meaning there is neither
a REPL init file nor an application specific init file, `lldb` will fallback to
the global ~/.lldbinit.

Secondly, it will look for an .lldbinit file in the current working directory.
For security reasons, :program:`lldb` will print a warning and not source this
Expand Down
16 changes: 8 additions & 8 deletions lldb/source/Interpreter/CommandInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "lldb/Interpreter/Property.h"
#include "lldb/Utility/Args.h"

#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/TargetList.h"
Expand Down Expand Up @@ -2090,17 +2091,16 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &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:
if (language == LanguageType::eLanguageTypeUnknown)
return;
}

llvm::sys::path::home_directory(init_file);
std::string init_file_name =
(llvm::Twine(".lldbinit-") +
llvm::Twine(Language::GetNameForLanguageType(language)) +
llvm::Twine("-repl"))
.str();
FileSystem::Instance().GetHomeDirectory(init_file);
llvm::sys::path::append(init_file, init_file_name);

FileSystem::Instance().Resolve(init_file);
}

Expand Down
2 changes: 1 addition & 1 deletion lldb/tools/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ int Driver::MainLoop() {
SBCommandInterpreter sb_interpreter = m_debugger.GetCommandInterpreter();

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