diff options
Diffstat (limited to 'contrib/llvm-project/lldb/tools/driver/Driver.cpp')
-rw-r--r-- | contrib/llvm-project/lldb/tools/driver/Driver.cpp | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/contrib/llvm-project/lldb/tools/driver/Driver.cpp b/contrib/llvm-project/lldb/tools/driver/Driver.cpp index 233e0dd977d3..16fa2f1393d5 100644 --- a/contrib/llvm-project/lldb/tools/driver/Driver.cpp +++ b/contrib/llvm-project/lldb/tools/driver/Driver.cpp @@ -86,6 +86,8 @@ static void reset_stdin_termios(); static bool g_old_stdin_termios_is_valid = false; static struct termios g_old_stdin_termios; +static bool disable_color(const raw_ostream &OS) { return false; } + static Driver *g_driver = nullptr; // In the Driver::MainLoop, we change the terminal settings. This function is @@ -186,6 +188,12 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) { m_debugger.SkipLLDBInitFiles(false); m_debugger.SkipAppInitFiles(false); + if (args.hasArg(OPT_no_use_colors)) { + m_debugger.SetUseColor(false); + WithColor::setAutoDetectFunction(disable_color); + m_option_data.m_debug_mode = true; + } + if (args.hasArg(OPT_version)) { m_option_data.m_print_version = true; } @@ -227,11 +235,6 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) { m_debugger.GetInstanceName()); } - if (args.hasArg(OPT_no_use_colors)) { - m_debugger.SetUseColor(false); - m_option_data.m_debug_mode = true; - } - if (auto *arg = args.getLastArg(OPT_file)) { auto arg_value = arg->getValue(); SBFileSpec file(arg_value); @@ -452,9 +455,14 @@ int Driver::MainLoop() { 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()); @@ -663,31 +671,30 @@ void sigint_handler(int signo) { _exit(signo); } -void sigtstp_handler(int signo) { +#ifndef _WIN32 +static void sigtstp_handler(int signo) { if (g_driver != nullptr) g_driver->GetDebugger().SaveInputTerminalState(); + // Unblock the signal and remove our handler. + sigset_t set; + sigemptyset(&set); + sigaddset(&set, signo); + pthread_sigmask(SIG_UNBLOCK, &set, nullptr); signal(signo, SIG_DFL); - kill(getpid(), signo); + + // Now re-raise the signal. We will immediately suspend... + raise(signo); + // ... and resume after a SIGCONT. + + // Now undo the modifications. + pthread_sigmask(SIG_BLOCK, &set, nullptr); signal(signo, sigtstp_handler); -} -void sigcont_handler(int signo) { if (g_driver != nullptr) g_driver->GetDebugger().RestoreInputTerminalState(); - - signal(signo, SIG_DFL); - kill(getpid(), signo); - signal(signo, sigcont_handler); -} - -void reproducer_handler(void *finalize_cmd) { - if (SBReproducer::Generate()) { - int result = std::system(static_cast<const char *>(finalize_cmd)); - (void)result; - fflush(stdout); - } } +#endif static void printHelp(LLDBOptTable &table, llvm::StringRef tool_name) { std::string usage_str = tool_name.str() + " [options]"; @@ -822,11 +829,10 @@ int main(int argc, char const *argv[]) { SBHostOS::ThreadCreated("<lldb.driver.main-thread>"); signal(SIGINT, sigint_handler); -#if !defined(_MSC_VER) +#if !defined(_WIN32) signal(SIGPIPE, SIG_IGN); signal(SIGWINCH, sigwinch_handler); signal(SIGTSTP, sigtstp_handler); - signal(SIGCONT, sigcont_handler); #endif int exit_code = 0; |