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