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