2 using System.Threading;
3 using System.Collections.Generic;
5 namespace Mono.Debugger.Soft
7 public class ThreadMirror : ObjectMirror
12 internal ThreadMirror (VirtualMachine vm, long id) : base (vm, id) {
15 internal ThreadMirror (VirtualMachine vm, long id, TypeMirror type, AppDomainMirror domain) : base (vm, id, type, domain) {
18 // FIXME: Cache, invalidate when the thread/runtime is resumed
19 public StackFrame[] GetFrames () {
20 FrameInfo[] frame_info = vm.conn.Thread_GetFrameInfo (id, 0, -1);
22 var frames = new List<StackFrame> ();
24 for (int i = 0; i < frame_info.Length; ++i) {
25 FrameInfo info = (FrameInfo)frame_info [i];
26 MethodMirror method = vm.GetMethod (info.method);
27 var f = new StackFrame (vm, info.id, this, method, info.il_offset, info.flags);
28 if (!(f.IsNativeTransition && !NativeTransitions))
32 return frames.ToArray ();
38 name = vm.conn.Thread_GetName (id);
49 public ThreadState ThreadState {
51 return (ThreadState)vm.conn.Thread_GetState (id);
55 public bool IsThreadPoolThread {
58 info = vm.conn.Thread_GetInfo (id);
59 return info.is_thread_pool;
65 * Return a unique identifier for this thread, multiple ThreadMirror objects
66 * may have the same ThreadId because of appdomains.
68 public long ThreadId {
70 if (thread_id == null)
71 thread_id = vm.conn.Thread_GetId (id);
72 return (long)thread_id;
77 * Return the system thread id (TID) for this thread, this id is not unique since
78 * a newly started thread might reuse a dead thread's id.
82 return vm.conn.Thread_GetTID (id);
87 * Get/set whenever GetFrames () should return frames for managed-to-native
88 * transitions, i.e frames whose IsNativeTransition property is set.
89 * This is needed because some clients might not be able to deal with those
92 public static bool NativeTransitions {
97 * Set the location where execution will return when this thread is
100 * ArgumentException - if L doesn't refer to a location in the
101 * current method of this thread.
102 * NotSupportedException - if continuing at L is not supported
103 * for any other reason.
104 * Since protocol version 29.
106 public void SetIP (Location loc) {
108 throw new ArgumentNullException ("loc");
110 vm.conn.Thread_SetIP (id, loc.Method.Id, loc.ILOffset);
111 } catch (CommandException ex) {
112 if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
113 throw new ArgumentException ("loc doesn't refer to a location in the current method of this thread.", "loc");