* gdb_string.h: Moved to ...
authorDoug Evans <dje@google.com>
Wed, 8 Aug 2012 19:48:19 +0000 (19:48 +0000)
committerDoug Evans <dje@google.com>
Wed, 8 Aug 2012 19:48:19 +0000 (19:48 +0000)
* common/gdb_string.h: ... here.
* common/vec.h: Remove #ifndef GDBSERVER conditional inclusion of
gdb_string.h and gdb_assert.h.

gdbserver/
* configure.ac: Add check for strstr.
* config.in: Regenerate.
* configure: Regenerate.

* linux-thread-db.c: #include "gdb_vecs.h".
(try_thread_db_load_from_pdir_1): New arg "subdir".  All callers
updated.
(try_thread_db_load_from_pdir): New arg "subdir".  All callers updated.
(thread_db_load_search): Use a vector to iterate over path elements.
Handle text appearing after "$pdir".

gdbserver/
* Makefile.in (SFILES): Add gdb_vecs.c.
(OBS): Add gdb_vecs.o.
(gdb_vecs_h, host_defs_h): New variables.
(thread-db.o): Add $(gdb_vecs_h) dependency.
(gdb_vecs.o): New rule.
* thread-db.c: #include "gdb_vecs.h".
(thread_db_load_search): Use a vector to iterate over path elements.
Handle text appearing after "$pdir".

gdb/ChangeLog
gdb/common/gdb_string.h [new file with mode: 0644]
gdb/common/vec.h
gdb/gdb_string.h [deleted file]
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/config.in
gdb/gdbserver/configure
gdb/gdbserver/configure.ac
gdb/gdbserver/thread-db.c
gdb/linux-thread-db.c

index 0fcf9692837725aa461e80dd5895de733c78c787..a48a7f3f4377bd92be05dfb9ea80ce0a85291e56 100644 (file)
@@ -1,3 +1,17 @@
+2012-08-08  Doug Evans  <dje@google.com>
+
+       * linux-thread-db.c: #include "gdb_vecs.h".
+       (try_thread_db_load_from_pdir_1): New arg "subdir".  All callers
+       updated.
+       (try_thread_db_load_from_pdir): New arg "subdir".  All callers updated.
+       (thread_db_load_search): Use a vector to iterate over path elements.
+       Handle text appearing after "$pdir".
+
+       * gdb_string.h: Moved to ...
+       * common/gdb_string.h: ... here.
+       * common/vec.h: Remove #ifndef GDBSERVER conditional inclusion of
+       gdb_string.h and gdb_assert.h.
+
 2012-08-08  Yao Qi  <yao@codesourcery.com>
 
        * tic6x-tdep.c (tic6x_register_to_value): Remove.
diff --git a/gdb/common/gdb_string.h b/gdb/common/gdb_string.h
new file mode 100644 (file)
index 0000000..aa037df
--- /dev/null
@@ -0,0 +1,70 @@
+/* Portable <string.h>
+
+   Copyright (C) 1995, 1998-2001, 2004, 2007-2012 Free Software
+   Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#if !defined(GDB_STRING_H)
+#define GDB_STRING_H
+
+#ifdef STDC_HEADERS
+#include <string.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h> /* strcasecmp etc..  */
+#endif
+#else
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#include <strings.h>
+#endif
+
+#ifndef strchr
+extern char *strchr (const char *, int);       /* X3.159-1989  4.11.5.2 */
+#endif
+
+#ifndef strrchr
+extern char *strrchr (const char *, int);      /* X3.159-1989  4.11.5.5 */
+#endif
+
+#ifndef strtok
+extern char *strtok (char *, const char *);    /* X3.159-1989  4.11.5.8 */
+#endif
+
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#else
+extern void *memset ();
+extern void *memcpy ();
+extern void *memmove ();
+extern int memcmp ();
+#endif
+#endif /* STDC_HEADERS */
+
+#if !HAVE_DECL_STRERROR
+#ifndef strerror
+extern char *strerror (int);   /* X3.159-1989  4.11.6.2 */
+#endif
+#endif
+
+#if !HAVE_DECL_STRSTR
+#ifndef strstr
+extern char *strstr (const char *, const char *); /* X3.159-1989  4.11.5.7 */
+#endif
+#endif
+
+#endif /* !defined(GDB_STRING_H) */
index fa15370dd9be496c4e369fa0e1ce1424f07cd937..49116e1f166627a74972d84a64196241b2741cad 100644 (file)
 
 #include <stddef.h>
 
