diff options
author | Haibo Huang <hhb@google.com> | 2019-07-02 15:03:49 -0700 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2019-07-03 02:43:40 +0000 |
commit | fd00b15a5ae20d59e3632e64eab829da7cdee3f1 (patch) | |
tree | 9783bf39b45d5dd61c72cf629135c02fd790f211 | |
parent | 2842118a24ccddd7fda20d7c3821063385af90df (diff) | |
download | gdb-fd00b15a5ae20d59e3632e64eab829da7cdee3f1.tar.gz |
Cherry-pick more 7.11 changes to 8.3
Cherry-picked commits:
b711aa8: Add Unix domain socket support to gdbserver 7.9.1.
The upstream domain socket change actually get reverted.
Original upstream change: f19c7ff839d7a32ebb48482ae7d318fb46ca823d
Reverted in: 80e24d09860dbeba7d435b4a4f0990f85dbc084e
Test: build
Bug: 62547070
Change-Id: I574cc11792fac018453e05d82fd835c4d45de7c1
-rw-r--r-- | gdb-8.3/gdb/gdbserver/remote-utils.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/gdb-8.3/gdb/gdbserver/remote-utils.c b/gdb-8.3/gdb/gdbserver/remote-utils.c index 4e6f9c62d..70c514a0d 100644 --- a/gdb-8.3/gdb/gdbserver/remote-utils.c +++ b/gdb-8.3/gdb/gdbserver/remote-utils.c @@ -330,11 +330,64 @@ remote_prepare (const char *name) /* Open a connection to a remote debugger. NAME is the filename used for communication. */ +// ANDROID BEGIN. +#ifndef USE_WIN32API +#include <sys/un.h> +#endif +// ANDROID END. + void remote_open (const char *name) { + client_state &cs = get_client_state (); const char *port_str; + // ANDROID BEGIN. + // The Android NDK uses Unix domain sockets because applications + // aren't allowed to bind to localhost TCP sockets, and developers + // debugging on production devices can't get root. + // Typical ndk-gdb usage is "gdbserver +debug-socket --attach 123". + if (name[0] == '+') + { +#ifdef USE_WIN32API + error ("Only <host>:<port> is supported on this platform."); +#else + struct sockaddr_un sockaddr; + socklen_t sockaddrlen; + + listen_desc = socket (AF_UNIX, SOCK_STREAM, 0); + if (listen_desc == -1) + perror_with_name ("Can't create Unix domain socket"); + + /* Skip the initial '+'. */ + name++; + + memset (&sockaddr, 0, sizeof sockaddr); + sockaddr.sun_family = AF_UNIX; + strlcpy (sockaddr.sun_path, name, sizeof (sockaddr.sun_path)); + sockaddrlen = sizeof (sockaddr.sun_family) + + strlen (sockaddr.sun_path) + 1; + + unlink (sockaddr.sun_path); + + if (bind (listen_desc, (struct sockaddr *) &sockaddr, sockaddrlen) + || listen (listen_desc, 1)) + perror_with_name ("Can't bind Unix domain socket"); + + fprintf (stderr, "Listening on Unix domain socket '%s'\n", + sockaddr.sun_path); + fflush (stderr); + + /* Register the event loop handler. */ + add_file_handler (listen_desc, handle_accept_event, NULL); + + cs.transport_is_reliable = 1; +#endif + + return; + } + // ANDROID END. + port_str = strchr (name, ':'); #ifdef USE_WIN32API if (port_str == NULL) |