blob: 221dc8c58b7a0a84831c3ce814539abcffd2d7db [file] [log] [blame]
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001//===-- SystemInitializerCommon.cpp -----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Initialization/SystemInitializerCommon.h"
11
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000012#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +000013#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +000014#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000015#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
16#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000017#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
Jonas Devlieghere46376962018-10-31 21:49:27 +000018#include "lldb/Host/FileSystem.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000019#include "lldb/Host/Host.h"
20#include "lldb/Host/HostInfo.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000021#include "lldb/Utility/Log.h"
Pavel Labath38d06322017-06-29 14:32:17 +000022#include "lldb/Utility/Timer.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000023
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000024#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000025#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
26#endif
27
28#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000029#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000030#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000031#endif
32
33#include "llvm/Support/TargetSelect.h"
34
35#include <string>
36
37using namespace lldb_private;
38
Kate Stoneb9c1b512016-09-06 20:57:50 +000039SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043void SystemInitializerCommon::Initialize() {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000044#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
46 if (disable_crash_dialog_var &&
47 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
48 // This will prevent Windows from displaying a dialog box requiring user
49 // interaction when
50 // LLDB crashes. This is mostly useful when automating LLDB, for example
51 // via the test
52 // suite, so that a crash in LLDB does not prevent completion of the test
53 // suite.
54 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
55 SEM_NOGPFAULTERRORBOX);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000056
Kate Stoneb9c1b512016-09-06 20:57:50 +000057 _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 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000064#endif
65
Jonas Devlieghere46376962018-10-31 21:49:27 +000066 FileSystem::Initialize();
Pavel Labathd8133092017-10-23 19:41:17 +000067 Log::Initialize();
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 HostInfo::Initialize();
Pavel Labathf9d16472017-05-15 13:02:37 +000069 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
70 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 // Initialize plug-ins
75 ObjectContainerBSDArchive::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 EmulateInstructionARM::Initialize();
78 EmulateInstructionMIPS::Initialize();
79 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 //----------------------------------------------------------------------
82 // Apple/Darwin hosted plugins
83 //----------------------------------------------------------------------
84 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000085
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000086#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Pavel Labathc29f7ff2017-02-23 10:33:16 +000087 ProcessPOSIXLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000088#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +000089#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +000091#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +000092}
93
Kate Stoneb9c1b512016-09-06 20:57:50 +000094void SystemInitializerCommon::Terminate() {
Pavel Labathf9d16472017-05-15 13:02:37 +000095 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
96 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 ObjectContainerBSDArchive::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 EmulateInstructionARM::Terminate();
100 EmulateInstructionMIPS::Terminate();
101 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000102
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000104
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000105#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000106 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000107#endif
108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109 HostInfo::Terminate();
Pavel Labath775588c2017-03-15 09:06:58 +0000110 Log::DisableAllLogChannels();
Jonas Devlieghere46376962018-10-31 21:49:27 +0000111 FileSystem::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000112}