1 //===-- 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 "Plugins/Instruction/ARM/EmulateInstructionARM.h"
13 #include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
14 #include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
15 #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h"
16 #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
17 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
18 #include "lldb/Host/FileSystem.h"
19 #include "lldb/Host/Host.h"
20 #include "lldb/Host/HostInfo.h"
21 #include "lldb/Utility/Log.h"
22 #include "lldb/Utility/Timer.h"
23 
24 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
25 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
26 #endif
27 
28 #if defined(_MSC_VER)
29 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
30 #include "lldb/Host/windows/windows.h"
31 #endif
32 
33 #include "llvm/Support/TargetSelect.h"
34 
35 #include <string>
36 
37 using namespace lldb_private;
38 
39 SystemInitializerCommon::SystemInitializerCommon() {}
40 
41 SystemInitializerCommon::~SystemInitializerCommon() {}
42 
43 void SystemInitializerCommon::Initialize() {
44 #if defined(_MSC_VER)
45   const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
46   if (disable_crash_dialog_var &&
47       llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
48     // This will prevent Windows from displaying a dialog box requiring user
49     // interaction when
50     // LLDB crashes.  This is mostly useful when automating LLDB, for example
51     // via the test
52     // suite, so that a crash in LLDB does not prevent completion of the test
53     // suite.
54     ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
55                    SEM_NOGPFAULTERRORBOX);
56 
57     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
58     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
59     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
60     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
61     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
62     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
63   }
64 #endif
65 
66   FileSystem::Initialize();
67   Log::Initialize();
68   HostInfo::Initialize();
69   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
70   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
71 
72   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
73 
74   // Initialize plug-ins
75   ObjectContainerBSDArchive::Initialize();
76 
77   EmulateInstructionARM::Initialize();
78   EmulateInstructionMIPS::Initialize();
79   EmulateInstructionMIPS64::Initialize();
80 
81   //----------------------------------------------------------------------
82   // Apple/Darwin hosted plugins
83   //----------------------------------------------------------------------
84   ObjectContainerUniversalMachO::Initialize();
85 
86 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
87   ProcessPOSIXLog::Initialize();
88 #endif
89 #if defined(_MSC_VER)
90   ProcessWindowsLog::Initialize();
91 #endif
92 }
93 
94 void SystemInitializerCommon::Terminate() {
95   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
96   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
97   ObjectContainerBSDArchive::Terminate();
98 
99   EmulateInstructionARM::Terminate();
100   EmulateInstructionMIPS::Terminate();
101   EmulateInstructionMIPS64::Terminate();
102 
103   ObjectContainerUniversalMachO::Terminate();
104 
105 #if defined(_MSC_VER)
106   ProcessWindowsLog::Terminate();
107 #endif
108 
109   HostInfo::Terminate();
110   Log::DisableAllLogChannels();
111   FileSystem::Terminate();
112 }
113