[mlir][py] Enable loading only specified dialects during creation. (#121421)
[llvm-project.git] / lldb / source / Initialization / SystemInitializerCommon.cpp
blob1a172a95aa1471eeb46ede6174626fdb418325c2
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 defined(__OpenBSD__)
23 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
24 #endif
26 #if defined(_WIN32)
27 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
28 #include "lldb/Host/windows/windows.h"
29 #include <crtdbg.h>
30 #endif
32 #include "llvm/Support/TargetSelect.h"
34 #include <string>
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() {
45 #if defined(_WIN32)
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
50 // interaction when
51 // LLDB crashes. This is mostly useful when automating LLDB, for example
52 // via the test
53 // suite, so that a crash in LLDB does not prevent completion of the test
54 // suite.
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);
65 #endif
67 InitializeLldbChannel();
69 Diagnostics::Initialize();
70 FileSystem::Initialize();
71 HostInfo::Initialize(m_shlib_dir_helper);
73 llvm::Error error = Socket::Initialize();
74 if (error)
75 return error;
77 LLDB_SCOPED_TIMER();
79 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
81 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
82 defined(__OpenBSD__)
83 ProcessPOSIXLog::Initialize();
84 #endif
85 #if defined(_WIN32)
86 ProcessWindowsLog::Initialize();
87 #endif
89 return llvm::Error::success();
92 void SystemInitializerCommon::Terminate() {
93 LLDB_SCOPED_TIMER();
95 #if defined(_WIN32)
96 ProcessWindowsLog::Terminate();
97 #endif
99 Socket::Terminate();
100 HostInfo::Terminate();
101 Log::DisableAllLogChannels();
102 FileSystem::Terminate();
103 Diagnostics::Terminate();