Include held locks in SIGQUIT thread dumps.

Handy if you have an ANR that's locking related. Quick tour:

   at org.apache.harmony.dalvik.NativeTestTarget.emptyJniStaticSynchronizedMethod0(Native method)
   - locked <0x60135aa8> (a java.lang.Class<org.apache.harmony.dalvik.NativeTestTarget>)
   at java.lang.reflect.Method.invoke(Native method)
   at C.whileTrue(Main.java:63)
   at C.synchronizedOnClassString(Main.java:56)
   - locked <0x60002a70> (a java.lang.Class<java.lang.String>)
   at C.nestedSynchronizationWithTryCatch(Main.java:44)
   - locked <0x61336b90> (a java.lang.String)
   - locked <0x61336bd0> (a java.lang.String)
   at C.nestedSynchronization(Main.java:35)
   - locked <0x61336b18> (a java.lang.String)
   - locked <0x61336b50> (a java.lang.String)
   at C.synchronizedOnClassC(Main.java:30)
   - locked <0x613366f8> (a java.lang.Class<C>)
   at C.noLocks(Main.java:27)
   at C.<clinit>(Main.java:24)
   - locked <0x613366f8> (a java.lang.Class<C>)
   at Main.main(Main.java:19)

A non-static synchronized native method works too:

   at org.apache.harmony.dalvik.NativeTestTarget.emptyJniSynchronizedMethod0(Native method)
   - locked <0x613371a8> (a org.apache.harmony.dalvik.NativeTestTarget)
   ...

Note that most stack traces don't look any different; the above is a
pathological example that exercises different kinds of locking. Testing
with system_server shows most threads don't hold any locks.

Future work (marked by TODO) is that explicit JNI MonitorEnter calls in
native code aren't shown.

Change-Id: I2747f5cddb4ef64b1935736f084a68fe8e4005e9
diff --git a/src/stack.h b/src/stack.h
index ff0bcd0..254451d 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -31,6 +31,7 @@
 class Method;
 class Object;
 class ShadowFrame;
+class StackIndirectReferenceTable;
 class ScopedJniThreadState;
 class Thread;
 
@@ -215,7 +216,7 @@
 class StackVisitor {
  protected:
   StackVisitor(const ManagedStack* stack, const std::vector<TraceStackFrame>* trace_stack,
-               Context* context = NULL)
+               Context* context)
       : stack_start_(stack), trace_stack_(trace_stack), cur_shadow_frame_(NULL),
         cur_quick_frame_(NULL), cur_quick_frame_pc_(0), num_frames_(0), cur_depth_(0),
         context_(context) {}
@@ -256,12 +257,12 @@
 
   uint32_t GetDexPc() const;
 
-  // Gets the height of the stack in the managed stack frames, including transitions.
+  // Returns the height of the stack in the managed stack frames, including transitions.
   size_t GetFrameHeight() {
     return GetNumFrames() - cur_depth_;
   }
 
-  // Get a frame ID where 0 is a special value.
+  // Returns a frame ID for JDWP use, starting from 1.
   size_t GetFrameId() {
     return GetFrameHeight() + 1;
   }
@@ -359,6 +360,12 @@
     return cur_shadow_frame_;
   }
 
+  StackIndirectReferenceTable* GetCurrentSirt() const {
+    Method** sp = GetCurrentQuickFrame();
+    ++sp; // Skip Method*; SIRT comes next;
+    return reinterpret_cast<StackIndirectReferenceTable*>(sp);
+  }
+
  private:
   size_t ComputeNumFrames() const;