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 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 12 | #include "Plugins/Instruction/ARM/EmulateInstructionARM.h" |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 13 | #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h" |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 14 | #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 15 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
| 16 | #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" |
| 17 | #include "Plugins/ObjectFile/ELF/ObjectFileELF.h" |
| 18 | #include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 19 | #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Timer.h" |
| 21 | #include "lldb/Host/Host.h" |
| 22 | #include "lldb/Host/HostInfo.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/Log.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 24 | |
| 25 | #if defined(__APPLE__) |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 26 | #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 27 | #endif |
| 28 | |
Pavel Labath | c29f7ff | 2017-02-23 10:33:16 +0000 | [diff] [blame] | 29 | #if defined(__linux__) || defined(__FreeBSD__) |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 30 | #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" |
| 31 | #endif |
| 32 | |
| 33 | #if defined(_MSC_VER) |
Adrian McCarthy | 18a9135d | 2015-10-28 18:21:45 +0000 | [diff] [blame] | 34 | #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" |
Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 35 | #include "lldb/Host/windows/windows.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 36 | #endif |
| 37 | |
Sean Callanan | 237c3ed | 2016-12-14 21:31:31 +0000 | [diff] [blame] | 38 | #include "llvm/Support/PrettyStackTrace.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 39 | #include "llvm/Support/TargetSelect.h" |
| 40 | |
| 41 | #include <string> |
| 42 | |
| 43 | using namespace lldb_private; |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | SystemInitializerCommon::SystemInitializerCommon() {} |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 46 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | SystemInitializerCommon::~SystemInitializerCommon() {} |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | void SystemInitializerCommon::Initialize() { |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 50 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG"); |
| 52 | if (disable_crash_dialog_var && |
| 53 | llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) { |
| 54 | // This will prevent Windows from displaying a dialog box requiring user |
| 55 | // interaction when |
| 56 | // LLDB crashes. This is mostly useful when automating LLDB, for example |
| 57 | // via the test |
| 58 | // suite, so that a crash in LLDB does not prevent completion of the test |
| 59 | // suite. |
| 60 | ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | |
| 61 | SEM_NOGPFAULTERRORBOX); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 62 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 63 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 64 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 65 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 66 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 67 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 68 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 69 | } |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 70 | #endif |
| 71 | |
Sean Callanan | 237c3ed | 2016-12-14 21:31:31 +0000 | [diff] [blame] | 72 | llvm::EnablePrettyStackTrace(); |
Pavel Labath | a2fc1e0 | 2017-02-22 11:51:12 +0000 | [diff] [blame] | 73 | InitializeLog(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 74 | HostInfo::Initialize(); |
| 75 | Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 76 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | process_gdb_remote::ProcessGDBRemoteLog::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 78 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 79 | // Initialize plug-ins |
| 80 | ObjectContainerBSDArchive::Initialize(); |
| 81 | ObjectFileELF::Initialize(); |
| 82 | ObjectFilePECOFF::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 83 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | EmulateInstructionARM::Initialize(); |
| 85 | EmulateInstructionMIPS::Initialize(); |
| 86 | EmulateInstructionMIPS64::Initialize(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 87 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | //---------------------------------------------------------------------- |
| 89 | // Apple/Darwin hosted plugins |
| 90 | //---------------------------------------------------------------------- |
| 91 | ObjectContainerUniversalMachO::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 92 | |
| 93 | #if defined(__APPLE__) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 94 | ObjectFileMachO::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 95 | #endif |
Pavel Labath | c29f7ff | 2017-02-23 10:33:16 +0000 | [diff] [blame] | 96 | #if defined(__linux__) || defined(__FreeBSD__) |
| 97 | ProcessPOSIXLog::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 98 | #endif |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 99 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | ProcessWindowsLog::Initialize(); |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 101 | #endif |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 104 | void SystemInitializerCommon::Terminate() { |
| 105 | Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION); |
| 106 | ObjectContainerBSDArchive::Terminate(); |
| 107 | ObjectFileELF::Terminate(); |
| 108 | ObjectFilePECOFF::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 110 | EmulateInstructionARM::Terminate(); |
| 111 | EmulateInstructionMIPS::Terminate(); |
| 112 | EmulateInstructionMIPS64::Terminate(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | ObjectContainerUniversalMachO::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 115 | #if defined(__APPLE__) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | ObjectFileMachO::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 117 | #endif |
| 118 | |
Hafiz Abid Qadeer | 23a4df2 | 2015-09-04 16:34:19 +0000 | [diff] [blame] | 119 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 120 | ProcessWindowsLog::Terminate(); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 121 | #endif |
| 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | HostInfo::Terminate(); |
Pavel Labath | 775588c | 2017-03-15 09:06:58 +0000 | [diff] [blame^] | 124 | Log::DisableAllLogChannels(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 125 | } |