Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,136 @@
//===-- Acceptor.cpp --------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "Acceptor.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ScopedPrinter.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/common/TCPSocket.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/UriParser.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::lldb_server;
using namespace llvm;
namespace {
struct SocketScheme {
const char *m_scheme;
const Socket::SocketProtocol m_protocol;
};
SocketScheme socket_schemes[] = {
{"tcp", Socket::ProtocolTcp},
{"udp", Socket::ProtocolUdp},
{"unix", Socket::ProtocolUnixDomain},
{"unix-abstract", Socket::ProtocolUnixAbstract},
};
bool FindProtocolByScheme(const char *scheme,
Socket::SocketProtocol &protocol) {
for (auto s : socket_schemes) {
if (!strcmp(s.m_scheme, scheme)) {
protocol = s.m_protocol;
return true;
}
}
return false;
}
const char *FindSchemeByProtocol(const Socket::SocketProtocol protocol) {
for (auto s : socket_schemes) {
if (s.m_protocol == protocol)
return s.m_scheme;
}
return nullptr;
}
}
Status Acceptor::Listen(int backlog) {
return m_listener_socket_up->Listen(StringRef(m_name), backlog);
}
Status Acceptor::Accept(const bool child_processes_inherit, Connection *&conn) {
Socket *conn_socket = nullptr;
auto error = m_listener_socket_up->Accept(conn_socket);
if (error.Success())
conn = new ConnectionFileDescriptor(conn_socket);
return error;
}
Socket::SocketProtocol Acceptor::GetSocketProtocol() const {
return m_listener_socket_up->GetSocketProtocol();
}
const char *Acceptor::GetSocketScheme() const {
return FindSchemeByProtocol(GetSocketProtocol());
}
std::string Acceptor::GetLocalSocketId() const { return m_local_socket_id(); }
std::unique_ptr<Acceptor> Acceptor::Create(StringRef name,
const bool child_processes_inherit,
Status &error) {
error.Clear();
Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain;
int port;
StringRef scheme, host, path;
// Try to match socket name as URL - e.g., tcp://localhost:5555
if (UriParser::Parse(name, scheme, host, port, path)) {
if (!FindProtocolByScheme(scheme.str().c_str(), socket_protocol))
error.SetErrorStringWithFormat("Unknown protocol scheme \"%s\"",
scheme.str().c_str());
else
name = name.drop_front(scheme.size() + strlen("://"));
} else {
std::string host_str;
std::string port_str;
int32_t port = INT32_MIN;
// Try to match socket name as $host:port - e.g., localhost:5555
if (Socket::DecodeHostAndPort(name, host_str, port_str, port, nullptr))
socket_protocol = Socket::ProtocolTcp;
}
if (error.Fail())
return std::unique_ptr<Acceptor>();
std::unique_ptr<Socket> listener_socket_up =
Socket::Create(socket_protocol, child_processes_inherit, error);
LocalSocketIdFunc local_socket_id;
if (error.Success()) {
if (listener_socket_up->GetSocketProtocol() == Socket::ProtocolTcp) {
TCPSocket *tcp_socket =
static_cast<TCPSocket *>(listener_socket_up.get());
local_socket_id = [tcp_socket]() {
auto local_port = tcp_socket->GetLocalPortNumber();
return (local_port != 0) ? llvm::to_string(local_port) : "";
};
} else {
const std::string socket_name = name;
local_socket_id = [socket_name]() { return socket_name; };
}
return std::unique_ptr<Acceptor>(
new Acceptor(std::move(listener_socket_up), name, local_socket_id));
}
return std::unique_ptr<Acceptor>();
}
Acceptor::Acceptor(std::unique_ptr<Socket> &&listener_socket, StringRef name,
const LocalSocketIdFunc &local_socket_id)
: m_listener_socket_up(std::move(listener_socket)), m_name(name.str()),
m_local_socket_id(local_socket_id) {}

View File

