blob: 5bf4ceaa1a555e43b080ea6b0aca1ab1eda5da30 [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
38#include "llvm/Support/TargetSelect.h"
39
40#include <string>
41
42using namespace lldb_private;
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044static void fatal_error_handler(void *user_data, const std::string &reason,
45 bool gen_crash_diag) {
46 Host::SetCrashDescription(reason.c_str());
47 ::abort();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048}
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054void SystemInitializerCommon::Initialize() {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000055#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000056 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
57 if (disable_crash_dialog_var &&
58 llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
59 // This will prevent Windows from displaying a dialog box requiring user
60 // interaction when
61 // LLDB crashes. This is mostly useful when automating LLDB, for example
62 // via the test
63 // suite, so that a crash in LLDB does not prevent completion of the test
64 // suite.
65 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
66 SEM_NOGPFAULTERRORBOX);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
69 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
70 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
71 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
72 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
73 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
74 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000075#endif
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 Log::Initialize();
78 HostInfo::Initialize();
79 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 llvm::install_fatal_error_handler(fatal_error_handler, 0);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000082
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 // Initialize plug-ins
86 ObjectContainerBSDArchive::Initialize();
87 ObjectFileELF::Initialize();
88 ObjectFilePECOFF::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 EmulateInstructionARM::Initialize();
91 EmulateInstructionMIPS::Initialize();
92 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000093
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 //----------------------------------------------------------------------
95 // Apple/Darwin hosted plugins
96 //----------------------------------------------------------------------
97 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000098
99#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 ObjectFileMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000101#endif
102#if defined(__linux__)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000103 static ConstString g_linux_log_name("linux");
104 ProcessPOSIXLog::Initialize(g_linux_log_name);
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000105#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +0000106#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000107 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +0000108#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000109}
110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111void SystemInitializerCommon::Terminate() {
112 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
113 ObjectContainerBSDArchive::Terminate();
114 ObjectFileELF::Terminate();
115 ObjectFilePECOFF::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000116
Kate Stoneb9c1b512016-09-06 20:57:50 +0000117 EmulateInstructionARM::Terminate();
118 EmulateInstructionMIPS::Terminate();
119 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000120
Kate Stoneb9c1b512016-09-06 20:57:50 +0000121 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000122#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 ObjectFileMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000124#endif
125
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000126#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000128#endif
129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130 HostInfo::Terminate();
131 Log::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000132}