Path: blob/main/contrib/llvm-project/lldb/source/Initialization/SystemInitializerCommon.cpp
39587 views
//===-- SystemInitializerCommon.cpp ---------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Initialization/SystemInitializerCommon.h"910#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"11#include "lldb/Host/FileSystem.h"12#include "lldb/Host/Host.h"13#include "lldb/Host/Socket.h"14#include "lldb/Target/Statistics.h"15#include "lldb/Utility/Diagnostics.h"16#include "lldb/Utility/LLDBLog.h"17#include "lldb/Utility/Timer.h"18#include "lldb/Version/Version.h"1920#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \21defined(__OpenBSD__)22#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"23#endif2425#if defined(_WIN32)26#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"27#include "lldb/Host/windows/windows.h"28#include <crtdbg.h>29#endif3031#include "llvm/Support/TargetSelect.h"3233#include <string>3435using namespace lldb_private;3637SystemInitializerCommon::SystemInitializerCommon(38HostInfo::SharedLibraryDirectoryHelper *helper)39: m_shlib_dir_helper(helper) {}4041SystemInitializerCommon::~SystemInitializerCommon() = default;4243llvm::Error SystemInitializerCommon::Initialize() {44#if defined(_WIN32)45const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");46if (disable_crash_dialog_var &&47llvm::StringRef(disable_crash_dialog_var).equals_insensitive("true")) {48// This will prevent Windows from displaying a dialog box requiring user49// interaction when50// LLDB crashes. This is mostly useful when automating LLDB, for example51// via the test52// suite, so that a crash in LLDB does not prevent completion of the test53// suite.54::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |55SEM_NOGPFAULTERRORBOX);5657_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);63}64#endif6566InitializeLldbChannel();6768Diagnostics::Initialize();69FileSystem::Initialize();70HostInfo::Initialize(m_shlib_dir_helper);7172llvm::Error error = Socket::Initialize();73if (error)74return error;7576LLDB_SCOPED_TIMER();7778process_gdb_remote::ProcessGDBRemoteLog::Initialize();7980#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \81defined(__OpenBSD__)82ProcessPOSIXLog::Initialize();83#endif84#if defined(_WIN32)85ProcessWindowsLog::Initialize();86#endif8788return llvm::Error::success();89}9091void SystemInitializerCommon::Terminate() {92LLDB_SCOPED_TIMER();9394#if defined(_WIN32)95ProcessWindowsLog::Terminate();96#endif9798Socket::Terminate();99HostInfo::Terminate();100Log::DisableAllLogChannels();101FileSystem::Terminate();102Diagnostics::Terminate();103}104105106