Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Initialization / SystemInitializerCommon.cpp
blob40e54cd7f0e09c3c1dbc851f4e133f6d4407b32d
1 //===-- SystemInitializerCommon.cpp ---------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Initialization/SystemInitializerCommon.h"
11 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/Host.h"
14 #include "lldb/Host/Socket.h"
15 #include "lldb/Target/Statistics.h"
16 #include "lldb/Utility/Diagnostics.h"
17 #include "lldb/Utility/LLDBLog.h"
18 #include "lldb/Utility/Timer.h"
19 #include "lldb/Version/Version.h"
21 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
22 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
23 #endif
25 #if defined(_WIN32)
26 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
27 #include "lldb/Host/windows/windows.h"
28 #include <crtdbg.h>
29 #endif
31 #include "llvm/Support/TargetSelect.h"
33 #include <string>
35 using namespace lldb_private;
37 SystemInitializerCommon::SystemInitializerCommon(
38 HostInfo::SharedLibraryDirectoryHelper *helper)
39 : m_shlib_dir_helper(helper) {}
41 SystemInitializerCommon::~SystemInitializerCommon() = default;
43 llvm::Error SystemInitializerCommon::Initialize() {
44 #if defined(_WIN32)
45 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
46 if (disable_crash_dialog_var &&
47 llvm::StringRef(disable_crash_dialog_var).equals_insensitive("true")) {
48 // This will prevent Windows from displaying a dialog box requiring user
49 // interaction when
50 // LLDB crashes. This is mostly useful when automating LLDB, for example
51 // via the test
52 // suite, so that a crash in LLDB does not prevent completion of the test
53 // suite.
54 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
55 SEM_NOGPFAULTERRORBOX);
57 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
58 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
59 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
60 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
61 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
62 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
64 #endif
66 InitializeLldbChannel();
68 Diagnostics::Initialize();
69 FileSystem::Initialize();
70 HostInfo::Initialize(m_shlib_dir_helper);
72 llvm::Error error = Socket::Initialize();
73 if (error)
74 return error;
76 LLDB_SCOPED_TIMER();
78 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
80 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
81 ProcessPOSIXLog::Initialize();
82 #endif
83 #if defined(_WIN32)
84 ProcessWindowsLog::Initialize();
85 #endif
87 return llvm::Error::success();
90 void SystemInitializerCommon::Terminate() {
91 LLDB_SCOPED_TIMER();
93 #if defined(_WIN32)
94 ProcessWindowsLog::Terminate();
95 #endif
97 Socket::Terminate();
98 HostInfo::Terminate();
99 Log::DisableAllLogChannels();
100 FileSystem::Terminate();
101 Diagnostics::Terminate();