@@ -0,0 +1,61 @@
//===-- Acceptor.h ----------------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_server_Acceptor_h_
#define lldb_server_Acceptor_h_
#include "lldb/Host/Socket.h"
#include "lldb/Utility/Connection.h"
#include "lldb/Utility/Status.h"
#include <functional>
#include <memory>
#include <string>
namespace llvm {
class StringRef;
}
namespace lldb_private {
namespace lldb_server {
class Acceptor {
public:
virtual ~Acceptor() = default;
Status Listen(int backlog);
Status Accept(const bool child_processes_inherit, Connection *&conn);
static std::unique_ptr<Acceptor> Create(llvm::StringRef name,
const bool child_processes_inherit,
Status &error);
Socket::SocketProtocol GetSocketProtocol() const;
const char *GetSocketScheme() const;
// Returns either TCP port number as string or domain socket path.
// Empty string is returned in case of error.
std::string GetLocalSocketId() const;
private:
typedef std::function<std::string()> LocalSocketIdFunc;
Acceptor(std::unique_ptr<Socket> &&listener_socket, llvm::StringRef name,
const LocalSocketIdFunc &local_socket_id);
const std::unique_ptr<Socket> m_listener_socket_up;
const std::string m_name;
const LocalSocketIdFunc m_local_socket_id;
};
} // namespace lldb_server
} // namespace lldb_private
#endif // lldb_server_Acceptor_h_

View File

@@ -0,0 +1,57 @@
if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
include_directories(
../../../../llvm/include
../../source/Plugins/Process/Linux
../../source/Plugins/Process/POSIX
)
endif ()
if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
include_directories(
../../../../llvm/include
../../source/Plugins/Process/FreeBSD
../../source/Plugins/Process/POSIX
)
endif ()
if ( CMAKE_SYSTEM_NAME MATCHES "NetBSD" )
include_directories(
../../../../llvm/include
../../source/Plugins/Process/NetBSD
../../source/Plugins/Process/POSIX
)
endif ()
include_directories(../../source)
set(LLDB_PLUGINS)
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
list(APPEND LLDB_PLUGINS lldbPluginProcessLinux)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "NetBSD")
list(APPEND LLDB_PLUGINS lldbPluginProcessNetBSD)
endif()
add_lldb_tool(lldb-server INCLUDE_IN_FRAMEWORK
Acceptor.cpp
lldb-gdbserver.cpp
lldb-platform.cpp
lldb-server.cpp
LLDBServerUtilities.cpp
LINK_LIBS
lldbBase
lldbCore
lldbHost
lldbInitialization
lldbInterpreter
${LLDB_PLUGINS}
${LLDB_SYSTEM_LIBS}
LINK_COMPONENTS
Support
)
target_link_libraries(lldb-server PRIVATE ${LLDB_SYSTEM_LIBS})

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.lldb-server</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>lldb-server</string>
<key>CFBundleVersion</key>
<string>2</string>
<key>SecTaskAccess</key>
<array>
<string>allowed</string>
<string>debug</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>com.apple.backboardd.launchapplications</key>
<true/>
<key>com.apple.backboardd.debugapplications</key>
<true/>
<key>com.apple.frontboard.launchapplications</key>
<true/>
<key>com.apple.frontboard.debugapplications</key>
<true/>
<key>run-unsigned-code</key>
<true/>
<key>seatbelt-profiles</key>
<array>
<string>debugserver</string>
</array>
<key>com.apple.diagnosticd.diagnostic</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.diagnosticd.diagnostic</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,5 @@
/*
* nub.defs
*/
#import <mach/mach_exc.defs>

View File

@@ -0,0 +1,65 @@
//===-- LLDBServerUtilities.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "LLDBServerUtilities.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Interpreter/Args.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
using namespace lldb;
using namespace lldb_private::lldb_server;
using namespace llvm;
static std::shared_ptr<raw_ostream> GetLogStream(StringRef log_file) {
if (!log_file.empty()) {
std::error_code EC;
std::shared_ptr<raw_ostream> stream_sp = std::make_shared<raw_fd_ostream>(
log_file, EC, sys::fs::F_Text | sys::fs::F_Append);
if (!EC)
return stream_sp;
errs() << llvm::formatv(
"Failed to open log file `{0}`: {1}\nWill log to stderr instead.\n",
log_file, EC.message());
}
// No need to delete the stderr stream.
return std::shared_ptr<raw_ostream>(&errs(), [](raw_ostream *) {});
}
bool LLDBServerUtilities::SetupLogging(const std::string &log_file,
const StringRef &log_channels,
uint32_t log_options) {
auto log_stream_sp = GetLogStream(log_file);
SmallVector<StringRef, 32> channel_array;
log_channels.split(channel_array, ":", /*MaxSplit*/ -1, /*KeepEmpty*/ false);
for (auto channel_with_categories : channel_array) {
std::string error;
llvm::raw_string_ostream error_stream(error);
Args channel_then_categories(channel_with_categories);
std::string channel(channel_then_categories.GetArgumentAtIndex(0));
channel_then_categories.Shift(); // Shift off the channel
bool success = Log::EnableLogChannel(
log_stream_sp, log_options, channel,
channel_then_categories.GetArgumentArrayRef(), error_stream);
if (!success) {
errs() << formatv("Unable to setup logging for channel \"{0}\": {1}",
channel, error_stream.str());
return false;
}
}
return true;
}

