summaryrefslogtreecommitdiffstats
path: root/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
diff options
context:
space:
mode:
authorOleksiy Vyalov <ovyalov@google.com>2014-11-27 20:51:24 +0000
committerOleksiy Vyalov <ovyalov@google.com>2014-11-27 20:51:24 +0000
commit2f206d6ee4404c6511826cd47cfebbfea293ba59 (patch)
tree11b6248f2f020e28868a9de7f33b58ae75f787b8 /lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
parentf9a02500b662551804e4f2d27311e2ec7ec9031c (diff)
downloadbcm5719-llvm-2f206d6ee4404c6511826cd47cfebbfea293ba59.tar.gz
bcm5719-llvm-2f206d6ee4404c6511826cd47cfebbfea293ba59.zip
Make LLGS to open a named pipe and write a listening port to it only when a proper port value is received.
llvm-svn: 222902
Diffstat (limited to 'lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp')
-rw-r--r--lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp45
1 files changed, 31 insertions, 14 deletions
diff --git a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
index a0486328d47..4a597704ea3 100644
--- a/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
+++ b/lldb/tools/lldb-gdbserver/lldb-gdbserver.cpp
@@ -306,6 +306,29 @@ JoinListenThread ()
return true;
}
+Error
+writePortToPipe (const char *const named_pipe_path, const uint16_t port)
+{
+ Error error;
+
+ // FIXME use new generic named pipe support.
+ int fd = ::open (named_pipe_path, O_WRONLY);
+ if (fd == -1)
+ {
+ error.SetErrorToErrno ();
+ return error;
+ }
+
+ char port_str[64];
+ const ssize_t port_str_len = ::snprintf (port_str, sizeof(port_str), "%u", port);
+ // Write the port number as a C string with the NULL terminator.
+ if (::write (fd, port_str, port_str_len + 1) == -1)
+ error.SetErrorToErrno ();
+
+ close (fd);
+ return error;
+}
+
void
ConnectToRemote (GDBRemoteCommunicationServer &gdb_server, bool reverse_connect, const char *const host_and_port, const char *const progname, const char *const named_pipe_path)
{
@@ -383,24 +406,18 @@ ConnectToRemote (GDBRemoteCommunicationServer &gdb_server, bool reverse_connect,
// If we have a named pipe to write the port number back to, do that now.
if (named_pipe_path && named_pipe_path[0] && connection_portno == 0)
{
- // FIXME use new generic named pipe support.
- int fd = ::open(named_pipe_path, O_WRONLY);
- const uint16_t bound_port = s_listen_connection_up->GetListeningPort(10);
- if (fd > -1 && bound_port > 0)
+ const uint16_t bound_port = s_listen_connection_up->GetListeningPort (10);
+ if (bound_port > 0)
{
-
- char port_str[64];
- const ssize_t port_str_len = ::snprintf (port_str, sizeof(port_str), "%u", bound_port);
- // Write the port number as a C string with the NULL terminator.
- ::write (fd, port_str, port_str_len + 1);
- close (fd);
+ error = writePortToPipe (named_pipe_path, bound_port);
+ if (error.Fail ())
+ {
+ fprintf (stderr, "failed to write to the named pipe \'%s\': %s", named_pipe_path, error.AsCString());
+ }
}
else
{
- if (fd < 0)
- fprintf (stderr, "failed to open named pipe '%s' for writing\n", named_pipe_path);
- else
- fprintf(stderr, "unable to get the bound port for the listening connection\n");
+ fprintf (stderr, "unable to get the bound port for the listening connection\n");
}
}
OpenPOWER on IntegriCloud