summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2016-03-30 15:02:15 -0700
committerJosh Gao <jmgao@google.com>2016-03-31 11:41:22 -0700
commitc2884b7c65dc55af6754a1bc18761d21c39948fe (patch)
tree9cfd42abbc8a960fdd60dc0755974f270414cbd5
parentebc53d95fdc1d798acb4f8978455ca29b4ad496e (diff)
downloadgdb-c2884b7c65dc55af6754a1bc18761d21c39948fe.tar.gz
Cherry-pick 7.10 changes to 7.11.
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 Change-Id: I2cba7ae5c05503afb81f732cbd78440ebd2c45e8
-rw-r--r--gdb-7.11/gdb/defs.h4
-rw-r--r--gdb-7.11/gdb/gdbserver/hostio.c8
-rw-r--r--gdb-7.11/gdb/gdbserver/linux-low.c5
-rw-r--r--gdb-7.11/gdb/gdbserver/remote-utils.c52
-rw-r--r--gdb-7.11/gdb/python/py-auto-load.c2
-rw-r--r--gdb-7.11/gdb/python/py-prettyprint.c2
-rw-r--r--gdb-7.11/gdb/python/python.c51
-rw-r--r--gdb-7.11/gdb/varobj.c10
8 files changed, 122 insertions, 12 deletions
diff --git a/gdb-7.11/gdb/defs.h b/gdb-7.11/gdb/defs.h
index f6ffeac0e..8d8e73410 100644
--- a/gdb-7.11/gdb/defs.h
+++ b/gdb-7.11/gdb/defs.h
@@ -690,4 +690,8 @@ enum block_enum
#include "utils.h"
+#ifdef HAVE_PYTHON
+extern int python_available (void);
+#endif
+
#endif /* #ifndef DEFS_H */
diff --git a/gdb-7.11/gdb/gdbserver/hostio.c b/gdb-7.11/gdb/gdbserver/hostio.c
index 242206e7d..ae0b303e8 100644
--- a/gdb-7.11/gdb/gdbserver/hostio.c
+++ b/gdb-7.11/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-7.11/gdb/gdbserver/linux-low.c b/gdb-7.11/gdb/gdbserver/linux-low.c
index 8b025bd1b..4c46e94fe 100644
--- a/gdb-7.11/gdb/gdbserver/linux-low.c
+++ b/gdb-7.11/gdb/gdbserver/linux-low.c
@@ -5783,10 +5783,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-7.11/gdb/gdbserver/remote-utils.c b/gdb-7.11/gdb/gdbserver/remote-utils.c
index e75147356..4ae6553c3 100644
--- a/gdb-7.11/gdb/gdbserver/remote-utils.c
+++ b/gdb-7.11/gdb/gdbserver/remote-utils.c
@@ -283,11 +283,63 @@ remote_prepare (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 (char *name)
{
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-7.11/gdb/python/py-auto-load.c b/gdb-7.11/gdb/python/py-auto-load.c
index 08ba58b8b..7e98e1619 100644
--- a/gdb-7.11/gdb/python/py-auto-load.c
+++ b/gdb-7.11/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-7.11/gdb/python/py-prettyprint.c b/gdb-7.11/gdb/python/py-prettyprint.c
index e97769b4d..283639908 100644
--- a/gdb-7.11/gdb/python/py-prettyprint.c
+++ b/gdb-7.11/gdb/python/py-prettyprint.c
@@ -722,7 +722,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;
cleanups = ensure_python_env (gdbarch, language);
diff --git a/gdb-7.11/gdb/python/python.c b/gdb-7.11/gdb/python/python.c
index 7202105b5..ef7431b4b 100644
--- a/gdb-7.11/gdb/python/python.c
+++ b/gdb-7.11/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"
@@ -1625,6 +1632,44 @@ finalize_python (void *ignore)
/* Provide a prototype to silence -Wmissing-prototypes. */
extern initialize_file_ftype _initialize_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)
{
@@ -1748,6 +1793,9 @@ message == an error message without a stack will be printed."),
#endif
#endif
+ if (!python_available ())
+ return;
+
Py_Initialize ();
PyEval_InitThreads ();
@@ -1886,6 +1934,9 @@ gdbpy_finish_initialization (const struct extension_language_defn *extlang)
PyObject *sys_path;
struct cleanup *cleanup;
+ if (!python_available())
+ return;
+
cleanup = ensure_python_env (get_current_arch (), current_language);
/* Add the initial data-directory to sys.path. */
diff --git a/gdb-7.11/gdb/varobj.c b/gdb-7.11/gdb/varobj.c
index 6f56cbada..d14c9eb11 100644
--- a/gdb-7.11/gdb/varobj.c
+++ b/gdb-7.11/gdb/varobj.c
@@ -566,7 +566,7 @@ varobj_get_display_hint (const struct varobj *var)
#if HAVE_PYTHON
struct cleanup *back_to;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return NULL;
back_to = varobj_ensure_python_env (var);
@@ -700,7 +700,7 @@ dynamic_varobj_has_child_method (const struct varobj *var)
PyObject *printer = var->dynamic->pretty_printer;
int result;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return 0;
back_to = varobj_ensure_python_env (var);
@@ -1211,7 +1211,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)
@@ -1497,7 +1497,7 @@ varobj_set_visualizer (struct varobj *var, const char *visualizer)
PyObject *mainmod, *globals, *constructor;
struct cleanup *back_to;
- if (!gdb_python_initialized)
+ if (!python_available () || !gdb_python_initialized)
return;
back_to = varobj_ensure_python_env (var);
@@ -2466,7 +2466,7 @@ varobj_value_get_print_value (struct value *value,
gdbarch = get_type_arch (value_type (value));
#if HAVE_PYTHON
- if (gdb_python_initialized)
+ if (python_available () && gdb_python_initialized)
{
PyObject *value_formatter = var->dynamic->pretty_printer;