11c3bbb01SEd Maste //===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===//
21c3bbb01SEd Maste //
31c3bbb01SEd Maste // The LLVM Compiler Infrastructure
41c3bbb01SEd Maste //
51c3bbb01SEd Maste // This file is distributed under the University of Illinois Open Source
61c3bbb01SEd Maste // License. See LICENSE.TXT for details.
71c3bbb01SEd Maste //
81c3bbb01SEd Maste //===----------------------------------------------------------------------===//
91c3bbb01SEd Maste
101c3bbb01SEd Maste #include "lldb/Initialization/SystemInitializerCommon.h"
111c3bbb01SEd Maste
121c3bbb01SEd Maste #include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
131c3bbb01SEd Maste #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
141c3bbb01SEd Maste #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
151c3bbb01SEd Maste #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
160e56f923SDimitry Andric #ifdef LLDB_ENABLE_ALL
170e56f923SDimitry Andric #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
180e56f923SDimitry Andric #endif // LLDB_ENABLE_ALL
191c3bbb01SEd Maste #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
20*b5893f02SDimitry Andric #include "lldb/Host/FileSystem.h"
21435933ddSDimitry Andric #include "lldb/Host/Host.h"
22435933ddSDimitry Andric #include "lldb/Host/HostInfo.h"
23f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
24*b5893f02SDimitry Andric #include "lldb/Utility/Reproducer.h"
25a580b014SDimitry Andric #include "lldb/Utility/Timer.h"
261c3bbb01SEd Maste
27f678e45dSDimitry Andric #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
281c3bbb01SEd Maste #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
291c3bbb01SEd Maste #endif
301c3bbb01SEd Maste
311c3bbb01SEd Maste #if defined(_MSC_VER)
329f2f44ceSEd Maste #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
334bb0738eSEd Maste #include "lldb/Host/windows/windows.h"
341c3bbb01SEd Maste #endif
351c3bbb01SEd Maste
361c3bbb01SEd Maste #include "llvm/Support/TargetSelect.h"
371c3bbb01SEd Maste
381c3bbb01SEd Maste #include <string>
391c3bbb01SEd Maste
401c3bbb01SEd Maste using namespace lldb_private;
41*b5893f02SDimitry Andric using namespace lldb_private::repro;
421c3bbb01SEd Maste
SystemInitializerCommon()43435933ddSDimitry Andric SystemInitializerCommon::SystemInitializerCommon() {}
441c3bbb01SEd Maste
~SystemInitializerCommon()45435933ddSDimitry Andric SystemInitializerCommon::~SystemInitializerCommon() {}
461c3bbb01SEd Maste
47*b5893f02SDimitry Andric llvm::Error
Initialize(const InitializerOptions & options)48*b5893f02SDimitry Andric SystemInitializerCommon::Initialize(const InitializerOptions &options) {
491c3bbb01SEd Maste #if defined(_MSC_VER)
501c3bbb01SEd Maste const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
51435933ddSDimitry Andric if (disable_crash_dialog_var &&
52435933ddSDimitry Andric llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
53435933ddSDimitry Andric // This will prevent Windows from displaying a dialog box requiring user
54435933ddSDimitry Andric // interaction when
55435933ddSDimitry Andric // LLDB crashes. This is mostly useful when automating LLDB, for example
56435933ddSDimitry Andric // via the test
57435933ddSDimitry Andric // suite, so that a crash in LLDB does not prevent completion of the test
58435933ddSDimitry Andric // suite.
59435933ddSDimitry Andric ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
60435933ddSDimitry Andric SEM_NOGPFAULTERRORBOX);
611c3bbb01SEd Maste
621c3bbb01SEd Maste _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
631c3bbb01SEd Maste _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
641c3bbb01SEd Maste _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
651c3bbb01SEd Maste _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
661c3bbb01SEd Maste _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
671c3bbb01SEd Maste _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
681c3bbb01SEd Maste }
691c3bbb01SEd Maste #endif
701c3bbb01SEd Maste
71*b5893f02SDimitry Andric ReproducerMode mode = ReproducerMode::Off;
72*b5893f02SDimitry Andric if (options.reproducer_capture)
73*b5893f02SDimitry Andric mode = ReproducerMode::Capture;
74*b5893f02SDimitry Andric if (options.reproducer_replay)
75*b5893f02SDimitry Andric mode = ReproducerMode::Replay;
76*b5893f02SDimitry Andric
77*b5893f02SDimitry Andric if (auto e = Reproducer::Initialize(mode, FileSpec(options.reproducer_path)))
78*b5893f02SDimitry Andric return e;
79*b5893f02SDimitry Andric
80*b5893f02SDimitry Andric FileSystem::Initialize();
81acac075bSDimitry Andric Log::Initialize();
821c3bbb01SEd Maste HostInfo::Initialize();
835517e702SDimitry Andric static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
845517e702SDimitry Andric Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
851c3bbb01SEd Maste
861c3bbb01SEd Maste process_gdb_remote::ProcessGDBRemoteLog::Initialize();
871c3bbb01SEd Maste
881c3bbb01SEd Maste // Initialize plug-ins
891c3bbb01SEd Maste ObjectContainerBSDArchive::Initialize();
901c3bbb01SEd Maste
911c3bbb01SEd Maste EmulateInstructionARM::Initialize();
921c3bbb01SEd Maste EmulateInstructionMIPS::Initialize();
931c3bbb01SEd Maste EmulateInstructionMIPS64::Initialize();
941c3bbb01SEd Maste
951c3bbb01SEd Maste //----------------------------------------------------------------------
961c3bbb01SEd Maste // Apple/Darwin hosted plugins
971c3bbb01SEd Maste //----------------------------------------------------------------------
980e56f923SDimitry Andric #ifdef LLDB_ENABLE_ALL
990e56f923SDimitry Andric ObjectContainerUniversalMachO::Initialize();
1000e56f923SDimitry Andric #endif // LLDB_ENABLE_ALL
1019228435aSDimitry Andric
102f678e45dSDimitry Andric #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
103f678e45dSDimitry Andric ProcessPOSIXLog::Initialize();
1041c3bbb01SEd Maste #endif
1051c3bbb01SEd Maste #if defined(_MSC_VER)
1061c3bbb01SEd Maste ProcessWindowsLog::Initialize();
1071c3bbb01SEd Maste #endif
108*b5893f02SDimitry Andric
109*b5893f02SDimitry Andric return llvm::Error::success();
1101c3bbb01SEd Maste }
1111c3bbb01SEd Maste
Terminate()112435933ddSDimitry Andric void SystemInitializerCommon::Terminate() {
1135517e702SDimitry Andric static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
1145517e702SDimitry Andric Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
1151c3bbb01SEd Maste ObjectContainerBSDArchive::Terminate();
1169f2f44ceSEd Maste
1171c3bbb01SEd Maste EmulateInstructionARM::Terminate();
1181c3bbb01SEd Maste EmulateInstructionMIPS::Terminate();
1191c3bbb01SEd Maste EmulateInstructionMIPS64::Terminate();
1201c3bbb01SEd Maste
1210e56f923SDimitry Andric #ifdef LLDB_ENABLE_ALL
1220e56f923SDimitry Andric ObjectContainerUniversalMachO::Terminate();
1230e56f923SDimitry Andric #endif // LLDB_ENABLE_ALL
1241c3bbb01SEd Maste
1259f2f44ceSEd Maste #if defined(_MSC_VER)
1261c3bbb01SEd Maste ProcessWindowsLog::Terminate();
1271c3bbb01SEd Maste #endif
1281c3bbb01SEd Maste
1294bb0738eSEd Maste HostInfo::Terminate();
130f678e45dSDimitry Andric Log::DisableAllLogChannels();
131*b5893f02SDimitry Andric FileSystem::Terminate();
132*b5893f02SDimitry Andric Reproducer::Terminate();
1331c3bbb01SEd Maste }
134