LLDB  mainline
SystemInitializerCommon.cpp
Go to the documentation of this file.
1 //===-- SystemInitializerCommon.cpp ---------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/Host.h"
14 #include "lldb/Host/Socket.h"
15 #include "lldb/Utility/LLDBLog.h"
17 #include "lldb/Utility/Timer.h"
18 #include "lldb/Version/Version.h"
19 
20 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
22 #endif
23 
24 #if defined(_WIN32)
27 #include <crtdbg.h>
28 #endif
29 
30 #include "llvm/Support/TargetSelect.h"
31 
32 #include <string>
33 
34 using namespace lldb_private;
35 using namespace lldb_private::repro;
36 
38  HostInfo::SharedLibraryDirectoryHelper *helper)
39  : m_shlib_dir_helper(helper) {}
40 
42 
43 /// Initialize the FileSystem based on the current reproducer mode.
45  auto &r = repro::Reproducer::Instance();
46 
47  if (repro::Generator *g = r.GetGenerator()) {
48  repro::VersionProvider &vp = g->GetOrCreate<repro::VersionProvider>();
50 
51  repro::FileProvider &fp = g->GetOrCreate<repro::FileProvider>();
52 
53  FileSystem::Initialize(llvm::FileCollector::createCollectorVFS(
54  llvm::vfs::getRealFileSystem(), fp.GetFileCollector()));
55 
56  fp.RecordInterestingDirectory(
57  g->GetOrCreate<repro::WorkingDirectoryProvider>().GetDirectory());
58  fp.RecordInterestingDirectory(
59  g->GetOrCreate<repro::HomeDirectoryProvider>().GetDirectory());
60 
61  return llvm::Error::success();
62  }
63 
65  return llvm::Error::success();
66 }
67 
69 #if defined(_WIN32)
70  const char *disable_crash_dialog_var = getenv("LLDB_DISABLE_CRASH_DIALOG");
71  if (disable_crash_dialog_var &&
72  llvm::StringRef(disable_crash_dialog_var).equals_insensitive("true")) {
73  // This will prevent Windows from displaying a dialog box requiring user
74  // interaction when
75  // LLDB crashes. This is mostly useful when automating LLDB, for example
76  // via the test
77  // suite, so that a crash in LLDB does not prevent completion of the test
78  // suite.
79  ::SetErrorMode(GetErrorMode() | SEM_FAILCRITICALERRORS |
80  SEM_NOGPFAULTERRORBOX);
81 
82  _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
83  _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
84  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
85  _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
86  _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
87  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
88  }
89 #endif
90 
91  // If the reproducer wasn't initialized before, we can safely assume it's
92  // off.
93  if (!Reproducer::Initialized()) {
94  if (auto e = Reproducer::Initialize(ReproducerMode::Off, llvm::None))
95  return e;
96  }
97 
98  if (auto e = InitializeFileSystem())
99  return e;
100 
102  HostInfo::Initialize(m_shlib_dir_helper);
103 
105  if (error)
106  return error;
107 
109 
111 
112 #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
114 #endif
115 #if defined(_WIN32)
117 #endif
118 
119  return llvm::Error::success();
120 }
121 
124 
125 #if defined(_WIN32)
127 #endif
128 
130  HostInfo::Terminate();
133  Reproducer::Terminate();
134 }
lldb_private::ProcessWindowsLog::Initialize
static void Initialize()
Definition: ProcessWindowsLog.cpp:30
FileSystem.h
lldb_private::process_gdb_remote::ProcessGDBRemoteLog::Initialize
static void Initialize()
Definition: ProcessGDBRemoteLog.cpp:42
lldb_private::SystemInitializerCommon::m_shlib_dir_helper
HostInfo::SharedLibraryDirectoryHelper * m_shlib_dir_helper
Definition: SystemInitializerCommon.h:33
lldb_private::ProcessPOSIXLog::Initialize
static void Initialize()
Definition: ProcessPOSIXLog.cpp:31
Host.h
SystemInitializerCommon.h
lldb_private::GetVersion
const char * GetVersion()
Retrieves a string representing the complete LLDB version, which includes the lldb version number,...
Definition: Version.cpp:38
lldb_private::Socket::Initialize
static llvm::Error Initialize()
Definition: Socket.cpp:81
lldb_private::InitializeLldbChannel
void InitializeLldbChannel()
Definition: LLDBLog.cpp:80
lldb_private::repro::FileProvider
Definition: ReproducerProvider.h:94
ProcessWindowsLog.h
ReproducerProvider.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::SystemInitializerCommon::Initialize
llvm::Error Initialize() override
Definition: SystemInitializerCommon.cpp:68
lldb_private::FileSystem::Terminate
static void Terminate()
Definition: common/FileSystem.cpp:58
Version.h
lldb_private::Log::DisableAllLogChannels
static void DisableAllLogChannels()
Definition: Log.cpp:268
Socket.h
Timer.h
ProcessPOSIXLog.h
LLDB_SCOPED_TIMER
#define LLDB_SCOPED_TIMER()
Definition: Timer.h:83
lldb_private::repro::VersionProvider
Provider for the LLDB version number.
Definition: ReproducerProvider.h:126
lldb_private::SystemInitializerCommon::~SystemInitializerCommon
~SystemInitializerCommon() override
lldb_private::FileSystem::Initialize
static void Initialize()
Definition: common/FileSystem.cpp:48
lldb_private::repro::VersionProvider::SetVersion
void SetVersion(std::string version)
Definition: ReproducerProvider.h:133
lldb_private::ProcessWindowsLog::Terminate
static void Terminate()
Definition: ProcessWindowsLog.cpp:35
lldb_private::Socket::Terminate
static void Terminate()
Definition: Socket.cpp:100
lldb_private::SystemInitializerCommon::SystemInitializerCommon
SystemInitializerCommon(HostInfo::SharedLibraryDirectoryHelper *helper)
Definition: SystemInitializerCommon.cpp:37
lldb_private::repro
Definition: SBReproducer.h:15
InitializeFileSystem
static llvm::Error InitializeFileSystem()
Initialize the FileSystem based on the current reproducer mode.
Definition: SystemInitializerCommon.cpp:44
windows.h
ProcessGDBRemoteLog.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:30
lldb_private::SystemInitializerCommon::Terminate
void Terminate() override
Definition: SystemInitializerCommon.cpp:122
fp
@ fp
Definition: CompactUnwindInfo.cpp:1248
lldb_private::repro::HomeDirectoryProvider
Provider for the home directory.
Definition: ReproducerProvider.h:189
lldb_private::repro::Reproducer::Instance
static Reproducer & Instance()
Definition: Reproducer.cpp:23
lldb_private::repro::Generator
The generator is responsible for the logic needed to generate a reproducer.
Definition: Reproducer.h:89
LLDBLog.h
lldb_private::repro::WorkingDirectoryProvider
Provider for the current working directory.
Definition: ReproducerProvider.h:168
lldb_private::repro::DirectoryProvider::GetDirectory
llvm::StringRef GetDirectory()
Definition: ReproducerProvider.h:149