-#ifndef GDBSERVER
 #include "gdb_string.h"
 #include "gdb_assert.h"
-#endif
 
 /* The macros here implement a set of templated vector types and
    associated interfaces.  These templates are implemented with
diff --git a/gdb/gdb_string.h b/gdb/gdb_string.h
deleted file mode 100644 (file)
index aa037df..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* Portable <string.h>
-
-   Copyright (C) 1995, 1998-2001, 2004, 2007-2012 Free Software
-   Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#if !defined(GDB_STRING_H)
-#define GDB_STRING_H
-
-#ifdef STDC_HEADERS
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-#include <strings.h> /* strcasecmp etc..  */
-#endif
-#else
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
-#ifndef strchr
-extern char *strchr (const char *, int);       /* X3.159-1989  4.11.5.2 */
-#endif
-
-#ifndef strrchr
-extern char *strrchr (const char *, int);      /* X3.159-1989  4.11.5.5 */
-#endif
-
-#ifndef strtok
-extern char *strtok (char *, const char *);    /* X3.159-1989  4.11.5.8 */
-#endif
-
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#else
-extern void *memset ();
-extern void *memcpy ();
-extern void *memmove ();
-extern int memcmp ();
-#endif
-#endif /* STDC_HEADERS */
-
-#if !HAVE_DECL_STRERROR
-#ifndef strerror
-extern char *strerror (int);   /* X3.159-1989  4.11.6.2 */
-#endif
-#endif
-
-#if !HAVE_DECL_STRSTR
-#ifndef strstr
-extern char *strstr (const char *, const char *); /* X3.159-1989  4.11.5.7 */
-#endif
-#endif
-
-#endif /* !defined(GDB_STRING_H) */
index d446361fa7e0c5dda885f9c16efd005315a7b8d1..5707850d86b4c7ced8c915aefbb71382b7592039 100644 (file)
@@ -1,3 +1,18 @@
+2012-08-08  Doug Evans  <dje@google.com>
+
+       * Makefile.in (SFILES): Add gdb_vecs.c.
+       (OBS): Add gdb_vecs.o.
+       (gdb_vecs_h, host_defs_h): New variables.
+       (thread-db.o): Add $(gdb_vecs_h) dependency.
+       (gdb_vecs.o): New rule.
+       * thread-db.c: #include "gdb_vecs.h".
+       (thread_db_load_search): Use a vector to iterate over path elements.
+       Handle text appearing after "$pdir".
+
+       * configure.ac: Add check for strstr.
+       * config.in: Regenerate.
+       * configure: Regenerate.
+
 2012-08-02  Ulrich Weigand  <ulrich.weigand@linaro.org>
 
        * hostio.c (handle_pread): If pread fails, fall back to attempting
index 446ea047fa838f2229b47babfbff13e05eb667ba..f62799e12558ac48c22a81b833cad8d0954131f4 100644 (file)
@@ -140,7 +140,7 @@ SFILES=     $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
        $(srcdir)/win32-arm-low.c $(srcdir)/win32-i386-low.c \
        $(srcdir)/win32-low.c $(srcdir)/wincecompat.c \
        $(srcdir)/hostio.c $(srcdir)/hostio-errno.c \
-       $(srcdir)/common/vec.c \
+       $(srcdir)/common/vec.c $(srcdir)/common/gdb_vecs.c \
        $(srcdir)/common/common-utils.c $(srcdir)/common/xml-utils.c \
        $(srcdir)/common/linux-osdata.c $(srcdir)/common/ptid.c \
        $(srcdir)/common/buffer.c
@@ -153,7 +153,7 @@ SOURCES = $(SFILES)
 TAGFILES = $(SOURCES) ${HFILES} ${ALLPARAM} ${POSSLIBS}
 
 OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o target.o \