View File

@@ -0,0 +1,24 @@
//===-- LLDBServerUtilities.h -----------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
#include <string>
namespace lldb_private {
namespace lldb_server {
class LLDBServerUtilities {
public:
static bool SetupLogging(const std::string &log_file,
const llvm::StringRef &log_channels,
uint32_t log_options);
};
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,380 @@
//===-- lldb-platform.cpp ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// C Includes
#include <errno.h>
#if defined(__APPLE__)
#include <netinet/in.h>
#endif
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
// C++ Includes
#include <fstream>
// Other libraries and framework includes
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
#include "Acceptor.h"
#include "LLDBServerUtilities.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.h"
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/HostGetOpt.h"
#include "lldb/Host/OptionParser.h"
#include "lldb/Host/common/TCPSocket.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Status.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::lldb_server;
using namespace lldb_private::process_gdb_remote;
using namespace llvm;
//----------------------------------------------------------------------
// option descriptors for getopt_long_only()
//----------------------------------------------------------------------
static int g_debug = 0;
static int g_verbose = 0;
static int g_server = 0;
static struct option g_long_options[] = {
{"debug", no_argument, &g_debug, 1},
{"verbose", no_argument, &g_verbose, 1},
{"log-file", required_argument, NULL, 'l'},
{"log-channels", required_argument, NULL, 'c'},
{"listen", required_argument, NULL, 'L'},
{"port-offset", required_argument, NULL, 'p'},
{"gdbserver-port", required_argument, NULL, 'P'},
{"min-gdbserver-port", required_argument, NULL, 'm'},
{"max-gdbserver-port", required_argument, NULL, 'M'},
{"socket-file", required_argument, NULL, 'f'},
{"server", no_argument, &g_server, 1},
{NULL, 0, NULL, 0}};
#if defined(__APPLE__)
#define LOW_PORT (IPPORT_RESERVED)
#define HIGH_PORT (IPPORT_HIFIRSTAUTO)
#else
#define LOW_PORT (1024u)
#define HIGH_PORT (49151u)
#endif
//----------------------------------------------------------------------
// Watch for signals
//----------------------------------------------------------------------
static void signal_handler(int signo) {
switch (signo) {
case SIGHUP:
// Use SIGINT first, if that does not work, use SIGHUP as a last resort.
// And we should not call exit() here because it results in the global
// destructors
// to be invoked and wreaking havoc on the threads still running.
Host::SystemLog(Host::eSystemLogWarning,
"SIGHUP received, exiting lldb-server...\n");
abort();
break;
}
}
static void display_usage(const char *progname, const char *subcommand) {
fprintf(stderr, "Usage:\n %s %s [--log-file log-file-name] [--log-channels "
"log-channel-list] [--port-file port-file-path] --server "
"--listen port\n",
progname, subcommand);
exit(0);
}
static Status save_socket_id_to_file(const std::string &socket_id,
const FileSpec &file_spec) {
FileSpec temp_file_spec(file_spec.GetDirectory().AsCString(), false);
Status error(llvm::sys::fs::create_directory(temp_file_spec.GetPath()));
if (error.Fail())
return Status("Failed to create directory %s: %s",
temp_file_spec.GetCString(), error.AsCString());
llvm::SmallString<64> temp_file_path;
temp_file_spec.AppendPathComponent("port-file.%%%%%%");
int FD;
auto err_code = llvm::sys::fs::createUniqueFile(temp_file_spec.GetPath(), FD,
temp_file_path);
if (err_code)
return Status("Failed to create temp file: %s", err_code.message().c_str());
llvm::FileRemover tmp_file_remover(temp_file_path);
{
llvm::raw_fd_ostream temp_file(FD, true);
temp_file << socket_id;
temp_file.close();
if (temp_file.has_error())
return Status("Failed to write to port file.");
}
err_code = llvm::sys::fs::rename(temp_file_path, file_spec.GetPath());
if (err_code)
return Status("Failed to rename file %s to %s: %s", temp_file_path.c_str(),
file_spec.GetPath().c_str(), err_code.message().c_str());
tmp_file_remover.releaseFile();
return Status();
}
//----------------------------------------------------------------------
// main
//----------------------------------------------------------------------
int main_platform(int argc, char *argv[]) {
const char *progname = argv[0];
const char *subcommand = argv[1];
argc--;
argv++;
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, signal_handler);
int long_option_index = 0;
Status error;
std::string listen_host_port;
int ch;
std::string log_file;
StringRef
log_channels; // e.g. "lldb process threads:gdb-remote default:linux all"
GDBRemoteCommunicationServerPlatform::PortMap gdbserver_portmap;
int min_gdbserver_port = 0;
int max_gdbserver_port = 0;
uint16_t port_offset = 0;
FileSpec socket_file;
bool show_usage = false;
int option_error = 0;
int socket_error = -1;
std::string short_options(OptionParser::GetShortOptionString(g_long_options));
#if __GLIBC__
optind = 0;
#else
optreset = 1;
optind = 1;
#endif
while ((ch = getopt_long_only(argc, argv, short_options.c_str(),
g_long_options, &long_option_index)) != -1) {
switch (ch) {
case 0: // Any optional that auto set themselves will return 0
break;
case 'L':
listen_host_port.append(optarg);
break;
case 'l': // Set Log File
if (optarg && optarg[0])
log_file.assign(optarg);
break;
case 'c': // Log Channels
if (optarg && optarg[0])
log_channels = StringRef(optarg);
break;
case 'f': // Socket file
if (optarg && optarg[0])
socket_file.SetFile(optarg, false);
break;
case 'p': {
if (!llvm::to_integer(optarg, port_offset)) {
llvm::errs() << "error: invalid port offset string " << optarg << "\n";
option_error = 4;
break;
}
if (port_offset < LOW_PORT || port_offset > HIGH_PORT) {
llvm::errs() << llvm::formatv("error: port offset {0} is not in the "
"valid user port range of {1} - {2}\n",
port_offset, LOW_PORT, HIGH_PORT);
option_error = 5;
}
} break;
case 'P':
case 'm':
case 'M': {
uint16_t portnum;
if (!llvm::to_integer(optarg, portnum)) {
llvm::errs() << "error: invalid port number string " << optarg << "\n";
option_error = 2;
break;
}
if (portnum < LOW_PORT || portnum > HIGH_PORT) {
llvm::errs() << llvm::formatv("error: port number {0} is not in the "
"valid user port range of {1} - {2}\n",
portnum, LOW_PORT, HIGH_PORT);
option_error = 1;
break;
}
if (ch == 'P')
gdbserver_portmap[portnum] = LLDB_INVALID_PROCESS_ID;
else if (ch == 'm')
min_gdbserver_port = portnum;
else
max_gdbserver_port = portnum;
} break;
case 'h': /* fall-through is intentional */
case '?':
show_usage = true;
break;
}
}
if (!LLDBServerUtilities::SetupLogging(log_file, log_channels, 0))
return -1;
// Make a port map for a port range that was specified.
if (min_gdbserver_port < max_gdbserver_port) {
for (uint16_t port = min_gdbserver_port; port < max_gdbserver_port; ++port)
gdbserver_portmap[port] = LLDB_INVALID_PROCESS_ID;
} else if (min_gdbserver_port != max_gdbserver_port) {
fprintf(stderr, "error: --min-gdbserver-port (%u) is greater than "
"--max-gdbserver-port (%u)\n",
min_gdbserver_port, max_gdbserver_port);
option_error = 3;
}
// Print usage and exit if no listening port is specified.
if (listen_host_port.empty())
show_usage = true;
if (show_usage || option_error) {
display_usage(progname, subcommand);
exit(option_error);
}
// Skip any options we consumed with getopt_long_only.
argc -= optind;
argv += optind;
lldb_private::Args inferior_arguments;
inferior_arguments.SetArguments(argc, const_cast<const char **>(argv));
const bool children_inherit_listen_socket = false;
// the test suite makes many connections in parallel, let's not miss any.
// The highest this should get reasonably is a function of the number
// of target CPUs. For now, let's just use 100.
const int backlog = 100;
std::unique_ptr<Acceptor> acceptor_up(Acceptor::Create(
listen_host_port, children_inherit_listen_socket, error));
if (error.Fail()) {
fprintf(stderr, "failed to create acceptor: %s", error.AsCString());
exit(socket_error);
}
error = acceptor_up->Listen(backlog);
if (error.Fail()) {
printf("failed to listen: %s\n", error.AsCString());
exit(socket_error);
}
if (socket_file) {
error =
save_socket_id_to_file(acceptor_up->GetLocalSocketId(), socket_file);
if (error.Fail()) {
fprintf(stderr, "failed to write socket id to %s: %s\n",
socket_file.GetPath().c_str(), error.AsCString());
return 1;
}
}
do {
GDBRemoteCommunicationServerPlatform platform(
acceptor_up->GetSocketProtocol(), acceptor_up->GetSocketScheme());
if (port_offset > 0)
platform.SetPortOffset(port_offset);
if (!gdbserver_portmap.empty()) {
platform.SetPortMap(std::move(gdbserver_portmap));
}
const bool children_inherit_accept_socket = true;
Connection *conn = nullptr;
error = acceptor_up->Accept(children_inherit_accept_socket, conn);
if (error.Fail()) {
printf("error: %s\n", error.AsCString());
exit(socket_error);
}
printf("Connection established.\n");
if (g_server) {
// Collect child zombie processes.
while (waitpid(-1, nullptr, WNOHANG) > 0)
;
if (fork()) {
// Parent doesn't need a connection to the lldb client
delete conn;
// Parent will continue to listen for new connections.
continue;
} else {
// Child process will handle the connection and exit.
g_server = 0;
// Listening socket is owned by parent process.
acceptor_up.release();
}
} else {
// If not running as a server, this process will not accept
// connections while a connection is active.
acceptor_up.reset();
}
platform.SetConnection(conn);
if (platform.IsConnected()) {
if (inferior_arguments.GetArgumentCount() > 0) {
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
uint16_t port = 0;
std::string socket_name;
Status error = platform.LaunchGDBServer(inferior_arguments,
"", // hostname
pid, port, socket_name);
if (error.Success())
platform.SetPendingGdbServer(pid, port, socket_name);
else
fprintf(stderr, "failed to start gdbserver: %s\n", error.AsCString());
}
// After we connected, we need to get an initial ack from...
if (platform.HandshakeWithClient()) {
bool interrupt = false;
bool done = false;
while (!interrupt && !done) {
if (platform.GetPacketAndSendResponse(llvm::None, error, interrupt,
done) !=
GDBRemoteCommunication::PacketResult::Success)
break;
}
if (error.Fail()) {
fprintf(stderr, "error: %s\n", error.AsCString());
}
} else {
fprintf(stderr, "error: handshake with client failed\n");
}
}
} while (g_server);
fprintf(stderr, "lldb-server exiting...\n");
return 0;
}

View File

@@ -0,0 +1,73 @@
//===-- lldb-server.cpp -----------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Initialization/SystemInitializerCommon.h"
#include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/lldb-private.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ManagedStatic.h"
#include <stdio.h>
#include <stdlib.h>
static llvm::ManagedStatic<lldb_private::SystemLifetimeManager>
g_debugger_lifetime;
static void display_usage(const char *progname) {
fprintf(stderr, "Usage:\n"
" %s v[ersion]\n"
" %s g[dbserver] [options]\n"
" %s p[latform] [options]\n"
"Invoke subcommand for additional help\n",
progname, progname, progname);
exit(0);
}
// Forward declarations of subcommand main methods.
int main_gdbserver(int argc, char *argv[]);
int main_platform(int argc, char *argv[]);
static void initialize() {
g_debugger_lifetime->Initialize(
llvm::make_unique<lldb_private::SystemInitializerCommon>(), nullptr);
}
static void terminate() { g_debugger_lifetime->Terminate(); }
//----------------------------------------------------------------------
// main
//----------------------------------------------------------------------
int main(int argc, char *argv[]) {
int option_error = 0;
const char *progname = argv[0];
if (argc < 2) {
display_usage(progname);
exit(option_error);
}
switch (argv[1][0]) {
case 'g':
initialize();
main_gdbserver(argc, argv);
terminate();
break;
case 'p':
initialize();
main_platform(argc, argv);
terminate();
break;
case 'v':
fprintf(stderr, "%s\n", lldb_private::GetVersion());
break;
default:
display_usage(progname);
exit(option_error);
}
}