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) |
| 52 | #include "lldb/Host/windows/windows.h" |
Adrian McCarthy | 18a9135d | 2015-10-28 18:21:45 +0000 | [diff] [blame] | 53 | #include "Plugins/Process/Windows/Common/ProcessWindowsLog.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(); |
| 100 | Timer::Initialize(); |
| 101 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 102 | |
| 103 | llvm::install_fatal_error_handler(fatal_error_handler, 0); |
| 104 | |
| 105 | process_gdb_remote::ProcessGDBRemoteLog::Initialize(); |
| 106 | |
| 107 | // Initialize plug-ins |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 108 | ClangASTContext::Initialize(); |
| 109 | GoASTContext::Initialize(); |
| 110 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 111 | ObjectContainerBSDArchive::Initialize(); |
| 112 | ObjectFileELF::Initialize(); |
| 113 | ObjectFilePECOFF::Initialize(); |
| 114 | DynamicLoaderPOSIXDYLD::Initialize(); |
Stephane Sezer | 38a1b7e | 2015-07-08 18:07:13 +0000 | [diff] [blame] | 115 | DynamicLoaderWindowsDYLD::Initialize(); |
Ed Maste | ae9f2b9 | 2015-07-02 17:35:22 +0000 | [diff] [blame] | 116 | platform_freebsd::PlatformFreeBSD::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 117 | platform_linux::PlatformLinux::Initialize(); |
Kamil Rytarowski | a019e81 | 2015-12-05 21:46:37 +0000 | [diff] [blame^] | 118 | platform_netbsd::PlatformNetBSD::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 119 | PlatformWindows::Initialize(); |
| 120 | PlatformKalimba::Initialize(); |
| 121 | platform_android::PlatformAndroid::Initialize(); |
| 122 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 123 | EmulateInstructionARM::Initialize(); |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 124 | EmulateInstructionMIPS::Initialize(); |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 125 | EmulateInstructionMIPS64::Initialize(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 126 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 127 | //---------------------------------------------------------------------- |
| 128 | // Apple/Darwin hosted plugins |
| 129 | //---------------------------------------------------------------------- |
| 130 | DynamicLoaderMacOSXDYLD::Initialize(); |
| 131 | ObjectContainerUniversalMachO::Initialize(); |
| 132 | |
| 133 | PlatformRemoteiOS::Initialize(); |
| 134 | PlatformMacOSX::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 135 | |
| 136 | #if defined(__APPLE__) |
Chaoren Lin | 2a7a94a | 2015-11-05 20:45:29 +0000 | [diff] [blame] | 137 | PlatformiOSSimulator::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 138 | DynamicLoaderDarwinKernel::Initialize(); |
| 139 | PlatformDarwinKernel::Initialize(); |
| 140 | ObjectFileMachO::Initialize(); |
| 141 | #endif |
| 142 | #if defined(__linux__) |
| 143 | static ConstString g_linux_log_name("linux"); |
| 144 | ProcessPOSIXLog::Initialize(g_linux_log_name); |
| 145 | #endif |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 146 | #if defined(_MSC_VER) |
| 147 | ProcessWindowsLog::Initialize(); |
| 148 | #endif |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 149 | #ifndef LLDB_DISABLE_PYTHON |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 150 | OperatingSystemPython::Initialize(); |
| 151 | #endif |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 152 | OperatingSystemGo::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | void |
| 156 | SystemInitializerCommon::Terminate() |
| 157 | { |
| 158 | Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 159 | ObjectContainerBSDArchive::Terminate(); |
| 160 | ObjectFileELF::Terminate(); |
| 161 | ObjectFilePECOFF::Terminate(); |
| 162 | DynamicLoaderPOSIXDYLD::Terminate(); |
Stephane Sezer | 38a1b7e | 2015-07-08 18:07:13 +0000 | [diff] [blame] | 163 | DynamicLoaderWindowsDYLD::Terminate(); |
Ed Maste | ae9f2b9 | 2015-07-02 17:35:22 +0000 | [diff] [blame] | 164 | platform_freebsd::PlatformFreeBSD::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 165 | platform_linux::PlatformLinux::Terminate(); |
Kamil Rytarowski | a019e81 | 2015-12-05 21:46:37 +0000 | [diff] [blame^] | 166 | platform_netbsd::PlatformNetBSD::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 167 | PlatformWindows::Terminate(); |
| 168 | PlatformKalimba::Terminate(); |
| 169 | platform_android::PlatformAndroid::Terminate(); |
| 170 | DynamicLoaderMacOSXDYLD::Terminate(); |
| 171 | ObjectContainerUniversalMachO::Terminate(); |
| 172 | PlatformMacOSX::Terminate(); |
| 173 | PlatformRemoteiOS::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 174 | |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 175 | ClangASTContext::Terminate(); |
| 176 | GoASTContext::Terminate(); |
| 177 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 178 | EmulateInstructionARM::Terminate(); |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 179 | EmulateInstructionMIPS::Terminate(); |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 180 | EmulateInstructionMIPS64::Terminate(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 181 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 182 | #if defined(__APPLE__) |
Chaoren Lin | 2a7a94a | 2015-11-05 20:45:29 +0000 | [diff] [blame] | 183 | PlatformiOSSimulator::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 184 | DynamicLoaderDarwinKernel::Terminate(); |
| 185 | ObjectFileMachO::Terminate(); |
| 186 | PlatformDarwinKernel::Terminate(); |
| 187 | #endif |
| 188 | |
Hafiz Abid Qadeer | 23a4df2 | 2015-09-04 16:34:19 +0000 | [diff] [blame] | 189 | #if defined(_MSC_VER) |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 190 | ProcessWindowsLog::Terminate(); |
| 191 | #endif |
| 192 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 193 | #ifndef LLDB_DISABLE_PYTHON |
| 194 | OperatingSystemPython::Terminate(); |
| 195 | #endif |
Ryan Brown | 65d4d5c | 2015-09-16 21:20:44 +0000 | [diff] [blame] | 196 | OperatingSystemGo::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 197 | |
| 198 | Log::Terminate(); |
| 199 | } |