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/Host.h"
19 #include "lldb/Host/HostInfo.h"
20 #include "lldb/Utility/Log.h"
21 #include "lldb/Utility/Timer.h"
22 
23 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
24 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
25 #endif
26 
27 #if defined(_MSC_VER)
28 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
29 #include "lldb/Host/windows/windows.h"
30 #endif
31 
32 #include "llvm/Support/PrettyStackTrace.h"
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 #if not defined(__APPLE__)
67   llvm::EnablePrettyStackTrace();
68 #endif
69   Log::Initialize();
70   HostInfo::Initialize();
71   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
72   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
73 
74   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
75 
76   // Initialize plug-ins
77   ObjectContainerBSDArchive::Initialize();
78 
79   EmulateInstructionARM::Initialize();
80   EmulateInstructionMIPS::Initialize();
81   EmulateInstructionMIPS64::Initialize();
82 
83   //----------------------------------------------------------------------
84   // Apple/Darwin hosted plugins
85   //----------------------------------------------------------------------
86   ObjectContainerUniversalMachO::Initialize();
87 
88 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
89   ProcessPOSIXLog::Initialize();
90 #endif
91 #if defined(_MSC_VER)
92   ProcessWindowsLog::Initialize();
93 #endif
94 }
95 
96 void SystemInitializerCommon::Terminate() {
97   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
98   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
99   ObjectContainerBSDArchive::Terminate();
100 
101   EmulateInstructionARM::Terminate();
102   EmulateInstructionMIPS::Terminate();
103   EmulateInstructionMIPS64::Terminate();
104 
105   ObjectContainerUniversalMachO::Terminate();
106 
107 #if defined(_MSC_VER)
108   ProcessWindowsLog::Terminate();
109 #endif
110 
111   HostInfo::Terminate();
112   Log::DisableAllLogChannels();
113 }
114