labath updated this revision to Diff 409196. labath added a comment. Use the term "global" and rename functions to make it more consistent with existing code.
It's worth noting that (as a part of the consistency), I have changed the cmake variable to point to a directory instead of a file. This means that the init file name is currently hardcoded -- currently it's "lldbinit", but we could change that into something more complex to support the workflow feature. In particular, I note the fact that the file name does not include a leading dot, as I believe is the practice for global configuration files. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D119831/new/ https://reviews.llvm.org/D119831 Files: lldb/cmake/modules/LLDBConfig.cmake lldb/include/lldb/API/SBCommandInterpreter.h lldb/include/lldb/Host/Config.h.cmake lldb/include/lldb/Interpreter/CommandInterpreter.h lldb/source/API/SBCommandInterpreter.cpp lldb/source/API/SBDebugger.cpp lldb/source/Interpreter/CommandInterpreter.cpp lldb/tools/driver/Driver.cpp
Index: lldb/tools/driver/Driver.cpp =================================================================== --- lldb/tools/driver/Driver.cpp +++ lldb/tools/driver/Driver.cpp @@ -452,9 +452,14 @@ SBCommandInterpreter sb_interpreter = m_debugger.GetCommandInterpreter(); - // Before we handle any options from the command line, we parse the - // REPL init file or the default file in the user's home directory. + // Process lldbinit files before handling any options from the command line. SBCommandReturnObject result; + sb_interpreter.SourceInitFileInGlobalDirectory(result); + if (m_option_data.m_debug_mode) { + result.PutError(m_debugger.GetErrorFile()); + result.PutOutput(m_debugger.GetOutputFile()); + } + sb_interpreter.SourceInitFileInHomeDirectory(result, m_option_data.m_repl); if (m_option_data.m_debug_mode) { result.PutError(m_debugger.GetErrorFile()); Index: lldb/source/Interpreter/CommandInterpreter.cpp =================================================================== --- lldb/source/Interpreter/CommandInterpreter.cpp +++ lldb/source/Interpreter/CommandInterpreter.cpp @@ -2380,6 +2380,21 @@ SourceInitFile(FileSpec(init_file.str()), result); } +void CommandInterpreter::SourceInitFileGlobal(CommandReturnObject &result) { +#ifdef LLDB_GLOBAL_INIT_DIRECTORY + if (!m_skip_lldbinit_files) { + FileSpec init_file(LLDB_GLOBAL_INIT_DIRECTORY); + if (init_file) + init_file.MakeAbsolute(HostInfo::GetShlibDir()); + + init_file.AppendPathComponent("lldbinit"); + SourceInitFile(init_file, result); + return; + } +#endif + result.SetStatus(eReturnStatusSuccessFinishNoResult); +} + const char *CommandInterpreter::GetCommandPrefix() { const char *prefix = GetDebugger().GetIOHandlerCommandPrefix(); return prefix == nullptr ? "" : prefix; Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -236,6 +236,7 @@ interp.get()->SkipLLDBInitFiles(false); interp.get()->SkipAppInitFiles(false); SBCommandReturnObject result; + interp.SourceInitFileInGlobalDirectory(result); interp.SourceInitFileInHomeDirectory(result, false); } else { interp.get()->SkipLLDBInitFiles(true); Index: lldb/source/API/SBCommandInterpreter.cpp =================================================================== --- lldb/source/API/SBCommandInterpreter.cpp +++ lldb/source/API/SBCommandInterpreter.cpp @@ -417,6 +417,21 @@ m_opaque_ptr = interpreter; } +void SBCommandInterpreter::SourceInitFileInGlobalDirectory( + SBCommandReturnObject &result) { + LLDB_INSTRUMENT_VA(this, result); + result.Clear(); + if (IsValid()) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + std::unique_lock<std::recursive_mutex> lock; + if (target_sp) + lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); + m_opaque_ptr->SourceInitFileGlobal(result.ref()); + } else { + result->AppendError("SBCommandInterpreter is not valid"); + } +} + void SBCommandInterpreter::SourceInitFileInHomeDirectory( SBCommandReturnObject &result) { LLDB_INSTRUMENT_VA(this, result); Index: lldb/include/lldb/Interpreter/CommandInterpreter.h =================================================================== --- lldb/include/lldb/Interpreter/CommandInterpreter.h +++ lldb/include/lldb/Interpreter/CommandInterpreter.h @@ -253,6 +253,7 @@ void SourceInitFileCwd(CommandReturnObject &result); void SourceInitFileHome(CommandReturnObject &result, bool is_repl); + void SourceInitFileGlobal(CommandReturnObject &result); bool AddCommand(llvm::StringRef name, const lldb::CommandObjectSP &cmd_sp, bool can_replace); Index: lldb/include/lldb/Host/Config.h.cmake =================================================================== --- lldb/include/lldb/Host/Config.h.cmake +++ lldb/include/lldb/Host/Config.h.cmake @@ -53,4 +53,6 @@ #define LLDB_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" +#cmakedefine LLDB_GLOBAL_INIT_DIRECTORY R"(${LLDB_GLOBAL_INIT_DIRECTORY})" + #endif // #ifndef LLDB_HOST_CONFIG_H Index: lldb/include/lldb/API/SBCommandInterpreter.h =================================================================== --- lldb/include/lldb/API/SBCommandInterpreter.h +++ lldb/include/lldb/API/SBCommandInterpreter.h @@ -145,6 +145,8 @@ const char *help, const char *syntax, const char *auto_repeat_command); + void SourceInitFileInGlobalDirectory(lldb::SBCommandReturnObject &result); + void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result); void SourceInitFileInHomeDirectory(lldb::SBCommandReturnObject &result, bool is_repl); Index: lldb/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/cmake/modules/LLDBConfig.cmake +++ lldb/cmake/modules/LLDBConfig.cmake @@ -72,6 +72,10 @@ option(LLDB_SKIP_STRIP "Whether to skip stripping of binaries when installing lldb." OFF) option(LLDB_SKIP_DSYM "Whether to skip generating a dSYM when installing lldb." OFF) +set(LLDB_GLOBAL_INIT_DIRECTORY "" CACHE STRING + "Path to the global lldbinit directory. Relative paths are resolved relative to the + directory containing the LLDB library.") + if (LLDB_USE_SYSTEM_DEBUGSERVER) # The custom target for the system debugserver has no install target, so we # need to remove it from the LLVM_DISTRIBUTION_COMPONENTS list.
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits