Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 1 | //===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Initialization/SystemInitializerCommon.h" |
| 10 | |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 11 | #include "Plugins/Instruction/ARM/EmulateInstructionARM.h" |
Bhushan D. Attarde | 794a4d5 | 2015-05-15 06:53:30 +0000 | [diff] [blame] | 12 | #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h" |
Mohit K. Bhakkad | cdc22a8 | 2015-05-07 05:56:27 +0000 | [diff] [blame] | 13 | #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 14 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
| 15 | #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 16 | #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h" |
Jonas Devlieghere | 4637696 | 2018-10-31 21:49:27 +0000 | [diff] [blame] | 17 | #include "lldb/Host/FileSystem.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/Host/Host.h" |
| 19 | #include "lldb/Host/HostInfo.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 20 | #include "lldb/Utility/Log.h" |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/Reproducer.h" |
Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 22 | #include "lldb/Utility/Timer.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 23 | |
Kamil Rytarowski | a87101d | 2017-03-21 17:26:55 +0000 | [diff] [blame] | 24 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 25 | #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" |
| 26 | #endif |
| 27 | |
| 28 | #if defined(_MSC_VER) |
Adrian McCarthy | 18a9135d | 2015-10-28 18:21:45 +0000 | [diff] [blame] | 29 | #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h" |
Zachary Turner | 74e08ca | 2016-03-02 22:05:52 +0000 | [diff] [blame] | 30 | #include "lldb/Host/windows/windows.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #include "llvm/Support/TargetSelect.h" |
| 34 | |
| 35 | #include <string> |
| 36 | |
| 37 | using namespace lldb_private; |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 38 | using namespace lldb_private::repro; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 39 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | SystemInitializerCommon::SystemInitializerCommon() {} |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | SystemInitializerCommon::~SystemInitializerCommon() {} |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 43 | |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 44 | llvm::Error |
| 45 | SystemInitializerCommon::Initialize(const InitializerOptions &options) { |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 46 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 47 | const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG"); |
| 48 | if (disable_crash_dialog_var && |
| 49 | llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) { |
| 50 | // This will prevent Windows from displaying a dialog box requiring user |
| 51 | // interaction when |
| 52 | // LLDB crashes. This is mostly useful when automating LLDB, for example |
| 53 | // via the test |
| 54 | // suite, so that a crash in LLDB does not prevent completion of the test |
| 55 | // suite. |
| 56 | ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | |
| 57 | SEM_NOGPFAULTERRORBOX); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 58 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 59 | _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 60 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 61 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 62 | _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 63 | _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
| 64 | _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
| 65 | } |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
Jonas Devlieghere | 4657517 | 2019-01-29 20:36:38 +0000 | [diff] [blame] | 68 | // Initialize the reproducer. |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 69 | ReproducerMode mode = ReproducerMode::Off; |
| 70 | if (options.reproducer_capture) |
| 71 | mode = ReproducerMode::Capture; |
| 72 | if (options.reproducer_replay) |
| 73 | mode = ReproducerMode::Replay; |
| 74 | |
| 75 | if (auto e = Reproducer::Initialize(mode, FileSpec(options.reproducer_path))) |
| 76 | return e; |
| 77 | |
Jonas Devlieghere | 4657517 | 2019-01-29 20:36:38 +0000 | [diff] [blame] | 78 | // Initialize the file system. |
| 79 | auto &r = repro::Reproducer::Instance(); |
| 80 | if (repro::Loader *loader = r.GetLoader()) { |
| 81 | FileSpec vfs_mapping = loader->GetFile<FileInfo>(); |
| 82 | if (vfs_mapping) { |
| 83 | if (llvm::Error e = FileSystem::Initialize(vfs_mapping)) |
| 84 | return e; |
| 85 | } else { |
| 86 | FileSystem::Initialize(); |
| 87 | } |
| 88 | } else if (repro::Generator *g = r.GetGenerator()) { |
| 89 | repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>(); |
| 90 | FileSystem::Initialize(fp.GetFileCollector()); |
| 91 | } else { |
| 92 | FileSystem::Initialize(); |
| 93 | } |
| 94 | |
Pavel Labath | d813309 | 2017-10-23 19:41:17 +0000 | [diff] [blame] | 95 | Log::Initialize(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 96 | HostInfo::Initialize(); |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 97 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 98 | Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 99 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 100 | process_gdb_remote::ProcessGDBRemoteLog::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 101 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | // Initialize plug-ins |
| 103 | ObjectContainerBSDArchive::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | EmulateInstructionARM::Initialize(); |
| 106 | EmulateInstructionMIPS::Initialize(); |
| 107 | EmulateInstructionMIPS64::Initialize(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | //---------------------------------------------------------------------- |
| 110 | // Apple/Darwin hosted plugins |
| 111 | //---------------------------------------------------------------------- |
| 112 | ObjectContainerUniversalMachO::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 113 | |
Kamil Rytarowski | a87101d | 2017-03-21 17:26:55 +0000 | [diff] [blame] | 114 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) |
Pavel Labath | c29f7ff | 2017-02-23 10:33:16 +0000 | [diff] [blame] | 115 | ProcessPOSIXLog::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 116 | #endif |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 117 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | ProcessWindowsLog::Initialize(); |
Adrian McCarthy | 42b3380 | 2015-04-10 16:18:08 +0000 | [diff] [blame] | 119 | #endif |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 120 | |
| 121 | return llvm::Error::success(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | void SystemInitializerCommon::Terminate() { |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 125 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 126 | Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | ObjectContainerBSDArchive::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | EmulateInstructionARM::Terminate(); |
| 130 | EmulateInstructionMIPS::Terminate(); |
| 131 | EmulateInstructionMIPS64::Terminate(); |
Tamas Berghammer | d8c338d | 2015-04-15 09:47:02 +0000 | [diff] [blame] | 132 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | ObjectContainerUniversalMachO::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 134 | |
Hafiz Abid Qadeer | 23a4df2 | 2015-09-04 16:34:19 +0000 | [diff] [blame] | 135 | #if defined(_MSC_VER) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 136 | ProcessWindowsLog::Terminate(); |
Zachary Turner | 610e529 | 2015-05-07 21:39:33 +0000 | [diff] [blame] | 137 | #endif |
| 138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 139 | HostInfo::Terminate(); |
Pavel Labath | 775588c | 2017-03-15 09:06:58 +0000 | [diff] [blame] | 140 | Log::DisableAllLogChannels(); |
Jonas Devlieghere | 4637696 | 2018-10-31 21:49:27 +0000 | [diff] [blame] | 141 | FileSystem::Terminate(); |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 142 | Reproducer::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 143 | } |