blob: 6cbc0b707df4b61494d9c475371a6d7244c5cca3 [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
12#include "lldb/Host/Host.h"
13#include "lldb/Host/HostInfo.h"
14#include "lldb/Core/Log.h"
15#include "lldb/Core/Timer.h"
Greg Clayton56939cb2015-09-17 22:23:34 +000016#include "lldb/Symbol/GoASTContext.h"
17#include "lldb/Symbol/ClangASTContext.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000018#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
19#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Stephane Sezer38a1b7e2015-07-08 18:07:13 +000020#include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h"
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000021#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +000022#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +000023#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000024#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
25#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
26#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
27#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
28#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
Ryan Brown65d4d5c2015-09-16 21:20:44 +000029#include "Plugins/OperatingSystem/Go/OperatingSystemGo.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000030#include "Plugins/Platform/Android/PlatformAndroid.h"
31#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
32#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
33#include "Plugins/Platform/Linux/PlatformLinux.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000034#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
35#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
Bruce Mitchenerd31113f2015-11-07 15:31:54 +000036#include "Plugins/Platform/NetBSD/PlatformNetBSD.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000037#include "Plugins/Platform/Windows/PlatformWindows.h"
38#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
39
40#if defined(__APPLE__)
Chaoren Lin2a7a94a2015-11-05 20:45:29 +000041#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000042#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
43#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
44#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
45#endif
46
47#if defined(__linux__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
49#endif
50
51#if defined(_MSC_VER)
52#include "lldb/Host/windows/windows.h"
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000053#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000054#endif
55
56#include "llvm/Support/TargetSelect.h"
57
58#include <string>
59
60using namespace lldb_private;
61
62static void
63fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag)
64{
65 Host::SetCrashDescription(reason.c_str());
66 ::abort();
67}
68
69SystemInitializerCommon::SystemInitializerCommon()
70{
71}
72
73SystemInitializerCommon::~SystemInitializerCommon()
74{
75}
76
77void
78SystemInitializerCommon::Initialize()
79{
80#if defined(_MSC_VER)
81 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
82 if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
83 {
84 // This will prevent Windows from displaying a dialog box requiring user interaction when
85 // LLDB crashes. This is mostly useful when automating LLDB, for example via the test
86 // suite, so that a crash in LLDB does not prevent completion of the test suite.
87 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
88
89 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
90 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
91 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
92 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
93 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
94 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
95 }
96#endif
97
98 Log::Initialize();
99 HostInfo::Initialize();
100 Timer::Initialize();
101 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
102
103 llvm::install_fatal_error_handler(fatal_error_handler, 0);
104
105 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
106
107 // Initialize plug-ins
Greg Clayton56939cb2015-09-17 22:23:34 +0000108 ClangASTContext::Initialize();
109 GoASTContext::Initialize();
110
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000111 ObjectContainerBSDArchive::Initialize();
112 ObjectFileELF::Initialize();
113 ObjectFilePECOFF::Initialize();
114 DynamicLoaderPOSIXDYLD::Initialize();
Stephane Sezer38a1b7e2015-07-08 18:07:13 +0000115 DynamicLoaderWindowsDYLD::Initialize();
Ed Masteae9f2b92015-07-02 17:35:22 +0000116 platform_freebsd::PlatformFreeBSD::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000117 platform_linux::PlatformLinux::Initialize();
Kamil Rytarowskia019e812015-12-05 21:46:37 +0000118 platform_netbsd::PlatformNetBSD::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000119 PlatformWindows::Initialize();
120 PlatformKalimba::Initialize();
121 platform_android::PlatformAndroid::Initialize();
122
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000123 EmulateInstructionARM::Initialize();
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +0000124 EmulateInstructionMIPS::Initialize();
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +0000125 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000126
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000127 //----------------------------------------------------------------------
128 // Apple/Darwin hosted plugins
129 //----------------------------------------------------------------------
130 DynamicLoaderMacOSXDYLD::Initialize();
131 ObjectContainerUniversalMachO::Initialize();
132
133 PlatformRemoteiOS::Initialize();
134 PlatformMacOSX::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000135
136#if defined(__APPLE__)
Chaoren Lin2a7a94a2015-11-05 20:45:29 +0000137 PlatformiOSSimulator::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000138 DynamicLoaderDarwinKernel::Initialize();
139 PlatformDarwinKernel::Initialize();
140 ObjectFileMachO::Initialize();
141#endif
142#if defined(__linux__)
143 static ConstString g_linux_log_name("linux");
144 ProcessPOSIXLog::Initialize(g_linux_log_name);
145#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +0000146#if defined(_MSC_VER)
147 ProcessWindowsLog::Initialize();
148#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000149#ifndef LLDB_DISABLE_PYTHON
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000150 OperatingSystemPython::Initialize();
151#endif
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000152 OperatingSystemGo::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000153}
154
155void
156SystemInitializerCommon::Terminate()
157{
158 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
159 ObjectContainerBSDArchive::Terminate();
160 ObjectFileELF::Terminate();
161 ObjectFilePECOFF::Terminate();
162 DynamicLoaderPOSIXDYLD::Terminate();
Stephane Sezer38a1b7e2015-07-08 18:07:13 +0000163 DynamicLoaderWindowsDYLD::Terminate();
Ed Masteae9f2b92015-07-02 17:35:22 +0000164 platform_freebsd::PlatformFreeBSD::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000165 platform_linux::PlatformLinux::Terminate();
Kamil Rytarowskia019e812015-12-05 21:46:37 +0000166 platform_netbsd::PlatformNetBSD::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000167 PlatformWindows::Terminate();
168 PlatformKalimba::Terminate();
169 platform_android::PlatformAndroid::Terminate();
170 DynamicLoaderMacOSXDYLD::Terminate();
171 ObjectContainerUniversalMachO::Terminate();
172 PlatformMacOSX::Terminate();
173 PlatformRemoteiOS::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000174
Greg Clayton56939cb2015-09-17 22:23:34 +0000175 ClangASTContext::Terminate();
176 GoASTContext::Terminate();
177
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000178 EmulateInstructionARM::Terminate();
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +0000179 EmulateInstructionMIPS::Terminate();
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +0000180 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000181
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000182#if defined(__APPLE__)
Chaoren Lin2a7a94a2015-11-05 20:45:29 +0000183 PlatformiOSSimulator::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000184 DynamicLoaderDarwinKernel::Terminate();
185 ObjectFileMachO::Terminate();
186 PlatformDarwinKernel::Terminate();
187#endif
188
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000189#if defined(_MSC_VER)
Zachary Turner610e5292015-05-07 21:39:33 +0000190 ProcessWindowsLog::Terminate();
191#endif
192
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000193#ifndef LLDB_DISABLE_PYTHON
194 OperatingSystemPython::Terminate();
195#endif
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000196 OperatingSystemGo::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000197
198 Log::Terminate();
199}