2015-04-01 05:03:22 +08:00
|
|
|
//===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-04-01 05:03:22 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Initialization/SystemInitializerCommon.h"
|
|
|
|
|
2015-04-15 17:47:02 +08:00
|
|
|
#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
|
2015-05-15 14:53:30 +08:00
|
|
|
#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
|
2015-05-07 13:56:27 +08:00
|
|
|
#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
|
|
|
|
#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
|
|
|
|
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
|
2018-11-01 05:49:27 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
|
|
|
#include "lldb/Host/HostInfo.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2018-12-04 01:28:29 +08:00
|
|
|
#include "lldb/Utility/Reproducer.h"
|
2017-06-29 22:32:17 +08:00
|
|
|
#include "lldb/Utility/Timer.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2017-03-22 01:26:55 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
2015-10-29 02:21:45 +08:00
|
|
|
#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
#include "lldb/Host/windows/windows.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
2018-12-04 01:28:29 +08:00
|
|
|
using namespace lldb_private::repro;
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SystemInitializerCommon::SystemInitializerCommon() {}
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SystemInitializerCommon::~SystemInitializerCommon() {}
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2019-02-22 06:26:16 +08:00
|
|
|
llvm::Error SystemInitializerCommon::Initialize() {
|
2015-04-01 05:03:22 +08:00
|
|
|
#if defined(_MSC_VER)
|
2016-09-07 04:57:50 +08: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);
|
|
|
|
|
|
|
|
_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-04-01 05:03:22 +08:00
|
|
|
#endif
|
|
|
|
|
2019-02-22 06:26:16 +08: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-04 01:28:29 +08:00
|
|
|
|
2019-01-30 04:36:38 +08:00
|
|
|
// Initialize the file system.
|
|
|
|
auto &r = repro::Reproducer::Instance();
|
|
|
|
if (repro::Loader *loader = r.GetLoader()) {
|
|
|
|
FileSpec vfs_mapping = loader->GetFile<FileInfo>();
|
|
|
|
if (vfs_mapping) {
|
|
|
|
if (llvm::Error e = FileSystem::Initialize(vfs_mapping))
|
|
|
|
return e;
|
|
|
|
} else {
|
|
|
|
FileSystem::Initialize();
|
|
|
|
}
|
|
|
|
} else if (repro::Generator *g = r.GetGenerator()) {
|
|
|
|
repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
|
|
|
|
FileSystem::Initialize(fp.GetFileCollector());
|
|
|
|
} else {
|
|
|
|
FileSystem::Initialize();
|
|
|
|
}
|
|
|
|
|
2017-10-24 03:41:17 +08:00
|
|
|
Log::Initialize();
|
2016-09-07 04:57:50 +08:00
|
|
|
HostInfo::Initialize();
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
|
|
|
|
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
process_gdb_remote::ProcessGDBRemoteLog::Initialize();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Initialize plug-ins
|
|
|
|
ObjectContainerBSDArchive::Initialize();
|
2015-04-15 17:47:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
EmulateInstructionARM::Initialize();
|
|
|
|
EmulateInstructionMIPS::Initialize();
|
|
|
|
EmulateInstructionMIPS64::Initialize();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Apple/Darwin hosted plugins
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
ObjectContainerUniversalMachO::Initialize();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2017-03-22 01:26:55 +08:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
|
2017-02-23 18:33:16 +08:00
|
|
|
ProcessPOSIXLog::Initialize();
|
2015-04-01 05:03:22 +08:00
|
|
|
#endif
|
2015-04-11 00:18:08 +08:00
|
|
|
#if defined(_MSC_VER)
|
2016-09-07 04:57:50 +08:00
|
|
|
ProcessWindowsLog::Initialize();
|
2015-04-11 00:18:08 +08:00
|
|
|
#endif
|
2018-12-04 01:28:29 +08:00
|
|
|
|
|
|
|
return llvm::Error::success();
|
2015-04-01 05:03:22 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void SystemInitializerCommon::Terminate() {
|
2017-05-15 21:02:37 +08:00
|
|
|
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
|
|
|
|
Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
|
2016-09-07 04:57:50 +08:00
|
|
|
ObjectContainerBSDArchive::Terminate();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
EmulateInstructionARM::Terminate();
|
|
|
|
EmulateInstructionMIPS::Terminate();
|
|
|
|
EmulateInstructionMIPS64::Terminate();
|
2015-04-15 17:47:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ObjectContainerUniversalMachO::Terminate();
|
2015-04-01 05:03:22 +08:00
|
|
|
|
2015-09-05 00:34:19 +08:00
|
|
|
#if defined(_MSC_VER)
|
2016-09-07 04:57:50 +08:00
|
|
|
ProcessWindowsLog::Terminate();
|
2015-05-08 05:39:33 +08:00
|
|
|
#endif
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
HostInfo::Terminate();
|
2017-03-15 17:06:58 +08:00
|
|
|
Log::DisableAllLogChannels();
|
2018-11-01 05:49:27 +08:00
|
|
|
FileSystem::Terminate();
|
2018-12-04 01:28:29 +08:00
|
|
|
Reproducer::Terminate();
|
2015-04-01 05:03:22 +08:00
|
|
|
}
|