blob: d1d55fcfde74a7bacdba91388721b2481e77ab14 [file] [log] [blame]
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001//===-- 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 Berghammerd8c338d2015-04-15 09:47:02 +000012#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +000013#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +000014#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000015#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
16#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000017#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
Jonas Devlieghere46376962018-10-31 21:49:27 +000018#include "lldb/Host/FileSystem.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/Host/Host.h"
20#include "lldb/Host/HostInfo.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000021#include "lldb/Utility/Log.h"
Jonas Devlieghere15eacd72018-12-03 17:28:29 +000022#include "lldb/Utility/Reproducer.h"
Pavel Labath38d06322017-06-29 14:32:17 +000023#include "lldb/Utility/Timer.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000024
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000025#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000026#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
27#endif
28
29#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000030#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000031#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000032#endif
33
34#include "llvm/Support/TargetSelect.h"
35
36#include <string>
37
38using namespace lldb_private;
Jonas Devlieghere15eacd72018-12-03 17:28:29 +000039using namespace lldb_private::repro;
Zachary Turnere6e2bb32015-03-31 21:03:22 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000044
Jonas Devlieghere15eacd72018-12-03 17:28:29 +000045llvm::Error
46SystemInitializerCommon::Initialize(const InitializerOptions &options) {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000047#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
49 if (disable_crash_dialog_var &&
50 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
51 // This will prevent Windows from displaying a dialog box requiring user
52 // interaction when
53 // LLDB crashes. This is mostly useful when automating LLDB, for example
54 // via the test
55 // suite, so that a crash in LLDB does not prevent completion of the test
56 // suite.
57 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
58 SEM_NOGPFAULTERRORBOX);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000059
Kate Stoneb9c1b512016-09-06 20:57:50 +000060 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
61 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
62 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
63 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
64 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
65 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
66 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000067#endif
68
Jonas Devlieghere15eacd72018-12-03 17:28:29 +000069 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 Devlieghere46376962018-10-31 21:49:27 +000078 FileSystem::Initialize();
Pavel Labathd8133092017-10-23 19:41:17 +000079 Log::Initialize();
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 HostInfo::Initialize();
Pavel Labathf9d16472017-05-15 13:02:37 +000081 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
82 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 // Initialize plug-ins
87 ObjectContainerBSDArchive::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000088
Kate Stoneb9c1b512016-09-06 20:57:50 +000089 EmulateInstructionARM::Initialize();
90 EmulateInstructionMIPS::Initialize();
91 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000092
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 //----------------------------------------------------------------------
94 // Apple/Darwin hosted plugins
95 //----------------------------------------------------------------------
96 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000097
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000098#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Pavel Labathc29f7ff2017-02-23 10:33:16 +000099 ProcessPOSIXLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000100#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +0000101#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +0000103#endif
Jonas Devlieghere15eacd72018-12-03 17:28:29 +0000104
105 return llvm::Error::success();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000106}
107
Kate Stoneb9c1b512016-09-06 20:57:50 +0000108void SystemInitializerCommon::Terminate() {
Pavel Labathf9d16472017-05-15 13:02:37 +0000109 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
110 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 ObjectContainerBSDArchive::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113 EmulateInstructionARM::Terminate();
114 EmulateInstructionMIPS::Terminate();
115 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000118
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000119#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000120 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000121#endif
122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 HostInfo::Terminate();
Pavel Labath775588c2017-03-15 09:06:58 +0000124 Log::DisableAllLogChannels();
Jonas Devlieghere46376962018-10-31 21:49:27 +0000125 FileSystem::Terminate();
Jonas Devlieghere15eacd72018-12-03 17:28:29 +0000126 Reproducer::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000127}