180814287SRaphael Isemann //===-- SystemInitializerFull.cpp -----------------------------------------===// 2e6e2bb38SZachary Turner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e6e2bb38SZachary Turner // 7e6e2bb38SZachary Turner //===----------------------------------------------------------------------===// 8e6e2bb38SZachary Turner 9d17cd902SAlex Langford #include "SystemInitializerFull.h" 102c1f46dcSZachary Turner #include "lldb/API/SBCommandInterpreter.h" 11e6e2bb38SZachary Turner #include "lldb/Core/Debugger.h" 12fbb4d1e4SJonas Devlieghere #include "lldb/Core/PluginManager.h" 13fbb4d1e4SJonas Devlieghere #include "lldb/Host/Config.h" 14e6e2bb38SZachary Turner #include "lldb/Host/Host.h" 15e6e2bb38SZachary Turner #include "lldb/Initialization/SystemInitializerCommon.h" 162c1f46dcSZachary Turner #include "lldb/Interpreter/CommandInterpreter.h" 178a203bb2SWalter Erquinigo #include "lldb/Target/ProcessTrace.h" 18b31d7879SJonas Devlieghere #include "lldb/Utility/Reproducer.h" 1938d0632eSPavel Labath #include "lldb/Utility/Timer.h" 20e6e2bb38SZachary Turner #include "llvm/Support/TargetSelect.h" 21e6e2bb38SZachary Turner 225a36558cSSaleem Abdulrasool #pragma clang diagnostic push 235a36558cSSaleem Abdulrasool #pragma clang diagnostic ignored "-Wglobal-constructors" 245a36558cSSaleem Abdulrasool #include "llvm/ExecutionEngine/MCJIT.h" 255a36558cSSaleem Abdulrasool #pragma clang diagnostic pop 265a36558cSSaleem Abdulrasool 27e6e2bb38SZachary Turner #include <string> 28e6e2bb38SZachary Turner 292d146aa2SJonas Devlieghere #define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p) 302d146aa2SJonas Devlieghere #include "Plugins/Plugins.def" 313e70a919SJonas Devlieghere 32*004a264fSPavel Labath #if LLDB_ENABLE_PYTHON 33*004a264fSPavel Labath #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" 34*004a264fSPavel Labath 35*004a264fSPavel Labath constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper 36*004a264fSPavel Labath *g_shlib_dir_helper = 37*004a264fSPavel Labath lldb_private::ScriptInterpreterPython::SharedLibraryDirectoryHelper; 38*004a264fSPavel Labath 39*004a264fSPavel Labath #else 40*004a264fSPavel Labath constexpr lldb_private::HostInfo::SharedLibraryDirectoryHelper 41*004a264fSPavel Labath *g_shlib_dir_helper = 0; 42*004a264fSPavel Labath #endif 43*004a264fSPavel Labath 44e6e2bb38SZachary Turner using namespace lldb_private; 45e6e2bb38SZachary Turner 46*004a264fSPavel Labath SystemInitializerFull::SystemInitializerFull() 47*004a264fSPavel Labath : SystemInitializerCommon(g_shlib_dir_helper) {} 48866b7a65SJonas Devlieghere SystemInitializerFull::~SystemInitializerFull() = default; 49e6e2bb38SZachary Turner 50936c6242SJonas Devlieghere llvm::Error SystemInitializerFull::Initialize() { 51b31d7879SJonas Devlieghere llvm::Error error = SystemInitializerCommon::Initialize(); 52b31d7879SJonas Devlieghere if (error) { 53b31d7879SJonas Devlieghere // During active replay, the ::Initialize call is replayed like any other 54b31d7879SJonas Devlieghere // SB API call and the return value is ignored. Since we can't intercept 55b31d7879SJonas Devlieghere // this, we terminate here before the uninitialized debugger inevitably 56b31d7879SJonas Devlieghere // crashes. 57b31d7879SJonas Devlieghere if (repro::Reproducer::Instance().IsReplaying()) 588da14fb7SJonas Devlieghere llvm::report_fatal_error(std::move(error)); 59b31d7879SJonas Devlieghere return error; 60b31d7879SJonas Devlieghere } 61fa3fa5b9SPavel Labath 62e6e2bb38SZachary Turner // Initialize LLVM and Clang 63e6e2bb38SZachary Turner llvm::InitializeAllTargets(); 64e6e2bb38SZachary Turner llvm::InitializeAllAsmPrinters(); 65e6e2bb38SZachary Turner llvm::InitializeAllTargetMCs(); 66e6e2bb38SZachary Turner llvm::InitializeAllDisassemblers(); 67e6e2bb38SZachary Turner 6880c3ea4eSJonas Devlieghere #define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p); 6980c3ea4eSJonas Devlieghere #include "Plugins/Plugins.def" 7050c9cd95SJonas Devlieghere 718a203bb2SWalter Erquinigo // Initialize plug-ins in core LLDB 728a203bb2SWalter Erquinigo ProcessTrace::Initialize(); 738a203bb2SWalter Erquinigo 7450c9cd95SJonas Devlieghere // Scan for any system or user LLDB plug-ins 75e6e2bb38SZachary Turner PluginManager::Initialize(); 76e6e2bb38SZachary Turner 7705097246SAdrian Prantl // The process settings need to know about installed plug-ins, so the 7880c3ea4eSJonas Devlieghere // Settings must be initialized AFTER PluginManager::Initialize is called. 79e6e2bb38SZachary Turner Debugger::SettingsInitialize(); 8015eacd74SJonas Devlieghere 8115eacd74SJonas Devlieghere return llvm::Error::success(); 82e6e2bb38SZachary Turner } 83e6e2bb38SZachary Turner 84b9c1b51eSKate Stone void SystemInitializerFull::Terminate() { 85e6e2bb38SZachary Turner Debugger::SettingsTerminate(); 86e6e2bb38SZachary Turner 878a203bb2SWalter Erquinigo // Terminate plug-ins in core LLDB 888a203bb2SWalter Erquinigo ProcessTrace::Terminate(); 898a203bb2SWalter Erquinigo 9050c9cd95SJonas Devlieghere // Terminate and unload and loaded system or user LLDB plug-ins 91e6e2bb38SZachary Turner PluginManager::Terminate(); 9256939cb3SGreg Clayton 9380c3ea4eSJonas Devlieghere #define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p); 9480c3ea4eSJonas Devlieghere #include "Plugins/Plugins.def" 95fbb4d1e4SJonas Devlieghere 96e6e2bb38SZachary Turner // Now shutdown the common parts, in reverse order. 97e6e2bb38SZachary Turner SystemInitializerCommon::Terminate(); 98e6e2bb38SZachary Turner } 99