List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:February 4 2008 12:05pm
Subject:bk commit into 5.1 tree (davi:1.2516) BUG#31891
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of davi.  When davi does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-04 10:05:06-02:00, davi@stripped +4 -0
  Bug#31891 Meaningful stack trace
  
  On crashes generate a user-friendly resolved and demangled stack
  trace when libc provides the necessary functions (newer libc on i386,
  x86_64, powerpc, ia64, alpha and s390). Otherwise print a numeric
  stack trace as before, relying on resolve_stack_dump utility.

  configure.in@stripped, 2008-02-04 10:05:04-02:00, davi@stripped +18 -3
    Add check for backtrace headers, backtrace functions and if
    __cxa_demangle (libstdc++) is available at link time.

  sql/mysqld.cc@stripped, 2008-02-04 10:05:04-02:00, davi@stripped +29 -0
    Print the value of the THD::killed variable when dumping. In
    some circumstances knowing if the thread was killed makes
    debugging easier.
    
    Locally export and wrap in C linkage the C++ function __cxa_demangle.

  sql/stacktrace.c@stripped, 2008-02-04 10:05:04-02:00, davi@stripped +62 -0
    Use the glibc backtrace function when available and demangle
    C++ function names if the __cxa_demangle function is available.

  sql/stacktrace.h@stripped, 2008-02-04 10:05:04-02:00, davi@stripped +8 -0
    Locally export and wrap in C linkage the C++ function __cxa_demangle
    if available.

diff -Nrup a/configure.in b/configure.in
--- a/configure.in	2008-02-01 08:50:16 -02:00
+++ b/configure.in	2008-02-04 10:05:04 -02:00
@@ -813,8 +813,8 @@ AC_CHECK_HEADERS(fcntl.h float.h floatin
  sys/timeb.h sys/types.h sys/un.h sys/vadvise.h sys/wait.h term.h \
  unistd.h utime.h sys/utime.h termio.h termios.h sched.h crypt.h alloca.h \
  sys/ioctl.h malloc.h sys/malloc.h sys/ipc.h sys/shm.h linux/config.h \
- sys/prctl.h \
- sys/resource.h sys/param.h port.h ieeefp.h)
+ sys/prctl.h sys/resource.h sys/param.h port.h ieeefp.h \
+ execinfo.h)
 
 AC_CHECK_HEADERS([xfs/xfs.h])
 
@@ -2041,7 +2041,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bs
   sighold sigset sigthreadmask port_create sleep \
   snprintf socket stpcpy strcasecmp strerror strsignal strnlen strpbrk strstr \
   strtol strtoll strtoul strtoull tell tempnam thr_setconcurrency vidattr \
-  posix_fallocate)
+  posix_fallocate backtrace backtrace_symbols backtrace_symbols_fd)
 
 #
 #
@@ -2330,6 +2330,21 @@ then
   AC_DEFINE([HAVE_BROKEN_NETINET_INCLUDES], [1], [Can netinet be included])
 fi
 AC_MSG_RESULT("$netinet_inc")
