MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:tim Date:September 6 2006 10:01pm
Subject:bk commit into 4.1 tree (tsmith:1.2538) BUG#21250
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of tsmith. When tsmith 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, 2006-09-07 00:01:00+02:00, tsmith@stripped +2 -0
  Bug #21250: esolve stack traces on AMD64 (backport to mysql-4.1)

  sql/stacktrace.c@stripped, 2006-09-07 00:00:06+02:00, tsmith@stripped +40 -15
    stacktrace dumps for amd64 (backport fix for bug 21250 to mysql-4.1)

  sql/stacktrace.h@stripped, 2006-09-07 00:00:06+02:00, tsmith@stripped +6 -2
    stacktrace dumps for amd64 (backport fix for bug 21250 to mysql-4.1)

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	tsmith
# Host:	maint1.mysql.com
# Root:	/data/localhome/tsmith/bk/bfx/my41-bfx

--- 1.16/sql/stacktrace.c	2006-09-06 23:59:32 +02:00
+++ 1.17/sql/stacktrace.c	2006-09-06 23:59:32 +02:00
@@ -21,6 +21,7 @@
 
 #ifdef HAVE_STACKTRACE
 #include <unistd.h>
+#include <strings.h>
 
 #define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)
 
@@ -44,7 +45,29 @@ void safe_print_str(const char* name, co
 }
 
 #ifdef TARGET_OS_LINUX
-#define SIGRETURN_FRAME_COUNT  2
+
+#ifdef __i386__
+#define SIGRETURN_FRAME_OFFSET 17
+#endif
+
+#ifdef __x86_64__
+#define SIGRETURN_FRAME_OFFSET 23
+#endif
+
+static my_bool is_nptl;
+
+/* Check if we are using NPTL or LinuxThreads on Linux */
+void check_thread_lib(void)
+{
+  char buf[5];
+
+#ifdef _CS_GNU_LIBPTHREAD_VERSION
+  confstr(_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf));
+  is_nptl = !strncasecmp(buf, "NPTL", sizeof(buf));
+#else
+  is_nptl = 0;
+#endif
+}
 
 #if defined(__alpha__) && defined(__GNUC__)
 /*
@@ -90,7 +113,7 @@ inline uint32* find_prev_pc(uint32* pc, 
 void  print_stacktrace(gptr stack_bottom, ulong thread_stack)
 {
   uchar** fp;
-  uint frame_count = 0;
+  uint frame_count = 0, sigreturn_frame_count;
 #if defined(__alpha__) && defined(__GNUC__)
   uint32* pc;
 #endif
@@ -100,28 +123,27 @@ void  print_stacktrace(gptr stack_bottom
 Attempting backtrace. You can use the following information to find out\n\
 where mysqld died. If you see no messages after this, something went\n\
 terribly wrong...\n");
-#ifdef __i386__  
+#ifdef __i386__
   __asm __volatile__ ("movl %%ebp,%0"
 		      :"=r"(fp)
 		      :"r"(fp));
-  if (!fp)
-  {
-    fprintf(stderr, "frame pointer (ebp) is NULL, did you compile with\n\
--fomit-frame-pointer? Aborting backtrace!\n");
-    return;
-  }
+#endif
+#ifdef __x86_64__
+  __asm __volatile__ ("movq %%rbp,%0"
+		      :"=r"(fp)
+		      :"r"(fp));
 #endif
 #if defined(__alpha__) && defined(__GNUC__) 
   __asm __volatile__ ("mov $30,%0"
 		      :"=r"(fp)
 		      :"r"(fp));
+#endif
   if (!fp)
   {
-    fprintf(stderr, "frame pointer (fp) is NULL, did you compile with\n\
+    fprintf(stderr, "frame pointer is NULL, did you compile with\n\
 -fomit-frame-pointer? Aborting backtrace!\n");
     return;
   }
-#endif /* __alpha__ */
 
   if (!stack_bottom || (gptr) stack_bottom > (gptr) &fp)
   {
@@ -151,13 +173,16 @@ terribly wrong...\n");
 		      :"r"(pc));
 #endif  /* __alpha__ */
 
+  /* We are 1 frame above signal frame with NPTL and 2 frames above with LT */
+  sigreturn_frame_count = is_nptl ? 1 : 2;
+  
   while (fp < (uchar**) stack_bottom)
   {
-#ifdef __i386__    
+#if defined(__i386__) || defined(__x86_64__)
     uchar** new_fp = (uchar**)*fp;
-    fprintf(stderr, "%p\n", frame_count == SIGRETURN_FRAME_COUNT ?
-	    *(fp+17) : *(fp+1));
-#endif /* __386__ */
+    fprintf(stderr, "%p\n", frame_count == sigreturn_frame_count ?
+	    *(fp + SIGRETURN_FRAME_OFFSET) : *(fp + 1));
+#endif /* defined(__386__)  || defined(__x86_64__) */
 
 #if defined(__alpha__) && defined(__GNUC__)
     uchar** new_fp = find_prev_fp(pc, fp);

--- 1.3/sql/stacktrace.h	2006-09-06 23:59:32 +02:00
+++ 1.4/sql/stacktrace.h	2006-09-06 23:59:32 +02:00
@@ -19,16 +19,20 @@ extern "C" {
 #endif
 
 #ifdef TARGET_OS_LINUX
-#if defined(HAVE_STACKTRACE) || (defined (__i386__) || (defined(__alpha__) && defined(__GNUC__)))
+#if defined(HAVE_STACKTRACE) || (defined (__x86_64__) || defined (__i386__) || (defined(__alpha__) && defined(__GNUC__)))
 #undef HAVE_STACKTRACE
 #define HAVE_STACKTRACE
 
 extern char* __bss_start;
 extern char* heap_start;
 
-#define init_stacktrace() { heap_start = (char*) &__bss_start; }
+#define init_stacktrace() do {                                 \
+                            heap_start = (char*) &__bss_start; \
+                            check_thread_lib();                \
+                          } while(0);
 void print_stacktrace(gptr stack_bottom, ulong thread_stack);
 void safe_print_str(const char* name, const char* val, int max_len);
+void check_thread_lib(void);  
 #endif /* (defined (__i386__) || (defined(__alpha__) && defined(__GNUC__))) */
 #endif /* TARGET_OS_LINUX */
 
Thread
bk commit into 4.1 tree (tsmith:1.2538) BUG#21250tim6 Sep