blob: 805e6091e68aba7e90d392996ad3a970d16fffcb [file] [log] [blame]
Zachary Turnere6e2bb32015-03-31 21:03:22 +00001//===-- 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
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000012#include "Plugins/Instruction/ARM/EmulateInstructionARM.h"
Bhushan D. Attarde794a4d52015-05-15 06:53:30 +000013#include "Plugins/Instruction/MIPS/EmulateInstructionMIPS.h"
Mohit K. Bhakkadcdc22a82015-05-07 05:56:27 +000014#include "Plugins/Instruction/MIPS64/EmulateInstructionMIPS64.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000015#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"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000019#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000020#include "lldb/Core/Timer.h"
21#include "lldb/Host/Host.h"
22#include "lldb/Host/HostInfo.h"
Zachary Turner6f9e6902017-03-03 20:56:28 +000023#include "lldb/Utility/Log.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000024
25#if defined(__APPLE__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000026#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000027#endif
28
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000029#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Zachary Turnere6e2bb32015-03-31 21:03:22 +000030#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
31#endif
32
33#if defined(_MSC_VER)
Adrian McCarthy18a9135d2015-10-28 18:21:45 +000034#include "Plugins/Process/Windows/Common/ProcessWindowsLog.h"
Zachary Turner74e08ca2016-03-02 22:05:52 +000035#include "lldb/Host/windows/windows.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000036#endif
37
Sean Callanan237c3ed2016-12-14 21:31:31 +000038#include "llvm/Support/PrettyStackTrace.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000039#include "llvm/Support/TargetSelect.h"
40
41#include <string>
42
43using namespace lldb_private;
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045SystemInitializerCommon::SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047SystemInitializerCommon::~SystemInitializerCommon() {}
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049void SystemInitializerCommon::Initialize() {
Zachary Turnere6e2bb32015-03-31 21:03:22 +000050#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +000051 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);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 _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 }
Zachary Turnere6e2bb32015-03-31 21:03:22 +000070#endif
71
Sean Callanan237c3ed2016-12-14 21:31:31 +000072 llvm::EnablePrettyStackTrace();
Pavel Labatha2fc1e02017-02-22 11:51:12 +000073 InitializeLog();
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 HostInfo::Initialize();
75 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
Zachary Turnere6e2bb32015-03-31 21:03:22 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 process_gdb_remote::ProcessGDBRemoteLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 // Initialize plug-ins
80 ObjectContainerBSDArchive::Initialize();
81 ObjectFileELF::Initialize();
82 ObjectFilePECOFF::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 EmulateInstructionARM::Initialize();
85 EmulateInstructionMIPS::Initialize();
86 EmulateInstructionMIPS64::Initialize();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 //----------------------------------------------------------------------
89 // Apple/Darwin hosted plugins
90 //----------------------------------------------------------------------
91 ObjectContainerUniversalMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000092
93#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 ObjectFileMachO::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000095#endif
Kamil Rytarowskia87101d2017-03-21 17:26:55 +000096#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
Pavel Labathc29f7ff2017-02-23 10:33:16 +000097 ProcessPOSIXLog::Initialize();
Zachary Turnere6e2bb32015-03-31 21:03:22 +000098#endif
Adrian McCarthy42b33802015-04-10 16:18:08 +000099#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 ProcessWindowsLog::Initialize();
Adrian McCarthy42b33802015-04-10 16:18:08 +0000101#endif
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000102}
103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104void SystemInitializerCommon::Terminate() {
105 Timer scoped_timer(LLVM_PRETTY_FUNCTION, LLVM_PRETTY_FUNCTION);
106 ObjectContainerBSDArchive::Terminate();
107 ObjectFileELF::Terminate();
108 ObjectFilePECOFF::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000109
Kate Stoneb9c1b512016-09-06 20:57:50 +0000110 EmulateInstructionARM::Terminate();
111 EmulateInstructionMIPS::Terminate();
112 EmulateInstructionMIPS64::Terminate();
Tamas Berghammerd8c338d2015-04-15 09:47:02 +0000113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 ObjectContainerUniversalMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000115#if defined(__APPLE__)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000116 ObjectFileMachO::Terminate();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000117#endif
118
Hafiz Abid Qadeer23a4df22015-09-04 16:34:19 +0000119#if defined(_MSC_VER)
Kate Stoneb9c1b512016-09-06 20:57:50 +0000120 ProcessWindowsLog::Terminate();
Zachary Turner610e5292015-05-07 21:39:33 +0000121#endif
122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123 HostInfo::Terminate();
Pavel Labath775588c2017-03-15 09:06:58 +0000124 Log::DisableAllLogChannels();
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000125}