blob: a6421d8f10d0c506d89e268aa4f0bb36b2e19023 [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- SystemInitializerFull.cpp -----------------------------------------===//
Zachary Turnere6e2bb32015-03-31 21:03:22 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Turnere6e2bb32015-03-31 21:03:22 +00006//
7//===----------------------------------------------------------------------===//
8
Alex Langfordd17cd902018-05-25 20:28:16 +00009#include "SystemInitializerFull.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000010#include "lldb/API/SBCommandInterpreter.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000011#include "lldb/Core/Debugger.h"
Jonas Devliegherefbb4d1e2020-02-07 14:58:18 -080012#include "lldb/Core/PluginManager.h"
13#include "lldb/Host/Config.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000014#include "lldb/Host/Host.h"
15#include "lldb/Initialization/SystemInitializerCommon.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000016#include "lldb/Interpreter/CommandInterpreter.h"
Walter Erquinigo8a203bb2020-10-14 10:25:39 -070017#include "lldb/Target/ProcessTrace.h"
Jonas Devlieghereb31d7872020-11-09 08:47:08 -080018#include "lldb/Utility/Reproducer.h"
Pavel Labath38d06322017-06-29 14:32:17 +000019#include "lldb/Utility/Timer.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000020#include "llvm/Support/TargetSelect.h"
21
Saleem Abdulrasool5a365582019-05-03 23:19:27 +000022#pragma clang diagnostic push
23#pragma clang diagnostic ignored "-Wglobal-constructors"
24#include "llvm/ExecutionEngine/MCJIT.h"
25#pragma clang diagnostic pop
26
Zachary Turnere6e2bb32015-03-31 21:03:22 +000027#include <string>
28
Jonas Devlieghere2d146aa2020-02-18 11:25:42 -080029#define LLDB_PLUGIN(p) LLDB_PLUGIN_DECLARE(p)
30#include "Plugins/Plugins.def"
Jonas Devlieghere3e70a912020-02-07 17:58:30 -080031
Zachary Turnere6e2bb32015-03-31 21:03:22 +000032using namespace lldb_private;
33
Jonas Devlieghere866b7a62020-02-17 22:57:06 -080034SystemInitializerFull::SystemInitializerFull() = default;
Jonas Devlieghere866b7a62020-02-17 22:57:06 -080035SystemInitializerFull::~SystemInitializerFull() = default;
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036
Jonas Devlieghere936c6242019-02-21 22:26:16 +000037llvm::Error SystemInitializerFull::Initialize() {
Jonas Devlieghereb31d7872020-11-09 08:47:08 -080038 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 Devlieghere8da14fb2020-11-10 08:12:41 -080045 llvm::report_fatal_error(std::move(error));
Jonas Devlieghereb31d7872020-11-09 08:47:08 -080046 return error;
47 }
Pavel Labathfa3fa5b2018-05-24 12:44:18 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 // Initialize LLVM and Clang
50 llvm::InitializeAllTargets();
51 llvm::InitializeAllAsmPrinters();
52 llvm::InitializeAllTargetMCs();
53 llvm::InitializeAllDisassemblers();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000054
Jonas Devlieghere80c3ea42020-02-18 19:13:45 -080055#define LLDB_PLUGIN(p) LLDB_PLUGIN_INITIALIZE(p);
56#include "Plugins/Plugins.def"
Jonas Devlieghere50c9cd92020-02-17 19:02:25 -080057
Walter Erquinigo8a203bb2020-10-14 10:25:39 -070058 // Initialize plug-ins in core LLDB
59 ProcessTrace::Initialize();
60
Jonas Devlieghere50c9cd92020-02-17 19:02:25 -080061 // Scan for any system or user LLDB plug-ins
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 PluginManager::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000063
Adrian Prantl05097242018-04-30 16:49:04 +000064 // The process settings need to know about installed plug-ins, so the
Jonas Devlieghere80c3ea42020-02-18 19:13:45 -080065 // Settings must be initialized AFTER PluginManager::Initialize is called.
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 Debugger::SettingsInitialize();
Jonas Devlieghere15eacd72018-12-03 17:28:29 +000067
68 return llvm::Error::success();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000069}
70
Kate Stoneb9c1b512016-09-06 20:57:50 +000071void SystemInitializerFull::Terminate() {
Pavel Labathf9d16472017-05-15 13:02:37 +000072 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
73 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 Debugger::SettingsTerminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000076
Walter Erquinigo8a203bb2020-10-14 10:25:39 -070077 // Terminate plug-ins in core LLDB
78 ProcessTrace::Terminate();
79
Jonas Devlieghere50c9cd92020-02-17 19:02:25 -080080 // Terminate and unload and loaded system or user LLDB plug-ins
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 PluginManager::Terminate();
Greg Clayton56939cb2015-09-17 22:23:34 +000082
Jonas Devlieghere80c3ea42020-02-18 19:13:45 -080083#define LLDB_PLUGIN(p) LLDB_PLUGIN_TERMINATE(p);
84#include "Plugins/Plugins.def"
Jonas Devliegherefbb4d1e2020-02-07 14:58:18 -080085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 // Now shutdown the common parts, in reverse order.
87 SystemInitializerCommon::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000088}