-       utils.o version.o vec.o \
+       utils.o version.o vec.o gdb_vecs.o \
        mem-break.o hostio.o event-loop.o tracepoint.o \
        xml-utils.o common-utils.o ptid.o buffer.o format.o \
        dll.o \
@@ -414,6 +414,8 @@ ax_h = $(srcdir)/ax.h
 agent_h = $(srcdir)/../common/agent.h
 linux_osdata_h = $(srcdir)/../common/linux-osdata.h
 vec_h = $(srcdir)/../common/vec.h
+gdb_vecs_h = $(srcdir)/../common/gdb_vecs.h
+host_defs_h = $(srcdir)/../common/host-defs.h
 # Since everything must include server.h, we make that depend on
 # generated files.
 server_h = $(srcdir)/server.h $(regcache_h) $(srcdir)/target.h \
@@ -485,7 +487,7 @@ remote-utils.o: remote-utils.c terminal.h $(server_h) $(gdbthread_h)
 server.o: server.c $(server_h) $(agent_h) $(gdbthread_h)
 target.o: target.c $(server_h) 
 thread-db.o: thread-db.c $(server_h) $(linux_low_h) $(gdb_proc_service_h) \
-       $(gdb_thread_db_h)
+       $(gdb_thread_db_h) $(gdb_vecs_h)
 tracepoint.o: tracepoint.c $(server_h) $(ax_h) $(agent_h) $(gdbthread_h)
 utils.o: utils.c $(server_h)
 gdbreplay.o: gdbreplay.c config.h
@@ -506,6 +508,9 @@ common-utils.o: ../common/common-utils.c $(server_h)
 vec.o: ../common/vec.c $(vec_h)
        $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
 
+gdb_vecs.o: ../common/gdb_vecs.c $(vec_h) $(gdb_vecs_h) $(host_defs_h)
+       $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
+
 xml-utils.o: ../common/xml-utils.c $(server_h)
        $(CC) -c $(CPPFLAGS) $(INTERNAL_CFLAGS) $< -DGDBSERVER
 
index 26742ac12bdc8efe22f942fe6af2435dfe5833d5..bacf005e2f0fa5c27acff3188d6dcd5286b34164 100644 (file)
    don't. */
 #undef HAVE_DECL_STRERROR
 
+/* Define to 1 if you have the declaration of `strstr', and to 0 if you don't.
+   */
+#undef HAVE_DECL_STRSTR
+
 /* Define to 1 if you have the declaration of `vasprintf', and to 0 if you
    don't. */
 #undef HAVE_DECL_VASPRINTF
index 63e25c239ea7fa27f3bbad360be3b651a6dd5714..69953c25c57202a5cece6cf7625399fcf7e76a89 100755 (executable)
@@ -4688,6 +4688,16 @@ fi
 cat >>confdefs.h <<_ACEOF
 #define HAVE_DECL_STRERROR $ac_have_decl
 _ACEOF
+ac_fn_c_check_decl "$LINENO" "strstr" "ac_cv_have_decl_strstr" "$ac_includes_default"
+if test "x$ac_cv_have_decl_strstr" = x""yes; then :
+  ac_have_decl=1
+else
+  ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_STRSTR $ac_have_decl
+_ACEOF
 ac_fn_c_check_decl "$LINENO" "perror" "ac_cv_have_decl_perror" "$ac_includes_default"
 if test "x$ac_cv_have_decl_perror" = x""yes; then :
   ac_have_decl=1
