LLVM  16.0.0git
InitLLVM.cpp
Go to the documentation of this file.
1 //===-- InitLLVM.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 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Signals.h"
16 
17 #ifdef _WIN32
18 #include "llvm/Support/Error.h"
20 #endif
21 
22 using namespace llvm;
23 using namespace llvm::sys;
24 
25 InitLLVM::InitLLVM(int &Argc, const char **&Argv,
26  bool InstallPipeSignalExitHandler) {
27  if (InstallPipeSignalExitHandler)
28  // The pipe signal handler must be installed before any other handlers are
29  // registered. This is because the Unix \ref RegisterHandlers function does
30  // not perform a sigaction() for SIGPIPE unless a one-shot handler is
31  // present, to allow long-lived processes (like lldb) to fully opt-out of
32  // llvm's SIGPIPE handling and ignore the signal safely.
34  // Initialize the stack printer after installing the one-shot pipe signal
35  // handler, so we can perform a sigaction() for SIGPIPE on Unix if requested.
36  StackPrinter.emplace(Argc, Argv);
39 
40 #ifdef _WIN32
41  // We use UTF-8 as the internal character encoding. On Windows,
42  // arguments passed to main() may not be encoded in UTF-8. In order
43  // to reliably detect encoding of command line arguments, we use an
44  // Windows API to obtain arguments, convert them to UTF-8, and then
45  // write them back to the Argv vector.
46  //
47  // There's probably other way to do the same thing (e.g. using
48  // wmain() instead of main()), but this way seems less intrusive
49  // than that.
50  std::string Banner = std::string(Argv[0]) + ": ";
51  ExitOnError ExitOnErr(Banner);
52 
54 
55  // GetCommandLineArguments doesn't terminate the vector with a
56  // nullptr. Do it to make it compatible with the real argv.
57  Args.push_back(nullptr);
58 
59  Argc = Args.size() - 1;
60  Argv = Args.data();
61 #endif
62 }
63 
Signals.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::install_out_of_memory_new_handler
void install_out_of_memory_new_handler()
Definition: ErrorHandling.cpp:193
llvm::InitLLVM::~InitLLVM
~InitLLVM()
Definition: InitLLVM.cpp:64
StringRef.h
ErrorHandling.h
ManagedStatic.h
Error.h
SwapByteOrder.h
WindowsSupport.h
llvm::ExitOnError
Helper for check-and-exit error handling.
Definition: Error.h:1347
llvm::llvm_shutdown
void llvm_shutdown()
llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
Definition: ManagedStatic.cpp:75
llvm::sys
Definition: Atomic.h:28
InitLLVM.h
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:92
llvm::sys::DefaultOneShotPipeSignalHandler
void DefaultOneShotPipeSignalHandler()
On Unix systems, this function exits with an "IO error" exit code.
llvm::InitLLVM::InitLLVM
InitLLVM(int &Argc, const char **&Argv, bool InstallPipeSignalExitHandler=true)
Definition: InitLLVM.cpp:25
llvm::sys::windows::GetCommandLineArguments
std::error_code GetCommandLineArguments(SmallVectorImpl< const char * > &Args, BumpPtrAllocator &Alloc)
PrettyStackTrace.h
llvm::sys::SetOneShotPipeSignalFunction
void SetOneShotPipeSignalFunction(void(*Handler)())
Registers a function to be called in a "one-shot" manner when a pipe signal is delivered to the proce...
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::sys::PrintStackTraceOnErrorSignal
void PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting=false)
When an error signal (such as SIGABRT or SIGSEGV) is delivered to the process, print a stack trace an...