List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:December 28 2007 1:21am
Subject:bk commit into 5.1 tree (davi:1.2644) 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, 2007-12-27 23:21:28-02:00, davi@stripped +3 -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, 2007-12-27 23:21:26-02:00, davi@stripped +39 -3
    Add check for backtrace headers, backtrace functions and if
    the compiler supports weak symbol attribute. Also check the
    __cxa_demangle function call signature.

  sql/mysqld.cc@stripped, 2007-12-27 23:21:26-02:00, davi@stripped +18 -0
    Print the value of the THD::killed variable when dumping.
    In some circumstances knowing if the thread was killed makes
    debugging easier.

  sql/stacktrace.c@stripped, 2007-12-27 23:21:26-02:00, davi@stripped +78 -0
    Use the glibc backtrace function when available and demangle
    C++ function names if the __cxa_demangle function is linked
    in (stdc++, by testing if the function is not null before 
    calling it).

diff -Nrup a/configure.in b/configure.in
--- a/configure.in	2007-12-11 14:41:07 -02:00
+++ b/configure.in	2007-12-27 23:21:26 -02:00
@@ -775,8 +775,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])
 
@@ -1978,7 +1978,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)
 
 #
 #
@@ -2267,6 +2267,42 @@ then
   AC_DEFINE([HAVE_BROKEN_NETINET_INCLUDES], [1], [Can netinet be included])
 fi
 AC_MSG_RESULT("$netinet_inc")
+
+AC_CACHE_CHECK([checking support for weak symbols], mysql_cv_weak_symbol,
+[AC_TRY_RUN([
+  int my_foobar(void) __attribute__((__weak__));
+  int foo(void)
+  {
+    if (my_foobar)
+      return -1;
+    else
+      return 0;
+  }
+  int main()
+  {
+    return foo();
+  }
+], [mysql_cv_weak_symbol=yes], [mysql_cv_weak_symbol=no])])
+
+if test "x$mysql_cv_weak_symbol" = xyes; then
+  AC_DEFINE(HAVE_WEAK_SYMBOL, 1,
+            [Define to 1 if compiler supports weak symbol attribute.])
+fi
+
+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_COMPILE([#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	2007-12-12 16:13:55 -02:00
+++ b/sql/mysqld.cc	2007-12-27 23:21:26 -02:00
@@ -2243,10 +2243,28 @@ the thread stack. Please read http://dev
   }
   if (thd)
   {
+    const char *kreason;
     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);
+    switch (thd->killed) {
+    case THD::NOT_KILLED:
+      kreason= "NOT_KILLED";
+      break;
+    case THD::KILL_BAD_DATA:
+      kreason= "KILL_BAD_DATA";
+      break;
+    case THD::KILL_QUERY:
+      kreason= "KILLED_NO_VALUE";
+      break;
+    case THD::KILLED_NO_VALUE:
+      kreason= "KILLED_NO_VALUE";
+      break;
+    default:
+      kreason= "UNKNOWN";
+    }
+    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	2007-12-27 23:21:26 -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,82 @@ inline uint32* find_prev_pc(uint32* pc, 
 }
 #endif /* defined(__alpha__) && defined(__GNUC__) */
 
+#if HAVE_BACKTRACE && HAVE_ABI_CXA_DEMANGLE && HAVE_WEAK_SYMBOL
+#define BACKTRACE_DEMANGLE 1
+#endif
+
+#ifdef BACKTRACE_DEMANGLE
+
+char *__cxa_demangle(const char *mangled_name, char *output_buffer,
+                     unsigned int *length, int *status) __attribute__((__weak__));
+
+static char *my_demangle(const char *mangled_name, int *status)
+{
+  if (__cxa_demangle)
+    return __cxa_demangle(mangled_name, NULL, NULL, status);
+  else
+    return NULL;
+}
+
+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__)
Thread
bk commit into 5.1 tree (davi:1.2644) BUG#31891Davi Arnaut28 Dec