2015-02-18 23:39:41 +08:00
|
|
|
//===-- lldb-server.cpp -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-02-18 23:39:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-05-24 20:44:18 +08:00
|
|
|
#include "SystemInitializerLLGS.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "lldb/Initialization/SystemLifetimeManager.h"
|
2016-02-10 18:35:48 +08:00
|
|
|
#include "lldb/lldb-private.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2018-07-17 18:04:19 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2019-10-11 19:47:07 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2015-04-01 05:03:22 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2018-07-17 18:04:19 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
2015-03-02 23:14:50 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2015-02-18 23:39:41 +08:00
|
|
|
|
2015-04-01 05:03:22 +08:00
|
|
|
static llvm::ManagedStatic<lldb_private::SystemLifetimeManager>
|
|
|
|
g_debugger_lifetime;
|
|
|
|
|
2015-02-18 23:39:41 +08:00
|
|
|
static void display_usage(const char *progname) {
|
|
|
|
fprintf(stderr, "Usage:\n"
|
2016-02-10 18:35:48 +08:00
|
|
|
" %s v[ersion]\n"
|
2015-02-18 23:39:41 +08:00
|
|
|
" %s g[dbserver] [options]\n"
|
|
|
|
" %s p[latform] [options]\n"
|
2016-02-10 18:35:48 +08:00
|
|
|
"Invoke subcommand for additional help\n",
|
|
|
|
progname, progname, progname);
|
2015-02-18 23:39:41 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forward declarations of subcommand main methods.
|
|
|
|
int main_gdbserver(int argc, char *argv[]);
|
|
|
|
int main_platform(int argc, char *argv[]);
|
|
|
|
|
2019-04-03 01:10:12 +08:00
|
|
|
namespace llgs {
|
2015-03-02 23:14:50 +08:00
|
|
|
static void initialize() {
|
2018-12-04 01:28:29 +08:00
|
|
|
if (auto e = g_debugger_lifetime->Initialize(
|
2019-08-15 06:19:23 +08:00
|
|
|
std::make_unique<SystemInitializerLLGS>(), nullptr))
|
2018-12-04 01:28:29 +08:00
|
|
|
llvm::consumeError(std::move(e));
|
2015-03-02 23:14:50 +08:00
|
|
|
}
|
|
|
|
|
2019-05-15 01:07:36 +08:00
|
|
|
static void terminate_debugger() { g_debugger_lifetime->Terminate(); }
|
2019-04-03 01:10:12 +08:00
|
|
|
} // namespace llgs
|
2015-03-02 23:14:50 +08:00
|
|
|
|
2015-02-18 23:39:41 +08:00
|
|
|
// main
|
|
|
|
int main(int argc, char *argv[]) {
|
2019-11-15 06:30:56 +08:00
|
|
|
llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);
|
2018-07-17 18:04:19 +08:00
|
|
|
llvm::PrettyStackTraceProgram X(argc, argv);
|
|
|
|
|
2015-02-18 23:39:41 +08:00
|
|
|
int option_error = 0;
|
|
|
|
const char *progname = argv[0];
|
|
|
|
if (argc < 2) {
|
|
|
|
display_usage(progname);
|
|
|
|
exit(option_error);
|
|
|
|
}
|
2016-02-10 18:35:48 +08:00
|
|
|
|
|
|
|
switch (argv[1][0]) {
|
|
|
|
case 'g':
|
2019-04-03 01:10:12 +08:00
|
|
|
llgs::initialize();
|
2016-02-10 18:35:48 +08:00
|
|
|
main_gdbserver(argc, argv);
|
2019-05-15 01:07:36 +08:00
|
|
|
llgs::terminate_debugger();
|
2016-02-10 18:35:48 +08:00
|
|
|
break;
|
|
|
|
case 'p':
|
2019-04-03 01:10:12 +08:00
|
|
|
llgs::initialize();
|
2016-02-10 18:35:48 +08:00
|
|
|
main_platform(argc, argv);
|
2019-05-15 01:07:36 +08:00
|
|
|
llgs::terminate_debugger();
|
2016-02-10 18:35:48 +08:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
fprintf(stderr, "%s\n", lldb_private::GetVersion());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
display_usage(progname);
|
|
|
|
exit(option_error);
|
2015-02-18 23:39:41 +08:00
|
|
|
}
|
|
|
|
}
|