xref: /src/contrib/llvm-project/lldb/source/Initialization/SystemInitializerCommon.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1cfca06d7SDimitry Andric //===-- SystemInitializerCommon.cpp ---------------------------------------===//
25e95aa85SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65e95aa85SEd Maste //
75e95aa85SEd Maste //===----------------------------------------------------------------------===//
85e95aa85SEd Maste 
95e95aa85SEd Maste #include "lldb/Initialization/SystemInitializerCommon.h"
105e95aa85SEd Maste 
115e95aa85SEd Maste #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
1294994d37SDimitry Andric #include "lldb/Host/FileSystem.h"
1314f1b3e8SDimitry Andric #include "lldb/Host/Host.h"
145f29bb8aSDimitry Andric #include "lldb/Host/Socket.h"
15e3b55780SDimitry Andric #include "lldb/Target/Statistics.h"
16e3b55780SDimitry Andric #include "lldb/Utility/Diagnostics.h"
17145449b1SDimitry Andric #include "lldb/Utility/LLDBLog.h"
181b306c26SDimitry Andric #include "lldb/Utility/Timer.h"
1977fc4c14SDimitry Andric #include "lldb/Version/Version.h"
205e95aa85SEd Maste 
21b1c73532SDimitry Andric #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
22b1c73532SDimitry Andric     defined(__OpenBSD__)
235e95aa85SEd Maste #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
245e95aa85SEd Maste #endif
255e95aa85SEd Maste 
265f29bb8aSDimitry Andric #if defined(_WIN32)
27e81d9d49SDimitry Andric #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
28f3fbd1c0SDimitry Andric #include "lldb/Host/windows/windows.h"
29ead24645SDimitry Andric #include <crtdbg.h>
305e95aa85SEd Maste #endif
315e95aa85SEd Maste 
325e95aa85SEd Maste #include "llvm/Support/TargetSelect.h"
335e95aa85SEd Maste 
345e95aa85SEd Maste #include <string>
355e95aa85SEd Maste 
365e95aa85SEd Maste using namespace lldb_private;
375e95aa85SEd Maste 
SystemInitializerCommon(HostInfo::SharedLibraryDirectoryHelper * helper)38344a3780SDimitry Andric SystemInitializerCommon::SystemInitializerCommon(
39344a3780SDimitry Andric     HostInfo::SharedLibraryDirectoryHelper *helper)
40344a3780SDimitry Andric     : m_shlib_dir_helper(helper) {}
415e95aa85SEd Maste 
42344a3780SDimitry Andric SystemInitializerCommon::~SystemInitializerCommon() = default;
435e95aa85SEd Maste 
Initialize()445f29bb8aSDimitry Andric llvm::Error SystemInitializerCommon::Initialize() {
455f29bb8aSDimitry Andric #if defined(_WIN32)
465e95aa85SEd Maste   const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
4714f1b3e8SDimitry Andric   if (disable_crash_dialog_var &&
48344a3780SDimitry Andric       llvm::StringRef(disable_crash_dialog_var).equals_insensitive("true")) {
4914f1b3e8SDimitry Andric     // This will prevent Windows from displaying a dialog box requiring user
5014f1b3e8SDimitry Andric     // interaction when
5114f1b3e8SDimitry Andric     // LLDB crashes.  This is mostly useful when automating LLDB, for example
5214f1b3e8SDimitry Andric     // via the test
5314f1b3e8SDimitry Andric     // suite, so that a crash in LLDB does not prevent completion of the test
5414f1b3e8SDimitry Andric     // suite.
5514f1b3e8SDimitry Andric     ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
5614f1b3e8SDimitry Andric                    SEM_NOGPFAULTERRORBOX);
575e95aa85SEd Maste 
585e95aa85SEd Maste     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
595e95aa85SEd Maste     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
605e95aa85SEd Maste     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
615e95aa85SEd Maste     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
625e95aa85SEd Maste     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
635e95aa85SEd Maste     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
645e95aa85SEd Maste   }
655e95aa85SEd Maste #endif
665e95aa85SEd Maste 
67145449b1SDimitry Andric   InitializeLldbChannel();
68e3b55780SDimitry Andric 
69e3b55780SDimitry Andric   Diagnostics::Initialize();
70e3b55780SDimitry Andric   FileSystem::Initialize();
71344a3780SDimitry Andric   HostInfo::Initialize(m_shlib_dir_helper);
725f29bb8aSDimitry Andric 
735f29bb8aSDimitry Andric   llvm::Error error = Socket::Initialize();
745f29bb8aSDimitry Andric   if (error)
755f29bb8aSDimitry Andric     return error;
765f29bb8aSDimitry Andric 
77b60736ecSDimitry Andric   LLDB_SCOPED_TIMER();
785e95aa85SEd Maste 
795e95aa85SEd Maste   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
805e95aa85SEd Maste 
81b1c73532SDimitry Andric #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) ||       \
82b1c73532SDimitry Andric     defined(__OpenBSD__)
8374a628f7SDimitry Andric   ProcessPOSIXLog::Initialize();
845e95aa85SEd Maste #endif
855f29bb8aSDimitry Andric #if defined(_WIN32)
865e95aa85SEd Maste   ProcessWindowsLog::Initialize();
875e95aa85SEd Maste #endif
8894994d37SDimitry Andric 
8994994d37SDimitry Andric   return llvm::Error::success();
905e95aa85SEd Maste }
915e95aa85SEd Maste 
Terminate()9214f1b3e8SDimitry Andric void SystemInitializerCommon::Terminate() {
93b60736ecSDimitry Andric   LLDB_SCOPED_TIMER();
945e95aa85SEd Maste 
955f29bb8aSDimitry Andric #if defined(_WIN32)
965e95aa85SEd Maste   ProcessWindowsLog::Terminate();
975e95aa85SEd Maste #endif
985e95aa85SEd Maste 
995f29bb8aSDimitry Andric   Socket::Terminate();
100f3fbd1c0SDimitry Andric   HostInfo::Terminate();
10174a628f7SDimitry Andric   Log::DisableAllLogChannels();
10294994d37SDimitry Andric   FileSystem::Terminate();
103e3b55780SDimitry Andric   Diagnostics::Terminate();
1045e95aa85SEd Maste }
105