Bug 816117 - Part 2: Pass the thread context to NS_StackWalk on Win32. r=bgirard
authorBas Schouten <bschouten@mozilla.com>
Sat, 08 Dec 2012 06:15:21 +0100
changeset 115413 cdae5d81c8e3985a1dc330442368f657c204a1fd
parent 115412 89dca2ab7d8650375951013fe0f842b119ada9c4
child 115414 33c70f306fd448f5a3c2006a0c140c609c66df04
push idunknown
push userunknown
push dateunknown
reviewersbgirard
bugs816117
milestone20.0a1
Bug 816117 - Part 2: Pass the thread context to NS_StackWalk on Win32. r=bgirard
tools/profiler/TableTicker.cpp
tools/profiler/platform-win32.cc
tools/profiler/platform.h
--- a/tools/profiler/TableTicker.cpp
+++ b/tools/profiler/TableTicker.cpp
@@ -814,26 +814,31 @@ void TableTicker::doBacktrace(ThreadProf
     sp_array,
     mozilla::ArrayLength(pc_array),
     0
   };
 
   // Start with the current function.
   StackWalkCallback(aSample->pc, aSample->sp, &array);
 
+  void *platformData = nullptr;
+#ifdef XP_WIN
+  platformData = aSample->context;
+#endif
+
 #ifdef XP_MACOSX
   pthread_t pt = GetProfiledThread(platform_data());
   void *stackEnd = reinterpret_cast<void*>(-1);
   if (pt)
     stackEnd = static_cast<char*>(pthread_get_stackaddr_np(pt));
   nsresult rv = NS_OK;
   if (aSample->fp >= aSample->sp && aSample->fp <= stackEnd)
     rv = FramePointerStackWalk(StackWalkCallback, 0, &array, reinterpret_cast<void**>(aSample->fp), stackEnd);
 #else
-  nsresult rv = NS_StackWalk(StackWalkCallback, 0, &array, thread);
+  nsresult rv = NS_StackWalk(StackWalkCallback, 0, &array, thread, platformData);
 #endif
   if (NS_SUCCEEDED(rv)) {
     aProfile.addTag(ProfileEntry('s', "(root)"));
 
     ProfileStack* stack = aProfile.GetStack();
     int pseudoStackPos = 0;
 
     /* We have two stacks, the native C stack we extracted from unwinding,
--- a/tools/profiler/platform-win32.cc
+++ b/tools/profiler/platform-win32.cc
@@ -131,16 +131,17 @@ class SamplerThread : public Thread {
       sample->pc = reinterpret_cast<Address>(context.Rip);
       sample->sp = reinterpret_cast<Address>(context.Rsp);
       sample->fp = reinterpret_cast<Address>(context.Rbp);
 #else
       sample->pc = reinterpret_cast<Address>(context.Eip);
       sample->sp = reinterpret_cast<Address>(context.Esp);
       sample->fp = reinterpret_cast<Address>(context.Ebp);
 #endif
+      sample->context = &context;
       sampler->SampleStack(sample);
       sampler->Tick(sample);
     }
     ResumeThread(profiled_thread);
   }
 
   Sampler* sampler_;
   const int interval_;
--- a/tools/profiler/platform.h
+++ b/tools/profiler/platform.h
@@ -206,17 +206,18 @@ class TickSample {
         frames_count(0) {}
   Address pc;  // Instruction pointer.
   Address sp;  // Stack pointer.
   Address fp;  // Frame pointer.
 #ifdef ENABLE_ARM_LR_SAVING
   Address lr;  // ARM link register
 #endif
   Address function;  // The last called JS function.
-  void*   context;   // The context from the signal handler, if available
+  void*   context;   // The context from the signal handler, if available. On
+                     // Win32 this may contain the windows thread context.
   static const int kMaxFramesCount = 64;
   Address stack[kMaxFramesCount];  // Call stack.
   int frames_count;  // Number of captured frames.
   mozilla::TimeStamp timestamp;
 };
 
 class Sampler {
  public: