blob: 89a3afe0947aee959284d8f434ada73ffaee731a [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"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000016
17#include "Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h"
18#include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
Stephane Sezer38a1b7e2015-07-08 18:07:13 +000019#include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h"
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000020#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +000021#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +000022#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000023#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
24#include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
25#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
26#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
27#include "Plugins/OperatingSystem/Python/OperatingSystemPython.h"
Ryan Brown65d4d5c2015-09-16 21:20:44 +000028#include "Plugins/OperatingSystem/Go/OperatingSystemGo.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000029#include "Plugins/Platform/Android/PlatformAndroid.h"
30#include "Plugins/Platform/FreeBSD/PlatformFreeBSD.h"
31#include "Plugins/Platform/Kalimba/PlatformKalimba.h"
32#include "Plugins/Platform/Linux/PlatformLinux.h"
33#include "Plugins/Platform/MacOSX/PlatformiOSSimulator.h"
34#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
35#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
36#include "Plugins/Platform/Windows/PlatformWindows.h"
37#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
38
39#if defined(__APPLE__)
40#include "Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.h"
41#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
42#include "Plugins/Platform/MacOSX/PlatformDarwinKernel.h"
43#endif
44
45#if defined(__linux__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000046#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
47#endif
48
49#if defined(_MSC_VER)
50#include "lldb/Host/windows/windows.h"
Adrian McCarthy27785dd2015-08-24 16:00:51 +000051#include "Plugins/Process/Windows/Live/ProcessWindowsLog.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000052#endif
53
54#include "llvm/Support/TargetSelect.h"
55
56#include <string>
57
58using namespace lldb_private;
59
60static void
61fatal_error_handler(void *user_data, const std::string &reason, bool gen_crash_diag)
62{
63 Host::SetCrashDescription(reason.c_str());
64 ::abort();
65}
66
67SystemInitializerCommon::SystemInitializerCommon()
68{
69}
70
71SystemInitializerCommon::~SystemInitializerCommon()
72{
73}
74
75void
76SystemInitializerCommon::Initialize()
77{
78#if defined(_MSC_VER)
79 const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
80 if (disable_crash_dialog_var && llvm::StringRef(disable_crash_dialog_var).equals_lower("true"))
81 {
82 // This will prevent Windows from displaying a dialog box requiring user interaction when
83 // LLDB crashes. This is mostly useful when automating LLDB, for example via the test
84 // suite, so that a crash in LLDB does not prevent completion of the test suite.
85 ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
86
87 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
88 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
89 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
90 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
91 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
92 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
93 }
94#endif
95
96 Log::Initialize();
97 HostInfo::Initialize();
98 Timer::Initialize();
99 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
100
101 llvm::install_fatal_error_handler(fatal_error_handler, 0);
102
103 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
104
105 // Initialize plug-ins
106 ObjectContainerBSDArchive::Initialize();
107 ObjectFileELF::Initialize();
108 ObjectFilePECOFF::Initialize();
109 DynamicLoaderPOSIXDYLD::Initialize();
Stephane Sezer38a1b7e2015-07-08 18:07:13 +0000110 DynamicLoaderWindowsDYLD::Initialize();
Ed Masteae9f2b92015-07-02 17:35:22 +0000111 platform_freebsd::PlatformFreeBSD::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000112 platform_linux::PlatformLinux::Initialize();
113 PlatformWindows::Initialize();
114 PlatformKalimba::Initialize();
115 platform_android::PlatformAndroid::Initialize();
116
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000117 EmulateInstructionARM::Initialize();
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +0000118 EmulateInstructionMIPS::Initialize();
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +0000119 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000120
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000121 //----------------------------------------------------------------------
122 // Apple/Darwin hosted plugins
123 //----------------------------------------------------------------------
124 DynamicLoaderMacOSXDYLD::Initialize();
125 ObjectContainerUniversalMachO::Initialize();
126
127 PlatformRemoteiOS::Initialize();
128 PlatformMacOSX::Initialize();
129 PlatformiOSSimulator::Initialize();
130
131#if defined(__APPLE__)
132 DynamicLoaderDarwinKernel::Initialize();
133 PlatformDarwinKernel::Initialize();
134 ObjectFileMachO::Initialize();
135#endif
136#if defined(__linux__)
137 static ConstString g_linux_log_name("linux");
138 ProcessPOSIXLog::Initialize(g_linux_log_name);
139#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +0000140#if defined(_MSC_VER)
141 ProcessWindowsLog::Initialize();
142#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000143#ifndef LLDB_DISABLE_PYTHON
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000144 OperatingSystemPython::Initialize();
145#endif
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000146 OperatingSystemGo::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000147}
148
149void
150SystemInitializerCommon::Terminate()
151{
152 Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);
153 ObjectContainerBSDArchive::Terminate();
154 ObjectFileELF::Terminate();
155 ObjectFilePECOFF::Terminate();
156 DynamicLoaderPOSIXDYLD::Terminate();
Stephane Sezer38a1b7e2015-07-08 18:07:13 +0000157 DynamicLoaderWindowsDYLD::Terminate();
Ed Masteae9f2b92015-07-02 17:35:22 +0000158 platform_freebsd::PlatformFreeBSD::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000159 platform_linux::PlatformLinux::Terminate();
160 PlatformWindows::Terminate();
161 PlatformKalimba::Terminate();
162 platform_android::PlatformAndroid::Terminate();
163 DynamicLoaderMacOSXDYLD::Terminate();
164 ObjectContainerUniversalMachO::Terminate();
165 PlatformMacOSX::Terminate();
166 PlatformRemoteiOS::Terminate();
167 PlatformiOSSimulator::Terminate();
168
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000169 EmulateInstructionARM::Terminate();
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +0000170 EmulateInstructionMIPS::Terminate();
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +0000171 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000172
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000173#if defined(__APPLE__)
174 DynamicLoaderDarwinKernel::Terminate();
175 ObjectFileMachO::Terminate();
176 PlatformDarwinKernel::Terminate();
177#endif
178
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000179#if defined(_MSC_VER)
Zachary Turner610e5292015-05-07 21:39:33 +0000180 ProcessWindowsLog::Terminate();
181#endif
182
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000183#ifndef LLDB_DISABLE_PYTHON
184 OperatingSystemPython::Terminate();
185#endif
Ryan Brown65d4d5c2015-09-16 21:20:44 +0000186 OperatingSystemGo::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000187
188 Log::Terminate();
189}