1 //===-- SystemInitializerCommon.cpp ---------------------------------------===//
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
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"
26 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
27 #include "lldb/Host/windows/windows.h"
31 #include "llvm/Support/TargetSelect.h"
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() {
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
50 // LLDB crashes. This is mostly useful when automating LLDB, for example
52 // suite, so that a crash in LLDB does not prevent completion of the test
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
);
66 InitializeLldbChannel();
68 Diagnostics::Initialize();
69 FileSystem::Initialize();
70 HostInfo::Initialize(m_shlib_dir_helper
);
72 llvm::Error error
= Socket::Initialize();
78 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
80 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
81 ProcessPOSIXLog::Initialize();
84 ProcessWindowsLog::Initialize();
87 return llvm::Error::success();
90 void SystemInitializerCommon::Terminate() {
94 ProcessWindowsLog::Terminate();
98 HostInfo::Terminate();
99 Log::DisableAllLogChannels();
100 FileSystem::Terminate();
101 Diagnostics::Terminate();