index 7013a21248bf255d756e730a754636568b9d60db..dc3c3cdd70771c5f57f46d4bd3b1deaa3b1be076 100644 (file)
@@ -174,7 +174,7 @@ AC_TRY_LINK([
   [AC_MSG_RESULT(no)])
 fi
 
-AC_CHECK_DECLS([strerror, perror, vasprintf, vsnprintf])
+AC_CHECK_DECLS([strerror, strstr, perror, vasprintf, vsnprintf])
 
 AC_CHECK_TYPES(socklen_t, [], [],
 [#include <sys/types.h>
index 795f9267ddb379150300663c192448105f34bb91..4a59df613c1a380cee9e73db3cad052854013797 100644 (file)
@@ -28,6 +28,7 @@ static int thread_db_use_events;
 
 #include "gdb_proc_service.h"
 #include "gdb_thread_db.h"
+#include "gdb_vecs.h"
 
 #ifndef USE_LIBTHREAD_DB_DIRECTLY
 #include <dlfcn.h>
@@ -741,39 +742,31 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 static int
 thread_db_load_search (void)
 {
-  const char *search_path;
-  int rc = 0;
+  VEC (char_ptr) *dir_vec;
+  char *this_dir;
+  int i, rc = 0;
 
   if (libthread_db_search_path == NULL)
     libthread_db_search_path = xstrdup (LIBTHREAD_DB_SEARCH_PATH);
 
-  search_path = libthread_db_search_path;
-  while (*search_path)
+  dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
+
+  for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
     {
-      const char *end = strchr (search_path, ':');
-      const char *this_dir = search_path;
+      const int pdir_len = sizeof ("$pdir") - 1;
       size_t this_dir_len;
 
-      if (end)
-       {
-         this_dir_len = end - search_path;
-         search_path += this_dir_len + 1;
-       }
-      else
-       {
-         this_dir_len = strlen (this_dir);
-         search_path += this_dir_len;
-       }
+      this_dir_len = strlen (this_dir);
 
-      if (this_dir_len == sizeof ("$pdir") - 1
-         && strncmp (this_dir, "$pdir", this_dir_len) == 0)
+      if (strncmp (this_dir, "$pdir", pdir_len) == 0
+         && (this_dir[pdir_len] == '\0'
+             || this_dir[pdir_len] == '/'))
        {
          /* We don't maintain a list of loaded libraries so we don't know
             where libpthread lives.  We *could* fetch the info, but we don't
             do that yet.  Ignore it.  */
        }
-      else if (this_dir_len == sizeof ("$sdir") - 1
-              && strncmp (this_dir, "$sdir", this_dir_len) == 0)
+      else if (strcmp (this_dir, "$sdir") == 0)
        {
          if (try_thread_db_load_from_sdir ())
            {
@@ -791,6 +784,7 @@ thread_db_load_search (void)
        }
     }
 
+  free_char_ptr_vec (dir_vec);
   if (debug_threads)
     fprintf (stderr, "thread_db_load_search returning %d\n", rc);
   return rc;
index 2c16e02d827342ff2627e8ba9d3210aab6f7f508..bd905274301e929be756fb6eedf06470b8e74348 100644 (file)
@@ -23,7 +23,7 @@
 #include <dlfcn.h>
 #include "gdb_proc_service.h"
 #include "gdb_thread_db.h"
-
+#include "gdb_vecs.h"
 #include "bfd.h"
 #include "command.h"
 #include "exceptions.h"
@@ -881,11 +881,12 @@ try_thread_db_load (const char *library)
 }
 
 /* Subroutine of try_thread_db_load_from_pdir to simplify it.
-   Try loading libthread_db from the same directory as OBJ.
+   Try loading libthread_db in directory(OBJ)/SUBDIR.
+   SUBDIR may be NULL.  It may also be something like "../lib64".
    The result is true for success.  */
 
 static int
-try_thread_db_load_from_pdir_1 (struct objfile *obj)
+try_thread_db_load_from_pdir_1 (struct objfile *obj, const char *subdir)
 {
   struct cleanup *cleanup;
   char *path, *cp;
@@ -898,14 +899,21 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj)
       return 0;
     }
 
-  path = xmalloc (strlen (obj->name) + 1 + strlen (LIBTHREAD_DB_SO) + 1);
+  path = xmalloc (strlen (obj->name) + (subdir ? strlen (subdir) + 1 : 0)
+                 + 1 + strlen (LIBTHREAD_DB_SO) + 1);
   cleanup = make_cleanup (xfree, path);
 
   strcpy (path, obj->name);
   cp = strrchr (path, '/');
   /* This should at minimum hit the first character.  */
   gdb_assert (cp != NULL);
-  strcpy (cp + 1, LIBTHREAD_DB_SO);
+  cp[1] = '\0';
+  if (subdir != NULL)
+    {
+      strcat (cp, subdir);
+      strcat (cp, "/");
+    }
+  strcat (cp, LIBTHREAD_DB_SO);
 
   if (!file_is_auto_load_safe (path, _("auto-load: Loading libthread-db "
                                       "library \"%s\" from $pdir.\n"),
@@ -919,11 +927,12 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj)
 }
 
 /* Handle $pdir in libthread-db-search-path.
-   Look for libthread_db in the directory of libpthread.
+   Look for libthread_db in directory(libpthread)/SUBDIR.
+   SUBDIR may be NULL.  It may also be something like "../lib64".
    The result is true for success.  */
 
 static int
-try_thread_db_load_from_pdir (void)
+try_thread_db_load_from_pdir (const char *subdir)
 {
   struct objfile *obj;
 
@@ -933,14 +942,15 @@ try_thread_db_load_from_pdir (void)
   ALL_OBJFILES (obj)
     if (libpthread_name_p (obj->name))
       {
-       if (try_thread_db_load_from_pdir_1 (obj))
+       if (try_thread_db_load_from_pdir_1 (obj, subdir))
          return 1;
 
        /* We may have found the separate-debug-info version of
           libpthread, and it may live in a directory without a matching
           libthread_db.  */
        if (obj->separate_debug_objfile_backlink != NULL)
-         return try_thread_db_load_from_pdir_1 (obj->separate_debug_objfile_backlink);
+         return try_thread_db_load_from_pdir_1 (obj->separate_debug_objfile_backlink,
+                                                subdir);
 
        return 0;
       }
@@ -998,37 +1008,41 @@ try_thread_db_load_from_dir (const char *dir, size_t dir_len)
 static int
 thread_db_load_search (void)
 {
-  const char *search_path = libthread_db_search_path;
-  int rc = 0;
+  VEC (char_ptr) *dir_vec;
+  struct cleanup *cleanups;
+  char *this_dir;
+  int i, rc = 0;
 
-  while (*search_path)
+  dir_vec = dirnames_to_char_ptr_vec (libthread_db_search_path);
+  cleanups = make_cleanup_free_char_ptr_vec (dir_vec);
+
+  for (i = 0; VEC_iterate (char_ptr, dir_vec, i, this_dir); ++i)
     {
-      const char *end = strchr (search_path, ':');
-      const char *this_dir = search_path;
+      const int pdir_len = sizeof ("$pdir") - 1;
       size_t this_dir_len;
 
-      if (end)
-       {
-         this_dir_len = end - search_path;
-         search_path += this_dir_len + 1;
-       }
-      else
-       {
-         this_dir_len = strlen (this_dir);
-         search_path += this_dir_len;
-       }
+      this_dir_len = strlen (this_dir);
 
-      if (this_dir_len == sizeof ("$pdir") - 1
-         && strncmp (this_dir, "$pdir", this_dir_len) == 0)
+      if (strncmp (this_dir, "$pdir", pdir_len) == 0
+         && (this_dir[pdir_len] == '\0'
+             || this_dir[pdir_len] == '/'))
        {
-         if (try_thread_db_load_from_pdir ())
+         char *subdir = NULL;
+         struct cleanup *free_subdir_cleanup = NULL;
+
+         if (this_dir[pdir_len] == '/')
            {
-             rc = 1;
-             break;
+             subdir = xmalloc (strlen (this_dir));
+             free_subdir_cleanup = make_cleanup (xfree, subdir);
+             strcpy (subdir, this_dir + pdir_len + 1);
            }
+         rc = try_thread_db_load_from_pdir (subdir);
+         if (free_subdir_cleanup != NULL)
+           do_cleanups (free_subdir_cleanup);
+         if (rc)
+           break;
        }
-      else if (this_dir_len == sizeof ("$sdir") - 1
-              && strncmp (this_dir, "$sdir", this_dir_len) == 0)
+      else if (strcmp (this_dir, "$sdir") == 0)
        {
          if (try_thread_db_load_from_sdir ())
            {
@@ -1046,6 +1060,7 @@ thread_db_load_search (void)
        }
     }
 
+  do_cleanups (cleanups);
   if (libthread_db_debug)
     printf_unfiltered (_("thread_db_load_search returning %d\n"), rc);
   return rc;
This page took 0.038846 seconds and 4 git commands to generate.