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