blob: 006ab23595c78bd97b7e5d5852c48d0e9360faf1 [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"
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/Host/Host.h"
19#include "lldb/Host/HostInfo.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000020#include "lldb/Utility/Log.h"
Pavel Labath38d06322017-06-29 14:32:17 +000021#include "lldb/Utility/Timer.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000022
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000023#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000024#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
25#endif
26
27#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000028#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000029#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000030#endif
31
32#include "llvm/Support/TargetSelect.h"
33
34#include <string>
35
36using namespace lldb_private;
37
Kate Stoneb9c1b512016-09-06 20:57:50 +000038SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042void SystemInitializerCommon::Initialize() {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000043#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000044 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
45 if (disable_crash_dialog_var &&
46 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
47 // This will prevent Windows from displaying a dialog box requiring user
48 // interaction when
49 // LLDB crashes. This is mostly useful when automating LLDB, for example
50 // via the test
51 // suite, so that a crash in LLDB does not prevent completion of the test
52 // suite.
53 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
54 SEM_NOGPFAULTERRORBOX);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000055
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
57 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
58 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
59 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
60 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
61 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
62 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000063#endif
64
Pavel Labathd8133092017-10-23 19:41:17 +000065 Log::Initialize();
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 HostInfo::Initialize();
Pavel Labathf9d16472017-05-15 13:02:37 +000067 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
68 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 // Initialize plug-ins
73 ObjectContainerBSDArchive::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 EmulateInstructionARM::Initialize();
76 EmulateInstructionMIPS::Initialize();
77 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 //----------------------------------------------------------------------
80 // Apple/Darwin hosted plugins
81 //----------------------------------------------------------------------
82 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000083
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000084#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Pavel Labathc29f7ff2017-02-23 10:33:16 +000085 ProcessPOSIXLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000086#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +000087#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +000089#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +000090}
91
Kate Stoneb9c1b512016-09-06 20:57:50 +000092void SystemInitializerCommon::Terminate() {
Pavel Labathf9d16472017-05-15 13:02:37 +000093 static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
94 Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 ObjectContainerBSDArchive::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000096
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 EmulateInstructionARM::Terminate();
98 EmulateInstructionMIPS::Terminate();
99 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000102
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000103#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000105#endif
106
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107 HostInfo::Terminate();
Pavel Labath775588c2017-03-15 09:06:58 +0000108 Log::DisableAllLogChannels();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000109}