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" |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/GoASTContext.h" |
| 17 | #include "lldb/Symbol/ClangASTContext.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 18 | #include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h" |
| 19 | #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h" |
Stephane Sezer | 38a1b7e | 2015-07-08 18:07:13 +0000 | [diff] [blame] | 20 | #include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h" |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 21 | #include "Plugins/Instruction/ARM/EmulateInstructionARM.h" |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 22 | #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h" |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 23 | #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 24 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
| 25 | #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" |
| 26 | #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" |
| 27 | #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" |
| 28 | #include "Plugins/OperatingSystem/Python/OperatingSystemPython.h" |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 29 | #include "Plugins/OperatingSystem/Go/OperatingSystemGo.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 30 | #include "Plugins/Platform/Android/PlatformAndroid.h" |
| 31 | #include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h" |
| 32 | #include "Plugins/Platform/Kalimba/PlatformKalimba.h" |
| 33 | #include "Plugins/Platform/Linux/PlatformLinux.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 34 | #include "Plugins/Platform/MacOSX/PlatformMacOSX.h" |
| 35 | #include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h" |
Bruce Mitchener | d31113f | 2015-11-07 15:31:54 +0000 | [diff] [blame] | 36 | #include "Plugins/Platform/NetBSD/PlatformNetBSD.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 37 | #include "Plugins/Platform/Windows/PlatformWindows.h" |
| 38 | #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" |
| 39 | |
| 40 | #if defined(__APPLE__) |
Chaoren Lin | 2a7a94a | 2015-11-05 20:45:29 +0000 | [diff] [blame] | 41 | #include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 42 | #include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h" |
| 43 | #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" |
| 44 | #include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h" |
| 45 | #endif |
| 46 | |
| 47 | #if defined(__linux__) |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 48 | #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" |
| 49 | #endif |
| 50 | |
| 51 | #if defined(_MSC_VER) |
Adrian McCarthy | 18a9135d | 2015-10-28 18:21:45 +0000 | [diff] [blame] | 52 | #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" |
Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame^] | 53 | #include "lldb/Host/windows/windows.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 54 | #endif |
| 55 | |
| 56 | #include "llvm/Support/TargetSelect.h" |
| 57 | |
| 58 | #include <string> |
| 59 | |
| 60 | using namespace lldb_private; |
| 61 | |
| 62 | static void |
| 63 | fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag) |
| 64 | { |
| 65 | Host::SetCrashDescription(reason.c_str()); |
| 66 | ::abort(); |
| 67 | } |
| 68 | |
| 69 | SystemInitializerCommon::SystemInitializerCommon() |
| 70 | { |
| 71 | } |
| 72 | |
| 73 | SystemInitializerCommon::~SystemInitializerCommon() |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | SystemInitializerCommon::Initialize() |
| 79 | { |
| 80 | #if defined(_MSC_VER) |
| 81 | const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG"); |
| 82 | if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) |
| 83 | { |
| 84 | // This will prevent Windows from displaying a dialog box requiring user interaction when |
| 85 | // LLDB crashes. This is mostly useful when automating LLDB, for example via the test |
| 86 | // suite, so that a crash in LLDB does not prevent completion of the test suite. |
| 87 | ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); |
| 88 | |
| 89 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 90 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 91 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 92 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 93 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 94 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | Log::Initialize(); |
| 99 | HostInfo::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 100 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 101 | |
| 102 | llvm::install_fatal_error_handler(fatal_error_handler, 0); |
| 103 | |
| 104 | process_gdb_remote::ProcessGDBRemoteLog::Initialize(); |
| 105 | |
| 106 | // Initialize plug-ins |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 107 | ClangASTContext::Initialize(); |
| 108 | GoASTContext::Initialize(); |
| 109 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 110 | ObjectContainerBSDArchive::Initialize(); |
| 111 | ObjectFileELF::Initialize(); |
| 112 | ObjectFilePECOFF::Initialize(); |
| 113 | DynamicLoaderPOSIXDYLD::Initialize(); |
Stephane Sezer | 38a1b7e | 2015-07-08 18:07:13 +0000 | [diff] [blame] | 114 | DynamicLoaderWindowsDYLD::Initialize(); |
Ed Maste | ae9f2b9 | 2015-07-02 17:35:22 +0000 | [diff] [blame] | 115 | platform_freebsd::PlatformFreeBSD::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 116 | platform_linux::PlatformLinux::Initialize(); |
Kamil Rytarowski | a019e81 | 2015-12-05 21:46:37 +0000 | [diff] [blame] | 117 | platform_netbsd::PlatformNetBSD::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 118 | PlatformWindows::Initialize(); |
| 119 | PlatformKalimba::Initialize(); |
| 120 | platform_android::PlatformAndroid::Initialize(); |
| 121 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 122 | EmulateInstructionARM::Initialize(); |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 123 | EmulateInstructionMIPS::Initialize(); |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 124 | EmulateInstructionMIPS64::Initialize(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 125 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 126 | //---------------------------------------------------------------------- |
| 127 | // Apple/Darwin hosted plugins |
| 128 | //---------------------------------------------------------------------- |
| 129 | DynamicLoaderMacOSXDYLD::Initialize(); |
| 130 | ObjectContainerUniversalMachO::Initialize(); |
| 131 | |
| 132 | PlatformRemoteiOS::Initialize(); |
| 133 | PlatformMacOSX::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 134 | |
| 135 | #if defined(__APPLE__) |
Chaoren Lin | 2a7a94a | 2015-11-05 20:45:29 +0000 | [diff] [blame] | 136 | PlatformiOSSimulator::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 137 | DynamicLoaderDarwinKernel::Initialize(); |
| 138 | PlatformDarwinKernel::Initialize(); |
| 139 | ObjectFileMachO::Initialize(); |
| 140 | #endif |
| 141 | #if defined(__linux__) |
| 142 | static ConstString g_linux_log_name("linux"); |
| 143 | ProcessPOSIXLog::Initialize(g_linux_log_name); |
| 144 | #endif |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 145 | #if defined(_MSC_VER) |
| 146 | ProcessWindowsLog::Initialize(); |
| 147 | #endif |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 148 | #ifndef LLDB_DISABLE_PYTHON |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 149 | OperatingSystemPython::Initialize(); |
| 150 | #endif |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 151 | OperatingSystemGo::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void |
| 155 | SystemInitializerCommon::Terminate() |
| 156 | { |
| 157 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 158 | ObjectContainerBSDArchive::Terminate(); |
| 159 | ObjectFileELF::Terminate(); |
| 160 | ObjectFilePECOFF::Terminate(); |
| 161 | DynamicLoaderPOSIXDYLD::Terminate(); |
Stephane Sezer | 38a1b7e | 2015-07-08 18:07:13 +0000 | [diff] [blame] | 162 | DynamicLoaderWindowsDYLD::Terminate(); |
Ed Maste | ae9f2b9 | 2015-07-02 17:35:22 +0000 | [diff] [blame] | 163 | platform_freebsd::PlatformFreeBSD::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 164 | platform_linux::PlatformLinux::Terminate(); |
Kamil Rytarowski | a019e81 | 2015-12-05 21:46:37 +0000 | [diff] [blame] | 165 | platform_netbsd::PlatformNetBSD::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 166 | PlatformWindows::Terminate(); |
| 167 | PlatformKalimba::Terminate(); |
| 168 | platform_android::PlatformAndroid::Terminate(); |
| 169 | DynamicLoaderMacOSXDYLD::Terminate(); |
| 170 | ObjectContainerUniversalMachO::Terminate(); |
| 171 | PlatformMacOSX::Terminate(); |
| 172 | PlatformRemoteiOS::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 173 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 174 | ClangASTContext::Terminate(); |
| 175 | GoASTContext::Terminate(); |
| 176 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 177 | EmulateInstructionARM::Terminate(); |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 178 | EmulateInstructionMIPS::Terminate(); |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 179 | EmulateInstructionMIPS64::Terminate(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 180 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 181 | #if defined(__APPLE__) |
Chaoren Lin | 2a7a94a | 2015-11-05 20:45:29 +0000 | [diff] [blame] | 182 | PlatformiOSSimulator::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 183 | DynamicLoaderDarwinKernel::Terminate(); |
| 184 | ObjectFileMachO::Terminate(); |
| 185 | PlatformDarwinKernel::Terminate(); |
| 186 | #endif |
| 187 | |
Hafiz Abid Qadeer | 23a4df2 | 2015-09-04 16:34:19 +0000 | [diff] [blame] | 188 | #if defined(_MSC_VER) |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 189 | ProcessWindowsLog::Terminate(); |
| 190 | #endif |
| 191 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 192 | #ifndef LLDB_DISABLE_PYTHON |
| 193 | OperatingSystemPython::Terminate(); |
| 194 | #endif |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 195 | OperatingSystemGo::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 196 | |
Zachary Turner | 41331af | 2016-02-19 19:20:44 +0000 | [diff] [blame] | 197 | HostInfo::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 198 | Log::Terminate(); |
| 199 | } |