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