Skip to content

Commit b6306aa

Browse files
author
git apple-llvm automerger
committed
Merge commit '0d39c7898ec6' from swift/release/5.3 into swift/master
2 parents 5a8999b + 0d39c78 commit b6306aa

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

lldb/docs/man/lldb.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,15 @@ CONFIGURATION FILES
298298
:program:`lldb` reads things like settings, aliases and commands from the
299299
.lldbinit file.
300300

301-
First, it will read the application specific init file whose name is
302-
~/.lldbinit followed by a "-" and the name of the current program. This would
303-
be ~/.lldbinit-lldb for the command line :program:`lldb` and ~/.lldbinit-Xcode
304-
for Xcode. If there is no application specific init file, the global
305-
~/.lldbinit is read.
301+
First, :program:`lldb` will try to read the application specific init file
302+
whose name is ~/.lldbinit followed by a "-" and the name of the current
303+
program. This would be ~/.lldbinit-lldb for the command line :program:`lldb`
304+
and ~/.lldbinit-Xcode for Xcode. If there is no application specific init
305+
file, :program:`lldb` will look for an init file in the home directory.
306+
If launched with a `REPL`_ option, it will first look for a REPL configuration
307+
file, specific to the REPL language. If this file doesn't exist, or :program:`lldb`
308+
wasn't launch with `REPL`_, meaning there is neither a REPL init file nor an
309+
application specific init file, `lldb` will fallback to the global ~/.lldbinit.
306310

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

lldb/include/lldb/API/SBCommandInterpreter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class SBCommandInterpreter {
120120
const char *help, const char *syntax);
121121

122122
void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result);
123+
void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result,
124+
bool is_repl);
123125

124126
void
125127
SourceInitFileInCurrentWorkingDirectory(lldb::SBCommandReturnObject &result);

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class CommandInterpreter : public Broadcaster,
213213
}
214214

215215
void SourceInitFileCwd(CommandReturnObject &result);
216-
void SourceInitFileHome(CommandReturnObject &result);
216+
void SourceInitFileHome(CommandReturnObject &result, bool is_repl = false);
217217

218218
bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp,
219219
bool can_replace);

lldb/source/API/SBCommandInterpreter.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,24 @@ void SBCommandInterpreter::SourceInitFileInHomeDirectory(
574574
}
575575
}
576576

577+
void SBCommandInterpreter::SourceInitFileInHomeDirectory(
578+
SBCommandReturnObject &result, bool is_repl) {
579+
LLDB_RECORD_METHOD(void, SBCommandInterpreter, SourceInitFileInHomeDirectory,
580+
(lldb::SBCommandReturnObject &, bool), result, is_repl);
581+
582+
result.Clear();
583+
if (IsValid()) {
584+
TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
585+
std::unique_lock<std::recursive_mutex> lock;
586+
if (target_sp)
587+
lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
588+
m_opaque_ptr->SourceInitFileHome(result.ref(), is_repl);
589+
} else {
590+
result->AppendError("SBCommandInterpreter is not valid");
591+
result->SetStatus(eReturnStatusFailed);
592+
}
593+
}
594+
577595
void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory(
578596
SBCommandReturnObject &result) {
579597
LLDB_RECORD_METHOD(void, SBCommandInterpreter,
@@ -922,6 +940,9 @@ void RegisterMethods<SBCommandInterpreterRunOptions>(Registry &R) {
922940
LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
923941
SourceInitFileInHomeDirectory,
924942
(lldb::SBCommandReturnObject &));
943+
LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
944+
SourceInitFileInHomeDirectory,
945+
(lldb::SBCommandReturnObject &, bool));
925946
LLDB_REGISTER_METHOD(void, SBCommandInterpreter,
926947
SourceInitFileInCurrentWorkingDirectory,
927948
(lldb::SBCommandReturnObject &));

lldb/source/API/SBDebugger.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ SBDebugger SBDebugger::Create(bool source_init_files,
219219
interp.get()->SkipLLDBInitFiles(false);
220220
interp.get()->SkipAppInitFiles(false);
221221
SBCommandReturnObject result;
222-
interp.SourceInitFileInHomeDirectory(result);
222+
interp.SourceInitFileInHomeDirectory(result, false);
223223
} else {
224224
interp.get()->SkipLLDBInitFiles(true);
225225
interp.get()->SkipAppInitFiles(true);

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,22 @@ static void GetHomeInitFile(llvm::SmallVectorImpl<char> &init_file,
20602060
FileSystem::Instance().Resolve(init_file);
20612061
}
20622062

2063+
static void GetHomeREPLInitFile(llvm::SmallVectorImpl<char> &init_file,
2064+
LanguageType language) {
2065+
std::string init_file_name;
2066+
2067+
switch (language) {
2068+
// TODO: Add support for a language used with a REPL.
2069+
default:
2070+
return;
2071+
}
2072+
2073+
llvm::sys::path::home_directory(init_file);
2074+
llvm::sys::path::append(init_file, init_file_name);
2075+
2076+
FileSystem::Instance().Resolve(init_file);
2077+
}
2078+
20632079
static void GetCwdInitFile(llvm::SmallVectorImpl<char> &init_file) {
20642080
llvm::StringRef s = ".lldbinit";
20652081
init_file.assign(s.begin(), s.end());
@@ -2134,15 +2150,27 @@ void CommandInterpreter::SourceInitFileCwd(CommandReturnObject &result) {
21342150

21352151
/// We will first see if there is an application specific ".lldbinit" file
21362152
/// whose name is "~/.lldbinit" followed by a "-" and the name of the program.
2137-
/// If this file doesn't exist, we fall back to just the "~/.lldbinit" file.
2138-
void CommandInterpreter::SourceInitFileHome(CommandReturnObject &result) {
2153+
/// If this file doesn't exist, we fall back to the REPL init file or the
2154+
/// default home init file in "~/.lldbinit".
2155+
void CommandInterpreter::SourceInitFileHome(CommandReturnObject &result,
2156+
bool is_repl) {
21392157
if (m_skip_lldbinit_files) {
21402158
result.SetStatus(eReturnStatusSuccessFinishNoResult);
21412159
return;
21422160
}
21432161

21442162
llvm::SmallString<128> init_file;
2145-
GetHomeInitFile(init_file);
2163+
2164+
if (is_repl) {
2165+
LanguageType language = {};
2166+
TargetSP target_sp = GetDebugger().GetSelectedTarget();
2167+
if (target_sp)
2168+
language = target_sp->GetLanguage();
2169+
GetHomeREPLInitFile(init_file, language);
2170+
}
2171+
2172+
if (init_file.empty())
2173+
GetHomeInitFile(init_file);
21462174

21472175
if (!m_skip_app_init_files) {
21482176
llvm::StringRef program_name =

lldb/tools/driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ int Driver::MainLoop() {
492492
// Before we handle any options from the command line, we parse the
493493
// .lldbinit file in the user's home directory.
494494
SBCommandReturnObject result;
495-
sb_interpreter.SourceInitFileInHomeDirectory(result);
495+
sb_interpreter.SourceInitFileInHomeDirectory(result, m_option_data.m_repl);
496496
if (m_option_data.m_debug_mode) {
497497
result.PutError(m_debugger.GetErrorFile());
498498
result.PutOutput(m_debugger.GetOutputFile());

0 commit comments

Comments
 (0)