Bug 921330: Fix sync unwind on Mac OS X. r=BenWa
authorAaron Klotz <aklotz@mozilla.com>
Tue, 15 Oct 2013 12:58:52 -0600
changeset 164635 5907769bfe89b1c9b416d8de885133ee84d7aeb8
parent 164634 875ab904cc997337dc16123586f3d2101e9d4764
child 164636 51170e07d7e9ac16a8d6cbae6bb95bc9ce8d5bc8
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBenWa
bugs921330
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 921330: Fix sync unwind on Mac OS X. r=BenWa
tools/profiler/platform-macos.cc
--- a/tools/profiler/platform-macos.cc
+++ b/tools/profiler/platform-macos.cc
@@ -407,37 +407,41 @@ void Sampler::UnregisterCurrentThread()
     if (info->ThreadId() == id) {
       delete info;
       sRegisteredThreads->erase(sRegisteredThreads->begin() + i);
       break;
     }
   }
 }
 
-__attribute__((noinline)) static Address GetPC()
-{
-  return reinterpret_cast<Address>(__builtin_return_address(0));
-}
-
 void TickSample::PopulateContext(void* aContext)
 {
+  // Note that this asm changes if PopulateContext's parameter list is altered
 #if defined(SPS_PLAT_amd64_darwin)
   asm (
-      "movq %%rsp, %0\n\t"
-      "movq %%rbp, %1\n\t"
+      // Compute caller's %rsp by adding to %rbp:
+      // 8 bytes for previous %rbp, 8 bytes for return address
+      "leaq 0x10(%%rbp), %0\n\t"
+      // Dereference %rbp to get previous %rbp
+      "movq (%%rbp), %1\n\t"
       :
-      "=g"(sp),
-      "=g"(fp)
+      "=r"(sp),
+      "=r"(fp)
   );
 #elif defined(SPS_PLAT_x86_darwin)
   asm (
-      "movl %%esp, %0\n\t"
-      "movl %%ebp, %1\n\t"
+      // Compute caller's %esp by adding to %ebp:
+      // 4 bytes for aContext + 4 bytes for return address +
+      // 4 bytes for previous %ebp
+      "leal 0xc(%%ebp), %0\n\t"
+      // Dereference %ebp to get previous %ebp
+      "movl (%%ebp), %1\n\t"
       :
-      "=g"(sp),
-      "=g"(fp)
+      "=r"(sp),
+      "=r"(fp)
   );
 #else
 # error "Unsupported architecture"
 #endif
-  pc = GetPC();
+  pc = reinterpret_cast<Address>(__builtin_extract_return_addr(
+                                    __builtin_return_address(0)));
 }