diff options
Diffstat (limited to 'tools/driver/Driver.cpp')
| -rw-r--r-- | tools/driver/Driver.cpp | 52 | 
1 files changed, 21 insertions, 31 deletions
| diff --git a/tools/driver/Driver.cpp b/tools/driver/Driver.cpp index 043aba7b07ba..6ab2bd93659f 100644 --- a/tools/driver/Driver.cpp +++ b/tools/driver/Driver.cpp @@ -11,6 +11,7 @@  #include "lldb/API/SBCommandInterpreter.h"  #include "lldb/API/SBCommandReturnObject.h"  #include "lldb/API/SBDebugger.h" +#include "lldb/API/SBFile.h"  #include "lldb/API/SBHostOS.h"  #include "lldb/API/SBLanguageRuntime.h"  #include "lldb/API/SBReproducer.h" @@ -18,8 +19,8 @@  #include "lldb/API/SBStringList.h"  #include "llvm/ADT/StringRef.h" -#include "llvm/Support/ConvertUTF.h"  #include "llvm/Support/Format.h" +#include "llvm/Support/InitLLVM.h"  #include "llvm/Support/Path.h"  #include "llvm/Support/PrettyStackTrace.h"  #include "llvm/Support/Process.h" @@ -229,6 +230,7 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {    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)) { @@ -262,14 +264,6 @@ SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {      m_debugger.SetScriptLanguage(m_debugger.GetScriptingLanguage(arg_value));    } -  if (args.hasArg(OPT_no_use_colors)) { -    m_option_data.m_debug_mode = true; -  } - -  if (args.hasArg(OPT_no_use_colors)) { -    m_debugger.SetUseColor(false); -  } -    if (args.hasArg(OPT_source_quietly)) {      m_option_data.m_source_quietly = true;    } @@ -506,16 +500,16 @@ int Driver::MainLoop() {    SBCommandReturnObject result;    sb_interpreter.SourceInitFileInHomeDirectory(result);    if (m_option_data.m_debug_mode) { -    result.PutError(m_debugger.GetErrorFileHandle()); -    result.PutOutput(m_debugger.GetOutputFileHandle()); +    result.PutError(m_debugger.GetErrorFile()); +    result.PutOutput(m_debugger.GetOutputFile());    }    // Source the local .lldbinit file if it exists and we're allowed to source.    // Here we want to always print the return object because it contains the    // warning and instructions to load local lldbinit files.    sb_interpreter.SourceInitFileInCurrentWorkingDirectory(result); -  result.PutError(m_debugger.GetErrorFileHandle()); -  result.PutOutput(m_debugger.GetOutputFileHandle()); +  result.PutError(m_debugger.GetErrorFile()); +  result.PutOutput(m_debugger.GetOutputFile());    // We allow the user to specify an exit code when calling quit which we will    // return when exiting. @@ -581,8 +575,8 @@ int Driver::MainLoop() {    }    if (m_option_data.m_debug_mode) { -    result.PutError(m_debugger.GetErrorFileHandle()); -    result.PutOutput(m_debugger.GetOutputFileHandle()); +    result.PutError(m_debugger.GetErrorFile()); +    result.PutOutput(m_debugger.GetOutputFile());    }    const bool handle_events = true; @@ -813,23 +807,9 @@ llvm::Optional<int> InitializeReproducer(opt::InputArgList &input_args) {    return llvm::None;  } -int -#ifdef _MSC_VER -wmain(int argc, wchar_t const *wargv[]) -#else -main(int argc, char const *argv[]) -#endif +int main(int argc, char const *argv[])  { -#ifdef _MSC_VER -  // Convert wide arguments to UTF-8 -  std::vector<std::string> argvStrings(argc); -  std::vector<const char *> argvPointers(argc); -  for (int i = 0; i != argc; ++i) { -    llvm::convertWideToUTF8(wargv[i], argvStrings[i]); -    argvPointers[i] = argvStrings[i].c_str(); -  } -  const char **argv = argvPointers.data(); -#endif +  llvm::InitLLVM IL(argc, argv);    // Print stack trace on crash.    llvm::StringRef ToolName = llvm::sys::path::filename(argv[0]); @@ -873,6 +853,16 @@ main(int argc, char const *argv[])    signal(SIGCONT, sigcont_handler);  #endif +  // Occasionally, during test teardown, LLDB writes to a closed pipe. +  // Sometimes the communication is inherently unreliable, so LLDB tries to +  // avoid being killed due to SIGPIPE. However, LLVM's default SIGPIPE behavior +  // is to exit with IO_ERR. Opt LLDB out of that. +  // +  // We don't disable LLVM's signal handling entirely because we still want +  // pretty stack traces, and file cleanup (for when, say, the clang embedded +  // in LLDB leaves behind temporary objects). +  llvm::sys::SetPipeSignalFunction(nullptr); +    int exit_code = 0;    // Create a scope for driver so that the driver object will destroy itself    // before SBDebugger::Terminate() is called. | 
