Path: blob/main/contrib/llvm-project/lldb/tools/lldb-server/lldb-server.cpp
34879 views
//===-- lldb-server.cpp -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "SystemInitializerLLGS.h"9#include "lldb/Host/Config.h"10#include "lldb/Initialization/SystemLifetimeManager.h"11#include "lldb/Version/Version.h"1213#include "llvm/ADT/STLExtras.h"14#include "llvm/ADT/StringRef.h"15#include "llvm/Support/InitLLVM.h"16#include "llvm/Support/ManagedStatic.h"17#include "llvm/Support/PrettyStackTrace.h"18#include "llvm/Support/Signals.h"1920#include <cstdio>21#include <cstdlib>2223static llvm::ManagedStatic<lldb_private::SystemLifetimeManager>24g_debugger_lifetime;2526static void display_usage(const char *progname) {27fprintf(stderr, "Usage:\n"28" %s v[ersion]\n"29" %s g[dbserver] [options]\n"30" %s p[latform] [options]\n"31"Invoke subcommand for additional help\n",32progname, progname, progname);33exit(0);34}3536// Forward declarations of subcommand main methods.37int main_gdbserver(int argc, char *argv[]);38int main_platform(int argc, char *argv[]);3940namespace llgs {41static void initialize() {42if (auto e = g_debugger_lifetime->Initialize(43std::make_unique<SystemInitializerLLGS>(), nullptr))44llvm::consumeError(std::move(e));45}4647static void terminate_debugger() { g_debugger_lifetime->Terminate(); }48} // namespace llgs4950// main51int main(int argc, char *argv[]) {52llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);53llvm::setBugReportMsg("PLEASE submit a bug report to " LLDB_BUG_REPORT_URL54" and include the crash backtrace.\n");5556int option_error = 0;57const char *progname = argv[0];58if (argc < 2) {59display_usage(progname);60exit(option_error);61}6263switch (argv[1][0]) {64case 'g':65llgs::initialize();66main_gdbserver(argc, argv);67llgs::terminate_debugger();68break;69case 'p':70llgs::initialize();71main_platform(argc, argv);72llgs::terminate_debugger();73break;74case 'v':75fprintf(stderr, "%s\n", lldb_private::GetVersion());76break;77default:78display_usage(progname);79exit(option_error);80}81}828384