Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 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 "lldb/Interpreter/ScriptInterpreterPython.h" |
| 17 | |
| 18 | #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" |
| 19 | #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h" |
| 20 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
| 21 | #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" |
| 22 | #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" |
| 23 | #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" |
| 24 | #include "Plugins/OperatingSystem/Python/OperatingSystemPython.h" |
| 25 | #include "Plugins/Platform/Android/PlatformAndroid.h" |
| 26 | #include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h" |
| 27 | #include "Plugins/Platform/Kalimba/PlatformKalimba.h" |
| 28 | #include "Plugins/Platform/Linux/PlatformLinux.h" |
| 29 | #include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h" |
| 30 | #include "Plugins/Platform/MacOSX/PlatformMacOSX.h" |
| 31 | #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" |
| 32 | #include "Plugins/Platform/Windows/PlatformWindows.h" |
| 33 | #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" |
| 34 | |
| 35 | #if defined(__APPLE__) |
| 36 | #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h" |
| 37 | #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" |
| 38 | #include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h" |
| 39 | #endif |
| 40 | |
| 41 | #if defined(__linux__) |
| 42 | #include "Plugins/Process/Linux/ProcessLinux.h" |
| 43 | #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" |
| 44 | #endif |
| 45 | |
| 46 | #if defined(_MSC_VER) |
| 47 | #include "lldb/Host/windows/windows.h" |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame^] | 48 | #include "Plugins/Process/Windows/ProcessWindowsLog.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
| 51 | #include "llvm/Support/TargetSelect.h" |
| 52 | |
| 53 | #include <string> |
| 54 | |
| 55 | using namespace lldb_private; |
| 56 | |
| 57 | static void |
| 58 | fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag) |
| 59 | { |
| 60 | Host::SetCrashDescription(reason.c_str()); |
| 61 | ::abort(); |
| 62 | } |
| 63 | |
| 64 | SystemInitializerCommon::SystemInitializerCommon() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | SystemInitializerCommon::~SystemInitializerCommon() |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | SystemInitializerCommon::Initialize() |
| 74 | { |
| 75 | #if defined(_MSC_VER) |
| 76 | const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG"); |
| 77 | if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) |
| 78 | { |
| 79 | // This will prevent Windows from displaying a dialog box requiring user interaction when |
| 80 | // LLDB crashes. This is mostly useful when automating LLDB, for example via the test |
| 81 | // suite, so that a crash in LLDB does not prevent completion of the test suite. |
| 82 | ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
| 83 | |
| 84 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 85 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 86 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 87 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 88 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 89 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 90 | } |
| 91 | #endif |
| 92 | |
| 93 | Log::Initialize(); |
| 94 | HostInfo::Initialize(); |
| 95 | Timer::Initialize(); |
| 96 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 97 | |
| 98 | llvm::install_fatal_error_handler(fatal_error_handler, 0); |
| 99 | |
| 100 | process_gdb_remote::ProcessGDBRemoteLog::Initialize(); |
| 101 | |
| 102 | // Initialize plug-ins |
| 103 | ObjectContainerBSDArchive::Initialize(); |
| 104 | ObjectFileELF::Initialize(); |
| 105 | ObjectFilePECOFF::Initialize(); |
| 106 | DynamicLoaderPOSIXDYLD::Initialize(); |
| 107 | PlatformFreeBSD::Initialize(); |
| 108 | platform_linux::PlatformLinux::Initialize(); |
| 109 | PlatformWindows::Initialize(); |
| 110 | PlatformKalimba::Initialize(); |
| 111 | platform_android::PlatformAndroid::Initialize(); |
| 112 | |
| 113 | //---------------------------------------------------------------------- |
| 114 | // Apple/Darwin hosted plugins |
| 115 | //---------------------------------------------------------------------- |
| 116 | DynamicLoaderMacOSXDYLD::Initialize(); |
| 117 | ObjectContainerUniversalMachO::Initialize(); |
| 118 | |
| 119 | PlatformRemoteiOS::Initialize(); |
| 120 | PlatformMacOSX::Initialize(); |
| 121 | PlatformiOSSimulator::Initialize(); |
| 122 | |
| 123 | #if defined(__APPLE__) |
| 124 | DynamicLoaderDarwinKernel::Initialize(); |
| 125 | PlatformDarwinKernel::Initialize(); |
| 126 | ObjectFileMachO::Initialize(); |
| 127 | #endif |
| 128 | #if defined(__linux__) |
| 129 | static ConstString g_linux_log_name("linux"); |
| 130 | ProcessPOSIXLog::Initialize(g_linux_log_name); |
| 131 | #endif |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame^] | 132 | #if defined(_MSC_VER) |
| 133 | ProcessWindowsLog::Initialize(); |
| 134 | #endif |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 135 | #ifndef LLDB_DISABLE_PYTHON |
| 136 | ScriptInterpreterPython::InitializePrivate(); |
| 137 | OperatingSystemPython::Initialize(); |
| 138 | #endif |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | SystemInitializerCommon::Terminate() |
| 143 | { |
| 144 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 145 | ObjectContainerBSDArchive::Terminate(); |
| 146 | ObjectFileELF::Terminate(); |
| 147 | ObjectFilePECOFF::Terminate(); |
| 148 | DynamicLoaderPOSIXDYLD::Terminate(); |
| 149 | PlatformFreeBSD::Terminate(); |
| 150 | platform_linux::PlatformLinux::Terminate(); |
| 151 | PlatformWindows::Terminate(); |
| 152 | PlatformKalimba::Terminate(); |
| 153 | platform_android::PlatformAndroid::Terminate(); |
| 154 | DynamicLoaderMacOSXDYLD::Terminate(); |
| 155 | ObjectContainerUniversalMachO::Terminate(); |
| 156 | PlatformMacOSX::Terminate(); |
| 157 | PlatformRemoteiOS::Terminate(); |
| 158 | PlatformiOSSimulator::Terminate(); |
| 159 | |
| 160 | #if defined(__APPLE__) |
| 161 | DynamicLoaderDarwinKernel::Terminate(); |
| 162 | ObjectFileMachO::Terminate(); |
| 163 | PlatformDarwinKernel::Terminate(); |
| 164 | #endif |
| 165 | |
| 166 | #ifndef LLDB_DISABLE_PYTHON |
| 167 | OperatingSystemPython::Terminate(); |
| 168 | #endif |
| 169 | |
| 170 | Log::Terminate(); |
| 171 | } |