Changed UploadStringAsync to handle UploadString encapsulated exceptions.
[mono.git] / mcs / class / Mono.Debugger.Soft / Mono.Debugger.Soft / ThreadMirror.cs
1 using System;
2 using System.Threading;
3 using System.Collections.Generic;
4
5 namespace Mono.Debugger.Soft
6 {
7         public class ThreadMirror : ObjectMirror
8         {
9                 string name;
10                 ThreadInfo info;
11
12                 internal ThreadMirror (VirtualMachine vm, long id) : base (vm, id) {
13                 }
14
15                 internal ThreadMirror (VirtualMachine vm, long id, TypeMirror type, AppDomainMirror domain) : base (vm, id, type, domain) {
16                 }
17
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);
21
22                         var frames = new List<StackFrame> ();
23
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))
29                                         frames.Add (f);
30                         }
31
32                         return frames.ToArray ();
33             }
34
35                 public string Name {
36                         get {
37                                 if (name == null)
38                                         name = vm.conn.Thread_GetName (id);
39                                 return name;
40                         }
41             }
42
43                 public new long Id {
44                         get {
45                                 return id;
46                         }
47                 }
48
49                 public ThreadState ThreadState {
50                         get {
51                                 return (ThreadState)vm.conn.Thread_GetState (id);
52                         }
53                 }
54
55                 public bool IsThreadPoolThread {
56                         get {
57                                 if (info == null)
58                                         info = vm.conn.Thread_GetInfo (id);
59                                 return info.is_thread_pool;
60                         }
61                 }
62
63                 long? thread_id;
64                 /*
65                  * Return a unique identifier for this thread, multiple ThreadMirror objects
66                  * may have the same ThreadId because of appdomains.
67                  */
68                 public long ThreadId {
69                         get {
70                                 if (thread_id == null)
71                                         thread_id = vm.conn.Thread_GetId (id);
72                                 return (long)thread_id;
73                         }
74                 }
75
76                 /*
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.
79                  */
80                 public long TID {
81                         get {
82                                 return vm.conn.Thread_GetTID (id);
83                         }
84                 }
85
86                 /*
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
90                  * frames.
91                  */
92                 public static bool NativeTransitions {
93                         get; set;
94                 }
95
96                 /*
97                  * Set the location where execution will return when this thread is
98                  * resumed.
99                  * Throws:
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.
105                  */
106                 public void SetIP (Location loc) {
107                         if (loc == null)
108                                 throw new ArgumentNullException ("loc");
109                         try {
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");
114                                 else
115                                         throw;
116                         }
117                 }
118     }
119 }