1 //===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Initialization/SystemInitializerCommon.h"
12 #include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
13 #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
14 #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
15 #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
16 #ifdef LLDB_ENABLE_ALL
17 #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
18 #endif // LLDB_ENABLE_ALL
19 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
20 #include "lldb/Host/FileSystem.h"
21 #include "lldb/Host/Host.h"
22 #include "lldb/Host/HostInfo.h"
23 #include "lldb/Utility/Log.h"
24 #include "lldb/Utility/Reproducer.h"
25 #include "lldb/Utility/Timer.h"
27 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
28 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
32 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
33 #include "lldb/Host/windows/windows.h"
36 #include "llvm/Support/TargetSelect.h"
40 using namespace lldb_private;
41 using namespace lldb_private::repro;
43 SystemInitializerCommon::SystemInitializerCommon() {}
45 SystemInitializerCommon::~SystemInitializerCommon() {}
48 SystemInitializerCommon::Initialize(const InitializerOptions &options) {
50 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
51 if (disable_crash_dialog_var &&
52 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
53 // This will prevent Windows from displaying a dialog box requiring user
55 // LLDB crashes. This is mostly useful when automating LLDB, for example
57 // suite, so that a crash in LLDB does not prevent completion of the test
59 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
60 SEM_NOGPFAULTERRORBOX);
62 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
63 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
64 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
65 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
66 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
67 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
71 ReproducerMode mode = ReproducerMode::Off;
72 if (options.reproducer_capture)
73 mode = ReproducerMode::Capture;
74 if (options.reproducer_replay)
75 mode = ReproducerMode::Replay;
77 if (auto e = Reproducer::Initialize(mode, FileSpec(options.reproducer_path)))
80 FileSystem::Initialize();
82 HostInfo::Initialize();
83 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
84 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
86 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
88 // Initialize plug-ins
89 ObjectContainerBSDArchive::Initialize();
91 EmulateInstructionARM::Initialize();
92 EmulateInstructionMIPS::Initialize();
93 EmulateInstructionMIPS64::Initialize();
95 //----------------------------------------------------------------------
96 // Apple/Darwin hosted plugins
97 //----------------------------------------------------------------------
98 #ifdef LLDB_ENABLE_ALL
99 ObjectContainerUniversalMachO::Initialize();
100 #endif // LLDB_ENABLE_ALL
102 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
103 ProcessPOSIXLog::Initialize();
105 #if defined(_MSC_VER)
106 ProcessWindowsLog::Initialize();
109 return llvm::Error::success();
112 void SystemInitializerCommon::Terminate() {
113 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
114 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
115 ObjectContainerBSDArchive::Terminate();
117 EmulateInstructionARM::Terminate();
118 EmulateInstructionMIPS::Terminate();
119 EmulateInstructionMIPS64::Terminate();
121 #ifdef LLDB_ENABLE_ALL
122 ObjectContainerUniversalMachO::Terminate();
123 #endif // LLDB_ENABLE_ALL
125 #if defined(_MSC_VER)
126 ProcessWindowsLog::Terminate();
129 HostInfo::Terminate();
130 Log::DisableAllLogChannels();
131 FileSystem::Terminate();
132 Reproducer::Terminate();