2015-03-31 21:03:22 +00:00
|
|
|
//===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-03-31 21:03:22 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Initialization/SystemInitializerCommon.h"
|
|
|
|
|
|
|
|
|
|
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
|
2018-10-31 21:49:27 +00:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2016-09-06 20:57:50 +00:00
|
|
|
#include "lldb/Host/Host.h"
|
|
|
|
|
#include "lldb/Host/HostInfo.h"
|
2019-04-10 04:57:18 +00:00
|
|
|
#include "lldb/Host/Socket.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-12-03 17:28:29 +00:00
|
|
|
#include "lldb/Utility/Reproducer.h"
|
2017-06-29 14:32:17 +00:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2019-06-13 04:35:22 +00:00
|
|
|
#include "lldb/lldb-private.h"
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2017-03-21 17:26:55 +00:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2015-03-31 21:03:22 +00:00
|
|
|
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-02 19:25:18 +00:00
|
|
|
#if defined(_WIN32)
|
2015-10-28 18:21:45 +00:00
|
|
|
#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
|
2016-03-02 22:05:52 +00:00
|
|
|
#include "lldb/Host/windows/windows.h"
|
2015-03-31 21:03:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
2018-12-03 17:28:29 +00:00
|
|
|
using namespace lldb_private::repro;
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
SystemInitializerCommon::SystemInitializerCommon() {}
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
SystemInitializerCommon::~SystemInitializerCommon() {}
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2019-02-21 22:26:16 +00:00
|
|
|
llvm::Error SystemInitializerCommon::Initialize() {
|
2019-05-02 19:25:18 +00:00
|
|
|
#if defined(_WIN32)
|
2016-09-06 20:57:50 +00:00
|
|
|
const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
|
|
|
|
|
if (disable_crash_dialog_var &&
|
|
|
|
|
llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
|
|
|
|
|
// This will prevent Windows from displaying a dialog box requiring user
|
|
|
|
|
// interaction when
|
|
|
|
|
// LLDB crashes. This is mostly useful when automating LLDB, for example
|
|
|
|
|
// via the test
|
|
|
|
|
// suite, so that a crash in LLDB does not prevent completion of the test
|
|
|
|
|
// suite.
|
|
|
|
|
::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
|
|
|
|
|
SEM_NOGPFAULTERRORBOX);
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
|
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
|
|
|
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
|
|
|
|
|
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
|
|
|
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
|
|
|
|
}
|
2015-03-31 21:03:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
2019-02-21 22:26:16 +00:00
|
|
|
// If the reproducer wasn't initialized before, we can safely assume it's
|
|
|
|
|
// off.
|
|
|
|
|
if (!Reproducer::Initialized()) {
|
|
|
|
|
if (auto e = Reproducer::Initialize(ReproducerMode::Off, llvm::None))
|
|
|
|
|
return e;
|
|
|
|
|
}
|
2018-12-03 17:28:29 +00:00
|
|
|
|
2019-01-29 20:36:38 +00:00
|
|
|
auto &r = repro::Reproducer::Instance();
|
|
|
|
|
if (repro::Loader *loader = r.GetLoader()) {
|
2019-06-12 22:17:38 +00:00
|
|
|
FileSpec vfs_mapping = loader->GetFile<FileProvider::Info>();
|
2019-01-29 20:36:38 +00:00
|
|
|
if (vfs_mapping) {
|
|
|
|
|
if (llvm::Error e = FileSystem::Initialize(vfs_mapping))
|
|
|
|
|
return e;
|
|
|
|
|
} else {
|
|
|
|
|
FileSystem::Initialize();
|
|
|
|
|
}
|
|
|
|
|
} else if (repro::Generator *g = r.GetGenerator()) {
|
2019-06-13 04:35:22 +00:00
|
|
|
repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
|
|
|
|
|
vp.SetVersion(lldb_private::GetVersion());
|
2019-01-29 20:36:38 +00:00
|
|
|
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
|
|
|
|
|
FileSystem::Initialize(fp.GetFileCollector());
|
|
|
|
|
} else {
|
|
|
|
|
FileSystem::Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-23 19:41:17 +00:00
|
|
|
Log::Initialize();
|
2016-09-06 20:57:50 +00:00
|
|
|
HostInfo::Initialize();
|
2019-04-10 04:57:18 +00:00
|
|
|
|
|
|
|
|
llvm::Error error = Socket::Initialize();
|
|
|
|
|
if (error)
|
|
|
|
|
return error;
|
|
|
|
|
|
2017-05-15 13:02:37 +00:00
|
|
|
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
|
|
|
|
|
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2017-03-21 17:26:55 +00:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2017-02-23 10:33:16 +00:00
|
|
|
ProcessPOSIXLog::Initialize();
|
2015-03-31 21:03:22 +00:00
|
|
|
#endif
|
2019-05-02 19:25:18 +00:00
|
|
|
#if defined(_WIN32)
|
2016-09-06 20:57:50 +00:00
|
|
|
ProcessWindowsLog::Initialize();
|
2015-04-10 16:18:08 +00:00
|
|
|
#endif
|
2018-12-03 17:28:29 +00:00
|
|
|
|
|
|
|
|
return llvm::Error::success();
|
2015-03-31 21:03:22 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-06 20:57:50 +00:00
|
|
|
void SystemInitializerCommon::Terminate() {
|
2017-05-15 13:02:37 +00:00
|
|
|
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
|
|
|
|
|
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
|
2015-03-31 21:03:22 +00:00
|
|
|
|
2019-05-02 19:25:18 +00:00
|
|
|
#if defined(_WIN32)
|
2016-09-06 20:57:50 +00:00
|
|
|
ProcessWindowsLog::Terminate();
|
2015-05-07 21:39:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
2019-04-10 04:57:18 +00:00
|
|
|
Socket::Terminate();
|
2016-09-06 20:57:50 +00:00
|
|
|
HostInfo::Terminate();
|
2017-03-15 09:06:58 +00:00
|
|
|
Log::DisableAllLogChannels();
|
2018-10-31 21:49:27 +00:00
|
|
|
FileSystem::Terminate();
|
2018-12-03 17:28:29 +00:00
|
|
|
Reproducer::Terminate();
|
2015-03-31 21:03:22 +00:00
|
|
|
}
|