blob: 1139955b18a5fea7b26989c7d0f13286400ed974 [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"
17#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
18#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000019#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000020#include "lldb/Core/Log.h"
21#include "lldb/Core/Timer.h"
22#include "lldb/Host/Host.h"
23#include "lldb/Host/HostInfo.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000024
25#if defined(__APPLE__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000026#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000027#endif
28
29#if defined(__linux__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000030#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
31#endif
32
33#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000034#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000035#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036#endif
37
Sean Callanan237c3ed2016-12-14 21:31:31 +000038#include "llvm/Support/PrettyStackTrace.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000039#include "llvm/Support/TargetSelect.h"
40
41#include <string>
42
43using namespace lldb_private;
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049void SystemInitializerCommon::Initialize() {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000050#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
52 if (disable_crash_dialog_var &&
53 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
54 // This will prevent Windows from displaying a dialog box requiring user
55 // interaction when
56 // LLDB crashes. This is mostly useful when automating LLDB, for example
57 // via the test
58 // suite, so that a crash in LLDB does not prevent completion of the test
59 // suite.
60 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
61 SEM_NOGPFAULTERRORBOX);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
64 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
65 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
66 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
67 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
68 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
69 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000070#endif
71
Sean Callanan237c3ed2016-12-14 21:31:31 +000072 llvm::EnablePrettyStackTrace();
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 Log::Initialize();
74 HostInfo::Initialize();
75 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 // Initialize plug-ins
80 ObjectContainerBSDArchive::Initialize();
81 ObjectFileELF::Initialize();
82 ObjectFilePECOFF::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 EmulateInstructionARM::Initialize();
85 EmulateInstructionMIPS::Initialize();
86 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 //----------------------------------------------------------------------
89 // Apple/Darwin hosted plugins
90 //----------------------------------------------------------------------
91 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000092
93#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 ObjectFileMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000095#endif
96#if defined(__linux__)
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 static ConstString g_linux_log_name("linux");
98 ProcessPOSIXLog::Initialize(g_linux_log_name);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000099#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +0000100#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +0000102#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000103}
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105void SystemInitializerCommon::Terminate() {
106 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
107 ObjectContainerBSDArchive::Terminate();
108 ObjectFileELF::Terminate();
109 ObjectFilePECOFF::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111 EmulateInstructionARM::Terminate();
112 EmulateInstructionMIPS::Terminate();
113 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000116#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 ObjectFileMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000118#endif
119
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000120#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000122#endif
123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124 HostInfo::Terminate();
125 Log::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000126}