Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- SystemInitializerFull.cpp -----------------------------------------===// |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 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 | |
Alex Langford | d17cd90 | 2018-05-25 20:28:16 +0000 | [diff] [blame] | 9 | #include "SystemInitializerFull.h" |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBCommandInterpreter.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 11 | #include "lldb/Core/Debugger.h" |
Jonas Devlieghere | fbb4d1e | 2020-02-07 14:58:18 -0800 | [diff] [blame] | 12 | #include "lldb/Core/PluginManager.h" |
| 13 | #include "lldb/Host/Config.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 14 | #include "lldb/Host/Host.h" |
| 15 | #include "lldb/Initialization/SystemInitializerCommon.h" |
Zachary Turner | 2c1f46d | 2015-07-30 20:28:07 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/CommandInterpreter.h" |
Walter Erquinigo | 8a203bb | 2020-10-14 10:25:39 -0700 | [diff] [blame] | 17 | #include "lldb/Target/ProcessTrace.h" |
Jonas Devlieghere | b31d787 | 2020-11-09 08:47:08 -0800 | [diff] [blame] | 18 | #include "lldb/Utility/Reproducer.h" |
Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 19 | #include "lldb/Utility/Timer.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 20 | #include "llvm/Support/TargetSelect.h" |
| 21 | |
Saleem Abdulrasool | 5a36558 | 2019-05-03 23:19:27 +0000 | [diff] [blame] | 22 | #pragma clang diagnostic push |
| 23 | #pragma clang diagnostic ignored "-Wglobal-constructors" |
| 24 | #include "llvm/ExecutionEngine/MCJIT.h" |
| 25 | #pragma clang diagnostic pop |
| 26 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 27 | #include <string> |
| 28 | |
Jonas Devlieghere | 2d146aa | 2020-02-18 11:25:42 -0800 | [diff] [blame] | 29 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p) |
| 30 | #include "Plugins/Plugins.def" |
Jonas Devlieghere | 3e70a91 | 2020-02-07 17:58:30 -0800 | [diff] [blame] | 31 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 32 | using namespace lldb_private; |
| 33 | |
Jonas Devlieghere | 866b7a6 | 2020-02-17 22:57:06 -0800 | [diff] [blame] | 34 | SystemInitializerFull::SystemInitializerFull() = default; |
Jonas Devlieghere | 866b7a6 | 2020-02-17 22:57:06 -0800 | [diff] [blame] | 35 | SystemInitializerFull::~SystemInitializerFull() = default; |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 36 | |
Jonas Devlieghere | 936c624 | 2019-02-21 22:26:16 +0000 | [diff] [blame] | 37 | llvm::Error SystemInitializerFull::Initialize() { |
Jonas Devlieghere | b31d787 | 2020-11-09 08:47:08 -0800 | [diff] [blame] | 38 | llvm::Error error = SystemInitializerCommon::Initialize(); |
| 39 | if (error) { |
| 40 | // During active replay, the ::Initialize call is replayed like any other |
| 41 | // SB API call and the return value is ignored. Since we can't intercept |
| 42 | // this, we terminate here before the uninitialized debugger inevitably |
| 43 | // crashes. |
| 44 | if (repro::Reproducer::Instance().IsReplaying()) |
Jonas Devlieghere | 8da14fb | 2020-11-10 08:12:41 -0800 | [diff] [blame] | 45 | llvm::report_fatal_error(std::move(error)); |
Jonas Devlieghere | b31d787 | 2020-11-09 08:47:08 -0800 | [diff] [blame] | 46 | return error; |
| 47 | } |
Pavel Labath | fa3fa5b | 2018-05-24 12:44:18 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | // Initialize LLVM and Clang |
| 50 | llvm::InitializeAllTargets(); |
| 51 | llvm::InitializeAllAsmPrinters(); |
| 52 | llvm::InitializeAllTargetMCs(); |
| 53 | llvm::InitializeAllDisassemblers(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 54 | |
Jonas Devlieghere | 80c3ea4 | 2020-02-18 19:13:45 -0800 | [diff] [blame] | 55 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); |
| 56 | #include "Plugins/Plugins.def" |
Jonas Devlieghere | 50c9cd9 | 2020-02-17 19:02:25 -0800 | [diff] [blame] | 57 | |
Walter Erquinigo | 8a203bb | 2020-10-14 10:25:39 -0700 | [diff] [blame] | 58 | // Initialize plug-ins in core LLDB |
| 59 | ProcessTrace::Initialize(); |
| 60 | |
Jonas Devlieghere | 50c9cd9 | 2020-02-17 19:02:25 -0800 | [diff] [blame] | 61 | // Scan for any system or user LLDB plug-ins |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 62 | PluginManager::Initialize(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 63 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 64 | // The process settings need to know about installed plug-ins, so the |
Jonas Devlieghere | 80c3ea4 | 2020-02-18 19:13:45 -0800 | [diff] [blame] | 65 | // Settings must be initialized AFTER PluginManager::Initialize is called. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 66 | Debugger::SettingsInitialize(); |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 67 | |
| 68 | return llvm::Error::success(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | void SystemInitializerFull::Terminate() { |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 72 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 73 | Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 74 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | Debugger::SettingsTerminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 76 | |
Walter Erquinigo | 8a203bb | 2020-10-14 10:25:39 -0700 | [diff] [blame] | 77 | // Terminate plug-ins in core LLDB |
| 78 | ProcessTrace::Terminate(); |
| 79 | |
Jonas Devlieghere | 50c9cd9 | 2020-02-17 19:02:25 -0800 | [diff] [blame] | 80 | // Terminate and unload and loaded system or user LLDB plug-ins |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | PluginManager::Terminate(); |
Greg Clayton | 56939cb | 2015-09-17 22:23:34 +0000 | [diff] [blame] | 82 | |
Jonas Devlieghere | 80c3ea4 | 2020-02-18 19:13:45 -0800 | [diff] [blame] | 83 | #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p); |
| 84 | #include "Plugins/Plugins.def" |
Jonas Devlieghere | fbb4d1e | 2020-02-07 14:58:18 -0800 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | // Now shutdown the common parts, in reverse order. |
| 87 | SystemInitializerCommon::Terminate(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 88 | } |