]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Initialization/SystemInitializerCommon.cpp
Vendor import of lldb trunk r321017:
[FreeBSD/FreeBSD.git] / source / Initialization / SystemInitializerCommon.cpp
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/Host/Host.h"
21 #include "lldb/Host/HostInfo.h"
22 #include "lldb/Utility/Log.h"
23 #include "lldb/Utility/Timer.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 #if not defined(__APPLE__)
73   llvm::EnablePrettyStackTrace();
74 #endif
75   Log::Initialize();
76   HostInfo::Initialize();
77   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
78   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
79
80   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
81
82   // Initialize plug-ins
83   ObjectContainerBSDArchive::Initialize();
84   ObjectFileELF::Initialize();
85   ObjectFilePECOFF::Initialize();
86
87   EmulateInstructionARM::Initialize();
88   EmulateInstructionMIPS::Initialize();
89   EmulateInstructionMIPS64::Initialize();
90
91   //----------------------------------------------------------------------
92   // Apple/Darwin hosted plugins
93   //----------------------------------------------------------------------
94   ObjectContainerUniversalMachO::Initialize();
95
96 #if defined(__APPLE__)
97   ObjectFileMachO::Initialize();
98 #endif
99 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
100   ProcessPOSIXLog::Initialize();
101 #endif
102 #if defined(_MSC_VER)
103   ProcessWindowsLog::Initialize();
104 #endif
105 }
106
107 void SystemInitializerCommon::Terminate() {
108   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
109   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
110   ObjectContainerBSDArchive::Terminate();
111   ObjectFileELF::Terminate();
112   ObjectFilePECOFF::Terminate();
113
114   EmulateInstructionARM::Terminate();
115   EmulateInstructionMIPS::Terminate();
116   EmulateInstructionMIPS64::Terminate();
117
118   ObjectContainerUniversalMachO::Terminate();
119 #if defined(__APPLE__)
120   ObjectFileMachO::Terminate();
121 #endif
122
123 #if defined(_MSC_VER)
124   ProcessWindowsLog::Terminate();
125 #endif
126
127   HostInfo::Terminate();
128   Log::DisableAllLogChannels();
129 }