]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Initialization/SystemInitializerCommon.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / 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 #ifdef LLDB_ENABLE_ALL
17 #include "Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h"
18 #endif // LLDB_ENABLE_ALL
19 #include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
20 #include "lldb/Host/FileSystem.h"
21 #include "lldb/Host/Host.h"
22 #include "lldb/Host/HostInfo.h"
23 #include "lldb/Utility/Log.h"
24 #include "lldb/Utility/Reproducer.h"
25 #include "lldb/Utility/Timer.h"
26
27 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
28 #include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
29 #endif
30
31 #if defined(_MSC_VER)
32 #include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
33 #include "lldb/Host/windows/windows.h"
34 #endif
35
36 #include "llvm/Support/TargetSelect.h"
37
38 #include <string>
39
40 using namespace lldb_private;
41 using namespace lldb_private::repro;
42
43 SystemInitializerCommon::SystemInitializerCommon() {}
44
45 SystemInitializerCommon::~SystemInitializerCommon() {}
46
47 llvm::Error
48 SystemInitializerCommon::Initialize(const InitializerOptions &options) {
49 #if defined(_MSC_VER)
50   const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
51   if (disable_crash_dialog_var &&
52       llvm::StringRef(disable_crash_dialog_var).equals_lower("true")) {
53     // This will prevent Windows from displaying a dialog box requiring user
54     // interaction when
55     // LLDB crashes.  This is mostly useful when automating LLDB, for example
56     // via the test
57     // suite, so that a crash in LLDB does not prevent completion of the test
58     // suite.
59     ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
60                    SEM_NOGPFAULTERRORBOX);
61
62     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
63     _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
64     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
65     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
66     _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
67     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
68   }
69 #endif
70
71   ReproducerMode mode = ReproducerMode::Off;
72   if (options.reproducer_capture)
73     mode = ReproducerMode::Capture;
74   if (options.reproducer_replay)
75     mode = ReproducerMode::Replay;
76
77   if (auto e = Reproducer::Initialize(mode, FileSpec(options.reproducer_path)))
78     return e;
79
80   FileSystem::Initialize();
81   Log::Initialize();
82   HostInfo::Initialize();
83   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
84   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
85
86   process_gdb_remote::ProcessGDBRemoteLog::Initialize();
87
88   // Initialize plug-ins
89   ObjectContainerBSDArchive::Initialize();
90
91   EmulateInstructionARM::Initialize();
92   EmulateInstructionMIPS::Initialize();
93   EmulateInstructionMIPS64::Initialize();
94
95   //----------------------------------------------------------------------
96   // Apple/Darwin hosted plugins
97   //----------------------------------------------------------------------
98 #ifdef LLDB_ENABLE_ALL
99   ObjectContainerUniversalMachO::Initialize();
100 #endif // LLDB_ENABLE_ALL
101
102 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
103   ProcessPOSIXLog::Initialize();
104 #endif
105 #if defined(_MSC_VER)
106   ProcessWindowsLog::Initialize();
107 #endif
108
109   return llvm::Error::success();
110 }
111
112 void SystemInitializerCommon::Terminate() {
113   static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
114   Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION);
115   ObjectContainerBSDArchive::Terminate();
116
117   EmulateInstructionARM::Terminate();
118   EmulateInstructionMIPS::Terminate();
119   EmulateInstructionMIPS64::Terminate();
120
121 #ifdef LLDB_ENABLE_ALL
122   ObjectContainerUniversalMachO::Terminate();
123 #endif // LLDB_ENABLE_ALL
124
125 #if defined(_MSC_VER)
126   ProcessWindowsLog::Terminate();
127 #endif
128
129   HostInfo::Terminate();
130   Log::DisableAllLogChannels();
131   FileSystem::Terminate();
132   Reproducer::Terminate();
133 }