Mark Wielaard c728a33
--- valgrind/coregrind/m_stacktrace.c.jj	2012-08-05 18:04:16.000000000 +0200
Mark Wielaard c728a33
+++ valgrind/coregrind/m_stacktrace.c	2012-08-10 12:13:46.069797051 +0200
707b2af
@@ -149,11 +149,23 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId
707b2af
       /* Try to derive a new (ip,sp,fp) triple from the current
707b2af
          set. */
707b2af
 
707b2af
-      /* On x86, first try the old-fashioned method of following the
707b2af
-         %ebp-chain.  Code which doesn't use this (that is, compiled
707b2af
-         with -fomit-frame-pointer) is not ABI compliant and so
707b2af
-         relatively rare.  Besides, trying the CFI first almost always
707b2af
-         fails, and is expensive. */
707b2af
+      /* On x86 GCC 4.6 and later now defaults to -fomit-frame-pointer
707b2af
+         together with emitting unwind info (-fasynchronous-unwind-tables).
707b2af
+         So, try CF info first.  */
707b2af
+      if ( VG_(use_CF_info)( &uregs, fp_min, fp_max ) ) {
707b2af
+         if (0 == uregs.xip || 1 == uregs.xip) break;
707b2af
+         if (sps) sps[i] = uregs.xsp;
707b2af
+         if (fps) fps[i] = uregs.xbp;
707b2af
+         ips[i++] = uregs.xip - 1; /* -1: refer to calling insn, not the RA */
707b2af
+         if (debug)
707b2af
+            VG_(printf)("     ipsC[%d]=0x%08lx\n", i-1, ips[i-1]);
707b2af
+         uregs.xip = uregs.xip - 1;
707b2af
+            /* as per comment at the head of this loop */
707b2af
+         continue;
707b2af
+      }
707b2af
+
707b2af
+      /* And only then the old-fashioned method of following the
707b2af
+         %ebp-chain.  */
707b2af
       /* Deal with frames resulting from functions which begin "pushl%
707b2af
          ebp ; movl %esp, %ebp" which is the ABI-mandated preamble. */
707b2af
       if (fp_min <= uregs.xbp &&
707b2af
@@ -179,20 +191,6 @@ UInt VG_(get_StackTrace_wrk) ( ThreadId
707b2af
          uregs.xip = uregs.xip - 1;
707b2af
             /* as per comment at the head of this loop */
707b2af
          continue;
707b2af
-      }
707b2af
-
707b2af
-      /* That didn't work out, so see if there is any CF info to hand
707b2af
-         which can be used. */
707b2af
-      if ( VG_(use_CF_info)( &uregs, fp_min, fp_max ) ) {
707b2af
-         if (0 == uregs.xip || 1 == uregs.xip) break;
707b2af
-         if (sps) sps[i] = uregs.xsp;
707b2af
-         if (fps) fps[i] = uregs.xbp;
707b2af
-         ips[i++] = uregs.xip - 1; /* -1: refer to calling insn, not the RA */
707b2af
-         if (debug)
707b2af
-            VG_(printf)("     ipsC[%d]=0x%08lx\n", i-1, ips[i-1]);
707b2af
-         uregs.xip = uregs.xip - 1;
707b2af
-            /* as per comment at the head of this loop */
707b2af
-         continue;
707b2af
       }
707b2af
 
707b2af
       /* And, similarly, try for MSVC FPO unwind info. */