public jvmtiError GetStackTrace(JniEnvironment nativeEnvironment, ThreadId threadId, int startDepth, int maxFrameCount, out FrameLocationData[] frames) { frames = null; using (var thread = VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, threadId)) { if (!thread.IsAlive) { return(jvmtiError.InvalidThread); } jvmtiFrameInfo[] frameBuffer = new jvmtiFrameInfo[maxFrameCount]; int frameCount; jvmtiError error = RawInterface.GetStackTrace(this, thread.Value, startDepth, maxFrameCount, frameBuffer, out frameCount); if (error != jvmtiError.None) { return(error); } var frameData = new FrameLocationData[frameCount]; for (int i = 0; i < frameCount; i++) { TaggedReferenceTypeId declaringClass; MethodId method = new MethodId(frameBuffer[i]._method.Handle); ulong index = (ulong)frameBuffer[i]._location.Value; error = GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass); if (error != jvmtiError.None) { return(error); } FrameId frameId = new FrameId(startDepth + i); Location location = new Location(declaringClass, method, index); frameData[i] = new FrameLocationData(frameId, location); } frames = frameData; return(jvmtiError.None); } }
public jvmtiError GetStackTrace(JniEnvironment nativeEnvironment, ThreadId threadId, int startDepth, int maxFrameCount, out FrameLocationData[] frames) { frames = null; using (var thread = VirtualMachine.GetLocalReferenceForThread(nativeEnvironment, threadId)) { if (!thread.IsAlive) return jvmtiError.InvalidThread; jvmtiFrameInfo[] frameBuffer = new jvmtiFrameInfo[maxFrameCount]; int frameCount; jvmtiError error = RawInterface.GetStackTrace(this, thread.Value, startDepth, maxFrameCount, frameBuffer, out frameCount); if (error != jvmtiError.None) return error; var frameData = new FrameLocationData[frameCount]; for (int i = 0; i < frameCount; i++) { TaggedReferenceTypeId declaringClass; MethodId method = new MethodId(frameBuffer[i]._method.Handle); ulong index = (ulong)frameBuffer[i]._location.Value; error = GetMethodDeclaringClass(nativeEnvironment, method, out declaringClass); if (error != jvmtiError.None) return error; FrameId frameId = new FrameId(startDepth + i); Location location = new Location(declaringClass, method, index); frameData[i] = new FrameLocationData(frameId, location); } frames = frameData; return jvmtiError.None; } }