llvm-project
82 строки · 2.4 Кб
1//===-- lldb-server.cpp -----------------------------------------*- C++ -*-===//
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
9#include "SystemInitializerLLGS.h"
10#include "lldb/Host/Config.h"
11#include "lldb/Initialization/SystemLifetimeManager.h"
12#include "lldb/Version/Version.h"
13
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/InitLLVM.h"
17#include "llvm/Support/ManagedStatic.h"
18#include "llvm/Support/PrettyStackTrace.h"
19#include "llvm/Support/Signals.h"
20
21#include <cstdio>
22#include <cstdlib>
23
24static llvm::ManagedStatic<lldb_private::SystemLifetimeManager>
25g_debugger_lifetime;
26
27static void display_usage(const char *progname) {
28fprintf(stderr, "Usage:\n"
29" %s v[ersion]\n"
30" %s g[dbserver] [options]\n"
31" %s p[latform] [options]\n"
32"Invoke subcommand for additional help\n",
33progname, progname, progname);
34exit(0);
35}
36
37// Forward declarations of subcommand main methods.
38int main_gdbserver(int argc, char *argv[]);
39int main_platform(int argc, char *argv[]);
40
41namespace llgs {
42static void initialize() {
43if (auto e = g_debugger_lifetime->Initialize(
44std::make_unique<SystemInitializerLLGS>(), nullptr))
45llvm::consumeError(std::move(e));
46}
47
48static void terminate_debugger() { g_debugger_lifetime->Terminate(); }
49} // namespace llgs
50
51// main
52int main(int argc, char *argv[]) {
53llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);
54llvm::setBugReportMsg("PLEASE submit a bug report to " LLDB_BUG_REPORT_URL
55" and include the crash backtrace.\n");
56
57int option_error = 0;
58const char *progname = argv[0];
59if (argc < 2) {
60display_usage(progname);
61exit(option_error);
62}
63
64switch (argv[1][0]) {
65case 'g':
66llgs::initialize();
67main_gdbserver(argc, argv);
68llgs::terminate_debugger();
69break;
70case 'p':
71llgs::initialize();
72main_platform(argc, argv);
73llgs::terminate_debugger();
74break;
75case 'v':
76fprintf(stderr, "%s\n", lldb_private::GetVersion());
77break;
78default:
79display_usage(progname);
80exit(option_error);
81}
82}
83