summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunlian Jiang <yunlian@google.com>2017-10-12 11:41:40 -0700
committerYunlian Jiang <yunlian@google.com>2017-10-12 18:46:32 +0000
commit71da02e89a9728a8c587062ccb11f39141d46f94 (patch)
tree0392fc1e058fa53cdbc1ecfd263bc8f65a438c70
parent714990b22a417798b0cece9a8c90f4cfaec637f9 (diff)
downloadgdb-71da02e89a9728a8c587062ccb11f39141d46f94.tar.gz
Cherry-pick 7.10 changes to 8.0.1.
Cherry-picked commits: e24220e gdb: disable python when python is not available. d73c546 use snprintf instead of strlcpy for portablitly c64829b Fallback to open if multifs_open fails. 2177073 Fix gdbserver process interruption. b711aa8 Add Unix domain socket support to gdbserver 7.9.1 Test: build.py passes with gdb 8.0.1.
-rw-r--r--gdb-8.0.1/gdb/defs.h4
-rw-r--r--gdb-8.0.1/gdb/gdbserver/hostio.c8
-rw-r--r--gdb-8.0.1/gdb/gdbserver/linux-low.c5
-rw-r--r--gdb-8.0.1/gdb/gdbserver/remote-utils.c52
-rw-r--r--gdb-8.0.1/gdb/python/py-auto-load.c2
-rw-r--r--gdb-8.0.1/gdb/python/py-prettyprint.c2
-rw-r--r--gdb-8.0.1/gdb/python/python.c51
-rw-r--r--gdb-8.0.1/gdb/varobj.c10
8 files changed, 122 insertions, 12 deletions
diff --git a/gdb-8.0.1/gdb/defs.h b/gdb-8.0.1/gdb/defs.h
index a0b586f40..5de109209 100644
--- a/gdb-8.0.1/gdb/defs.h
+++ b/gdb-8.0.1/gdb/defs.h
@@ -750,4 +750,8 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
#include "utils.h"
+#ifdef HAVE_PYTHON
+extern int python_available (void);
+#endif
+
#endif /* #ifndef DEFS_H */
diff --git a/gdb-8.0.1/gdb/gdbserver/hostio.c b/gdb-8.0.1/gdb/gdbserver/hostio.c
index cd40e28fb..7510f7638 100644
--- a/gdb-8.0.1/gdb/gdbserver/hostio.c
+++ b/gdb-8.0.1/gdb/gdbserver/hostio.c
@@ -297,7 +297,7 @@ handle_open (char *own_buf)
{
char filename[HOSTIO_PATH_MAX];
char *p;
- int fileio_flags, fileio_mode, flags, fd;
+ int fileio_flags, fileio_mode, flags, fd = -1;
mode_t mode;
struct fd_list *new_fd;
@@ -321,7 +321,11 @@ handle_open (char *own_buf)
if (hostio_fs_pid != 0 && the_target->multifs_open != NULL)
fd = the_target->multifs_open (hostio_fs_pid, filename,
flags, mode);
- else
+
+ /* HACK: multifs_open will fail for android applications, because run-as does
+ not switch to the same mount namespace as the running application. Retry
+ with regular open if this happens. */
+ if (fd == -1)
fd = open (filename, flags, mode);
if (fd == -1)
diff --git a/gdb-8.0.1/gdb/gdbserver/linux-low.c b/gdb-8.0.1/gdb/gdbserver/linux-low.c
index e27cbf825..57fd30795 100644
--- a/gdb-8.0.1/gdb/gdbserver/linux-low.c
+++ b/gdb-8.0.1/gdb/gdbserver/linux-low.c
@@ -6061,10 +6061,7 @@ static void
linux_request_interrupt (void)
{
extern unsigned long signal_pid;
-
- /* Send a SIGINT to the process group. This acts just like the user
- typed a ^C on the controlling terminal. */
- kill (-signal_pid, SIGINT);
+ kill (signal_pid, SIGINT);
}
/* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
diff --git a/gdb-8.0.1/gdb/gdbserver/remote-utils.c b/gdb-8.0.1/gdb/gdbserver/remote-utils.c
index 25b7e41a9..fdce13a54 100644
--- a/gdb-8.0.1/gdb/gdbserver/remote-utils.c
+++ b/gdb-8.0.1/gdb/gdbserver/remote-utils.c
@@ -283,11 +283,63 @@ 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)
{
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;
+ snprintf(sockaddr.sun_path, sizeof (sockaddr.sun_path), "%s", name);
+ 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);
+
+ transport_is_reliable = 1;
+#endif
+
+ return;
+ }
+ // ANDROID END.
+
port_str = strchr (name, ':');
#ifdef USE_WIN32API
if (port_str == NULL)
diff --git a/gdb-8.0.1/gdb/python/py-auto-load.c b/gdb-8.0.1/gdb/python/py-auto-load.c
index 32cb7e92b..5e15a28e9 100644
--- a/gdb-8.0.1/gdb/python/py-auto-load.c
+++ b/gdb-8.0.1/gdb/python/py-auto-load.c
@@ -46,6 +46,8 @@ show_auto_load_python_scripts (struct ui_file *file, int from_tty,
int
gdbpy_auto_load_enabled (const struct extension_language_defn *extlang)
{
+ if (!python_available ())
+ return 0;
return auto_load_python_scripts;
}
diff --git a/gdb-8.0.1/gdb/python/py-prettyprint.c b/gdb-8.0.1/gdb/python/py-prettyprint.c
index 66929bfea..b303e8ce4 100644
--- a/gdb-8.0.1/gdb/python/py-prettyprint.c
+++ b/gdb-8.0.1/gdb/python/py-prettyprint.c
@@ -668,7 +668,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
if (!value_bytes_available (val, embedded_offset, TYPE_LENGTH (type)))
return EXT_LANG_RC_NOP;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return EXT_LANG_RC_NOP;
gdbpy_enter enter_py (gdbarch, language);
diff --git a/gdb-8.0.1/gdb/python/python.c b/gdb-8.0.1/gdb/python/python.c
index be92f36b6..8c8755b03 100644
--- a/gdb-8.0.1/gdb/python/python.c
+++ b/gdb-8.0.1/gdb/python/python.c
@@ -33,6 +33,13 @@
#include "python.h"
#include "extension-priv.h"
#include "cli/cli-utils.h"
+#include "gdb_wait.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <sys/types.h>
#include <ctype.h>
#include "location.h"
#include "ser-event.h"
@@ -1575,6 +1582,9 @@ do_start_initialization ()
#endif
#endif
+ if (!python_available ())
+ return false;
+
Py_Initialize ();
PyEval_InitThreads ();
@@ -1696,6 +1706,44 @@ do_start_initialization ()
#endif /* HAVE_PYTHON */
+#ifdef HAVE_PYTHON
+/* Check whether python is available at runtime. */
+
+int
+python_available(void)
+{
+#ifndef HAVE_WORKING_FORK
+ return 1;
+#endif
+
+ static int python_status = -1;
+ int child_status = 0;
+
+ if (python_status != -1)
+ return python_status;
+
+ pid_t pid = fork ();
+
+ if (pid < 0)
+ perror_with_name (("fork"));
+
+ if (pid == 0)
+ {
+ freopen ("/dev/null", "w", stderr);
+ Py_Initialize ();
+ _exit(0);
+ }
+
+ wait (&child_status);
+ if (WIFEXITED (child_status) && WEXITSTATUS (child_status) == 0)
+ python_status = 1;
+ else
+ python_status = 0;
+
+ return python_status;
+}
+#endif
+
void
_initialize_python (void)
{
@@ -1849,6 +1897,9 @@ do_finish_initialization (const struct extension_language_defn *extlang)
static void
gdbpy_finish_initialization (const struct extension_language_defn *extlang)
{
+ if (!python_available())
+ return;
+
gdbpy_enter enter_py (get_current_arch (), current_language);
if (!do_finish_initialization (extlang))
diff --git a/gdb-8.0.1/gdb/varobj.c b/gdb-8.0.1/gdb/varobj.c
index 5f21d84f5..4b3164268 100644
--- a/gdb-8.0.1/gdb/varobj.c
+++ b/gdb-8.0.1/gdb/varobj.c
@@ -563,7 +563,7 @@ varobj_get_display_hint (const struct varobj *var)
gdb::unique_xmalloc_ptr<char> result;
#if HAVE_PYTHON
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return NULL;
gdbpy_enter_varobj enter_py (var);
@@ -693,7 +693,7 @@ dynamic_varobj_has_child_method (const struct varobj *var)
{
PyObject *printer = var->dynamic->pretty_printer;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return 0;
gdbpy_enter_varobj enter_py (var);
@@ -1200,7 +1200,7 @@ install_new_value_visualizer (struct varobj *var)
#if HAVE_PYTHON
/* If the constructor is None, then we want the raw value. If VAR
does not have a value, just skip this. */
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return;
if (var->dynamic->constructor != Py_None && var->value != NULL)
@@ -1472,7 +1472,7 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
#if HAVE_PYTHON
PyObject *mainmod;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return;
gdbpy_enter_varobj enter_py (var);
@@ -2415,7 +2415,7 @@ varobj_value_get_print_value (struct value *value,
std::string thevalue;
#if HAVE_PYTHON
- if (gdb_python_initialized)
+ if (python_available () && gdb_python_initialized)
{
PyObject *value_formatter = var->dynamic->pretty_printer;