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__) || \
23 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
27 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
28 #include "lldb/Host/windows/windows.h"
32 #include "llvm/Support/TargetSelect.h"
36 using namespace lldb_private
;
38 SystemInitializerCommon::SystemInitializerCommon(
39 HostInfo::SharedLibraryDirectoryHelper
*helper
)
40 : m_shlib_dir_helper(helper
) {}
42 SystemInitializerCommon::~SystemInitializerCommon() = default;
44 llvm::Error
SystemInitializerCommon::Initialize() {
46 const char *disable_crash_dialog_var
= getenv("LLDB_DISABLE_CRASH_DIALOG");
47 if (disable_crash_dialog_var
&&
48 llvm::StringRef(disable_crash_dialog_var
).equals_insensitive("true")) {
49 // This will prevent Windows from displaying a dialog box requiring user
51 // LLDB crashes. This is mostly useful when automating LLDB, for example
53 // suite, so that a crash in LLDB does not prevent completion of the test
55 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS
|
56 SEM_NOGPFAULTERRORBOX
);
58 _CrtSetReportMode(_CRT_ASSERT
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
59 _CrtSetReportMode(_CRT_WARN
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
60 _CrtSetReportMode(_CRT_ERROR
, _CRTDBG_MODE_FILE
| _CRTDBG_MODE_DEBUG
);
61 _CrtSetReportFile(_CRT_ASSERT
, _CRTDBG_FILE_STDERR
);
62 _CrtSetReportFile(_CRT_WARN
, _CRTDBG_FILE_STDERR
);
63 _CrtSetReportFile(_CRT_ERROR
, _CRTDBG_FILE_STDERR
);
67 InitializeLldbChannel();
69 Diagnostics::Initialize();
70 FileSystem::Initialize();
71 HostInfo::Initialize(m_shlib_dir_helper
);
73 llvm::Error error
= Socket::Initialize();
79 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
81 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
83 ProcessPOSIXLog::Initialize();
86 ProcessWindowsLog::Initialize();
89 return llvm::Error::success();
92 void SystemInitializerCommon::Terminate() {
96 ProcessWindowsLog::Terminate();
100 HostInfo::Terminate();
101 Log::DisableAllLogChannels();
102 FileSystem::Terminate();
103 Diagnostics::Terminate();