2013-11-22 02:39:32 +08:00
|
|
|
//===-- lldb-gdbserver.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/lldb-python.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
#include <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
// C++ Includes
|
|
|
|
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "lldb/lldb-private-log.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
|
|
|
#include "lldb/Core/ConnectionFileDescriptor.h"
|
|
|
|
#include "lldb/Core/ConnectionMachPort.h"
|
|
|
|
#include "lldb/Core/Debugger.h"
|
2014-01-28 08:34:23 +08:00
|
|
|
#include "lldb/Core/PluginManager.h"
|
2013-11-22 02:39:32 +08:00
|
|
|
#include "lldb/Core/StreamFile.h"
|
2013-11-23 09:58:15 +08:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2014-01-22 02:46:22 +08:00
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2013-11-22 02:39:32 +08:00
|
|
|
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
|
|
|
|
#include "Plugins/Process/gdb-remote/ProcessGDBRemoteLog.h"
|
2014-01-28 08:34:23 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// option descriptors for getopt_long_only()
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int g_debug = 0;
|
|
|
|
int g_verbose = 0;
|
|
|
|
|
|
|
|
static struct option g_long_options[] =
|
|
|
|
{
|
|
|
|
{ "debug", no_argument, &g_debug, 1 },
|
2014-01-28 08:34:23 +08:00
|
|
|
{ "platform", required_argument, NULL, 'p' },
|
2013-11-22 02:39:32 +08:00
|
|
|
{ "verbose", no_argument, &g_verbose, 1 },
|
2014-01-22 02:46:22 +08:00
|
|
|
{ "lldb-command", required_argument, NULL, 'c' },
|
2013-11-22 02:39:32 +08:00
|
|
|
{ "log-file", required_argument, NULL, 'l' },
|
|
|
|
{ "log-flags", required_argument, NULL, 'f' },
|
2014-07-01 05:05:18 +08:00
|
|
|
{ "attach", required_argument, NULL, 'a' },
|
2013-11-22 02:39:32 +08:00
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Watch for signals
|
|
|
|
//----------------------------------------------------------------------
|
2014-07-01 05:05:18 +08:00
|
|
|
static int g_sigpipe_received = 0;
|
|
|
|
static int g_sighup_received_count = 0;
|
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
void
|
|
|
|
signal_handler(int signo)
|
|
|
|
{
|
2014-07-01 05:05:18 +08:00
|
|
|
Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
fprintf (stderr, "lldb-gdbserver:%s received signal %d\n", __FUNCTION__, signo);
|
|
|
|
if (log)
|
|
|
|
log->Printf ("lldb-gdbserver:%s received signal %d", __FUNCTION__, signo);
|
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
switch (signo)
|
|
|
|
{
|
|
|
|
case SIGPIPE:
|
|
|
|
g_sigpipe_received = 1;
|
|
|
|
break;
|
|
|
|
case SIGHUP:
|
2014-07-01 05:05:18 +08:00
|
|
|
#if 1
|
|
|
|
++g_sighup_received_count;
|
|
|
|
|
|
|
|
// For now, swallow SIGHUP.
|
|
|
|
if (log)
|
|
|
|
log->Printf ("lldb-gdbserver:%s swallowing SIGHUP (receive count=%d)", __FUNCTION__, g_sighup_received_count);
|
|
|
|
signal (SIGHUP, signal_handler);
|
|
|
|
#else
|
2013-11-22 02:39:32 +08:00
|
|
|
// 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-gdbserver...\n");
|
|
|
|
abort();
|
2014-07-01 05:05:18 +08:00
|
|
|
#endif
|
2013-11-22 02:39:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
display_usage (const char *progname)
|
|
|
|
{
|
2014-03-05 07:41:34 +08:00
|
|
|
fprintf(stderr, "Usage:\n %s [--log-file log-file-path] [--log-flags flags] [--lldb-command command]* [--platform platform_name] [[HOST]:PORT] "
|
2014-01-22 02:46:22 +08:00
|
|
|
"[-- PROGRAM ARG1 ARG2 ...]\n", progname);
|
2013-11-22 02:39:32 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2014-01-28 08:34:23 +08:00
|
|
|
static void
|
|
|
|
dump_available_platforms (FILE *output_file)
|
|
|
|
{
|
|
|
|
fprintf (output_file, "Available platform plugins:\n");
|
|
|
|
for (int i = 0; ; ++i)
|
|
|
|
{
|
|
|
|
const char *plugin_name = PluginManager::GetPlatformPluginNameAtIndex (i);
|
|
|
|
const char *plugin_desc = PluginManager::GetPlatformPluginDescriptionAtIndex (i);
|
|
|
|
|
|
|
|
if (!plugin_name || !plugin_desc)
|
|
|
|
break;
|
|
|
|
|
|
|
|
fprintf (output_file, "%s\t%s\n", plugin_name, plugin_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Platform::GetDefaultPlatform () )
|
|
|
|
{
|
|
|
|
// add this since the default platform doesn't necessarily get registered by
|
|
|
|
// the plugin name (e.g. 'host' doesn't show up as a
|
|
|
|
// registered platform plugin even though it's the default).
|
|
|
|
fprintf (output_file, "%s\tDefault platform for this host.\n", Platform::GetDefaultPlatform ()->GetPluginName ().AsCString ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
initialize_lldb_gdbserver ()
|
|
|
|
{
|
|
|
|
PluginManager::Initialize ();
|
|
|
|
Debugger::Initialize (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
terminate_lldb_gdbserver ()
|
|
|
|
{
|
|
|
|
Debugger::Terminate();
|
|
|
|
PluginManager::Terminate ();
|
|
|
|
}
|
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
static void
|
|
|
|
run_lldb_commands (const lldb::DebuggerSP &debugger_sp, const std::vector<std::string> lldb_commands)
|
|
|
|
{
|
|
|
|
for (const auto &lldb_command : lldb_commands)
|
|
|
|
{
|
|
|
|
printf("(lldb) %s\n", lldb_command.c_str ());
|
|
|
|
|
|
|
|
lldb_private::CommandReturnObject result;
|
|
|
|
debugger_sp->GetCommandInterpreter ().HandleCommand (lldb_command.c_str (), eLazyBoolNo, result);
|
|
|
|
const char *output = result.GetOutputData ();
|
|
|
|
if (output && output[0])
|
|
|
|
puts (output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static lldb::PlatformSP
|
|
|
|
setup_platform (const std::string platform_name)
|
|
|
|
{
|
|
|
|
lldb::PlatformSP platform_sp;
|
|
|
|
|
|
|
|
if (platform_name.empty())
|
|
|
|
{
|
|
|
|
printf ("using the default platform: ");
|
|
|
|
platform_sp = Platform::GetDefaultPlatform ();
|
|
|
|
printf ("%s\n", platform_sp->GetPluginName ().AsCString ());
|
|
|
|
return platform_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
platform_sp = Platform::Create (platform_name.c_str(), error);
|
|
|
|
if (error.Fail ())
|
|
|
|
{
|
|
|
|
// the host platform isn't registered with that name (at
|
|
|
|
// least, not always. Check if the given name matches
|
|
|
|
// the default platform name. If so, use it.
|
|
|
|
if ( Platform::GetDefaultPlatform () && ( Platform::GetDefaultPlatform ()->GetPluginName () == ConstString (platform_name.c_str()) ) )
|
|
|
|
{
|
|
|
|
platform_sp = Platform::GetDefaultPlatform ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "error: failed to create platform with name '%s'\n", platform_name.c_str());
|
|
|
|
dump_available_platforms (stderr);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("using platform: %s\n", platform_name.c_str ());
|
|
|
|
|
|
|
|
return platform_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handle_attach_to_pid (GDBRemoteCommunicationServer &gdb_server, lldb::pid_t pid)
|
|
|
|
{
|
|
|
|
Error error = gdb_server.AttachToProcess (pid);
|
|
|
|
if (error.Fail ())
|
|
|
|
{
|
|
|
|
fprintf (stderr, "error: failed to attach to pid %" PRIu64 ": %s\n", pid, error.AsCString());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handle_attach_to_process_name (GDBRemoteCommunicationServer &gdb_server, const std::string &process_name)
|
|
|
|
{
|
|
|
|
// FIXME implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handle_attach (GDBRemoteCommunicationServer &gdb_server, const std::string &attach_target)
|
|
|
|
{
|
|
|
|
assert (!attach_target.empty () && "attach_target cannot be empty");
|
|
|
|
|
|
|
|
// First check if the attach_target is convertable to a long. If so, we'll use it as a pid.
|
|
|
|
char *end_p = nullptr;
|
|
|
|
const long int pid = strtol (attach_target.c_str (), &end_p, 10);
|
|
|
|
|
|
|
|
// We'll call it a match if the entire argument is consumed.
|
|
|
|
if (end_p && static_cast<size_t> (end_p - attach_target.c_str ()) == attach_target.size ())
|
|
|
|
handle_attach_to_pid (gdb_server, static_cast<lldb::pid_t> (pid));
|
|
|
|
else
|
|
|
|
handle_attach_to_process_name (gdb_server, attach_target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handle_launch (GDBRemoteCommunicationServer &gdb_server, int argc, const char *const argv[])
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
error = gdb_server.SetLaunchArguments (argv, argc);
|
|
|
|
if (error.Fail ())
|
|
|
|
{
|
|
|
|
fprintf (stderr, "error: failed to set launch args for '%s': %s\n", argv[0], error.AsCString());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int launch_flags = eLaunchFlagStopAtEntry | eLaunchFlagDebug;
|
|
|
|
|
|
|
|
error = gdb_server.SetLaunchFlags (launch_flags);
|
|
|
|
if (error.Fail ())
|
|
|
|
{
|
|
|
|
fprintf (stderr, "error: failed to set launch flags for '%s': %s\n", argv[0], error.AsCString());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = gdb_server.LaunchProcess ();
|
|
|
|
if (error.Fail ())
|
|
|
|
{
|
|
|
|
fprintf (stderr, "error: failed to launch '%s': %s\n", argv[0], error.AsCString());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
start_listener (GDBRemoteCommunicationServer &gdb_server, const char *const host_and_port, const char *const progname)
|
|
|
|
{
|
|
|
|
Error error;
|
|
|
|
|
|
|
|
if (host_and_port && host_and_port[0])
|
|
|
|
{
|
|
|
|
std::unique_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
|
|
|
|
if (conn_ap.get())
|
|
|
|
{
|
|
|
|
std::string final_host_and_port;
|
|
|
|
std::string listening_host;
|
|
|
|
std::string listening_port;
|
|
|
|
|
|
|
|
// If host_and_port starts with ':', default the host to be "localhost" and expect the remainder to be the port.
|
|
|
|
if (host_and_port[0] == ':')
|
|
|
|
final_host_and_port.append ("localhost");
|
|
|
|
final_host_and_port.append (host_and_port);
|
|
|
|
|
|
|
|
const std::string::size_type colon_pos = final_host_and_port.find(':');
|
|
|
|
if (colon_pos != std::string::npos)
|
|
|
|
{
|
|
|
|
listening_host = final_host_and_port.substr(0, colon_pos);
|
|
|
|
listening_port = final_host_and_port.substr(colon_pos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string connect_url ("listen://");
|
|
|
|
connect_url.append (final_host_and_port);
|
|
|
|
|
|
|
|
printf ("Listening to port %s for a connection from %s...\n", listening_port.c_str (), listening_host.c_str ());
|
|
|
|
if (conn_ap->Connect(connect_url.c_str(), &error) == eConnectionStatusSuccess)
|
|
|
|
{
|
|
|
|
printf ("Connection established.\n");
|
|
|
|
gdb_server.SetConnection (conn_ap.release());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "failed to connect to '%s': %s\n", final_host_and_port.c_str (), error.AsCString ());
|
|
|
|
display_usage (progname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gdb_server.IsConnected())
|
|
|
|
{
|
|
|
|
// After we connected, we need to get an initial ack from...
|
|
|
|
if (gdb_server.HandshakeWithClient(&error))
|
|
|
|
{
|
|
|
|
// We'll use a half a second timeout interval so that an exit conditions can
|
|
|
|
// be checked that often.
|
|
|
|
const uint32_t TIMEOUT_USEC = 500000;
|
|
|
|
|
|
|
|
bool interrupt = false;
|
|
|
|
bool done = false;
|
|
|
|
while (!interrupt && !done && (g_sighup_received_count < 1))
|
|
|
|
{
|
|
|
|
const GDBRemoteCommunication::PacketResult result = gdb_server.GetPacketAndSendResponse (TIMEOUT_USEC, error, interrupt, done);
|
|
|
|
if ((result != GDBRemoteCommunication::PacketResult::Success) &&
|
|
|
|
(result != GDBRemoteCommunication::PacketResult::ErrorReplyTimeout))
|
|
|
|
{
|
|
|
|
// We're bailing out - we only support successful handling and timeouts.
|
|
|
|
fprintf(stderr, "leaving packet loop due to PacketResult %d\n", result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error.Fail())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: %s\n", error.AsCString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "error: handshake with client failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf (stderr, "no connection information provided, unable to run\n");
|
|
|
|
display_usage (progname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2014-07-01 05:05:18 +08:00
|
|
|
// Setup signal handlers first thing.
|
2013-11-22 02:39:32 +08:00
|
|
|
signal (SIGPIPE, signal_handler);
|
|
|
|
signal (SIGHUP, signal_handler);
|
2014-07-01 05:05:18 +08:00
|
|
|
|
|
|
|
const char *progname = argv[0];
|
2013-11-22 02:39:32 +08:00
|
|
|
int long_option_index = 0;
|
|
|
|
StreamSP log_stream_sp;
|
|
|
|
Args log_args;
|
|
|
|
Error error;
|
|
|
|
int ch;
|
2014-01-28 08:34:23 +08:00
|
|
|
std::string platform_name;
|
2014-07-01 05:05:18 +08:00
|
|
|
std::string attach_target;
|
2014-01-28 08:34:23 +08:00
|
|
|
|
|
|
|
initialize_lldb_gdbserver ();
|
2014-01-22 02:46:22 +08:00
|
|
|
|
|
|
|
lldb::DebuggerSP debugger_sp = Debugger::CreateInstance ();
|
|
|
|
|
|
|
|
debugger_sp->SetInputFileHandle(stdin, false);
|
|
|
|
debugger_sp->SetOutputFileHandle(stdout, false);
|
|
|
|
debugger_sp->SetErrorFileHandle(stderr, false);
|
|
|
|
|
2014-01-24 06:05:44 +08:00
|
|
|
// ProcessLaunchInfo launch_info;
|
2013-11-22 02:58:35 +08:00
|
|
|
ProcessAttachInfo attach_info;
|
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
bool show_usage = false;
|
|
|
|
int option_error = 0;
|
2013-11-23 02:55:04 +08:00
|
|
|
#if __GLIBC__
|
|
|
|
optind = 0;
|
|
|
|
#else
|
|
|
|
optreset = 1;
|
|
|
|
optind = 1;
|
|
|
|
#endif
|
2014-01-22 02:46:22 +08:00
|
|
|
|
2013-11-23 09:58:15 +08:00
|
|
|
std::string short_options(OptionParser::GetShortOptionString(g_long_options));
|
|
|
|
|
2014-01-22 02:46:22 +08:00
|
|
|
std::vector<std::string> lldb_commands;
|
|
|
|
|
2013-11-23 09:58:15 +08:00
|
|
|
while ((ch = getopt_long_only(argc, argv, short_options.c_str(), g_long_options, &long_option_index)) != -1)
|
2013-11-22 02:39:32 +08:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case 0: // Any optional that auto set themselves will return 0
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': // Set Log File
|
|
|
|
if (optarg && optarg[0])
|
|
|
|
{
|
|
|
|
if ((strcasecmp(optarg, "stdout") == 0) || (strcmp(optarg, "/dev/stdout") == 0))
|
|
|
|
{
|
|
|
|
log_stream_sp.reset (new StreamFile (stdout, false));
|
|
|
|
}
|
|
|
|
else if ((strcasecmp(optarg, "stderr") == 0) || (strcmp(optarg, "/dev/stderr") == 0))
|
|
|
|
{
|
|
|
|
log_stream_sp.reset (new StreamFile (stderr, false));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FILE *log_file = fopen(optarg, "w");
|
|
|
|
if (log_file)
|
|
|
|
{
|
|
|
|
setlinebuf(log_file);
|
|
|
|
log_stream_sp.reset (new StreamFile (log_file, true));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *errno_str = strerror(errno);
|
|
|
|
fprintf (stderr, "Failed to open log file '%s' for writing: errno = %i (%s)", optarg, errno, errno_str ? errno_str : "unknown error");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': // Log Flags
|
|
|
|
if (optarg && optarg[0])
|
|
|
|
log_args.AppendArgument(optarg);
|
|
|
|
break;
|
2014-01-22 02:46:22 +08:00
|
|
|
|
|
|
|
case 'c': // lldb commands
|
|
|
|
if (optarg && optarg[0])
|
|
|
|
lldb_commands.push_back(optarg);
|
|
|
|
break;
|
|
|
|
|
2014-01-28 08:34:23 +08:00
|
|
|
case 'p': // platform name
|
|
|
|
if (optarg && optarg[0])
|
|
|
|
platform_name = optarg;
|
|
|
|
break;
|
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
case 'a': // attach {pid|process_name}
|
|
|
|
if (optarg && optarg[0])
|
|
|
|
attach_target = optarg;
|
|
|
|
break;
|
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
case 'h': /* fall-through is intentional */
|
|
|
|
case '?':
|
|
|
|
show_usage = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-22 02:46:22 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
if (show_usage || option_error)
|
|
|
|
{
|
|
|
|
display_usage(progname);
|
|
|
|
exit(option_error);
|
|
|
|
}
|
2014-01-22 02:46:22 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
if (log_stream_sp)
|
|
|
|
{
|
|
|
|
if (log_args.GetArgumentCount() == 0)
|
|
|
|
log_args.AppendArgument("default");
|
|
|
|
ProcessGDBRemoteLog::EnableLog (log_stream_sp, 0,log_args.GetConstArgumentVector(), log_stream_sp.get());
|
|
|
|
}
|
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
// Skip any options we consumed with getopt_long_only.
|
2013-11-22 02:39:32 +08:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
2014-01-22 02:46:22 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
if (argc == 0)
|
|
|
|
{
|
|
|
|
display_usage(progname);
|
|
|
|
exit(255);
|
|
|
|
}
|
2014-01-18 04:18:59 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
// Run any commands requested.
|
|
|
|
run_lldb_commands (debugger_sp, lldb_commands);
|
2014-01-22 02:46:22 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
// Setup the platform that GDBRemoteCommunicationServer will use.
|
|
|
|
lldb::PlatformSP platform_sp = setup_platform (platform_name);
|
2014-01-28 08:34:23 +08:00
|
|
|
|
2014-01-24 06:05:44 +08:00
|
|
|
const bool is_platform = false;
|
2014-07-01 05:05:18 +08:00
|
|
|
GDBRemoteCommunicationServer gdb_server (is_platform, platform_sp, debugger_sp);
|
2014-01-24 06:05:44 +08:00
|
|
|
|
2014-07-01 05:05:18 +08:00
|
|
|
const char *const host_and_port = argv[0];
|
2013-11-22 02:39:32 +08:00
|
|
|
argc -= 1;
|
|
|
|
argv += 1;
|
2014-07-01 05:05:18 +08:00
|
|
|
|
2013-11-22 02:39:32 +08:00
|
|
|
// Any arguments left over are for the the program that we need to launch. If there
|
|
|
|
// are no arguments, then the GDB server will start up and wait for an 'A' packet
|
2014-07-01 05:05:18 +08:00
|
|
|
// to launch a program, or a vAttach packet to attach to an existing process, unless
|
|
|
|
// explicitly asked to attach with the --attach={pid|program_name} form.
|
|
|
|
if (!attach_target.empty ())
|
|
|
|
handle_attach (gdb_server, attach_target);
|
|
|
|
else if (argc > 0)
|
|
|
|
handle_launch (gdb_server, argc, argv);
|
|
|
|
|
|
|
|
start_listener (gdb_server, host_and_port, progname);
|
2013-11-22 02:39:32 +08:00
|
|
|
|
2014-01-28 08:34:23 +08:00
|
|
|
terminate_lldb_gdbserver ();
|
2013-11-22 02:39:32 +08:00
|
|
|
|
|
|
|
fprintf(stderr, "lldb-gdbserver exiting...\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|