1 //===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Initialization/SystemInitializerCommon.h" 11 12 #include "Plugins/Instruction/ARM/EmulateInstructionARM.h" 13 #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h" 14 #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" 15 #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" 16 #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" 17 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" 18 #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" 19 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" 20 #include "lldb/Core/Log.h" 21 #include "lldb/Core/Timer.h" 22 #include "lldb/Host/Host.h" 23 #include "lldb/Host/HostInfo.h" 24 25 #if defined(__APPLE__) 26 #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" 27 #endif 28 29 #if defined(__linux__) 30 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" 31 #endif 32 33 #if defined(_MSC_VER) 34 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" 35 #include "lldb/Host/windows/windows.h" 36 #endif 37 38 #include "llvm/Support/TargetSelect.h" 39 40 #include <string> 41 42 using namespace lldb_private; 43 44 static void fatal_error_handler(void *user_data, const std::string &reason, 45 bool gen_crash_diag) { 46 Host::SetCrashDescription(reason.c_str()); 47 ::abort(); 48 } 49 50 SystemInitializerCommon::SystemInitializerCommon() {} 51 52 SystemInitializerCommon::~SystemInitializerCommon() {} 53 54 void SystemInitializerCommon::Initialize() { 55 #if defined(_MSC_VER) 56 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG"); 57 if (disable_crash_dialog_var && 58 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) { 59 // This will prevent Windows from displaying a dialog box requiring user 60 // interaction when 61 // LLDB crashes. This is mostly useful when automating LLDB, for example 62 // via the test 63 // suite, so that a crash in LLDB does not prevent completion of the test 64 // suite. 65 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | 66 SEM_NOGPFAULTERRORBOX); 67 68 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 69 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 70 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); 71 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); 72 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); 73 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); 74 } 75 #endif 76 77 Log::Initialize(); 78 HostInfo::Initialize(); 79 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); 80 81 llvm::install_fatal_error_handler(fatal_error_handler, 0); 82 83 process_gdb_remote::ProcessGDBRemoteLog::Initialize(); 84 85 // Initialize plug-ins 86 ObjectContainerBSDArchive::Initialize(); 87 ObjectFileELF::Initialize(); 88 ObjectFilePECOFF::Initialize(); 89 90 EmulateInstructionARM::Initialize(); 91 EmulateInstructionMIPS::Initialize(); 92 EmulateInstructionMIPS64::Initialize(); 93 94 //---------------------------------------------------------------------- 95 // Apple/Darwin hosted plugins 96 //---------------------------------------------------------------------- 97 ObjectContainerUniversalMachO::Initialize(); 98 99 #if defined(__APPLE__) 100 ObjectFileMachO::Initialize(); 101 #endif 102 #if defined(__linux__) 103 static ConstString g_linux_log_name("linux"); 104 ProcessPOSIXLog::Initialize(g_linux_log_name); 105 #endif 106 #if defined(_MSC_VER) 107 ProcessWindowsLog::Initialize(); 108 #endif 109 } 110 111 void SystemInitializerCommon::Terminate() { 112 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); 113 ObjectContainerBSDArchive::Terminate(); 114 ObjectFileELF::Terminate(); 115 ObjectFilePECOFF::Terminate(); 116 117 EmulateInstructionARM::Terminate(); 118 EmulateInstructionMIPS::Terminate(); 119 EmulateInstructionMIPS64::Terminate(); 120 121 ObjectContainerUniversalMachO::Terminate(); 122 #if defined(__APPLE__) 123 ObjectFileMachO::Terminate(); 124 #endif 125 126 #if defined(_MSC_VER) 127 ProcessWindowsLog::Terminate(); 128 #endif 129 130 HostInfo::Terminate(); 131 Log::Terminate(); 132 } 133