+
+AC_LANG_SAVE
+AC_LANG_CPLUSPLUS
+AC_CHECK_HEADERS(cxxabi.h)
+AC_CACHE_CHECK([checking for abi::__cxa_demangle], mysql_cv_cxa_demangle,
+[AC_TRY_LINK([#include <cxxabi.h>], [
+  char *foo= 0; int bar= 0;
+  foo= abi::__cxa_demangle(foo, foo, 0, &bar);
+], [mysql_cv_cxa_demangle=yes], [mysql_cv_cxa_demangle=no])])
+AC_LANG_RESTORE
+
+if test "x$mysql_cv_cxa_demangle" = xyes; then
+  AC_DEFINE(HAVE_ABI_CXA_DEMANGLE, 1,
+            [Define to 1 if you have the `abi::__cxa_demangle' function.])
+fi
 
 #--------------------------------------------------------------------
 # Check for requested features
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2008-01-25 15:14:58 -02:00
+++ b/sql/mysqld.cc	2008-02-04 10:05:04 -02:00
@@ -2177,6 +2177,16 @@ static void check_data_home(const char *
 #define UNSAFE_DEFAULT_LINUX_THREADS 200
 #endif
 
+
+#if BACKTRACE_DEMANGLE
+#include <cxxabi.h>
+extern "C" char *my_demangle(const char *mangled_name, int *status)
+{
+  return abi::__cxa_demangle(mangled_name, NULL, NULL, status);
+}
+#endif
+
+
 extern "C" sig_handler handle_segfault(int sig)
 {
   time_t curr_time;
@@ -2248,10 +2258,29 @@ the thread stack. Please read http://dev
   }
   if (thd)
   {
+    const char *kreason= "UNKNOWN";
+    switch (thd->killed) {
+    case THD::NOT_KILLED:
+      kreason= "NOT_KILLED";
+      break;
+    case THD::KILL_BAD_DATA:
+      kreason= "KILL_BAD_DATA";
+      break;
+    case THD::KILL_CONNECTION:
+      kreason= "KILL_CONNECTION";
+      break;
+    case THD::KILL_QUERY:
+      kreason= "KILL_QUERY";
+      break;
+    case THD::KILLED_NO_VALUE:
+      kreason= "KILLED_NO_VALUE";
+      break;
+    }
     fprintf(stderr, "Trying to get some variables.\n\
 Some pointers may be invalid and cause the dump to abort...\n");
     safe_print_str("thd->query", thd->query, 1024);
     fprintf(stderr, "thd->thread_id=%lu\n", (ulong) thd->thread_id);
+    fprintf(stderr, "thd->killed=%s\n", kreason);
   }
   fprintf(stderr, "\
 The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains\n\
diff -Nrup a/sql/stacktrace.c b/sql/stacktrace.c
--- a/sql/stacktrace.c	2007-07-23 14:39:47 -03:00
+++ b/sql/stacktrace.c	2008-02-04 10:05:04 -02:00
@@ -17,11 +17,16 @@
 #include "stacktrace.h"
 #include <signal.h>
 #include <my_pthread.h>
+#include <m_string.h>
 
 #ifdef HAVE_STACKTRACE
 #include <unistd.h>
 #include <strings.h>
 
+#if HAVE_EXECINFO_H
+#include <execinfo.h>
+#endif
+
 #define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
 
 char *heap_start;
@@ -93,9 +98,66 @@ inline uint32* find_prev_pc(uint32* pc, 
 }
 #endif /* defined(__alpha__) && defined(__GNUC__) */
 
+#ifdef BACKTRACE_DEMANGLE
+static void my_demangle_symbols(char **addrs, int n)
+{
+  int status, i;
+  char *begin, *end, *demangled;
+
+  for (i= 0; i < n; i++)
+  {
+    demangled= NULL;
+    begin= strchr(addrs[i], '(');
+    end= begin ? strchr(begin, '+') : NULL;
+
+    if (begin && end)
+    {
+      *begin++= *end++= '\0';
+      demangled= my_demangle(begin, &status);
+      if (!demangled || status)
+      {
+        demangled= NULL;
+        begin[-1]= '(';
+        end[-1]= '+';
+      }
+    }
+
+    if (demangled)
+      fprintf(stderr, "%s(%s+%s\n", addrs[i], demangled, end);
+    else
+      fprintf(stderr, "%s\n", addrs[i]);
+  }
+}
+#endif
+
+
+#if HAVE_BACKTRACE
+static void backtrace_current_thread(void)
+{
+  void *addrs[128];
+  char **strings= NULL;
+  int n = backtrace(addrs, array_elements(addrs));
+#ifdef BACKTRACE_DEMANGLE
+  if ((strings= backtrace_symbols(addrs, n)))
+  {
+    my_demangle_symbols(strings, n);
+    free(strings);
+  }
+  else
+#endif
+  {
+    backtrace_symbols_fd(addrs, n, fileno(stderr));
+  }
+}
+#endif
+
 
 void  print_stacktrace(uchar* stack_bottom, ulong thread_stack)
 {
+#if HAVE_BACKTRACE
+  backtrace_current_thread();
+  return;
+#endif
   uchar** fp;
   uint frame_count = 0, sigreturn_frame_count;
 #if defined(__alpha__) && defined(__GNUC__)
diff -Nrup a/sql/stacktrace.h b/sql/stacktrace.h
--- a/sql/stacktrace.h	2007-05-10 06:59:30 -03:00
+++ b/sql/stacktrace.h	2008-02-04 10:05:04 -02:00
@@ -17,6 +17,14 @@
 extern "C" {
 #endif
 
+#if HAVE_BACKTRACE && HAVE_CXXABI_H && HAVE_ABI_CXA_DEMANGLE
+#define BACKTRACE_DEMANGLE 1
+#endif
+
+#if BACKTRACE_DEMANGLE
+char *my_demangle(const char *mangled_name, int *status);
+#endif
+
 #ifdef TARGET_OS_LINUX
 #if defined(HAVE_STACKTRACE) || (defined (__x86_64__) || defined (__i386__) || (defined(__alpha__) && defined(__GNUC__)))
 #undef HAVE_STACKTRACE
Thread
bk commit into 5.1 tree (davi:1.2516) BUG#31891Davi Arnaut4 Feb
  • Re: bk commit into 5.1 tree (davi:1.2516) BUG#31891Sergei Golubchik7 Feb
    • Re: bk commit into 5.1 tree (davi:1.2516) BUG#31891Davi Arnaut7 Feb
      • Re: bk commit into 5.1 tree (davi:1.2516) BUG#31891Sergei Golubchik8 Feb
        • Re: bk commit into 5.1 tree (davi:1.2516) BUG#31891Davi Arnaut8 Feb