~ubuntu-branches/ubuntu/maverick/monodevelop/maverick

« back to all changes in this revision

Viewing changes to debian/patches/inject_Mono.Debugger.Soft_source.patch

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AbsentInformationException.cs
 
2
===================================================================
 
3
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AbsentInformationException.cs       2010-06-16 12:45:23.061079066 +0100
 
5
@@ -0,0 +1,10 @@
 
6
+using System;
 
7
+
 
8
+namespace Mono.Debugger.Soft
 
9
+{
 
10
+       public class AbsentInformationException : Exception {
 
11
+               
 
12
+               public AbsentInformationException () : base ("Debug information is not available for this frame.") {
 
13
+               }
 
14
+       }
 
15
+}
 
16
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainCreateEvent.cs
 
17
===================================================================
 
18
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
19
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainCreateEvent.cs     2010-06-16 12:45:23.061079066 +0100
 
20
@@ -0,0 +1,20 @@
 
21
+
 
22
+namespace Mono.Debugger.Soft
 
23
+{
 
24
+       public class AppDomainCreateEvent : Event {
 
25
+               AppDomainMirror domain;
 
26
+               long id;
 
27
+
 
28
+               internal AppDomainCreateEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AppDomainCreate, vm, req_id, thread_id) {
 
29
+                       this.id = id;
 
30
+               }
 
31
+
 
32
+               public AppDomainMirror Domain {
 
33
+                       get {
 
34
+                               if (domain == null)
 
35
+                                       domain = vm.GetDomain (id);
 
36
+                               return domain;
 
37
+                       }
 
38
+               }
 
39
+       }
 
40
+}
 
41
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainMirror.cs
 
42
===================================================================
 
43
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
44
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainMirror.cs  2010-06-16 12:45:23.061079066 +0100
 
45
@@ -0,0 +1,95 @@
 
46
+using System;
 
47
+
 
48
+namespace Mono.Debugger.Soft
 
49
+{
 
50
+       public class AppDomainMirror : Mirror
 
51
+       {
 
52
+               string friendly_name;
 
53
+               AssemblyMirror entry_assembly, corlib;
 
54
+
 
55
+               internal AppDomainMirror (VirtualMachine vm, long id) : base (vm, id) {
 
56
+               }
 
57
+
 
58
+               public string FriendlyName {
 
59
+                       get {
 
60
+                               if (friendly_name == null)
 
61
+                                       friendly_name = vm.conn.Domain_GetName (id);
 
62
+                               return friendly_name;
 
63
+                       }
 
64
+           }
 
65
+
 
66
+               // Not cached
 
67
+               public AssemblyMirror[] GetAssemblies () {
 
68
+                       long[] ids = vm.conn.Domain_GetAssemblies (id);
 
69
+                       AssemblyMirror[] assemblies = new AssemblyMirror [ids.Length];
 
70
+                       // FIXME: Uniqueness
 
71
+                       for (int i = 0; i < ids.Length; ++i)
 
72
+                               assemblies [i] = vm.GetAssembly (ids [i]);
 
73
+                       return assemblies;
 
74
+           }
 
75
+
 
76
+               // This returns null when called before the first AssemblyLoad event
 
77
+               public AssemblyMirror GetEntryAssembly () {
 
78
+                       if (entry_assembly == null) {
 
79
+                               long ass_id = vm.conn.Domain_GetEntryAssembly (id);
 
80
+
 
81
+                               entry_assembly = vm.GetAssembly (ass_id);
 
82
+                       }
 
83
+                       return entry_assembly;
 
84
+           }
 
85
+
 
86
+               public AssemblyMirror Corlib {
 
87
+                       get {
 
88
+                               if (corlib == null) {
 
89
+                                       long ass_id = vm.conn.Domain_GetCorlib (id);
 
90
+
 
91
+                                       corlib = vm.GetAssembly (ass_id);
 
92
+                               }
 
93
+                               return corlib;
 
94
+                       }
 
95
+           }
 
96
+
 
97
+               public StringMirror CreateString (string s) {
 
98
+                       if (s == null)
 
99
+                               throw new ArgumentNullException ("s");
 
100
+
 
101
+                       return vm.GetObject<StringMirror> (vm.conn.Domain_CreateString (id, s));
 
102
+               }
 
103
+
 
104
+               public ObjectMirror CreateBoxedValue (Value value) {
 
105
+                       if (value == null)
 
106
+                               throw new ArgumentNullException ("value");
 
107
+                       if (!(value is PrimitiveValue) && !(value is StructMirror))
 
108
+                               throw new ArgumentException ("Value must be a PrimitiveValue or a StructMirror", "value");
 
109
+                       if ((value is PrimitiveValue) && (value as PrimitiveValue).Value == null)
 
110
+                               return null;
 
111
+
 
112
+                       TypeMirror t = null;
 
113
+                       if (value is PrimitiveValue)
 
114
+                               t = GetCorrespondingType ((value as PrimitiveValue).Value.GetType ());
 
115
+                       else
 
116
+                               t = (value as StructMirror).Type;
 
117
+
 
118
+                       return vm.GetObject<ObjectMirror> (vm.conn.Domain_CreateBoxedValue (id, t.Id, vm.EncodeValue (value)));
 
119
+               }
 
120
+
 
121
+               TypeMirror[] primitiveTypes = new TypeMirror [32];
 
122
+               
 
123
+               public TypeMirror GetCorrespondingType (Type t) {
 
124
+                       if (t == null)
 
125
+                               throw new ArgumentNullException ("t");
 
126
+                       TypeCode tc = Type.GetTypeCode (t);
 
127
+
 
128
+                       if (tc == TypeCode.Empty || tc == TypeCode.Object)
 
129
+                               throw new ArgumentException ("t must be a primitive type", "t");
 
130
+
 
131
+                       int tc_index = (int)tc;
 
132
+                       if (primitiveTypes [tc_index] == null) {
 
133
+                               primitiveTypes [tc_index] = Corlib.GetType ("System." + t.Name, false, false);
 
134
+                               if (primitiveTypes [tc_index] == null)
 
135
+                                       throw new NotImplementedException ();
 
136
+                       }
 
137
+                       return primitiveTypes [tc_index];
 
138
+               }
 
139
+    }
 
140
+}
 
141
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainUnloadEvent.cs
 
142
===================================================================
 
143
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
144
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AppDomainUnloadEvent.cs     2010-06-16 12:45:23.061079066 +0100
 
145
@@ -0,0 +1,20 @@
 
146
+
 
147
+namespace Mono.Debugger.Soft
 
148
+{
 
149
+       public class AppDomainUnloadEvent : Event {
 
150
+               AppDomainMirror domain;
 
151
+               long id;
 
152
+
 
153
+               internal AppDomainUnloadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AppDomainUnload, vm, req_id, thread_id) {
 
154
+                       this.id = id;
 
155
+               }
 
156
+
 
157
+               public AppDomainMirror Domain {
 
158
+                       get {
 
159
+                               if (domain == null)
 
160
+                                       domain = vm.GetDomain (id);
 
161
+                               return domain;
 
162
+                       }
 
163
+               }
 
164
+       }
 
165
+}
 
166
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ArrayMirror.cs
 
167
===================================================================
 
168
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
169
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ArrayMirror.cs      2010-06-16 12:45:23.061079066 +0100
 
170
@@ -0,0 +1,140 @@
 
171
+using System;
 
172
+using System.Collections;
 
173
+using System.Collections.Generic;
 
174
+
 
175
+namespace Mono.Debugger.Soft
 
176
+{
 
177
+       public class ArrayMirror : ObjectMirror, IEnumerable {
 
178
+
 
179
+               public int[] lengths;
 
180
+               public int[] lower_bounds;
 
181
+               public int rank;
 
182
+
 
183
+               internal ArrayMirror (VirtualMachine vm, long id) : base (vm, id) {
 
184
+               }
 
185
+
 
186
+               public int Length {
 
187
+                       get {
 
188
+                               GetLengths ();
 
189
+
 
190
+                               int length = lengths [0];
 
191
+
 
192
+                               for (int i = 1; i < Rank; i++) {
 
193
+                                       length *= lengths [i];
 
194
+                               }
 
195
+
 
196
+                               return length;
 
197
+                       }
 
198
+               }
 
199
+
 
200
+               public int Rank {
 
201
+                       get {
 
202
+                               GetLengths ();
 
203
+
 
204
+                               return rank;
 
205
+                       }
 
206
+               }
 
207
+
 
208
+               public int GetLength (int dimension) {
 
209
+                       GetLengths ();
 
210
+
 
211
+                       if (dimension < 0 || dimension >= Rank)
 
212
+                               throw new ArgumentOutOfRangeException ("dimension");
 
213
+
 
214
+                       return lengths [dimension];
 
215
+               }
 
216
+
 
217
+               public int GetLowerBound (int dimension) {
 
218
+                       GetLengths ();
 
219
+
 
220
+                       if (dimension < 0 || dimension >= Rank)
 
221
+                               throw new ArgumentOutOfRangeException ("dimension");
 
222
+
 
223
+                       return lower_bounds [dimension];
 
224
+               }
 
225
+
 
226
+               void GetLengths () {
 
227
+                       if (lengths == null)
 
228
+                               lengths = vm.conn.Array_GetLength (id, out this.rank, out this.lower_bounds);
 
229
+               }
 
230
+
 
231
+               public Value this [int index] {
 
232
+                       get {
 
233
+                               // FIXME: Multiple dimensions
 
234
+                               if (index < 0 || index > Length - 1)
 
235
+                                       throw new IndexOutOfRangeException ();
 
236
+                               return vm.DecodeValue (vm.conn.Array_GetValues (id, index, 1) [0]);
 
237
+                       }
 
238
+                       set {
 
239
+                               // FIXME: Multiple dimensions
 
240
+                               if (index < 0 || index > Length - 1)
 
241
+                                       throw new IndexOutOfRangeException ();
 
242
+                               vm.conn.Array_SetValues (id, index, new ValueImpl [] { vm.EncodeValue (value) });
 
243
+                       }
 
244
+               }
 
245
+
 
246
+               public IList<Value> GetValues (int index, int length) {
 
247
+                       // FIXME: Multiple dimensions
 
248
+                               if (index < 0 || index > Length - length)
 
249
+                                       throw new IndexOutOfRangeException ();
 
250
+                       return vm.DecodeValues (vm.conn.Array_GetValues (id, index, length));
 
251
+               }
 
252
+
 
253
+               public void SetValues (int index, Value[] values) {
 
254
+                       if (values == null)
 
255
+                               throw new ArgumentNullException ("values");
 
256
+                       // FIXME: Multiple dimensions
 
257
+                       if (index < 0 || index > Length - values.Length)
 
258
+                               throw new IndexOutOfRangeException ();
 
259
+                       vm.conn.Array_SetValues (id, index, vm.EncodeValues (values));
 
260
+               }
 
261
+
 
262
+               IEnumerator IEnumerable.GetEnumerator ()
 
263
+               {
 
264
+                       return new SimpleEnumerator (this);
 
265
+               }
 
266
+
 
267
+               internal class SimpleEnumerator : IEnumerator, ICloneable
 
268
+               {
 
269
+                       ArrayMirror arr;
 
270
+                       int pos, length;
 
271
+
 
272
+                       public SimpleEnumerator (ArrayMirror arr)
 
273
+                       {
 
274
+                               this.arr = arr;
 
275
+                               this.pos = -1;
 
276
+                               this.length = arr.Length;
 
277
+                       }
 
278
+
 
279
+                       public object Current {
 
280
+                               get {
 
281
+                                       if (pos < 0 )
 
282
+                                               throw new InvalidOperationException ("Enumeration has not started.");
 
283
+                                       if  (pos >= length)
 
284
+                                               throw new InvalidOperationException ("Enumeration has already ended");
 
285
+                                       return arr [pos];
 
286
+                               }
 
287
+                       }
 
288
+
 
289
+                       public bool MoveNext()
 
290
+                       {
 
291
+                               if (pos < length)
 
292
+                                       pos++;
 
293
+                               if(pos < length)
 
294
+                                       return true;
 
295
+                               else
 
296
+                                       return false;
 
297
+                       }
 
298
+
 
299
+                       public void Reset()
 
300
+                       {
 
301
+                               pos = -1;
 
302
+                       }
 
303
+
 
304
+                       public object Clone ()
 
305
+                       {
 
306
+                               return MemberwiseClone ();
 
307
+                       }
 
308
+               }
 
309
+       }
 
310
+}
 
311
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyLoadEvent.cs
 
312
===================================================================
 
313
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
314
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyLoadEvent.cs        2010-06-16 12:45:23.061079066 +0100
 
315
@@ -0,0 +1,20 @@
 
316
+
 
317
+namespace Mono.Debugger.Soft
 
318
+{
 
319
+       public class AssemblyLoadEvent : Event {
 
320
+               AssemblyMirror assembly;
 
321
+               long id;
 
322
+
 
323
+               internal AssemblyLoadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AssemblyLoad, vm, req_id, thread_id) {
 
324
+                       this.id = id;
 
325
+               }
 
326
+
 
327
+               public AssemblyMirror Assembly {
 
328
+                       get {
 
329
+                               if (assembly == null)
 
330
+                                       assembly = vm.GetAssembly (id);
 
331
+                               return assembly;
 
332
+                       }
 
333
+               }
 
334
+       }
 
335
+}
 
336
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyMirror.cs
 
337
===================================================================
 
338
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
339
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyMirror.cs   2010-06-16 12:45:23.061079066 +0100
 
340
@@ -0,0 +1,100 @@
 
341
+using System;
 
342
+using System.Reflection;
 
343
+using Mono.Debugger;
 
344
+using Mono.Cecil;
 
345
+
 
346
+namespace Mono.Debugger.Soft
 
347
+{
 
348
+       public class AssemblyMirror : Mirror
 
349
+       {
 
350
+               string location;
 
351
+               MethodMirror entry_point;
 
352
+               bool entry_point_set;
 
353
+               ModuleMirror main_module;
 
354
+               AssemblyName aname;
 
355
+               AssemblyDefinition meta;
 
356
+
 
357
+               internal AssemblyMirror (VirtualMachine vm, long id) : base (vm, id) {
 
358
+               }
 
359
+
 
360
+               public string Location {
 
361
+                       get {
 
362
+                               if (location == null)
 
363
+                                       location = vm.conn.Assembly_GetLocation (id);
 
364
+                               return location;
 
365
+                       }
 
366
+           }
 
367
+
 
368
+               public MethodMirror EntryPoint {
 
369
+                       get {
 
370
+                               if (!entry_point_set) {
 
371
+                                       long mid = vm.conn.Assembly_GetEntryPoint (id);
 
372
+
 
373
+                                       if (mid != 0)
 
374
+                                               entry_point = vm.GetMethod (mid);
 
375
+                                       entry_point_set = true;
 
376
+                               }
 
377
+                               return entry_point;
 
378
+                       }
 
379
+           }
 
380
+
 
381
+               public ModuleMirror ManifestModule {
 
382
+                       get {
 
383
+                               if (main_module == null) {
 
384
+                                       main_module = vm.GetModule (vm.conn.Assembly_GetManifestModule (id));
 
385
+                               }
 
386
+                               return main_module;
 
387
+                       }
 
388
+               }
 
389
+
 
390
+               public virtual AssemblyName GetName () {
 
391
+                       if (aname == null) {
 
392
+                               string name = vm.conn.Assembly_GetName (id);
 
393
+                               aname = new AssemblyName (name);
 
394
+                       }
 
395
+                       return aname;
 
396
+               }
 
397
+
 
398
+               public ObjectMirror GetAssemblyObject () {
 
399
+                       return vm.GetObject (vm.conn.Assembly_GetObject (id));
 
400
+               }
 
401
+
 
402
+               public TypeMirror GetType (string name, bool throwOnError, bool ignoreCase)
 
403
+               {
 
404
+                       if (name == null)
 
405
+                               throw new ArgumentNullException (name);
 
406
+                       if (name.Length == 0)
 
407
+                               throw new ArgumentException ("name", "Name cannot be empty");
 
408
+
 
409
+                       if (throwOnError)
 
410
+                               throw new NotImplementedException ();
 
411
+                       return vm.GetType (vm.conn.Assembly_GetType (id, name, ignoreCase));
 
412
+               }
 
413
+
 
414
+               public TypeMirror GetType (String name, Boolean throwOnError)
 
415
+               {
 
416
+                       return GetType (name, throwOnError, false);
 
417
+               }
 
418
+
 
419
+               public TypeMirror GetType (String name) {
 
420
+                       return GetType (name, false, false);
 
421
+               }
 
422
+
 
423
+               /* 
 
424
+                * An optional Cecil assembly which could be used to access metadata instead
 
425
+                * of reading it from the debuggee.
 
426
+                */
 
427
+               public AssemblyDefinition Metadata {
 
428
+                       get {
 
429
+                               return meta;
 
430
+                       }
 
431
+                       set {
 
432
+                               if (value.MainModule.Name != ManifestModule.Name)
 
433
+                                       throw new ArgumentException ("The supplied assembly is named '" + value.MainModule.Name + "', while the assembly in the debuggee is named '" + ManifestModule.Name + "'.");
 
434
+                               if (value.MainModule.Mvid != ManifestModule.ModuleVersionId)
 
435
+                                       throw new ArgumentException ("The supplied assembly's main module has guid '" + value.MainModule.Mvid + ", while the assembly in the debuggee has guid '" + ManifestModule.ModuleVersionId + "'.", "value");
 
436
+                               meta = value;
 
437
+                       }
 
438
+               }
 
439
+    }
 
440
+}
 
441
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyUnloadEvent.cs
 
442
===================================================================
 
443
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
444
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/AssemblyUnloadEvent.cs      2010-06-16 12:45:23.061079066 +0100
 
445
@@ -0,0 +1,20 @@
 
446
+
 
447
+namespace Mono.Debugger.Soft
 
448
+{
 
449
+       public class AssemblyUnloadEvent : Event {
 
450
+               AssemblyMirror assembly;
 
451
+               long id;
 
452
+
 
453
+               internal AssemblyUnloadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AssemblyUnload, vm, req_id, thread_id) {
 
454
+                       this.id = id;
 
455
+               }
 
456
+
 
457
+               public AssemblyMirror Assembly {
 
458
+                       get {
 
459
+                               if (assembly == null)
 
460
+                                       assembly = vm.GetAssembly (id);
 
461
+                               return assembly;
 
462
+                       }
 
463
+               }
 
464
+       }
 
465
+}
 
466
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/BreakpointEvent.cs
 
467
===================================================================
 
468
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
469
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/BreakpointEvent.cs  2010-06-16 12:45:23.061079066 +0100
 
470
@@ -0,0 +1,20 @@
 
471
+
 
472
+namespace Mono.Debugger.Soft
 
473
+{
 
474
+       public class BreakpointEvent : Event {
 
475
+               MethodMirror method;
 
476
+               long id;
 
477
+
 
478
+               internal BreakpointEvent (VirtualMachine vm, int req_id, long thread_id, long id, long loc) : base (EventType.Breakpoint, vm, req_id, thread_id) {
 
479
+                       this.id = id;
 
480
+               }
 
481
+
 
482
+               public MethodMirror Method {
 
483
+                       get {
 
484
+                               if (method == null)
 
485
+                                       method = vm.GetMethod (id);
 
486
+                               return method;
 
487
+                       }
 
488
+               }
 
489
+       }
 
490
+}
 
491
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/BreakpointEventRequest.cs
 
492
===================================================================
 
493
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
494
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/BreakpointEventRequest.cs   2010-06-16 12:45:23.061079066 +0100
 
495
@@ -0,0 +1,28 @@
 
496
+using System;
 
497
+using System.Collections.Generic;
 
498
+using System.Linq;
 
499
+
 
500
+namespace Mono.Debugger.Soft
 
501
+{
 
502
+       public sealed class BreakpointEventRequest : EventRequest {
 
503
+
 
504
+               MethodMirror method;
 
505
+               long location;
 
506
+               
 
507
+               internal BreakpointEventRequest (VirtualMachine vm, MethodMirror method, long location) : base (vm, EventType.Breakpoint) {
 
508
+                       if (method == null)
 
509
+                               throw new ArgumentNullException ("method");
 
510
+                       CheckMirror (vm, method);
 
511
+                       if (method.Locations.Count > 0 && !method.Locations.Any (l => l.ILOffset == location))
 
512
+                               throw new ArgumentException ("A breakpoint can only be set at an IL offset which is equal to the ILOffset property of one of the locations in method.Locations", "location");
 
513
+                       this.method = method;
 
514
+                       this.location = location;
 
515
+               }
 
516
+
 
517
+               public override void Enable () {
 
518
+                       var mods = new List <Modifier> ();
 
519
+                       mods.Add (new LocationModifier () { Method = method.Id, Location = location });
 
520
+                       SendReq (mods);
 
521
+               }
 
522
+       }
 
523
+}
 
524
\ No newline at end of file
 
525
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
 
526
===================================================================
 
527
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
528
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Connection.cs       2010-06-16 12:45:23.061079066 +0100
 
529
@@ -0,0 +1,1793 @@
 
530
+using System;
 
531
+using System.IO;
 
532
+using System.Net;
 
533
+using System.Net.Sockets;
 
534
+using System.Threading;
 
535
+using System.Collections.Generic;
 
536
+using System.Text;
 
537
+using Mono.Cecil.Metadata;
 
538
+
 
539
+namespace Mono.Debugger.Soft
 
540
+{
 
541
+       public class VersionInfo {
 
542
+               public string VMVersion {
 
543
+                       get; set;
 
544
+               }
 
545
+
 
546
+               public int MajorVersion {
 
547
+                       get; set;
 
548
+               }
 
549
+
 
550
+               public int MinorVersion {
 
551
+                       get; set;
 
552
+               }
 
553
+       }
 
554
+
 
555
+       class DebugInfo {
 
556
+               public int max_il_offset;
 
557
+               public string filename;
 
558
+               public int[] il_offsets;
 
559
+               public int[] line_numbers;
 
560
+       }
 
561
+
 
562
+       struct FrameInfo {
 
563
+               public long id;
 
564
+               public long method;
 
565
+               public int il_offset;
 
566
+               public StackFrameFlags flags;
 
567
+       }
 
568
+
 
569
+       class TypeInfo {
 
570
+               public string ns, name, full_name;
 
571
+               public long assembly, module, base_type, element_type;
 
572
+               public int token, rank, attributes;
 
573
+               public bool is_byref, is_pointer, is_primitive, is_valuetype, is_enum;
 
574
+               public long[] nested;
 
575
+       }
 
576
+
 
577
+       class MethodInfo {
 
578
+               public int attributes, iattributes, token;
 
579
+       }
 
580
+
 
581
+       class MethodBodyInfo {
 
582
+               public byte[] il;
 
583
+       }
 
584
+
 
585
+       struct ParamInfo {
 
586
+               public int call_conv;
 
587
+               public int param_count;
 
588
+               public int generic_param_count;
 
589
+               public long ret_type;
 
590
+               public long[] param_types;
 
591
+               public string[] param_names;
 
592
+       }
 
593
+
 
594
+       struct LocalsInfo {
 
595
+               public long[] types;
 
596
+               public string[] names;
 
597
+               public int[] live_range_start;
 
598
+               public int[] live_range_end;
 
599
+       }
 
600
+
 
601
+       struct PropInfo {
 
602
+               public long id;
 
603
+               public string name;
 
604
+               public long get_method, set_method;
 
605
+               public int attrs;
 
606
+       }
 
607
+
 
608
+       class CattrNamedArgInfo {
 
609
+               public bool is_property;
 
610
+               public long id;
 
611
+               public ValueImpl value;
 
612
+       }
 
613
+
 
614
+       class CattrInfo {
 
615
+               public long ctor_id;
 
616
+               public ValueImpl[] ctor_args;
 
617
+               public CattrNamedArgInfo[] named_args;
 
618
+       }
 
619
+
 
620
+       class ThreadInfo {
 
621
+               public bool is_thread_pool;
 
622
+       }
 
623
+
 
624
+       enum ValueTypeId {
 
625
+               VALUE_TYPE_ID_NULL = 0xf0,
 
626
+               VALUE_TYPE_ID_TYPE = 0xf1
 
627
+       }
 
628
+
 
629
+       enum InvokeFlags {
 
630
+               NONE = 0x0,
 
631
+               DISABLE_BREAKPOINTS = 0x1,
 
632
+               SINGLE_THREADED = 0x2
 
633
+       }
 
634
+
 
635
+       class ValueImpl {
 
636
+               public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
 
637
+               public long Objid;
 
638
+               public object Value;
 
639
+               public long Klass; // For ElementType.ValueType
 
640
+               public ValueImpl[] Fields; // for ElementType.ValueType
 
641
+               public bool IsEnum; // For ElementType.ValueType
 
642
+               public long Id; /* For VALUE_TYPE_ID_TYPE */
 
643
+       }
 
644
+
 
645
+       class ModuleInfo {
 
646
+               public string Name, ScopeName, FQName, Guid;
 
647
+               public long Assembly;
 
648
+       }               
 
649
+
 
650
+       enum TokenType {
 
651
+               STRING = 0,
 
652
+               TYPE = 1,
 
653
+               FIELD = 2,
 
654
+               METHOD = 3,
 
655
+               UNKNOWN = 4
 
656
+       }
 
657
+
 
658
+       enum StackFrameFlags {
 
659
+               DEBUGGER_INVOKE = 1
 
660
+       }
 
661
+
 
662
+       class ResolvedToken {
 
663
+               public TokenType Type;
 
664
+               public string Str;
 
665
+               public long Id;
 
666
+       }
 
667
+
 
668
+       class Modifier {
 
669
+       }
 
670
+
 
671
+       class CountModifier : Modifier {
 
672
+               public int Count {
 
673
+                       get; set;
 
674
+               }
 
675
+       }
 
676
+
 
677
+       class LocationModifier : Modifier {
 
678
+               public long Method {
 
679
+                       get; set;
 
680
+               }
 
681
+
 
682
+               public long Location {
 
683
+                       get; set;
 
684
+               }
 
685
+       }
 
686
+
 
687
+       class StepModifier : Modifier {
 
688
+               public long Thread {
 
689
+                       get; set;
 
690
+               }
 
691
+
 
692
+               public int Depth {
 
693
+                       get; set;
 
694
+               }
 
695
+
 
696
+               public int Size {
 
697
+                       get; set;
 
698
+               }
 
699
+       }
 
700
+
 
701
+       class ThreadModifier : Modifier {
 
702
+               public long Thread {
 
703
+                       get; set;
 
704
+               }
 
705
+       }
 
706
+
 
707
+       class ExceptionModifier : Modifier {
 
708
+               public long Type {
 
709
+                       get; set;
 
710
+               }
 
711
+               public bool Caught {
 
712
+                       get; set;
 
713
+               }
 
714
+               public bool Uncaught {
 
715
+                       get; set;
 
716
+               }
 
717
+       }
 
718
+
 
719
+       class AssemblyModifier : Modifier {
 
720
+               public long[] Assemblies {
 
721
+                       get; set;
 
722
+               }
 
723
+       }
 
724
+
 
725
+       public enum ErrorCode {
 
726
+               NONE = 0,
 
727
+               INVALID_OBJECT = 20,
 
728
+               INVALID_FIELDID = 25,
 
729
+               INVALID_FRAMEID = 30,
 
730
+               NOT_IMPLEMENTED = 100,
 
731
+               NOT_SUSPENDED = 101,
 
732
+               INVALID_ARGUMENT = 102,
 
733
+               ERR_UNLOADED = 103,
 
734
+               ERR_NO_INVOCATION = 104,
 
735
+               ABSENT_INFORMATION = 105
 
736
+       }
 
737
+
 
738
+       public class ErrorHandlerEventArgs : EventArgs {
 
739
+
 
740
+               public ErrorCode ErrorCode {
 
741
+                       get; set;
 
742
+               }
 
743
+       }
 
744
+
 
745
+       /*
 
746
+        * Represents the connection to the debuggee
 
747
+        */
 
748
+       class Connection
 
749
+       {
 
750
+               /*
 
751
+                * The protocol and the packet format is based on JDWP, the differences 
 
752
+                * are in the set of supported events, and the commands.
 
753
+                */
 
754
+               public const string HANDSHAKE_STRING = "DWP-Handshake";
 
755
+
 
756
+               public const int HEADER_LENGTH = 11;
 
757
+
 
758
+               /*
 
759
+                * Th version of the wire-protocol implemented by the library. The library
 
760
+                * and the debuggee can communicate if they implement the same major version.
 
761
+                * If they implement a different minor version, they can communicate, but some
 
762
+                * features might not be available. This allows older clients to communicate
 
763
+                * with newer runtimes, and vice versa.
 
764
+                */
 
765
+               public const int MAJOR_VERSION = 2;
 
766
+               public const int MINOR_VERSION = 1;
 
767
+
 
768
+               enum WPSuspendPolicy {
 
769
+                       NONE = 0,
 
770
+                       EVENT_THREAD = 1,
 
771
+                       ALL = 2
 
772
+               }
 
773
+
 
774
+               enum CommandSet {
 
775
+                       VM = 1,
 
776
+                       OBJECT_REF = 9,
 
777
+                       STRING_REF = 10,
 
778
+                       THREAD = 11,
 
779
+                       ARRAY_REF = 13,
 
780
+                       EVENT_REQUEST = 15,
 
781
+                       STACK_FRAME = 16,
 
782
+                       APPDOMAIN = 20,
 
783
+                       ASSEMBLY = 21,
 
784
+                       METHOD = 22,
 
785
+                       TYPE = 23,
 
786
+                       MODULE = 24,
 
787
+                       EVENT = 64
 
788
+               }
 
789
+
 
790
+               enum EventKind {
 
791
+                       VM_START = 0,
 
792
+                       VM_DEATH = 1,
 
793
+                       THREAD_START = 2,
 
794
+                       THREAD_DEATH = 3,
 
795
+                       APPDOMAIN_CREATE = 4, // Not in JDI
 
796
+                       APPDOMAIN_UNLOAD = 5, // Not in JDI
 
797
+                       METHOD_ENTRY = 6,
 
798
+                       METHOD_EXIT = 7,
 
799
+                       ASSEMBLY_LOAD = 8,
 
800
+                       ASSEMBLY_UNLOAD = 9,
 
801
+                       BREAKPOINT = 10,
 
802
+                       STEP = 11,
 
803
+                       TYPE_LOAD = 12,
 
804
+                       EXCEPTION = 13
 
805
+               }
 
806
+
 
807
+               enum ModifierKind {
 
808
+                       COUNT = 1,
 
809
+                       THREAD_ONLY = 3,
 
810
+                       LOCATION_ONLY = 7,
 
811
+                       EXCEPTION_ONLY = 8,
 
812
+                       STEP = 10,
 
813
+                       ASSEMBLY_ONLY = 11
 
814
+               }
 
815
+
 
816
+               enum CmdVM {
 
817
+                       VERSION = 1,
 
818
+                       ALL_THREADS = 2,
 
819
+                       SUSPEND = 3,
 
820
+                       RESUME = 4,
 
821
+                       EXIT = 5,
 
822
+                       DISPOSE = 6,
 
823
+                       INVOKE_METHOD = 7,
 
824
+                       SET_PROTOCOL_VERSION = 8,
 
825
+                       ABORT_INVOKE = 9
 
826
+               }
 
827
+
 
828
+               enum CmdEvent {
 
829
+                       COMPOSITE = 100
 
830
+               }
 
831
+
 
832
+               enum CmdThread {
 
833
+                       GET_FRAME_INFO = 1,
 
834
+                       GET_NAME = 2,
 
835
+                       GET_STATE = 3,
 
836
+                       GET_INFO = 4,
 
837
+                       /* FIXME: Merge into GET_INFO when the major protocol version is increased */
 
838
+                       GET_ID = 5
 
839
+               }
 
840
+
 
841
+               enum CmdEventRequest {
 
842
+                       SET = 1,
 
843
+                       CLEAR = 2,
 
844
+                       CLEAR_ALL_BREAKPOINTS = 3
 
845
+               }
 
846
+
 
847
+               enum CmdAppDomain {
 
848
+                       GET_ROOT_DOMAIN = 1,
 
849
+                       GET_FRIENDLY_NAME = 2,
 
850
+                       GET_ASSEMBLIES = 3,
 
851
+                       GET_ENTRY_ASSEMBLY = 4,
 
852
+                       CREATE_STRING = 5,
 
853
+                       GET_CORLIB = 6,
 
854
+                       CREATE_BOXED_VALUE = 7
 
855
+               }
 
856
+
 
857
+               enum CmdAssembly {
 
858
+                       GET_LOCATION = 1,
 
859
+                       GET_ENTRY_POINT = 2,
 
860
+                       GET_MANIFEST_MODULE = 3,
 
861
+                       GET_OBJECT = 4,
 
862
+                       GET_TYPE = 5,
 
863
+                       GET_NAME = 6
 
864
+               }
 
865
+
 
866
+               enum CmdModule {
 
867
+                       GET_INFO = 1,
 
868
+               }
 
869
+
 
870
+               enum CmdMethod {
 
871
+                       GET_NAME = 1,
 
872
+                       GET_DECLARING_TYPE = 2,
 
873
+                       GET_DEBUG_INFO = 3,
 
874
+                       GET_PARAM_INFO = 4,
 
875
+                       GET_LOCALS_INFO = 5,
 
876
+                       GET_INFO = 6,
 
877
+                       GET_BODY = 7,
 
878
+                       RESOLVE_TOKEN = 8
 
879
+               }
 
880
+
 
881
+               enum CmdType {
 
882
+                       GET_INFO = 1,
 
883
+                       GET_METHODS = 2,
 
884
+                       GET_FIELDS = 3,
 
885
+                       GET_VALUES = 4,
 
886
+                       GET_OBJECT = 5,
 
887
+                       GET_SOURCE_FILES = 6,
 
888
+                       SET_VALUES = 7,
 
889
+                       IS_ASSIGNABLE_FROM = 8,
 
890
+                       GET_PROPERTIES = 9,
 
891
+                       GET_CATTRS = 10,
 
892
+                       GET_FIELD_CATTRS = 11,
 
893
+                       GET_PROPERTY_CATTRS = 12,
 
894
+                       /* FIXME: Merge into GET_SOURCE_FILES when the major protocol version is increased */
 
895
+                       GET_SOURCE_FILES_2 = 13
 
896
+               }
 
897
+
 
898
+               enum CmdStackFrame {
 
899
+                       GET_VALUES = 1,
 
900
+                       GET_THIS = 2,
 
901
+                       SET_VALUES = 3
 
902
+               }
 
903
+
 
904
+               enum CmdArrayRef {
 
905
+                       GET_LENGTH = 1,
 
906
+                       GET_VALUES = 2,
 
907
+                       SET_VALUES = 3
 
908
+               }
 
909
+
 
910
+               enum CmdStringRef {
 
911
+                       GET_VALUE = 1
 
912
+               }
 
913
+
 
914
+               enum CmdObjectRef {
 
915
+                       GET_TYPE = 1,
 
916
+                       GET_VALUES = 2,
 
917
+                       IS_COLLECTED = 3,
 
918
+                       GET_ADDRESS = 4,
 
919
+                       GET_DOMAIN = 5,
 
920
+                       SET_VALUES = 6
 
921
+               }
 
922
+
 
923
+               class Header {
 
924
+                       public int id;
 
925
+                       public int command_set;
 
926
+                       public int command;
 
927
+                       public int flags;
 
928
+               }                       
 
929
+
 
930
+               public static int GetPacketLength (byte[] header) {
 
931
+                       int offset = 0;
 
932
+                       return decode_int (header, ref offset);
 
933
+               }
 
934
+
 
935
+               public static bool IsReplyPacket (byte[] packet) {
 
936
+                       int offset = 8;
 
937
+                       return decode_byte (packet, ref offset) == 0x80;
 
938
+               }
 
939
+
 
940
+               public static int GetPacketId (byte[] packet) {
 
941
+                       int offset = 4;
 
942
+                       return decode_int (packet, ref offset);
 
943
+               }
 
944
+
 
945
+               static int decode_byte (byte[] packet, ref int offset) {
 
946
+                       return packet [offset++];
 
947
+               }
 
948
+
 
949
+               static int decode_short (byte[] packet, ref int offset) {
 
950
+                       int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
 
951
+                       offset += 2;
 
952
+                       return res;
 
953
+               }
 
954
+
 
955
+               static int decode_int (byte[] packet, ref int offset) {
 
956
+                       int res = ((int)packet [offset] << 24) | ((int)packet [offset + 1] << 16) | ((int)packet [offset + 2] << 8) | (int)packet [offset + 3];
 
957
+                       offset += 4;
 
958
+                       return res;
 
959
+               }
 
960
+
 
961
+               static long decode_id (byte[] packet, ref int offset) {
 
962
+                       return decode_int (packet, ref offset);
 
963
+               }
 
964
+
 
965
+               static long decode_long (byte[] packet, ref int offset) {
 
966
+                       uint high = (uint)decode_int (packet, ref offset);
 
967
+                       uint low = (uint)decode_int (packet, ref offset);
 
968
+
 
969
+                       return (long)(((ulong)high << 32) | (ulong)low);
 
970
+               }
 
971
+
 
972
+               public static SuspendPolicy decode_suspend_policy (int suspend_policy) {
 
973
+                       switch ((WPSuspendPolicy)suspend_policy) {
 
974
+                       case WPSuspendPolicy.NONE:
 
975
+                               return SuspendPolicy.None;
 
976
+                       case WPSuspendPolicy.EVENT_THREAD:
 
977
+                               return SuspendPolicy.EventThread;
 
978
+                       case WPSuspendPolicy.ALL:
 
979
+                               return SuspendPolicy.All;
 
980
+                       default:
 
981
+                               throw new NotImplementedException ();
 
982
+                       }
 
983
+               }
 
984
+
 
985
+               static Header decode_command_header (byte[] packet) {
 
986
+                       int offset = 0;
 
987
+                       Header res = new Header ();
 
988
+
 
989
+                       decode_int (packet, ref offset);
 
990
+                       res.id = decode_int (packet, ref offset);
 
991
+                       res.flags = decode_byte (packet, ref offset);
 
992
+                       res.command_set = decode_byte (packet, ref offset);
 
993
+                       res.command = decode_byte (packet, ref offset);
 
994
+
 
995
+                       return res;
 
996
+               }
 
997
+
 
998
+               static void encode_byte (byte[] buf, int b, ref int offset) {
 
999
+                       buf [offset] = (byte)b;
 
1000
+                       offset ++;
 
1001
+               }
 
1002
+
 
1003
+               static void encode_int (byte[] buf, int i, ref int offset) {
 
1004
+                       buf [offset] = (byte)((i >> 24) & 0xff);
 
1005
+                       buf [offset + 1] = (byte)((i >> 16) & 0xff);
 
1006
+                       buf [offset + 2] = (byte)((i >> 8) & 0xff);
 
1007
+                       buf [offset + 3] = (byte)((i >> 0) & 0xff);
 
1008
+                       offset += 4;
 
1009
+               }
 
1010
+
 
1011
+               static void encode_id (byte[] buf, long id, ref int offset) {
 
1012
+                       encode_int (buf, (int)id, ref offset);
 
1013
+               }
 
1014
+
 
1015
+               static void encode_long (byte[] buf, long l, ref int offset) {
 
1016
+                       encode_int (buf, (int)((l >> 32) & 0xffffffff), ref offset);
 
1017
+                       encode_int (buf, (int)(l & 0xffffffff), ref offset);
 
1018
+               }
 
1019
+
 
1020
+               public static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
 
1021
+                       byte[] buf = new byte [dataLen + 11];
 
1022
+                       int offset = 0;
 
1023
+                       
 
1024
+                       encode_int (buf, buf.Length, ref offset);
 
1025
+                       encode_int (buf, id, ref offset);
 
1026
+                       encode_byte (buf, 0, ref offset);
 
1027
+                       encode_byte (buf, commandSet, ref offset);
 
1028
+                       encode_byte (buf, command, ref offset);
 
1029
+
 
1030
+                       for (int i = 0; i < dataLen; ++i)
 
1031
+                               buf [offset + i] = data [i];
 
1032
+
 
1033
+                       return buf;
 
1034
+               }
 
1035
+
 
1036
+               class PacketReader {
 
1037
+                       byte[] packet;
 
1038
+                       int offset;
 
1039
+
 
1040
+                       public PacketReader (byte[] packet) {
 
1041
+                               this.packet = packet;
 
1042
+
 
1043
+                               // For event packets
 
1044
+                               Header header = decode_command_header (packet);
 
1045
+                               CommandSet = (CommandSet)header.command_set;
 
1046
+                               Command = header.command;
 
1047
+
 
1048
+                               // For reply packets
 
1049
+                               offset = 0;
 
1050
+                               ReadInt (); // length
 
1051
+                               ReadInt (); // id
 
1052
+                               ReadByte (); // flags
 
1053
+                               ErrorCode = ReadShort ();
 
1054
+                       }
 
1055
+
 
1056
+                       public CommandSet CommandSet {
 
1057
+                               get; set;
 
1058
+                       }
 
1059
+
 
1060
+                       public int Command {
 
1061
+                               get; set;
 
1062
+                       }
 
1063
+
 
1064
+                       public int ErrorCode {
 
1065
+                               get; set;
 
1066
+                       }
 
1067
+
 
1068
+                       public int Offset {
 
1069
+                               get {
 
1070
+                                       return offset;
 
1071
+                               }
 
1072
+                       }
 
1073
+
 
1074
+                       public int ReadByte () {
 
1075
+                               return decode_byte (packet, ref offset);
 
1076
+                       }
 
1077
+
 
1078
+                       public int ReadShort () {
 
1079
+                               return decode_short (packet, ref offset);
 
1080
+                       }
 
1081
+
 
1082
+                       public int ReadInt () {
 
1083
+                               return decode_int (packet, ref offset);
 
1084
+                       }
 
1085
+
 
1086
+                       public long ReadId () {
 
1087
+                               return decode_id (packet, ref offset);
 
1088
+                       }
 
1089
+
 
1090
+                       public long ReadLong () {
 
1091
+                               return decode_long (packet, ref offset);
 
1092
+                       }
 
1093
+
 
1094
+                       public float ReadFloat () {
 
1095
+                               float f = DataConverter.FloatFromBE (packet, offset);
 
1096
+                               offset += 4;
 
1097
+                               return f;
 
1098
+                       }
 
1099
+
 
1100
+                       public double ReadDouble () {
 
1101
+                               double d = DataConverter.DoubleFromBE (packet, offset);
 
1102
+                               offset += 8;
 
1103
+                               return d;
 
1104
+                       }
 
1105
+
 
1106
+                       public string ReadString () {
 
1107
+                               int len = decode_int (packet, ref offset);
 
1108
+                               string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
 
1109
+                               offset += len;
 
1110
+                               return res;
 
1111
+                       }
 
1112
+
 
1113
+                       public ValueImpl ReadValue () {
 
1114
+                               ElementType etype = (ElementType)ReadByte ();
 
1115
+
 
1116
+                               switch (etype) {
 
1117
+                               case ElementType.Void:
 
1118
+                                       return new ValueImpl { Type = etype };
 
1119
+                               case ElementType.I1:
 
1120
+                                       return new ValueImpl { Type = etype, Value = (sbyte)ReadInt () };
 
1121
+                               case ElementType.U1:
 
1122
+                                       return new ValueImpl { Type = etype, Value = (byte)ReadInt () };
 
1123
+                               case ElementType.Boolean:
 
1124
+                                       return new ValueImpl { Type = etype, Value = ReadInt () != 0 };
 
1125
+                               case ElementType.I2:
 
1126
+                                       return new ValueImpl { Type = etype, Value = (short)ReadInt () };
 
1127
+                               case ElementType.U2:
 
1128
+                                       return new ValueImpl { Type = etype, Value = (ushort)ReadInt () };
 
1129
+                               case ElementType.Char:
 
1130
+                                       return new ValueImpl { Type = etype, Value = (char)ReadInt () };
 
1131
+                               case ElementType.I4:
 
1132
+                                       return new ValueImpl { Type = etype, Value = ReadInt () };
 
1133
+                               case ElementType.U4:
 
1134
+                                       return new ValueImpl { Type = etype, Value = (uint)ReadInt () };
 
1135
+                               case ElementType.I8:
 
1136
+                                       return new ValueImpl { Type = etype, Value = ReadLong () };
 
1137
+                               case ElementType.U8:
 
1138
+                                       return new ValueImpl { Type = etype, Value = (ulong)ReadLong () };
 
1139
+                               case ElementType.R4:
 
1140
+                                       return new ValueImpl { Type = etype, Value = ReadFloat () };
 
1141
+                               case ElementType.R8:
 
1142
+                                       return new ValueImpl { Type = etype, Value = ReadDouble () };
 
1143
+                               case ElementType.I:
 
1144
+                               case ElementType.U:
 
1145
+                               case ElementType.Ptr:
 
1146
+                                       // FIXME: The client and the debuggee might have different word sizes
 
1147
+                                       return new ValueImpl { Type = etype, Value = ReadLong () };
 
1148
+                               case ElementType.String:
 
1149
+                               case ElementType.SzArray:
 
1150
+                               case ElementType.Class:
 
1151
+                               case ElementType.Array:
 
1152
+                               case ElementType.Object:
 
1153
+                                       long objid = ReadId ();
 
1154
+                                       return new ValueImpl () { Type = etype, Objid = objid };
 
1155
+                               case ElementType.ValueType:
 
1156
+                                       bool is_enum = ReadByte () == 1;
 
1157
+                                       long klass = ReadId ();
 
1158
+                                       long nfields = ReadInt ();
 
1159
+                                       ValueImpl[] fields = new ValueImpl [nfields];
 
1160
+                                       for (int i = 0; i < nfields; ++i)
 
1161
+                                               fields [i] = ReadValue ();
 
1162
+                                       return new ValueImpl () { Type = etype, Klass = klass, Fields = fields, IsEnum = is_enum };
 
1163
+                               case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
 
1164
+                                       return new ValueImpl { Type = etype };
 
1165
+                               case (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE:
 
1166
+                                       return new ValueImpl () { Type = etype, Id = ReadId () };
 
1167
+                               default:
 
1168
+                                       throw new NotImplementedException ("Unable to handle type " + etype);
 
1169
+                               }
 
1170
+                       }
 
1171
+               }
 
1172
+
 
1173
+               class PacketWriter {
 
1174
+
 
1175
+                       byte[] data;
 
1176
+                       int offset;
 
1177
+
 
1178
+                       public PacketWriter () {
 
1179
+                               // FIXME:
 
1180
+                               data = new byte [1024];
 
1181
+                               offset = 0;
 
1182
+                       }
 
1183
+
 
1184
+                       public PacketWriter WriteByte (byte val) {
 
1185
+                               encode_byte (data, val, ref offset);
 
1186
+                               return this;
 
1187
+                       }
 
1188
+
 
1189
+                       public PacketWriter WriteInt (int val) {
 
1190
+                               encode_int (data, val, ref offset);
 
1191
+                               return this;
 
1192
+                       }
 
1193
+
 
1194
+                       public PacketWriter WriteId (long id) {
 
1195
+                               encode_id (data, id, ref offset);
 
1196
+                               return this;
 
1197
+                       }
 
1198
+
 
1199
+                       public PacketWriter WriteLong (long val) {
 
1200
+                               encode_long (data, val, ref offset);
 
1201
+                               return this;
 
1202
+                       }
 
1203
+
 
1204
+                       public PacketWriter WriteFloat (float f) {
 
1205
+                               byte[] b = DataConverter.GetBytesBE (f);
 
1206
+                               for (int i = 0; i < 4; ++i)
 
1207
+                                       data [offset + i] = b [i];
 
1208
+                               offset += 4;
 
1209
+                               return this;
 
1210
+                       }
 
1211
+
 
1212
+                       public PacketWriter WriteDouble (double d) {
 
1213
+                               byte[] b = DataConverter.GetBytesBE (d);
 
1214
+                               for (int i = 0; i < 8; ++i)
 
1215
+                                       data [offset + i] = b [i];
 
1216
+                               offset += 8;
 
1217
+                               return this;
 
1218
+                       }
 
1219
+
 
1220
+                       public PacketWriter WriteInts (int[] ids) {
 
1221
+                               for (int i = 0; i < ids.Length; ++i)
 
1222
+                                       WriteInt (ids [i]);
 
1223
+                               return this;
 
1224
+                       }
 
1225
+
 
1226
+                       public PacketWriter WriteIds (long[] ids) {
 
1227
+                               for (int i = 0; i < ids.Length; ++i)
 
1228
+                                       WriteId (ids [i]);
 
1229
+                               return this;
 
1230
+                       }
 
1231
+
 
1232
+                       public PacketWriter WriteString (string s) {
 
1233
+                               encode_int (data, s.Length, ref offset);
 
1234
+                               byte[] b = Encoding.UTF8.GetBytes (s);
 
1235
+                               Buffer.BlockCopy (b, 0, data, offset, b.Length);
 
1236
+                               offset += b.Length;
 
1237
+                               return this;
 
1238
+                       }
 
1239
+
 
1240
+                       public PacketWriter WriteBool (bool val) {
 
1241
+                               WriteByte (val ? (byte)1 : (byte)0);
 
1242
+                               return this;
 
1243
+                       }
 
1244
+
 
1245
+                       public PacketWriter WriteValue (ValueImpl v) {
 
1246
+                               ElementType t;
 
1247
+
 
1248
+                               if (v.Value != null)
 
1249
+                                       t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
 
1250
+                               else
 
1251
+                                       t = v.Type;
 
1252
+                               WriteByte ((byte)t);
 
1253
+                               switch (t) {
 
1254
+                               case ElementType.Boolean:
 
1255
+                                       WriteInt ((bool)v.Value ? 1 : 0);
 
1256
+                                       break;
 
1257
+                               case ElementType.Char:
 
1258
+                                       WriteInt ((int)(char)v.Value);
 
1259
+                                       break;
 
1260
+                               case ElementType.I1:
 
1261
+                                       WriteInt ((int)(sbyte)v.Value);
 
1262
+                                       break;
 
1263
+                               case ElementType.U1:
 
1264
+                                       WriteInt ((int)(byte)v.Value);
 
1265
+                                       break;
 
1266
+                               case ElementType.I2:
 
1267
+                                       WriteInt ((int)(short)v.Value);
 
1268
+                                       break;
 
1269
+                               case ElementType.U2:
 
1270
+                                       WriteInt ((int)(ushort)v.Value);
 
1271
+                                       break;
 
1272
+                               case ElementType.I4:
 
1273
+                                       WriteInt ((int)(int)v.Value);
 
1274
+                                       break;
 
1275
+                               case ElementType.U4:
 
1276
+                                       WriteInt ((int)(uint)v.Value);
 
1277
+                                       break;
 
1278
+                               case ElementType.I8:
 
1279
+                                       WriteLong ((long)(long)v.Value);
 
1280
+                                       break;
 
1281
+                               case ElementType.U8:
 
1282
+                                       WriteLong ((long)(ulong)v.Value);
 
1283
+                                       break;
 
1284
+                               case ElementType.R4:
 
1285
+                                       WriteFloat ((float)v.Value);
 
1286
+                                       break;
 
1287
+                               case ElementType.R8:
 
1288
+                                       WriteDouble ((double)v.Value);
 
1289
+                                       break;
 
1290
+                               case ElementType.String:
 
1291
+                               case ElementType.SzArray:
 
1292
+                               case ElementType.Class:
 
1293
+                               case ElementType.Array:
 
1294
+                               case ElementType.Object:
 
1295
+                                       WriteId (v.Objid);
 
1296
+                                       break;
 
1297
+                               case ElementType.ValueType:
 
1298
+                                       // FIXME: 
 
1299
+                                       if (v.IsEnum)
 
1300
+                                               throw new NotImplementedException ();
 
1301
+                                       WriteByte (0);
 
1302
+                                       WriteId (v.Klass);
 
1303
+                                       WriteInt (v.Fields.Length);
 
1304
+                                       for (int i = 0; i < v.Fields.Length; ++i)
 
1305
+                                               WriteValue (v.Fields [i]);
 
1306
+                                       break;
 
1307
+                               case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
 
1308
+                                       break;
 
1309
+                               default:
 
1310
+                                       throw new NotImplementedException ();
 
1311
+                               }
 
1312
+
 
1313
+                               return this;
 
1314
+                       }
 
1315
+
 
1316
+                       public PacketWriter WriteValues (ValueImpl[] values) {
 
1317
+                               for (int i = 0; i < values.Length; ++i)
 
1318
+                                       WriteValue (values [i]);
 
1319
+                               return this;
 
1320
+                       }
 
1321
+
 
1322
+                       public byte[] Data {
 
1323
+                               get {
 
1324
+                                       return data;
 
1325
+                               }
 
1326
+                       }
 
1327
+
 
1328
+                       public int Offset {
 
1329
+                               get {
 
1330
+                                       return offset;
 
1331
+                               }
 
1332
+                       }
 
1333
+               }
 
1334
+
 
1335
+               delegate void ReplyCallback (int packet_id, byte[] packet);
 
1336
+
 
1337
+               Socket socket;
 
1338
+               bool closed;
 
1339
+               Thread receiver_thread;
 
1340
+               Dictionary<int, byte[]> reply_packets;
 
1341
+               Dictionary<int, ReplyCallback> reply_cbs;
 
1342
+               object reply_packets_monitor;
 
1343
+
 
1344
+               public event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
 
1345
+
 
1346
+               public Connection (Socket socket) {
 
1347
+                       this.socket = socket;
 
1348
+                       //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
 
1349
+                       closed = false;
 
1350
+                       reply_packets = new Dictionary<int, byte[]> ();
 
1351
+                       reply_cbs = new Dictionary<int, ReplyCallback> ();
 
1352
+                       reply_packets_monitor = new Object ();
 
1353
+               }
 
1354
+
 
1355
+               int Receive (byte[] buf, int buf_offset, int len) {
 
1356
+                       int offset = 0;
 
1357
+
 
1358
+                       while (offset < len) {
 
1359
+                               int n = socket.Receive (buf, buf_offset + offset, len - offset, SocketFlags.None);
 
1360
+
 
1361
+                               if (n == 0)
 
1362
+                                       return offset;
 
1363
+                               offset += n;
 
1364
+                       }
 
1365
+
 
1366
+                       return offset;
 
1367
+               }
 
1368
+
 
1369
+               public VersionInfo Version;
 
1370
+
 
1371
+               // Do the wire protocol handshake
 
1372
+               public void Connect () {
 
1373
+                       byte[] buf = new byte [HANDSHAKE_STRING.Length];
 
1374
+                       char[] cbuf = new char [buf.Length];
 
1375
+
 
1376
+                       // FIXME: Add a timeout
 
1377
+                       int n = Receive (buf, 0, buf.Length);
 
1378
+                       if (n == 0)
 
1379
+                               throw new IOException ("DWP Handshake failed.");
 
1380
+                       for (int i = 0; i < buf.Length; ++i)
 
1381
+                               cbuf [i] = (char)buf [i];
 
1382
+
 
1383
+                       if (new String (cbuf) != HANDSHAKE_STRING)
 
1384
+                               throw new IOException ("DWP Handshake failed.");
 
1385
+
 
1386
+                       socket.Send (buf);
 
1387
+
 
1388
+                       receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
 
1389
+                       receiver_thread.Start ();
 
1390
+
 
1391
+                       Version = VM_GetVersion ();
 
1392
+
 
1393
+                       //
 
1394
+                       // Tell the debuggee our protocol version, so newer debuggees can work
 
1395
+                       // with older clients
 
1396
+                       //
 
1397
+
 
1398
+                       //
 
1399
+                       // Older debuggees might not support this request
 
1400
+                       EventHandler<ErrorHandlerEventArgs> OrigErrorHandler = ErrorHandler;
 
1401
+                       ErrorHandler = null;
 
1402
+                       ErrorHandler += delegate (object sender, ErrorHandlerEventArgs args) {
 
1403
+                               throw new NotSupportedException ();
 
1404
+                       };
 
1405
+                       try {
 
1406
+                               VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
 
1407
+                       } catch (NotSupportedException) {
 
1408
+                       }
 
1409
+                       ErrorHandler = OrigErrorHandler;
 
1410
+               }
 
1411
+
 
1412
+               public EndPoint EndPoint {
 
1413
+                       get {
 
1414
+                               return socket.RemoteEndPoint;
 
1415
+                       }
 
1416
+               }
 
1417
+
 
1418
+               public byte[] ReadPacket () {
 
1419
+                       // FIXME: Throw ClosedConnectionException () if the connection is closed
 
1420
+                       // FIXME: Throw ClosedConnectionException () if another thread closes the connection
 
1421
+                       // FIXME: Locking
 
1422
+                       byte[] header = new byte [HEADER_LENGTH];
 
1423
+
 
1424
+                       int len = Receive (header, 0, header.Length);
 
1425
+                       if (len == 0)
 
1426
+                               return new byte [0];
 
1427
+                       if (len != HEADER_LENGTH) {
 
1428
+                               // FIXME:
 
1429
+                               throw new IOException ("Packet of length " + len + " is read.");
 
1430
+                       }
 
1431
+
 
1432
+                       int packetLength = GetPacketLength (header);
 
1433
+                       if (packetLength < 11)
 
1434
+                               throw new IOException ("Invalid packet length.");
 
1435
+
 
1436
+                       if (packetLength == 11) {
 
1437
+                               return header;
 
1438
+                       } else {
 
1439
+                               byte[] buf = new byte [packetLength];
 
1440
+                               for (int i = 0; i < header.Length; ++i)
 
1441
+                                       buf [i] = header [i];
 
1442
+                               len = Receive (buf, header.Length, packetLength - header.Length);
 
1443
+                               if (len != packetLength - header.Length)
 
1444
+                                       throw new IOException ();
 
1445
+                               return buf;
 
1446
+                       }
 
1447
+               }
 
1448
+
 
1449
+               public void WritePacket (byte[] packet) {
 
1450
+                       // FIXME: Throw ClosedConnectionException () if the connection is closed
 
1451
+                       // FIXME: Throw ClosedConnectionException () if another thread closes the connection
 
1452
+                       // FIXME: Locking
 
1453
+                       socket.Send (packet);
 
1454
+               }
 
1455
+
 
1456
+               public void Close () {
 
1457
+                       closed = true;
 
1458
+               }
 
1459
+
 
1460
+               public bool IsClosed {
 
1461
+                       get {
 
1462
+                               return closed;
 
1463
+                       }
 
1464
+               }
 
1465
+
 
1466
+               bool disconnected;
 
1467
+
 
1468
+               void receiver_thread_main () {
 
1469
+                       while (true) {
 
1470
+                               try {
 
1471
+                                       bool res = ReceivePacket ();
 
1472
+                                       if (!res)
 
1473
+                                               break;
 
1474
+                               } catch (Exception ex) {
 
1475
+                                       Console.WriteLine (ex);
 
1476
+                                       break;
 
1477
+                               }
 
1478
+                       }
 
1479
+
 
1480
+                       lock (reply_packets_monitor) {
 
1481
+                               disconnected = true;
 
1482
+                               Monitor.PulseAll (reply_packets_monitor);
 
1483
+                       }
 
1484
+                       EventHandler.VMDisconnect (0, 0, null);
 
1485
+               }
 
1486
+
 
1487
+               bool ReceivePacket () {
 
1488
+                               byte[] packet = ReadPacket ();
 
1489
+
 
1490
+                               if (packet.Length == 0) {
 
1491
+                                       return false;
 
1492
+                               }
 
1493
+
 
1494
+                               if (IsReplyPacket (packet)) {
 
1495
+                                       int id = GetPacketId (packet);
 
1496
+                                       ReplyCallback cb = null;
 
1497
+                                       lock (reply_packets_monitor) {
 
1498
+                                               reply_cbs.TryGetValue (id, out cb);
 
1499
+                                               if (cb == null) {
 
1500
+                                                       reply_packets [id] = packet;
 
1501
+                                                       Monitor.PulseAll (reply_packets_monitor);
 
1502
+                                               }
 
1503
+                                       }
 
1504
+
 
1505
+                                       if (cb != null)
 
1506
+                                               cb.Invoke (id, packet);
 
1507
+                               } else {
 
1508
+                                       PacketReader r = new PacketReader (packet);
 
1509
+
 
1510
+                                       if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
 
1511
+                                               r.ReadByte (); // suspend_policy
 
1512
+                                               int nevents = r.ReadInt ();
 
1513
+
 
1514
+                                               for (int i = 0; i < nevents; ++i) {
 
1515
+                                                       EventKind kind = (EventKind)r.ReadByte ();
 
1516
+                                                       int req_id = r.ReadInt ();
 
1517
+
 
1518
+                                                       if (kind == EventKind.VM_START) {
 
1519
+                                                               long thread_id = r.ReadId ();
 
1520
+                                                               EventHandler.VMStart (req_id, thread_id, null);
 
1521
+                                                       } else if (kind == EventKind.VM_DEATH) {
 
1522
+                                                               EventHandler.VMDeath (req_id, 0, null);
 
1523
+                                                       } else if (kind == EventKind.THREAD_START) {
 
1524
+                                                               long thread_id = r.ReadId ();
 
1525
+                                                               EventHandler.ThreadStart (req_id, thread_id, thread_id);
 
1526
+                                                       } else if (kind == EventKind.THREAD_DEATH) {
 
1527
+                                                               long thread_id = r.ReadId ();
 
1528
+                                                               EventHandler.ThreadDeath (req_id, thread_id, thread_id);
 
1529
+                                                       } else if (kind == EventKind.ASSEMBLY_LOAD) {
 
1530
+                                                               long thread_id = r.ReadId ();
 
1531
+                                                               long id = r.ReadId ();
 
1532
+                                                               EventHandler.AssemblyLoad (req_id, thread_id, id);
 
1533
+                                                       } else if (kind == EventKind.ASSEMBLY_UNLOAD) {
 
1534
+                                                               long thread_id = r.ReadId ();
 
1535
+                                                               long id = r.ReadId ();
 
1536
+                                                               EventHandler.AssemblyUnload (req_id, thread_id, id);
 
1537
+                                                       } else if (kind == EventKind.TYPE_LOAD) {
 
1538
+                                                               long thread_id = r.ReadId ();
 
1539
+                                                               long id = r.ReadId ();
 
1540
+                                                               EventHandler.TypeLoad (req_id, thread_id, id);
 
1541
+                                                       } else if (kind == EventKind.METHOD_ENTRY) {
 
1542
+                                                               long thread_id = r.ReadId ();
 
1543
+                                                               long id = r.ReadId ();
 
1544
+                                                               EventHandler.MethodEntry (req_id, thread_id, id);
 
1545
+                                                       } else if (kind == EventKind.METHOD_EXIT) {
 
1546
+                                                               long thread_id = r.ReadId ();
 
1547
+                                                               long id = r.ReadId ();
 
1548
+                                                               EventHandler.MethodExit (req_id, thread_id, id);
 
1549
+                                                       } else if (kind == EventKind.BREAKPOINT) {
 
1550
+                                                               long thread_id = r.ReadId ();
 
1551
+                                                               long id = r.ReadId ();
 
1552
+                                                               long loc = r.ReadLong ();
 
1553
+                                                               EventHandler.Breakpoint (req_id, thread_id, id, loc);
 
1554
+                                                       } else if (kind == EventKind.STEP) {
 
1555
+                                                               long thread_id = r.ReadId ();
 
1556
+                                                               long id = r.ReadId ();
 
1557
+                                                               long loc = r.ReadLong ();
 
1558
+                                                               EventHandler.Step (req_id, thread_id, id, loc);
 
1559
+                                                       } else if (kind == EventKind.EXCEPTION) {
 
1560
+                                                               long thread_id = r.ReadId ();
 
1561
+                                                               long id = r.ReadId ();
 
1562
+                                                               long loc = 0; // FIXME
 
1563
+                                                               EventHandler.Exception (req_id, thread_id, id, loc);
 
1564
+                                                       } else if (kind == EventKind.APPDOMAIN_CREATE) {
 
1565
+                                                               long thread_id = r.ReadId ();
 
1566
+                                                               long id = r.ReadId ();
 
1567
+                                                               EventHandler.AppDomainCreate (req_id, thread_id, id);
 
1568
+                                                       } else if (kind == EventKind.APPDOMAIN_UNLOAD) {
 
1569
+                                                               long thread_id = r.ReadId ();
 
1570
+                                                               long id = r.ReadId ();
 
1571
+                                                               EventHandler.AppDomainUnload (req_id, thread_id, id);
 
1572
+                                                       } else {
 
1573
+                                                               throw new NotImplementedException ("Unknown event kind: " + kind);
 
1574
+                                                       }
 
1575
+                                               }
 
1576
+                                       }
 
1577
+                               }
 
1578
+
 
1579
+                               return true;
 
1580
+               }
 
1581
+
 
1582
+               public IEventHandler EventHandler {
 
1583
+                       get; set;
 
1584
+               }
 
1585
+
 
1586
+               /* Send a request and call cb when a result is received */
 
1587
+               int Send (CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb) {
 
1588
+                       int id = IdGenerator;
 
1589
+
 
1590
+                       lock (reply_packets_monitor) {
 
1591
+                               reply_cbs [id] = delegate (int packet_id, byte[] p) {
 
1592
+                                       /* Run the callback on a tp thread to avoid blocking the receive thread */
 
1593
+                                       PacketReader r = new PacketReader (p);
 
1594
+                                       cb.BeginInvoke (r, null, null);
 
1595
+                               };
 
1596
+                       }
 
1597
+                                               
 
1598
+                       if (packet == null)
 
1599
+                               WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
 
1600
+                       else
 
1601
+                               WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
 
1602
+
 
1603
+                       return id;
 
1604
+               }
 
1605
+
 
1606
+               PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
 
1607
+                       int id = IdGenerator;
 
1608
+
 
1609
+                       if (packet == null)
 
1610
+                               WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
 
1611
+                       else
 
1612
+                               WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
 
1613
+
 
1614
+                       int packetId = id;
 
1615
+
 
1616
+                       /* Wait for the reply packet */
 
1617
+                       while (true) {
 
1618
+                               lock (reply_packets_monitor) {
 
1619
+                                       if (reply_packets.ContainsKey (packetId)) {
 
1620
+                                               byte[] reply = reply_packets [packetId];
 
1621
+                                               reply_packets.Remove (packetId);
 
1622
+                                               PacketReader r = new PacketReader (reply);
 
1623
+                                               if (r.ErrorCode != 0) {
 
1624
+                                                       if (ErrorHandler != null)
 
1625
+                                                               ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
 
1626
+                                                       throw new NotImplementedException ("No error handler set.");
 
1627
+                                               } else {
 
1628
+                                                       return r;
 
1629
+                                               }
 
1630
+                                       } else {
 
1631
+                                               if (disconnected)
 
1632
+                                                       throw new VMDisconnectedException ();
 
1633
+                                               Monitor.Wait (reply_packets_monitor);
 
1634
+                                       }
 
1635
+                               }
 
1636
+                       }
 
1637
+               }
 
1638
+
 
1639
+               PacketReader SendReceive (CommandSet command_set, int command) {
 
1640
+                       return SendReceive (command_set, command, null);
 
1641
+               }
 
1642
+
 
1643
+               int packet_id_generator;
 
1644
+
 
1645
+               int IdGenerator {
 
1646
+                       get {
 
1647
+                               return Interlocked.Increment (ref packet_id_generator);
 
1648
+                       }
 
1649
+               }
 
1650
+
 
1651
+               CattrInfo[] ReadCattrs (PacketReader r) {
 
1652
+                       CattrInfo[] res = new CattrInfo [r.ReadInt ()];
 
1653
+                       for (int i = 0; i < res.Length; ++i) {
 
1654
+                               CattrInfo info = new CattrInfo ();
 
1655
+                               info.ctor_id = r.ReadId ();
 
1656
+                               info.ctor_args = new ValueImpl [r.ReadInt ()];
 
1657
+                               for (int j = 0; j < info.ctor_args.Length; ++j) {
 
1658
+                                       info.ctor_args [j] = r.ReadValue ();
 
1659
+                               }
 
1660
+                               info.named_args = new CattrNamedArgInfo [r.ReadInt ()];
 
1661
+                               for (int j = 0; j < info.named_args.Length; ++j) {
 
1662
+                                       CattrNamedArgInfo arg = new CattrNamedArgInfo ();
 
1663
+                                       int arg_type = r.ReadByte ();
 
1664
+                                       arg.is_property = arg_type == 0x54;
 
1665
+                                       arg.id = r.ReadId ();
 
1666
+                                       arg.value = r.ReadValue ();
 
1667
+                                       info.named_args [j] = arg;
 
1668
+                               }
 
1669
+                               res [i] = info;
 
1670
+                       }
 
1671
+                       return res;
 
1672
+               }
 
1673
+
 
1674
+               static ElementType TypeCodeToElementType (TypeCode c) {
 
1675
+                       switch (c) {
 
1676
+                       case TypeCode.Boolean:
 
1677
+                               return ElementType.Boolean;
 
1678
+                       case TypeCode.Char:
 
1679
+                               return ElementType.Char;
 
1680
+                       case TypeCode.SByte:
 
1681
+                               return ElementType.I1;
 
1682
+                       case TypeCode.Byte:
 
1683
+                               return ElementType.U1;
 
1684
+                       case TypeCode.Int16:
 
1685
+                               return ElementType.I2;
 
1686
+                       case TypeCode.UInt16:
 
1687
+                               return ElementType.U2;
 
1688
+                       case TypeCode.Int32:
 
1689
+                               return ElementType.I4;
 
1690
+                       case TypeCode.UInt32:
 
1691
+                               return ElementType.U4;
 
1692
+                       case TypeCode.Int64:
 
1693
+                               return ElementType.I8;
 
1694
+                       case TypeCode.UInt64:
 
1695
+                               return ElementType.U8;
 
1696
+                       case TypeCode.Single:
 
1697
+                               return ElementType.R4;
 
1698
+                       case TypeCode.Double:
 
1699
+                               return ElementType.R8;
 
1700
+                       default:
 
1701
+                               throw new NotImplementedException ();
 
1702
+                       }
 
1703
+               }
 
1704
+
 
1705
+               /*
 
1706
+                * Implementation of debugger commands
 
1707
+                */
 
1708
+
 
1709
+               public VersionInfo VM_GetVersion () {
 
1710
+                       var res = SendReceive (CommandSet.VM, (int)CmdVM.VERSION, null);
 
1711
+                       VersionInfo info = new VersionInfo ();
 
1712
+                       info.VMVersion = res.ReadString ();
 
1713
+                       info.MajorVersion = res.ReadInt ();
 
1714
+                       info.MinorVersion = res.ReadInt ();
 
1715
+                       return info;
 
1716
+               }
 
1717
+
 
1718
+               public void VM_SetProtocolVersion (int major, int minor) {
 
1719
+                       SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
 
1720
+               }
 
1721
+
 
1722
+               public long[] VM_GetThreads () {
 
1723
+                       var res = SendReceive (CommandSet.VM, (int)CmdVM.ALL_THREADS, null);
 
1724
+                       int len = res.ReadInt ();
 
1725
+                       long[] arr = new long [len];
 
1726
+                       for (int i = 0; i < len; ++i)
 
1727
+                               arr [i] = res.ReadId ();
 
1728
+                       return arr;
 
1729
+               }
 
1730
+
 
1731
+               public void VM_Suspend () {
 
1732
+                       SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
 
1733
+               }
 
1734
+
 
1735
+               public void VM_Resume () {
 
1736
+                       SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
 
1737
+               }
 
1738
+
 
1739
+               public void VM_Exit (int exitCode) {
 
1740
+                       SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
 
1741
+               }
 
1742
+
 
1743
+               public void VM_Dispose () {
 
1744
+                       SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
 
1745
+               }
 
1746
+
 
1747
+               public ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
 
1748
+                       exc = null;
 
1749
+                       PacketReader r = SendReceive (CommandSet.VM, (int)CmdVM.INVOKE_METHOD, new PacketWriter ().WriteId (thread).WriteInt ((int)flags).WriteId (method).WriteValue (this_arg).WriteInt (arguments.Length).WriteValues (arguments));
 
1750
+                       if (r.ReadByte () == 0) {
 
1751
+                               exc = r.ReadValue ();
 
1752
+                               return null;
 
1753
+                       } else {
 
1754
+                               return r.ReadValue ();
 
1755
+                       }
 
1756
+               }
 
1757
+
 
1758
+               public delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ErrorCode error, object state);
 
1759
+
 
1760
+               public int VM_BeginInvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, InvokeMethodCallback callback, object state) {
 
1761
+                       return Send (CommandSet.VM, (int)CmdVM.INVOKE_METHOD, new PacketWriter ().WriteId (thread).WriteInt ((int)flags).WriteId (method).WriteValue (this_arg).WriteInt (arguments.Length).WriteValues (arguments), delegate (PacketReader r) {
 
1762
+                                       ValueImpl v, exc;
 
1763
+
 
1764
+                                       if (r.ErrorCode != 0) {
 
1765
+                                               callback (null, null, (ErrorCode)r.ErrorCode, state);
 
1766
+                                       } else {
 
1767
+                                               if (r.ReadByte () == 0) {
 
1768
+                                                       exc = r.ReadValue ();
 
1769
+                                                       v = null;
 
1770
+                                               } else {
 
1771
+                                                       v = r.ReadValue ();
 
1772
+                                                       exc = null;
 
1773
+                                               }
 
1774
+
 
1775
+                                               callback (v, exc, 0, state);
 
1776
+                                       }
 
1777
+                               });
 
1778
+               }
 
1779
+
 
1780
+               public void VM_AbortInvoke (long thread, int id)
 
1781
+               {
 
1782
+                       SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
 
1783
+               }
 
1784
+
 
1785
+               /*
 
1786
+                * DOMAIN
 
1787
+                */
 
1788
+
 
1789
+               public long RootDomain {
 
1790
+                       get {
 
1791
+                               return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
 
1792
+                       }
 
1793
+               }
 
1794
+
 
1795
+               public string Domain_GetName (long id) {
 
1796
+                       return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
 
1797
+               }
 
1798
+
 
1799
+               public long[] Domain_GetAssemblies (long id) {
 
1800
+                       var res = SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ASSEMBLIES, new PacketWriter ().WriteId (id));
 
1801
+                       int count = res.ReadInt ();
 
1802
+                       long[] assemblies = new long [count];
 
1803
+                       for (int i = 0; i < count; ++i)
 
1804
+                               assemblies [i] = res.ReadId ();
 
1805
+                       return assemblies;
 
1806
+               }
 
1807
+
 
1808
+               public long Domain_GetEntryAssembly (long id) {
 
1809
+                       return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
 
1810
+               }
 
1811
+
 
1812
+               public long Domain_GetCorlib (long id) {
 
1813
+                       return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
 
1814
+               }
 
1815
+
 
1816
+               public long Domain_CreateString (long id, string s) {
 
1817
+                       return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_STRING, new PacketWriter ().WriteId (id).WriteString (s)).ReadId ();
 
1818
+               }
 
1819
+
 
1820
+               public long Domain_CreateBoxedValue (long id, long type_id, ValueImpl v) {
 
1821
+                       return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.CREATE_BOXED_VALUE, new PacketWriter ().WriteId (id).WriteId (type_id).WriteValue (v)).ReadId ();
 
1822
+               }
 
1823
+
 
1824
+               /*
 
1825
+                * METHOD
 
1826
+                */
 
1827
+
 
1828
+               public string Method_GetName (long id) {
 
1829
+                       return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
 
1830
+               }
 
1831
+
 
1832
+               public long Method_GetDeclaringType (long id) {
 
1833
+                       return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
 
1834
+               }
 
1835
+
 
1836
+               public DebugInfo Method_GetDebugInfo (long id) {
 
1837
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
 
1838
+
 
1839
+                       DebugInfo info = new DebugInfo ();
 
1840
+                       info.max_il_offset = res.ReadInt ();
 
1841
+                       info.filename = res.ReadString ();
 
1842
+
 
1843
+                       int n_il_offsets = res.ReadInt ();
 
1844
+                       info.il_offsets = new int [n_il_offsets];
 
1845
+                       info.line_numbers = new int [n_il_offsets];
 
1846
+                       for (int i = 0; i < n_il_offsets; ++i) {
 
1847
+                               info.il_offsets [i] = res.ReadInt ();
 
1848
+                               info.line_numbers [i] = res.ReadInt ();
 
1849
+                       }
 
1850
+
 
1851
+                       return info;
 
1852
+               }
 
1853
+
 
1854
+               public ParamInfo Method_GetParamInfo (long id) {
 
1855
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
 
1856
+
 
1857
+                       ParamInfo info = new ParamInfo ();
 
1858
+                       info.call_conv = res.ReadInt ();
 
1859
+                       info.param_count = res.ReadInt ();
 
1860
+                       info.generic_param_count = res.ReadInt ();
 
1861
+                       info.ret_type = res.ReadId ();
 
1862
+                       info.param_types = new long [info.param_count];
 
1863
+                       for (int i = 0; i < info.param_count; ++i)
 
1864
+                               info.param_types [i] = res.ReadId ();
 
1865
+                       info.param_names = new string [info.param_count];                       
 
1866
+                       for (int i = 0; i < info.param_count; ++i)
 
1867
+                               info.param_names [i] = res.ReadString ();
 
1868
+
 
1869
+                       return info;
 
1870
+               }
 
1871
+
 
1872
+               public LocalsInfo Method_GetLocalsInfo (long id) {
 
1873
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
 
1874
+
 
1875
+                       LocalsInfo info = new LocalsInfo ();
 
1876
+                       int nlocals = res.ReadInt ();
 
1877
+                       info.types = new long [nlocals];
 
1878
+                       for (int i = 0; i < nlocals; ++i)
 
1879
+                               info.types [i] = res.ReadId ();
 
1880
+                       info.names = new string [nlocals];
 
1881
+                       for (int i = 0; i < nlocals; ++i)
 
1882
+                               info.names [i] = res.ReadString ();
 
1883
+                       info.live_range_start = new int [nlocals];
 
1884
+                       info.live_range_end = new int [nlocals];
 
1885
+                       for (int i = 0; i < nlocals; ++i) {
 
1886
+                               info.live_range_start [i] = res.ReadInt ();
 
1887
+                               info.live_range_end [i] = res.ReadInt ();
 
1888
+                       }
 
1889
+
 
1890
+                       return info;
 
1891
+               }
 
1892
+
 
1893
+               public MethodInfo Method_GetInfo (long id) {
 
1894
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
 
1895
+
 
1896
+                       MethodInfo info = new MethodInfo ();
 
1897
+                       info.attributes = res.ReadInt ();
 
1898
+                       info.iattributes = res.ReadInt ();
 
1899
+                       info.token = res.ReadInt ();
 
1900
+
 
1901
+                       return info;
 
1902
+               }
 
1903
+
 
1904
+               public MethodBodyInfo Method_GetBody (long id) {
 
1905
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
 
1906
+
 
1907
+                       MethodBodyInfo info = new MethodBodyInfo ();
 
1908
+                       info.il = new byte [res.ReadInt ()];
 
1909
+                       for (int i = 0; i < info.il.Length; ++i)
 
1910
+                               info.il [i] = (byte)res.ReadByte ();
 
1911
+
 
1912
+                       return info;
 
1913
+               }
 
1914
+
 
1915
+               public ResolvedToken Method_ResolveToken (long id, int token) {
 
1916
+                       var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.RESOLVE_TOKEN, new PacketWriter ().WriteId (id).WriteInt (token));
 
1917
+
 
1918
+                       TokenType type = (TokenType)res.ReadByte ();
 
1919
+                       switch (type) {
 
1920
+                       case TokenType.STRING:
 
1921
+                               return new ResolvedToken () { Type = type, Str = res.ReadString () };
 
1922
+                       case TokenType.TYPE:
 
1923
+                       case TokenType.METHOD:
 
1924
+                       case TokenType.FIELD:
 
1925
+                               return new ResolvedToken () { Type = type, Id = res.ReadId () };
 
1926
+                       case TokenType.UNKNOWN:
 
1927
+                               return new ResolvedToken () { Type = type };
 
1928
+                       default:
 
1929
+                               throw new NotImplementedException ();
 
1930
+                       }
 
1931
+               }
 
1932
+
 
1933
+               /*
 
1934
+                * THREAD
 
1935
+                */
 
1936
+
 
1937
+               public string Thread_GetName (long id) {
 
1938
+                       return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
 
1939
+               }
 
1940
+
 
1941
+               public FrameInfo[] Thread_GetFrameInfo (long id, int start_frame, int length) {
 
1942
+                       var res = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_FRAME_INFO, new PacketWriter ().WriteId (id).WriteInt (start_frame).WriteInt (length));
 
1943
+                       int count = res.ReadInt ();
 
1944
+
 
1945
+                       var frames = new FrameInfo [count];
 
1946
+                       for (int i = 0; i < count; ++i) {
 
1947
+                               frames [i].id = res.ReadInt ();
 
1948
+                               frames [i].method = res.ReadId ();
 
1949
+                               frames [i].il_offset = res.ReadInt ();
 
1950
+                               frames [i].flags = (StackFrameFlags)res.ReadByte ();
 
1951
+                       }
 
1952
+                       return frames;
 
1953
+               }
 
1954
+
 
1955
+               public int Thread_GetState (long id) {
 
1956
+                       return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
 
1957
+               }
 
1958
+
 
1959
+               public ThreadInfo Thread_GetInfo (long id) {
 
1960
+                       PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
 
1961
+
 
1962
+                       ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
 
1963
+
 
1964
+                       return res;
 
1965
+               }
 
1966
+
 
1967
+               public long Thread_GetId (long id) {
 
1968
+                       return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
 
1969
+               }
 
1970
+
 
1971
+               /*
 
1972
+                * MODULE
 
1973
+                */
 
1974
+
 
1975
+               public ModuleInfo Module_GetInfo (long id) {
 
1976
+                       PacketReader r = SendReceive (CommandSet.MODULE, (int)CmdModule.GET_INFO, new PacketWriter ().WriteId (id));
 
1977
+                       ModuleInfo info = new ModuleInfo { Name = r.ReadString (), ScopeName = r.ReadString (), FQName = r.ReadString (), Guid = r.ReadString (), Assembly = r.ReadId () };
 
1978
+                       return info;
 
1979
+               }
 
1980
+
 
1981
+               /*
 
1982
+                * ASSEMBLY
 
1983
+                */
 
1984
+
 
1985
+               public string Assembly_GetLocation (long id) {
 
1986
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
 
1987
+               }
 
1988
+
 
1989
+               public long Assembly_GetEntryPoint (long id) {
 
1990
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
 
1991
+               }
 
1992
+
 
1993
+               public long Assembly_GetManifestModule (long id) {
 
1994
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
 
1995
+               }
 
1996
+
 
1997
+               public long Assembly_GetObject (long id) {
 
1998
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
 
1999
+               }
 
2000
+
 
2001
+               public long Assembly_GetType (long id, string name, bool ignoreCase) {
 
2002
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_TYPE, new PacketWriter ().WriteId (id).WriteString (name).WriteBool (ignoreCase)).ReadId ();
 
2003
+               }
 
2004
+
 
2005
+               public string Assembly_GetName (long id) {
 
2006
+                       return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
 
2007
+               }
 
2008
+
 
2009
+               /*
 
2010
+                * TYPE
 
2011
+                */
 
2012
+
 
2013
+               public TypeInfo Type_GetInfo (long id) {
 
2014
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INFO, new PacketWriter ().WriteId (id));
 
2015
+                       TypeInfo res = new TypeInfo ();
 
2016
+
 
2017
+                       res.ns = r.ReadString ();
 
2018
+                       res.name = r.ReadString ();
 
2019
+                       res.full_name = r.ReadString ();
 
2020
+                       res.assembly = r.ReadId ();
 
2021
+                       res.module = r.ReadId ();
 
2022
+                       res.base_type = r.ReadId ();
 
2023
+                       res.element_type = r.ReadId ();
 
2024
+                       res.token = r.ReadInt ();
 
2025
+                       res.rank = r.ReadByte ();
 
2026
+                       res.attributes = r.ReadInt ();
 
2027
+                       int b = r.ReadByte ();
 
2028
+                       res.is_byref = (b & 1) != 0;
 
2029
+                       res.is_pointer = (b & 2) != 0;
 
2030
+                       res.is_primitive = (b & 4) != 0;
 
2031
+                       res.is_valuetype = (b & 8) != 0;
 
2032
+                       res.is_enum = (b & 16) != 0;
 
2033
+
 
2034
+                       int nested_len = r.ReadInt ();
 
2035
+                       res.nested = new long [nested_len];
 
2036
+                       for (int i = 0; i < nested_len; ++i)
 
2037
+                               res.nested [i] = r.ReadId ();
 
2038
+
 
2039
+                       return res;
 
2040
+               }
 
2041
+
 
2042
+               public long[] Type_GetMethods (long id) {
 
2043
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
 
2044
+
 
2045
+                       int n = r.ReadInt ();
 
2046
+                       long[] res = new long [n];
 
2047
+                       for (int i = 0; i < n; ++i)
 
2048
+                               res [i] = r.ReadId ();
 
2049
+                       return res;
 
2050
+               }
 
2051
+
 
2052
+               public long[] Type_GetFields (long id, out string[] names, out long[] types, out int[] attrs) {
 
2053
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELDS, new PacketWriter ().WriteId (id));
 
2054
+
 
2055
+                       int n = r.ReadInt ();
 
2056
+                       long[] res = new long [n];
 
2057
+                       names = new string [n];
 
2058
+                       types = new long [n];
 
2059
+                       attrs = new int [n];
 
2060
+                       for (int i = 0; i < n; ++i) {
 
2061
+                               res [i] = r.ReadId ();
 
2062
+                               names [i] = r.ReadString ();
 
2063
+                               types [i] = r.ReadId ();
 
2064
+                               attrs [i] = r.ReadInt ();
 
2065
+                       }
 
2066
+                       return res;
 
2067
+               }
 
2068
+
 
2069
+               public PropInfo[] Type_GetProperties (long id) {
 
2070
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
 
2071
+
 
2072
+                       int n = r.ReadInt ();
 
2073
+                       PropInfo[] res = new PropInfo [n];
 
2074
+                       for (int i = 0; i < n; ++i) {
 
2075
+                               res [i] = new PropInfo ();
 
2076
+                               res [i].id = r.ReadId ();
 
2077
+                               res [i].name = r.ReadString ();
 
2078
+                               res [i].get_method = r.ReadId ();
 
2079
+                               res [i].set_method = r.ReadId ();
 
2080
+                               res [i].attrs = r.ReadInt ();
 
2081
+                       }
 
2082
+
 
2083
+                       return res;
 
2084
+               }
 
2085
+
 
2086
+               public long Type_GetObject (long id) {
 
2087
+                       return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
 
2088
+               }
 
2089
+
 
2090
+               public ValueImpl[] Type_GetValues (long id, long[] fields) {
 
2091
+                       int len = fields.Length;
 
2092
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
 
2093
+
 
2094
+                       ValueImpl[] res = new ValueImpl [len];
 
2095
+                       for (int i = 0; i < len; ++i)
 
2096
+                               res [i] = r.ReadValue ();
 
2097
+                       return res;
 
2098
+               }                       
 
2099
+
 
2100
+               public void Type_SetValues (long id, long[] fields, ValueImpl[] values) {
 
2101
+                       SendReceive (CommandSet.TYPE, (int)CmdType.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
 
2102
+               }
 
2103
+
 
2104
+               public string[] Type_GetSourceFiles (long id, bool return_full_paths) {
 
2105
+                       var r = SendReceive (CommandSet.TYPE, return_full_paths ? (int)CmdType.GET_SOURCE_FILES_2 : (int)CmdType.GET_SOURCE_FILES, new PacketWriter ().WriteId (id));
 
2106
+                       int len = r.ReadInt ();
 
2107
+                       string[] res = new string [len];
 
2108
+                       for (int i = 0; i < len; ++i)
 
2109
+                               res [i] = r.ReadString ();
 
2110
+                       return res;
 
2111
+               }
 
2112
+
 
2113
+               public bool Type_IsAssignableFrom (long id, long c_id) {
 
2114
+                       return SendReceive (CommandSet.TYPE, (int)CmdType.IS_ASSIGNABLE_FROM, new PacketWriter ().WriteId (id).WriteId (c_id)).ReadByte () > 0;
 
2115
+               }
 
2116
+
 
2117
+               public CattrInfo[] Type_GetCustomAttributes (long id, long attr_type_id, bool inherit) {
 
2118
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_CATTRS, new PacketWriter ().WriteId (id).WriteId (attr_type_id));
 
2119
+                       return ReadCattrs (r);
 
2120
+               }
 
2121
+
 
2122
+               public CattrInfo[] Type_GetFieldCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
 
2123
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_FIELD_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
 
2124
+                       return ReadCattrs (r);
 
2125
+               }
 
2126
+
 
2127
+               public CattrInfo[] Type_GetPropertyCustomAttributes (long id, long field_id, long attr_type_id, bool inherit) {
 
2128
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTY_CATTRS, new PacketWriter ().WriteId (id).WriteId (field_id).WriteId (attr_type_id));
 
2129
+                       return ReadCattrs (r);
 
2130
+               }
 
2131
+                       
 
2132
+               /*
 
2133
+                * EVENTS
 
2134
+                */
 
2135
+
 
2136
+               public int EnableEvent (EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods) {
 
2137
+                       var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
 
2138
+                       if (mods != null) {
 
2139
+                               if (mods.Count > 255)
 
2140
+                                       throw new NotImplementedException ();
 
2141
+                               w.WriteByte ((byte)mods.Count);
 
2142
+                               foreach (Modifier mod in mods) {
 
2143
+                                       if (mod is CountModifier) {
 
2144
+                                               w.WriteByte ((byte)ModifierKind.COUNT);
 
2145
+                                               w.WriteInt ((mod as CountModifier).Count);
 
2146
+                                       } else if (mod is LocationModifier) {
 
2147
+                                               w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
 
2148
+                                               w.WriteId ((mod as LocationModifier).Method);
 
2149
+                                               w.WriteLong ((mod as LocationModifier).Location);
 
2150
+                                       } else if (mod is StepModifier) {
 
2151
+                                               w.WriteByte ((byte)ModifierKind.STEP);
 
2152
+                                               w.WriteId ((mod as StepModifier).Thread);
 
2153
+                                               w.WriteInt ((mod as StepModifier).Size);
 
2154
+                                               w.WriteInt ((mod as StepModifier).Depth);
 
2155
+                                       } else if (mod is ThreadModifier) {
 
2156
+                                               w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
 
2157
+                                               w.WriteId ((mod as ThreadModifier).Thread);
 
2158
+                                       } else if (mod is ExceptionModifier) {
 
2159
+                                               var em = mod as ExceptionModifier;
 
2160
+                                               w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
 
2161
+                                               w.WriteId (em.Type);
 
2162
+                                               if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
 
2163
+                                                       /* This is only supported in protocol version 2.1 */
 
2164
+                                                       w.WriteBool (em.Caught);
 
2165
+                                                       w.WriteBool (em.Uncaught);
 
2166
+                                               } else if (!em.Caught || !em.Uncaught) {
 
2167
+                                                       throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
 
2168
+                                               }
 
2169
+                                       } else if (mod is AssemblyModifier) {
 
2170
+                                               w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
 
2171
+                                               var amod = (mod as AssemblyModifier);
 
2172
+                                               w.WriteInt (amod.Assemblies.Length);
 
2173
+                                               foreach (var id in amod.Assemblies)
 
2174
+                                                       w.WriteId (id);
 
2175
+                                       } else {
 
2176
+                                               throw new NotImplementedException ();
 
2177
+                                       }
 
2178
+                               }
 
2179
+                       } else {
 
2180
+                               w.WriteByte (0);
 
2181
+                       }
 
2182
+                       return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
 
2183
+               }
 
2184
+
 
2185
+               public void ClearEventRequest (EventType etype, int req_id) {
 
2186
+                       SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR, new PacketWriter ().WriteByte ((byte)etype).WriteInt (req_id));
 
2187
+               }                       
 
2188
+
 
2189
+               public void ClearAllBreakpoints () {
 
2190
+                       SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
 
2191
+               }
 
2192
+                       
 
2193
+               /*
 
2194
+                * STACK FRAME
 
2195
+                */
 
2196
+               public ValueImpl StackFrame_GetThis (long thread_id, long id) {
 
2197
+                       PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_THIS, new PacketWriter ().WriteId (thread_id).WriteId (id));
 
2198
+                       return r.ReadValue ();
 
2199
+               }
 
2200
+
 
2201
+               public ValueImpl[] StackFrame_GetValues (long thread_id, long id, int[] pos) {
 
2202
+                       /* pos < 0 -> argument at pos (-pos) - 1 */
 
2203
+                       /* pos >= 0 -> local at pos */
 
2204
+                       int len = pos.Length;
 
2205
+                       PacketReader r = SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.GET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos));
 
2206
+
 
2207
+                       ValueImpl[] res = new ValueImpl [len];
 
2208
+                       for (int i = 0; i < len; ++i)
 
2209
+                               res [i] = r.ReadValue ();
 
2210
+                       return res;
 
2211
+               }
 
2212
+
 
2213
+               public void StackFrame_SetValues (long thread_id, long id, int[] pos, ValueImpl[] values) {
 
2214
+                       /* pos < 0 -> argument at pos (-pos) - 1 */
 
2215
+                       /* pos >= 0 -> local at pos */
 
2216
+                       int len = pos.Length;
 
2217
+                       SendReceive (CommandSet.STACK_FRAME, (int)CmdStackFrame.SET_VALUES, new PacketWriter ().WriteId (thread_id).WriteId (id).WriteInt (len).WriteInts (pos).WriteValues (values));
 
2218
+               }
 
2219
+
 
2220
+               /*
 
2221
+                * ARRAYS
 
2222
+                */
 
2223
+               public int[] Array_GetLength (long id, out int rank, out int[] lower_bounds) {
 
2224
+                       var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_LENGTH, new PacketWriter ().WriteId (id));
 
2225
+                       rank = r.ReadInt ();
 
2226
+                       int[] res = new int [rank];
 
2227
+                       lower_bounds = new int [rank];
 
2228
+                       for (int i = 0; i < rank; ++i) {
 
2229
+                               res [i] = r.ReadInt ();
 
2230
+                               lower_bounds [i] = r.ReadInt ();
 
2231
+                       }
 
2232
+                       return res;
 
2233
+               }
 
2234
+
 
2235
+               public ValueImpl[] Array_GetValues (long id, int index, int len) {
 
2236
+                       var r = SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (len));
 
2237
+                       ValueImpl[] res = new ValueImpl [len];
 
2238
+                       for (int i = 0; i < len; ++i)
 
2239
+                               res [i] = r.ReadValue ();
 
2240
+                       return res;
 
2241
+               }
 
2242
+
 
2243
+               public void Array_SetValues (long id, int index, ValueImpl[] values) {
 
2244
+                       SendReceive (CommandSet.ARRAY_REF, (int)CmdArrayRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (index).WriteInt (values.Length).WriteValues (values));
 
2245
+               }
 
2246
+
 
2247
+               /*
 
2248
+                * STRINGS
 
2249
+                */
 
2250
+               public string String_GetValue (long id) {
 
2251
+                       return SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id)).ReadString ();
 
2252
+               }                       
 
2253
+
 
2254
+               /*
 
2255
+                * OBJECTS
 
2256
+                */
 
2257
+               public long Object_GetType (long id) {
 
2258
+                       return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
 
2259
+               }                       
 
2260
+
 
2261
+               public long Object_GetDomain (long id) {
 
2262
+                       return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
 
2263
+               }                       
 
2264
+
 
2265
+               public ValueImpl[] Object_GetValues (long id, long[] fields) {
 
2266
+                       int len = fields.Length;
 
2267
+                       PacketReader r = SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_VALUES, new PacketWriter ().WriteId (id).WriteInt (len).WriteIds (fields));
 
2268
+
 
2269
+                       ValueImpl[] res = new ValueImpl [len];
 
2270
+                       for (int i = 0; i < len; ++i)
 
2271
+                               res [i] = r.ReadValue ();
 
2272
+                       return res;
 
2273
+               }
 
2274
+
 
2275
+               public void Object_SetValues (long id, long[] fields, ValueImpl[] values) {
 
2276
+                       SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.SET_VALUES, new PacketWriter ().WriteId (id).WriteInt (fields.Length).WriteIds (fields).WriteValues (values));
 
2277
+               }
 
2278
+
 
2279
+               public bool Object_IsCollected (long id) {
 
2280
+                       return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
 
2281
+               }                       
 
2282
+
 
2283
+               public long Object_GetAddress (long id) {
 
2284
+                       return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
 
2285
+               }                       
 
2286
+
 
2287
+       }
 
2288
+
 
2289
+       /* This is the interface exposed by the debugger towards the debugger agent */
 
2290
+       interface IEventHandler
 
2291
+       {
 
2292
+               void VMStart (int req_id, long thread_id, string vm_uri);
 
2293
+
 
2294
+               void VMDeath (int req_id, long thread_id, string vm_uri);
 
2295
+
 
2296
+               void VMDisconnect (int req_id, long thread_id, string vm_uri);
 
2297
+
 
2298
+               void ThreadStart (int req_id, long thread_id, long id);
 
2299
+
 
2300
+               void ThreadDeath (int req_id, long thread_id, long id);
 
2301
+
 
2302
+               void AssemblyLoad (int req_id, long thread_id, long id);
 
2303
+
 
2304
+               void AssemblyUnload (int req_id, long thread_id, long id);
 
2305
+
 
2306
+               void TypeLoad (int req_id, long thread_id, long id);
 
2307
+
 
2308
+               void MethodEntry (int req_id, long thread_id, long id);
 
2309
+
 
2310
+               void MethodExit (int req_id, long thread_id, long id);
 
2311
+
 
2312
+               void Breakpoint (int req_id, long thread_id, long method_id, long loc);
 
2313
+
 
2314
+               void Step (int req_id, long thread_id, long method_id, long loc);
 
2315
+
 
2316
+               void Exception (int req_id, long thread_id, long exc_id, long loc);
 
2317
+
 
2318
+               void AppDomainCreate (int req_id, long thread_id, long id);
 
2319
+
 
2320
+               void AppDomainUnload (int req_id, long thread_id, long id);
 
2321
+       }
 
2322
+}
 
2323
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeDataMirror.cs
 
2324
===================================================================
 
2325
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
2326
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeDataMirror.cs        2010-06-16 12:45:23.061079066 +0100
 
2327
@@ -0,0 +1,143 @@
 
2328
+using System;
 
2329
+using System.Collections.Generic;
 
2330
+using System.Runtime.CompilerServices;
 
2331
+using System.Runtime.InteropServices;
 
2332
+using System.Reflection;
 
2333
+using System.Text;
 
2334
+using Mono.Cecil.Metadata;
 
2335
+
 
2336
+namespace Mono.Debugger.Soft {
 
2337
+
 
2338
+       public sealed class CustomAttributeDataMirror {
 
2339
+               MethodMirror ctorInfo;
 
2340
+               IList<CustomAttributeTypedArgumentMirror> ctorArgs;
 
2341
+               IList<CustomAttributeNamedArgumentMirror> namedArgs;
 
2342
+
 
2343
+               internal CustomAttributeDataMirror (MethodMirror ctorInfo, object [] ctorArgs, object [] namedArgs)
 
2344
+               {
 
2345
+                       this.ctorInfo = ctorInfo;
 
2346
+                       
 
2347
+                       this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgumentMirror> 
 
2348
+                               (ctorArgs != null ? UnboxValues<CustomAttributeTypedArgumentMirror> (ctorArgs) : new CustomAttributeTypedArgumentMirror [0]);
 
2349
+                       
 
2350
+                       this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgumentMirror> 
 
2351
+                               (namedArgs != null ? UnboxValues<CustomAttributeNamedArgumentMirror> (namedArgs) : new CustomAttributeNamedArgumentMirror [0]);
 
2352
+               }
 
2353
+
 
2354
+               [ComVisible (true)]
 
2355
+               public MethodMirror Constructor {
 
2356
+                       get {
 
2357
+                               return ctorInfo;
 
2358
+                       }
 
2359
+               }
 
2360
+
 
2361
+               [ComVisible (true)]
 
2362
+               public IList<CustomAttributeTypedArgumentMirror> ConstructorArguments {
 
2363
+                       get {
 
2364
+                               return ctorArgs;
 
2365
+                       }
 
2366
+               }
 
2367
+
 
2368
+               public IList<CustomAttributeNamedArgumentMirror> NamedArguments {
 
2369
+                       get {
 
2370
+                               return namedArgs;
 
2371
+                       }
 
2372
+               }
 
2373
+
 
2374
+               public override string ToString ()
 
2375
+               {
 
2376
+                       StringBuilder sb = new StringBuilder ();
 
2377
+
 
2378
+                       sb.Append ("[" + ctorInfo.DeclaringType.FullName + "(");
 
2379
+                       if (ctorArgs != null) {
 
2380
+                               for (int i = 0; i < ctorArgs.Count; i++) {
 
2381
+                                       sb.Append (ctorArgs [i].ToString ());
 
2382
+                                       if (i + 1 < ctorArgs.Count)
 
2383
+                                               sb.Append (", ");
 
2384
+                               }
 
2385
+                       }
 
2386
+
 
2387
+                       if (namedArgs != null) {
 
2388
+                               if (namedArgs.Count > 0)
 
2389
+                                       sb.Append (", ");
 
2390
+                       
 
2391
+                               for (int j = 0; j < namedArgs.Count; j++) {
 
2392
+                                       sb.Append (namedArgs [j].ToString ());
 
2393
+                                       if (j + 1 < namedArgs.Count)
 
2394
+                                               sb.Append (", ");
 
2395
+                               }
 
2396
+                       }
 
2397
+                       sb.AppendFormat (")]");
 
2398
+
 
2399
+                       return sb.ToString ();
 
2400
+               }
 
2401
+
 
2402
+               static T [] UnboxValues<T> (object [] values)
 
2403
+               {
 
2404
+                       T [] retval = new T [values.Length];
 
2405
+                       for (int i = 0; i < values.Length; i++)
 
2406
+                               retval [i] = (T) values [i];
 
2407
+
 
2408
+                       return retval;
 
2409
+               }
 
2410
+
 
2411
+               /* 
 
2412
+                * Construct a normal object from the value, so accessing the cattr doesn't 
 
2413
+                * require remoting calls.
 
2414
+                */
 
2415
+               static CustomAttributeTypedArgumentMirror CreateArg (VirtualMachine vm, ValueImpl vi) {
 
2416
+                       object val;
 
2417
+
 
2418
+                       /* Instead of receiving a mirror of the Type object, we receive the id of the type */
 
2419
+                       if (vi.Type == (ElementType)ValueTypeId.VALUE_TYPE_ID_TYPE)
 
2420
+                               val = vm.GetType (vi.Id);
 
2421
+                       else {
 
2422
+                               Value v = vm.DecodeValue (vi);
 
2423
+                               if (v is PrimitiveValue)
 
2424
+                                       val = (v as PrimitiveValue).Value;
 
2425
+                               else if (v is StringMirror)
 
2426
+                                       val = (v as StringMirror).Value;
 
2427
+                               else
 
2428
+                                       // FIXME:
 
2429
+                                       val = v;
 
2430
+                       }
 
2431
+                       return new CustomAttributeTypedArgumentMirror (null, val);
 
2432
+               }
 
2433
+
 
2434
+               internal static CustomAttributeDataMirror[] Create (VirtualMachine vm, CattrInfo[] info) {
 
2435
+                       var res = new CustomAttributeDataMirror [info.Length];
 
2436
+                       for (int i = 0; i < info.Length; ++i) {
 
2437
+                               CattrInfo attr = info [i];
 
2438
+                               MethodMirror ctor = vm.GetMethod (attr.ctor_id);
 
2439
+                               var ctor_args = new object [attr.ctor_args.Length];
 
2440
+                               for (int j = 0; j < ctor_args.Length; ++j)
 
2441
+                                       ctor_args [j] = CreateArg (vm, attr.ctor_args [j]);
 
2442
+                               var named_args = new object [attr.named_args.Length];
 
2443
+                               for (int j = 0; j < named_args.Length; ++j) {
 
2444
+                                       CattrNamedArgInfo arg = attr.named_args [j];
 
2445
+                                       CustomAttributeTypedArgumentMirror val;
 
2446
+
 
2447
+                                       val = CreateArg (vm, arg.value);
 
2448
+
 
2449
+                                       if (arg.is_property) {
 
2450
+                                               foreach (var prop in ctor.DeclaringType.GetProperties ()) {
 
2451
+                                                       if (prop.Id == arg.id)
 
2452
+                                                               named_args [j] = new CustomAttributeNamedArgumentMirror (prop, null, val);
 
2453
+                                               }
 
2454
+                                       } else {
 
2455
+                                               foreach (var field in ctor.DeclaringType.GetFields ()) {
 
2456
+                                                       if (field.Id == arg.id)
 
2457
+                                                               named_args [j] = new CustomAttributeNamedArgumentMirror (null, field, val);
 
2458
+                                               }
 
2459
+                                       }
 
2460
+                                       if (named_args [j] == null)
 
2461
+                                               throw new NotImplementedException ();
 
2462
+                               }
 
2463
+                               res [i] = new CustomAttributeDataMirror (vm.GetMethod (attr.ctor_id), ctor_args, named_args);
 
2464
+                       }
 
2465
+
 
2466
+                       return res;
 
2467
+               }
 
2468
+       }
 
2469
+
 
2470
+}
 
2471
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeNamedArgumentMirror.cs
 
2472
===================================================================
 
2473
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
2474
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeNamedArgumentMirror.cs       2010-06-16 12:45:23.061079066 +0100
 
2475
@@ -0,0 +1,37 @@
 
2476
+using System;
 
2477
+using System.Runtime.InteropServices;
 
2478
+using System.Reflection;
 
2479
+
 
2480
+namespace Mono.Debugger.Soft {
 
2481
+
 
2482
+       public struct CustomAttributeNamedArgumentMirror {
 
2483
+               CustomAttributeTypedArgumentMirror arg;
 
2484
+               PropertyInfoMirror prop;
 
2485
+               FieldInfoMirror field;
 
2486
+
 
2487
+               internal CustomAttributeNamedArgumentMirror (PropertyInfoMirror prop, FieldInfoMirror field, CustomAttributeTypedArgumentMirror arg)
 
2488
+               {
 
2489
+                       this.arg = arg;
 
2490
+                       this.prop = prop;
 
2491
+                       this.field = field;
 
2492
+               }
 
2493
+
 
2494
+               public PropertyInfoMirror Property {
 
2495
+                       get {
 
2496
+                               return prop;
 
2497
+                       }
 
2498
+               }
 
2499
+
 
2500
+               public FieldInfoMirror Field {
 
2501
+                       get {
 
2502
+                               return field;
 
2503
+                       }
 
2504
+               }
 
2505
+
 
2506
+               public CustomAttributeTypedArgumentMirror TypedValue {
 
2507
+                       get {
 
2508
+                               return arg;
 
2509
+                       }
 
2510
+               }
 
2511
+       }
 
2512
+}
 
2513
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeTypedArgumentMirror.cs
 
2514
===================================================================
 
2515
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
2516
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/CustomAttributeTypedArgumentMirror.cs       2010-06-16 12:45:23.061079066 +0100
 
2517
@@ -0,0 +1,59 @@
 
2518
+using System;
 
2519
+using System.Runtime.InteropServices;
 
2520
+using System.Collections.ObjectModel;
 
2521
+using System.Reflection;
 
2522
+
 
2523
+namespace Mono.Debugger.Soft {
 
2524
+
 
2525
+       public struct CustomAttributeTypedArgumentMirror {
 
2526
+               Type type;
 
2527
+               object value;
 
2528
+
 
2529
+               internal CustomAttributeTypedArgumentMirror (Type type, object value)
 
2530
+               {
 
2531
+                       this.type = type;
 
2532
+                       this.value = value;
 
2533
+
 
2534
+                       if (value != null)
 
2535
+                               this.type = value.GetType ();
 
2536
+                       else
 
2537
+                               this.type = typeof (void);
 
2538
+
 
2539
+                       // MS seems to convert arrays into a ReadOnlyCollection
 
2540
+                       if (value is Array) {
 
2541
+                               Array a = (Array)value;
 
2542
+
 
2543
+                               Type etype = a.GetType ().GetElementType ();
 
2544
+                               CustomAttributeTypedArgumentMirror[] new_value = new CustomAttributeTypedArgumentMirror [a.GetLength (0)];
 
2545
+                               for (int i = 0; i < new_value.Length; ++i)
 
2546
+                                       new_value [i] = new CustomAttributeTypedArgumentMirror (etype, a.GetValue (i));
 
2547
+                               this.value = new ReadOnlyCollection <CustomAttributeTypedArgumentMirror> (new_value);
 
2548
+                       }
 
2549
+               }
 
2550
+
 
2551
+               public Type ArgumentType {
 
2552
+                       get {
 
2553
+                               return type;
 
2554
+                       }
 
2555
+               }
 
2556
+
 
2557
+               public object Value {
 
2558
+                       get {
 
2559
+                               return value;
 
2560
+                       }
 
2561
+               }
 
2562
+
 
2563
+               public override string ToString ()
 
2564
+               {
 
2565
+                       string val = value != null ? value.ToString () : String.Empty;
 
2566
+                       if (ArgumentType == typeof (string))
 
2567
+                               return "\"" + val + "\"";
 
2568
+                       if (ArgumentType == typeof (Type)) 
 
2569
+                               return "typeof (" + val + ")";
 
2570
+                       if (ArgumentType.IsEnum)
 
2571
+                               return "(" + ArgumentType.Name + ")" + val;
 
2572
+
 
2573
+                       return val;
 
2574
+               }
 
2575
+       }
 
2576
+}
 
2577
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/DataConverter.cs
 
2578
===================================================================
 
2579
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
2580
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/DataConverter.cs    2010-06-16 12:45:23.061079066 +0100
 
2581
@@ -0,0 +1,1836 @@
 
2582
+//
 
2583
+// Authors:
 
2584
+//   Miguel de Icaza (miguel@novell.com)
 
2585
+//
 
2586
+// See the following url for documentation:
 
2587
+//     http://www.mono-project.com/Mono_DataConvert
 
2588
+//
 
2589
+// Compilation Options:
 
2590
+//     MONO_DATACONVERTER_PUBLIC:
 
2591
+//         Makes the class public instead of the default internal.
 
2592
+//
 
2593
+//     MONO_DATACONVERTER_STATIC_METHODS:     
 
2594
+//         Exposes the public static methods.
 
2595
+//
 
2596
+// TODO:
 
2597
+//   Support for "DoubleWordsAreSwapped" for ARM devices
 
2598
+//
 
2599
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
 
2600
+//
 
2601
+// Permission is hereby granted, free of charge, to any person obtaining
 
2602
+// a copy of this software and associated documentation files (the
 
2603
+// "Software"), to deal in the Software without restriction, including
 
2604
+// without limitation the rights to use, copy, modify, merge, publish,
 
2605
+// distribute, sublicense, and/or sell copies of the Software, and to
 
2606
+// permit persons to whom the Software is furnished to do so, subject to
 
2607
+// the following conditions:
 
2608
+// 
 
2609
+// The above copyright notice and this permission notice shall be
 
2610
+// included in all copies or substantial portions of the Software.
 
2611
+// 
 
2612
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
2613
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
2614
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
2615
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
2616
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
2617
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
2618
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
2619
+//
 
2620
+using System;
 
2621
+using System.Collections;
 
2622
+using System.Text;
 
2623
+
 
2624
+#pragma warning disable 3021
 
2625
+
 
2626
+namespace Mono {
 
2627
+
 
2628
+#if MONO_DATACONVERTER_PUBLIC
 
2629
+       unsafe public abstract class DataConverter {
 
2630
+#else
 
2631
+       unsafe internal abstract class DataConverter {
 
2632
+
 
2633
+// Disables the warning: CLS compliance checking will not be performed on
 
2634
+//  `XXXX' because it is not visible from outside this assembly
 
2635
+#pragma warning disable  3019
 
2636
+#endif
 
2637
+               static DataConverter SwapConv = new SwapConverter ();
 
2638
+               static DataConverter CopyConv = new CopyConverter ();
 
2639
+
 
2640
+               public static readonly bool IsLittleEndian = BitConverter.IsLittleEndian;
 
2641
+                       
 
2642
+               public abstract double GetDouble (byte [] data, int index);
 
2643
+               public abstract float  GetFloat  (byte [] data, int index);
 
2644
+               public abstract long   GetInt64  (byte [] data, int index);
 
2645
+               public abstract int    GetInt32  (byte [] data, int index);
 
2646
+
 
2647
+               public abstract short  GetInt16  (byte [] data, int index);
 
2648
+
 
2649
+                [CLSCompliant (false)]
 
2650
+               public abstract uint   GetUInt32 (byte [] data, int index);
 
2651
+                [CLSCompliant (false)]
 
2652
+               public abstract ushort GetUInt16 (byte [] data, int index);
 
2653
+                [CLSCompliant (false)]
 
2654
+               public abstract ulong  GetUInt64 (byte [] data, int index);
 
2655
+               
 
2656
+               public abstract void PutBytes (byte [] dest, int destIdx, double value);
 
2657
+               public abstract void PutBytes (byte [] dest, int destIdx, float value);
 
2658
+               public abstract void PutBytes (byte [] dest, int destIdx, int value);
 
2659
+               public abstract void PutBytes (byte [] dest, int destIdx, long value);
 
2660
+               public abstract void PutBytes (byte [] dest, int destIdx, short value);
 
2661
+
 
2662
+                [CLSCompliant (false)]
 
2663
+               public abstract void PutBytes (byte [] dest, int destIdx, ushort value);
 
2664
+                [CLSCompliant (false)]
 
2665
+               public abstract void PutBytes (byte [] dest, int destIdx, uint value);
 
2666
+                [CLSCompliant (false)]
 
2667
+               public abstract void PutBytes (byte [] dest, int destIdx, ulong value);
 
2668
+
 
2669
+               public byte[] GetBytes (double value)
 
2670
+               {
 
2671
+                       byte [] ret = new byte [8];
 
2672
+                       PutBytes (ret, 0, value);
 
2673
+                       return ret;
 
2674
+               }
 
2675
+               
 
2676
+               public byte[] GetBytes (float value)
 
2677
+               {
 
2678
+                       byte [] ret = new byte [4];
 
2679
+                       PutBytes (ret, 0, value);
 
2680
+                       return ret;
 
2681
+               }
 
2682
+               
 
2683
+               public byte[] GetBytes (int value)
 
2684
+               {
 
2685
+                       byte [] ret = new byte [4];
 
2686
+                       PutBytes (ret, 0, value);
 
2687
+                       return ret;
 
2688
+               }
 
2689
+               
 
2690
+               public byte[] GetBytes (long value)
 
2691
+               {
 
2692
+                       byte [] ret = new byte [8];
 
2693
+                       PutBytes (ret, 0, value);
 
2694
+                       return ret;
 
2695
+               }
 
2696
+               
 
2697
+               public byte[] GetBytes (short value)
 
2698
+               {
 
2699
+                       byte [] ret = new byte [2];
 
2700
+                       PutBytes (ret, 0, value);
 
2701
+                       return ret;
 
2702
+               }
 
2703
+
 
2704
+                [CLSCompliant (false)]
 
2705
+               public byte[] GetBytes (ushort value)
 
2706
+               {
 
2707
+                       byte [] ret = new byte [2];
 
2708
+                       PutBytes (ret, 0, value);
 
2709
+                       return ret;
 
2710
+               }
 
2711
+               
 
2712
+                [CLSCompliant (false)]
 
2713
+               public byte[] GetBytes (uint value)
 
2714
+               {
 
2715
+                       byte [] ret = new byte [4];
 
2716
+                       PutBytes (ret, 0, value);
 
2717
+                       return ret;
 
2718
+               }
 
2719
+               
 
2720
+                [CLSCompliant (false)]
 
2721
+               public byte[] GetBytes (ulong value)
 
2722
+               {
 
2723
+                       byte [] ret = new byte [8];
 
2724
+                       PutBytes (ret, 0, value);
 
2725
+                       return ret;
 
2726
+               }
 
2727
+               
 
2728
+               static public DataConverter LittleEndian {
 
2729
+                       get {
 
2730
+                               return BitConverter.IsLittleEndian ? CopyConv : SwapConv;
 
2731
+                       }
 
2732
+               }
 
2733
+
 
2734
+               static public DataConverter BigEndian {
 
2735
+                       get {
 
2736
+                               return BitConverter.IsLittleEndian ? SwapConv : CopyConv;
 
2737
+                       }
 
2738
+               }
 
2739
+
 
2740
+               static public DataConverter Native {
 
2741
+                       get {
 
2742
+                               return CopyConv;
 
2743
+                       }
 
2744
+               }
 
2745
+
 
2746
+               static int Align (int current, int align)
 
2747
+               {
 
2748
+                       return ((current + align - 1) / align) * align;
 
2749
+               }
 
2750
+                       
 
2751
+               class PackContext {
 
2752
+                       // Buffer
 
2753
+                       public byte [] buffer;
 
2754
+                       int next;
 
2755
+
 
2756
+                       public string description;
 
2757
+                       public int i; // position in the description
 
2758
+                       public DataConverter conv;
 
2759
+                       public int repeat;
 
2760
+                       
 
2761
+                       //
 
2762
+                       // if align == -1, auto align to the size of the byte array
 
2763
+                       // if align == 0, do not do alignment
 
2764
+                       // Any other values aligns to that particular size
 
2765
+                       //
 
2766
+                       public int align;
 
2767
+
 
2768
+                       public void Add (byte [] group)
 
2769
+                       {
 
2770
+                               //Console.WriteLine ("Adding {0} bytes to {1} (next={2}", group.Length,
 
2771
+                               // buffer == null ? "null" : buffer.Length.ToString (), next);
 
2772
+                               
 
2773
+                               if (buffer == null){
 
2774
+                                       buffer = group;
 
2775
+                                       next = group.Length;
 
2776
+                                       return;
 
2777
+                               }
 
2778
+                               if (align != 0){
 
2779
+                                       if (align == -1)
 
2780
+                                               next = Align (next, group.Length);
 
2781
+                                       else
 
2782
+                                               next = Align (next, align);
 
2783
+                                       align = 0;
 
2784
+                               }
 
2785
+
 
2786
+                               if (next + group.Length > buffer.Length){
 
2787
+                                       byte [] nb = new byte [System.Math.Max (next, 16) * 2 + group.Length];
 
2788
+                                       Array.Copy (buffer, nb, buffer.Length);
 
2789
+                                       Array.Copy (group, 0, nb, next, group.Length);
 
2790
+                                       next = next + group.Length;
 
2791
+                                       buffer = nb;
 
2792
+                               } else {
 
2793
+                                       Array.Copy (group, 0, buffer, next, group.Length);
 
2794
+                                       next += group.Length;
 
2795
+                               }
 
2796
+                       }
 
2797
+
 
2798
+                       public byte [] Get ()
 
2799
+                       {
 
2800
+                               if (buffer == null)
 
2801
+                                       return new byte [0];
 
2802
+                               
 
2803
+                               if (buffer.Length != next){
 
2804
+                                       byte [] b = new byte [next];
 
2805
+                                       Array.Copy (buffer, b, next);
 
2806
+                                       return b;
 
2807
+                               }
 
2808
+                               return buffer;
 
2809
+                       }
 
2810
+               }
 
2811
+
 
2812
+               //
 
2813
+               // Format includes:
 
2814
+               // Control:
 
2815
+               //   ^    Switch to big endian encoding
 
2816
+               //   _    Switch to little endian encoding
 
2817
+               //   %    Switch to host (native) encoding
 
2818
+               //   !    aligns the next data type to its natural boundary (for strings this is 4).
 
2819
+               //
 
2820
+               // Types:
 
2821
+               //   s    Int16
 
2822
+               //   S    UInt16
 
2823
+               //   i    Int32
 
2824
+               //   I    UInt32
 
2825
+               //   l    Int64
 
2826
+               //   L    UInt64
 
2827
+               //   f    float
 
2828
+               //   d    double
 
2829
+               //   b    byte
 
2830
+                //   c    1-byte signed character
 
2831
+                //   C    1-byte unsigned character
 
2832
+               //   z8   string encoded as UTF8 with 1-byte null terminator
 
2833
+               //   z6   string encoded as UTF16 with 2-byte null terminator
 
2834
+               //   z7   string encoded as UTF7 with 1-byte null terminator
 
2835
+               //   zb   string encoded as BigEndianUnicode with 2-byte null terminator
 
2836
+               //   z3   string encoded as UTF32 with 4-byte null terminator
 
2837
+               //   z4   string encoded as UTF32 big endian with 4-byte null terminator
 
2838
+               //   $8   string encoded as UTF8
 
2839
+               //   $6   string encoded as UTF16
 
2840
+               //   $7   string encoded as UTF7
 
2841
+               //   $b   string encoded as BigEndianUnicode
 
2842
+               //   $3   string encoded as UTF32
 
2843
+               //   $4   string encoded as UTF-32 big endian encoding
 
2844
+               //   x    null byte
 
2845
+               //
 
2846
+               // Repeats, these are prefixes:
 
2847
+               //   N    a number between 1 and 9, indicates a repeat count (process N items
 
2848
+               //        with the following datatype
 
2849
+               //   [N]  For numbers larger than 9, use brackets, for example [20]
 
2850
+               //   *    Repeat the next data type until the arguments are exhausted
 
2851
+               //
 
2852
+               static public byte [] Pack (string description, params object [] args)
 
2853
+               {
 
2854
+                       int argn = 0;
 
2855
+                       PackContext b = new PackContext ();
 
2856
+                       b.conv = CopyConv;
 
2857
+                       b.description = description;
 
2858
+
 
2859
+                       for (b.i = 0; b.i < description.Length; ){
 
2860
+                               object oarg;
 
2861
+
 
2862
+                               if (argn < args.Length)
 
2863
+                                       oarg = args [argn];
 
2864
+                               else {
 
2865
+                                       if (b.repeat != 0)
 
2866
+                                               break;
 
2867
+                                       
 
2868
+                                       oarg = null;
 
2869
+                               }
 
2870
+
 
2871
+                               int save = b.i;
 
2872
+                               
 
2873
+                               if (PackOne (b, oarg)){
 
2874
+                                       argn++;
 
2875
+                                       if (b.repeat > 0){
 
2876
+                                               if (--b.repeat > 0)
 
2877
+                                                       b.i = save;
 
2878
+                                               else
 
2879
+                                                       b.i++;
 
2880
+                                       } else
 
2881
+                                               b.i++;
 
2882
+                               } else
 
2883
+                                       b.i++;
 
2884
+                       }
 
2885
+                       return b.Get ();
 
2886
+               }
 
2887
+
 
2888
+               static public byte [] PackEnumerable (string description, IEnumerable args)
 
2889
+               {
 
2890
+                       PackContext b = new PackContext ();
 
2891
+                       b.conv = CopyConv;
 
2892
+                       b.description = description;
 
2893
+                       
 
2894
+                       IEnumerator enumerator = args.GetEnumerator ();
 
2895
+                       bool ok = enumerator.MoveNext ();
 
2896
+
 
2897
+                       for (b.i = 0; b.i < description.Length; ){
 
2898
+                               object oarg;
 
2899
+
 
2900
+                               if (ok)
 
2901
+                                       oarg = enumerator.Current;
 
2902
+                               else {
 
2903
+                                       if (b.repeat != 0)
 
2904
+                                               break;
 
2905
+                                       oarg = null;
 
2906
+                               }
 
2907
+                                               
 
2908
+                               int save = b.i;
 
2909
+                               
 
2910
+                               if (PackOne (b, oarg)){
 
2911
+                                       ok = enumerator.MoveNext ();
 
2912
+                                       if (b.repeat > 0){
 
2913
+                                               if (--b.repeat > 0)
 
2914
+                                                       b.i = save;
 
2915
+                                               else
 
2916
+                                                       b.i++;
 
2917
+                                       } else
 
2918
+                                               b.i++;
 
2919
+                               } else
 
2920
+                                       b.i++;
 
2921
+                       }
 
2922
+                       return b.Get ();
 
2923
+               }
 
2924
+                       
 
2925
+               //
 
2926
+               // Packs one datum `oarg' into the buffer `b', using the string format
 
2927
+               // in `description' at position `i'
 
2928
+               //
 
2929
+               // Returns: true if we must pick the next object from the list
 
2930
+               //
 
2931
+               static bool PackOne (PackContext b, object oarg)
 
2932
+               {
 
2933
+                       int n;
 
2934
+                       
 
2935
+                       switch (b.description [b.i]){
 
2936
+                       case '^':
 
2937
+                               b.conv = BigEndian;
 
2938
+                               return false;
 
2939
+                       case '_':
 
2940
+                               b.conv = LittleEndian;
 
2941
+                               return false;
 
2942
+                       case '%':
 
2943
+                               b.conv = Native;
 
2944
+                               return false;
 
2945
+
 
2946
+                       case '!':
 
2947
+                               b.align = -1;
 
2948
+                               return false;
 
2949
+                               
 
2950
+                       case 'x':
 
2951
+                               b.Add (new byte [] { 0 });
 
2952
+                               return false;
 
2953
+                               
 
2954
+                               // Type Conversions
 
2955
+                       case 'i':
 
2956
+                               b.Add (b.conv.GetBytes (Convert.ToInt32 (oarg)));
 
2957
+                               break;
 
2958
+                               
 
2959
+                       case 'I':
 
2960
+                               b.Add (b.conv.GetBytes (Convert.ToUInt32 (oarg)));
 
2961
+                               break;
 
2962
+                               
 
2963
+                       case 's':
 
2964
+                               b.Add (b.conv.GetBytes (Convert.ToInt16 (oarg)));
 
2965
+                               break;
 
2966
+                               
 
2967
+                       case 'S':
 
2968
+                               b.Add (b.conv.GetBytes (Convert.ToUInt16 (oarg)));
 
2969
+                               break;
 
2970
+                               
 
2971
+                       case 'l':
 
2972
+                               b.Add (b.conv.GetBytes (Convert.ToInt64 (oarg)));
 
2973
+                               break;
 
2974
+                               
 
2975
+                       case 'L':
 
2976
+                               b.Add (b.conv.GetBytes (Convert.ToUInt64 (oarg)));
 
2977
+                               break;
 
2978
+                               
 
2979
+                       case 'f':
 
2980
+                               b.Add (b.conv.GetBytes (Convert.ToSingle (oarg)));
 
2981
+                               break;
 
2982
+                               
 
2983
+                       case 'd':
 
2984
+                               b.Add (b.conv.GetBytes (Convert.ToDouble (oarg)));
 
2985
+                               break;
 
2986
+                               
 
2987
+                       case 'b':
 
2988
+                               b.Add (new byte [] { Convert.ToByte (oarg) });
 
2989
+                               break;
 
2990
+
 
2991
+                       case 'c':
 
2992
+                               b.Add (new byte [] { (byte) (Convert.ToSByte (oarg)) });
 
2993
+                               break;
 
2994
+
 
2995
+                       case 'C':
 
2996
+                               b.Add (new byte [] { Convert.ToByte (oarg) });
 
2997
+                               break;
 
2998
+
 
2999
+                               // Repeat acount;
 
3000
+                       case '1': case '2': case '3': case '4': case '5':
 
3001
+                       case '6': case '7': case '8': case '9':
 
3002
+                               b.repeat = ((short) b.description [b.i]) - ((short) '0');
 
3003
+                               return false;
 
3004
+
 
3005
+                       case '*':
 
3006
+                               b.repeat = Int32.MaxValue;
 
3007
+                               return false;
 
3008
+                               
 
3009
+                       case '[':
 
3010
+                               int count = -1, j;
 
3011
+                               
 
3012
+                               for (j = b.i+1; j < b.description.Length; j++){
 
3013
+                                       if (b.description [j] == ']')
 
3014
+                                               break;
 
3015
+                                       n = ((short) b.description [j]) - ((short) '0');
 
3016
+                                       if (n >= 0 && n <= 9){
 
3017
+                                               if (count == -1)
 
3018
+                                                       count = n;
 
3019
+                                               else
 
3020
+                                                       count = count * 10 + n;
 
3021
+                                       }
 
3022
+                               }
 
3023
+                               if (count == -1)
 
3024
+                                       throw new ArgumentException ("invalid size specification");
 
3025
+                               b.i = j;
 
3026
+                               b.repeat = count;
 
3027
+                               return false;
 
3028
+                               
 
3029
+                       case '$': case 'z':
 
3030
+                               bool add_null = b.description [b.i] == 'z';
 
3031
+                               b.i++;
 
3032
+                               if (b.i >= b.description.Length)
 
3033
+                                       throw new ArgumentException ("$ description needs a type specified", "description");
 
3034
+                               char d = b.description [b.i];
 
3035
+                               Encoding e;
 
3036
+                               
 
3037
+                               switch (d){
 
3038
+                               case '8':
 
3039
+                                       e = Encoding.UTF8;
 
3040
+                                       n = 1;
 
3041
+                                       break;
 
3042
+                               case '6':
 
3043
+                                       e = Encoding.Unicode;
 
3044
+                                       n = 2;
 
3045
+                                       break;
 
3046
+                               case '7':
 
3047
+                                       e = Encoding.UTF7;
 
3048
+                                       n = 1;
 
3049
+                                       break;
 
3050
+                               case 'b':
 
3051
+                                       e = Encoding.BigEndianUnicode;
 
3052
+                                       n = 2;
 
3053
+                                       break;
 
3054
+                               case '3':
 
3055
+                                       e = Encoding.GetEncoding (12000);
 
3056
+                                       n = 4;
 
3057
+                                       break;
 
3058
+                               case '4':
 
3059
+                                       e = Encoding.GetEncoding (12001);
 
3060
+                                       n = 4;
 
3061
+                                       break;
 
3062
+                                       
 
3063
+                               default:
 
3064
+                                       throw new ArgumentException ("Invalid format for $ specifier", "description");
 
3065
+                               }
 
3066
+                               if (b.align == -1)
 
3067
+                                       b.align = 4;
 
3068
+                               b.Add (e.GetBytes (Convert.ToString (oarg)));
 
3069
+                               if (add_null)
 
3070
+                                       b.Add (new byte [n]);
 
3071
+                               break;
 
3072
+                       default:
 
3073
+                               throw new ArgumentException (String.Format ("invalid format specified `{0}'",
 
3074
+                                                                           b.description [b.i]));
 
3075
+                       }
 
3076
+                       return true;
 
3077
+               }
 
3078
+
 
3079
+               static bool Prepare (byte [] buffer, ref int idx, int size, ref bool align)
 
3080
+               {
 
3081
+                       if (align){
 
3082
+                               idx = Align (idx, size);
 
3083
+                               align = false;
 
3084
+                       }
 
3085
+                       if (idx + size > buffer.Length){
 
3086
+                               idx = buffer.Length;
 
3087
+                               return false;
 
3088
+                       }
 
3089
+                       return true;
 
3090
+               }
 
3091
+               
 
3092
+               static public IList Unpack (string description, byte [] buffer, int startIndex)
 
3093
+               {
 
3094
+                       DataConverter conv = CopyConv;
 
3095
+                       ArrayList result = new ArrayList ();
 
3096
+                       int idx = startIndex;
 
3097
+                       bool align = false;
 
3098
+                       int repeat = 0, n;
 
3099
+                       
 
3100
+                       for (int i = 0; i < description.Length && idx < buffer.Length; ){
 
3101
+                               int save = i;
 
3102
+                               
 
3103
+                               switch (description [i]){
 
3104
+                               case '^':
 
3105
+                                       conv = BigEndian;
 
3106
+                                       break;
 
3107
+                               case '_':
 
3108
+                                       conv = LittleEndian;
 
3109
+                                       break;
 
3110
+                               case '%':
 
3111
+                                       conv = Native;
 
3112
+                                       break;
 
3113
+                               case 'x':
 
3114
+                                       idx++;
 
3115
+                                       break;
 
3116
+
 
3117
+                               case '!':
 
3118
+                                       align = true;
 
3119
+                                       break;
 
3120
+
 
3121
+                                       // Type Conversions
 
3122
+                               case 'i':
 
3123
+                                       if (Prepare (buffer, ref idx, 4, ref align)){
 
3124
+                                               result.Add (conv.GetInt32 (buffer, idx));
 
3125
+                                               idx += 4;
 
3126
+                                       } 
 
3127
+                                       break;
 
3128
+                               
 
3129
+                               case 'I':
 
3130
+                                       if (Prepare (buffer, ref idx, 4, ref align)){
 
3131
+                                               result.Add (conv.GetUInt32 (buffer, idx));
 
3132
+                                               idx += 4;
 
3133
+                                       }
 
3134
+                                       break;
 
3135
+                               
 
3136
+                               case 's':
 
3137
+                                       if (Prepare (buffer, ref idx, 2, ref align)){
 
3138
+                                               result.Add (conv.GetInt16 (buffer, idx));
 
3139
+                                               idx += 2;
 
3140
+                                       }
 
3141
+                                       break;
 
3142
+                               
 
3143
+                               case 'S':
 
3144
+                                       if (Prepare (buffer, ref idx, 2, ref align)){
 
3145
+                                               result.Add (conv.GetUInt16 (buffer, idx));
 
3146
+                                               idx += 2;
 
3147
+                                       }
 
3148
+                                       break;
 
3149
+                               
 
3150
+                               case 'l':
 
3151
+                                       if (Prepare (buffer, ref idx, 8, ref align)){
 
3152
+                                               result.Add (conv.GetInt64 (buffer, idx));
 
3153
+                                               idx += 8;
 
3154
+                                       }
 
3155
+                                       break;
 
3156
+                               
 
3157
+                               case 'L':
 
3158
+                                       if (Prepare (buffer, ref idx, 8, ref align)){
 
3159
+                                               result.Add (conv.GetUInt64 (buffer, idx));
 
3160
+                                               idx += 8;
 
3161
+                                       }
 
3162
+                                       break;
 
3163
+                               
 
3164
+                               case 'f':
 
3165
+                                       if (Prepare (buffer, ref idx, 4, ref align)){
 
3166
+                                               result.Add (conv.GetDouble (buffer, idx));
 
3167
+                                               idx += 4;
 
3168
+                                       }
 
3169
+                                       break;
 
3170
+                               
 
3171
+                               case 'd':
 
3172
+                                       if (Prepare (buffer, ref idx, 8, ref align)){
 
3173
+                                               result.Add (conv.GetDouble (buffer, idx));
 
3174
+                                               idx += 8;
 
3175
+                                       }
 
3176
+                                       break;
 
3177
+                               
 
3178
+                               case 'b':
 
3179
+                                       if (Prepare (buffer, ref idx, 1, ref align)){
 
3180
+                                               result.Add (buffer [idx]);
 
3181
+                                               idx++;
 
3182
+                                       }
 
3183
+                                       break;
 
3184
+
 
3185
+                               case 'c': case 'C':
 
3186
+                                       if (Prepare (buffer, ref idx, 1, ref align)){
 
3187
+                                               char c;
 
3188
+                                               
 
3189
+                                               if (description [i] == 'c')
 
3190
+                                                       c = ((char) ((sbyte)buffer [idx]));
 
3191
+                                               else
 
3192
+                                                       c = ((char) ((byte)buffer [idx]));
 
3193
+                                               
 
3194
+                                               result.Add (c);
 
3195
+                                               idx++;
 
3196
+                                       }
 
3197
+                                       break;
 
3198
+                                       
 
3199
+                                       // Repeat acount;
 
3200
+                               case '1': case '2': case '3': case '4': case '5':
 
3201
+                               case '6': case '7': case '8': case '9':
 
3202
+                                       repeat = ((short) description [i]) - ((short) '0');
 
3203
+                                       save = i + 1;
 
3204
+                                       break;
 
3205
+
 
3206
+                               case '*':
 
3207
+                                       repeat = Int32.MaxValue;
 
3208
+                                       break;
 
3209
+                               
 
3210
+                               case '[':
 
3211
+                                       int count = -1, j;
 
3212
+                               
 
3213
+                                       for (j = i+1; j < description.Length; j++){
 
3214
+                                               if (description [j] == ']')
 
3215
+                                                       break;
 
3216
+                                               n = ((short) description [j]) - ((short) '0');
 
3217
+                                               if (n >= 0 && n <= 9){
 
3218
+                                                       if (count == -1)
 
3219
+                                                               count = n;
 
3220
+                                                       else
 
3221
+                                                               count = count * 10 + n;
 
3222
+                                               }
 
3223
+                                       }
 
3224
+                                       if (count == -1)
 
3225
+                                               throw new ArgumentException ("invalid size specification");
 
3226
+                                       i = j;
 
3227
+                                       repeat = count;
 
3228
+                                       break;
 
3229
+                               
 
3230
+                               case '$': case 'z':
 
3231
+                                       // bool with_null = description [i] == 'z';
 
3232
+                                       i++;
 
3233
+                                       if (i >= description.Length)
 
3234
+                                               throw new ArgumentException ("$ description needs a type specified", "description");
 
3235
+                                       char d = description [i];
 
3236
+                                       Encoding e;
 
3237
+                                       if (align){
 
3238
+                                               idx = Align (idx, 4);
 
3239
+                                               align = false;
 
3240
+                                       }
 
3241
+                                       if (idx >= buffer.Length)
 
3242
+                                               break;
 
3243
+                               
 
3244
+                                       switch (d){
 
3245
+                                       case '8':
 
3246
+                                               e = Encoding.UTF8;
 
3247
+                                               n = 1;
 
3248
+                                               break;
 
3249
+                                       case '6':
 
3250
+                                               e = Encoding.Unicode;
 
3251
+                                               n = 2;
 
3252
+                                               break;
 
3253
+                                       case '7':
 
3254
+                                               e = Encoding.UTF7;
 
3255
+                                               n = 1;
 
3256
+                                               break;
 
3257
+                                       case 'b':
 
3258
+                                               e = Encoding.BigEndianUnicode;
 
3259
+                                               n = 2;
 
3260
+                                               break;
 
3261
+                                       case '3':
 
3262
+                                               e = Encoding.GetEncoding (12000);
 
3263
+                                               n = 4;
 
3264
+                                               break;
 
3265
+                                       case '4':
 
3266
+                                               e = Encoding.GetEncoding (12001);
 
3267
+                                               n = 4;
 
3268
+                                               break;
 
3269
+                                       
 
3270
+                                       default:
 
3271
+                                               throw new ArgumentException ("Invalid format for $ specifier", "description");
 
3272
+                                       }
 
3273
+                                       int k = idx;
 
3274
+                                       switch (n){
 
3275
+                                       case 1:
 
3276
+                                               for (; k < buffer.Length && buffer [k] != 0; k++)
 
3277
+                                                       ;
 
3278
+                                               result.Add (e.GetChars (buffer, idx, k-idx));
 
3279
+                                               if (k == buffer.Length)
 
3280
+                                                       idx = k;
 
3281
+                                               else
 
3282
+                                                       idx = k+1;
 
3283
+                                               break;
 
3284
+                                               
 
3285
+                                       case 2:
 
3286
+                                               for (; k < buffer.Length; k++){
 
3287
+                                                       if (k+1 == buffer.Length){
 
3288
+                                                               k++;
 
3289
+                                                               break;
 
3290
+                                                       }
 
3291
+                                                       if (buffer [k] == 0 && buffer [k+1] == 0)
 
3292
+                                                               break;
 
3293
+                                               }
 
3294
+                                               result.Add (e.GetChars (buffer, idx, k-idx));
 
3295
+                                               if (k == buffer.Length)
 
3296
+                                                       idx = k;
 
3297
+                                               else
 
3298
+                                                       idx = k+2;
 
3299
+                                               break;
 
3300
+                                               
 
3301
+                                       case 4:
 
3302
+                                               for (; k < buffer.Length; k++){
 
3303
+                                                       if (k+3 >= buffer.Length){
 
3304
+                                                               k = buffer.Length;
 
3305
+                                                               break;
 
3306
+                                                       }
 
3307
+                                                       if (buffer[k]==0 && buffer[k+1] == 0 && buffer[k+2] == 0 && buffer[k+3]== 0)
 
3308
+                                                               break;
 
3309
+                                               }
 
3310
+                                               result.Add (e.GetChars (buffer, idx, k-idx));
 
3311
+                                               if (k == buffer.Length)
 
3312
+                                                       idx = k;
 
3313
+                                               else
 
3314
+                                                       idx = k+4;
 
3315
+                                               break;
 
3316
+                                       }
 
3317
+                                       break;
 
3318
+                               default:
 
3319
+                                       throw new ArgumentException (String.Format ("invalid format specified `{0}'",
 
3320
+                                                                                   description [i]));
 
3321
+                               }
 
3322
+
 
3323
+                               if (repeat > 0){
 
3324
+                                       if (--repeat > 0)
 
3325
+                                               i = save;
 
3326
+                               } else
 
3327
+                                       i++;
 
3328
+                       }
 
3329
+                       return result;
 
3330
+               }
 
3331
+
 
3332
+               internal void Check (byte [] dest, int destIdx, int size)
 
3333
+               {
 
3334
+                       if (dest == null)
 
3335
+                               throw new ArgumentNullException ("dest");
 
3336
+                       if (destIdx < 0 || destIdx > dest.Length - size)
 
3337
+                               throw new ArgumentException ("destIdx");
 
3338
+               }
 
3339
+               
 
3340
+               class CopyConverter : DataConverter {
 
3341
+                       public override double GetDouble (byte [] data, int index)
 
3342
+                       {
 
3343
+                               if (data == null)
 
3344
+                                       throw new ArgumentNullException ("data");
 
3345
+                               if (data.Length - index < 8)
 
3346
+                                       throw new ArgumentException ("index");
 
3347
+                               if (index < 0)
 
3348
+                                       throw new ArgumentException ("index");
 
3349
+                               double ret;
 
3350
+                               byte *b = (byte *)&ret;
 
3351
+
 
3352
+                               for (int i = 0; i < 8; i++)
 
3353
+                                       b [i] = data [index+i];
 
3354
+
 
3355
+                               return ret;
 
3356
+                       }
 
3357
+
 
3358
+                       public override ulong GetUInt64 (byte [] data, int index)
 
3359
+                       {
 
3360
+                               if (data == null)
 
3361
+                                       throw new ArgumentNullException ("data");
 
3362
+                               if (data.Length - index < 8)
 
3363
+                                       throw new ArgumentException ("index");
 
3364
+                               if (index < 0)
 
3365
+                                       throw new ArgumentException ("index");
 
3366
+
 
3367
+                               ulong ret;
 
3368
+                               byte *b = (byte *)&ret;
 
3369
+
 
3370
+                               for (int i = 0; i < 8; i++)
 
3371
+                                       b [i] = data [index+i];
 
3372
+
 
3373
+                               return ret;
 
3374
+                       }
 
3375
+
 
3376
+                       public override long GetInt64 (byte [] data, int index)
 
3377
+                       {
 
3378
+                               if (data == null)
 
3379
+                                       throw new ArgumentNullException ("data");
 
3380
+                               if (data.Length - index < 8)
 
3381
+                                       throw new ArgumentException ("index");
 
3382
+                               if (index < 0)
 
3383
+                                       throw new ArgumentException ("index");
 
3384
+
 
3385
+                               long ret;
 
3386
+                               byte *b = (byte *)&ret;
 
3387
+
 
3388
+                               for (int i = 0; i < 8; i++)
 
3389
+                                       b [i] = data [index+i];
 
3390
+
 
3391
+                               return ret;
 
3392
+                       }
 
3393
+                       
 
3394
+                       public override float GetFloat  (byte [] data, int index)
 
3395
+                       {
 
3396
+                               if (data == null)
 
3397
+                                       throw new ArgumentNullException ("data");
 
3398
+                               if (data.Length - index < 4)
 
3399
+                                       throw new ArgumentException ("index");
 
3400
+                               if (index < 0)
 
3401
+                                       throw new ArgumentException ("index");
 
3402
+
 
3403
+                               float ret;
 
3404
+                               byte *b = (byte *)&ret;
 
3405
+
 
3406
+                               for (int i = 0; i < 4; i++)
 
3407
+                                       b [i] = data [index+i];
 
3408
+
 
3409
+                               return ret;
 
3410
+                       }
 
3411
+                       
 
3412
+                       public override int GetInt32  (byte [] data, int index)
 
3413
+                       {
 
3414
+                               if (data == null)
 
3415
+                                       throw new ArgumentNullException ("data");
 
3416
+                               if (data.Length - index < 4)
 
3417
+                                       throw new ArgumentException ("index");
 
3418
+                               if (index < 0)
 
3419
+                                       throw new ArgumentException ("index");
 
3420
+
 
3421
+                               int ret;
 
3422
+                               byte *b = (byte *)&ret;
 
3423
+
 
3424
+                               for (int i = 0; i < 4; i++)
 
3425
+                                       b [i] = data [index+i];
 
3426
+
 
3427
+                               return ret;
 
3428
+                       }
 
3429
+                       
 
3430
+                       public override uint GetUInt32 (byte [] data, int index)
 
3431
+                       {
 
3432
+                               if (data == null)
 
3433
+                                       throw new ArgumentNullException ("data");
 
3434
+                               if (data.Length - index < 4)
 
3435
+                                       throw new ArgumentException ("index");
 
3436
+                               if (index < 0)
 
3437
+                                       throw new ArgumentException ("index");
 
3438
+
 
3439
+                               uint ret;
 
3440
+                               byte *b = (byte *)&ret;
 
3441
+
 
3442
+                               for (int i = 0; i < 4; i++)
 
3443
+                                       b [i] = data [index+i];
 
3444
+
 
3445
+                               return ret;
 
3446
+                       }
 
3447
+                       
 
3448
+                       public override short GetInt16 (byte [] data, int index)
 
3449
+                       {
 
3450
+                               if (data == null)
 
3451
+                                       throw new ArgumentNullException ("data");
 
3452
+                               if (data.Length - index < 2)
 
3453
+                                       throw new ArgumentException ("index");
 
3454
+                               if (index < 0)
 
3455
+                                       throw new ArgumentException ("index");
 
3456
+
 
3457
+                               short ret;
 
3458
+                               byte *b = (byte *)&ret;
 
3459
+
 
3460
+                               for (int i = 0; i < 2; i++)
 
3461
+                                       b [i] = data [index+i];
 
3462
+
 
3463
+                               return ret;
 
3464
+                       }
 
3465
+                       
 
3466
+                       public override ushort GetUInt16 (byte [] data, int index)
 
3467
+                       {
 
3468
+                               if (data == null)
 
3469
+                                       throw new ArgumentNullException ("data");
 
3470
+                               if (data.Length - index < 2)
 
3471
+                                       throw new ArgumentException ("index");
 
3472
+                               if (index < 0)
 
3473
+                                       throw new ArgumentException ("index");
 
3474
+
 
3475
+                               ushort ret;
 
3476
+                               byte *b = (byte *)&ret;
 
3477
+
 
3478
+                               for (int i = 0; i < 2; i++)
 
3479
+                                       b [i] = data [index+i];
 
3480
+
 
3481
+                               return ret;
 
3482
+                       }
 
3483
+                       
 
3484
+                       public override void PutBytes (byte [] dest, int destIdx, double value)
 
3485
+                       {
 
3486
+                               Check (dest, destIdx, 8);
 
3487
+                               fixed (byte *target = &dest [destIdx]){
 
3488
+                                       long *source = (long *) &value;
 
3489
+
 
3490
+                                       *((long *)target) = *source;
 
3491
+                               }
 
3492
+                       }
 
3493
+                       
 
3494
+                       public override void PutBytes (byte [] dest, int destIdx, float value)
 
3495
+                       {
 
3496
+                               Check (dest, destIdx, 4);
 
3497
+                               fixed (byte *target = &dest [destIdx]){
 
3498
+                                       uint *source = (uint *) &value;
 
3499
+
 
3500
+                                       *((uint *)target) = *source;
 
3501
+                               }
 
3502
+                       }
 
3503
+                       
 
3504
+                       public override void PutBytes (byte [] dest, int destIdx, int value)
 
3505
+                       {
 
3506
+                               Check (dest, destIdx, 4);
 
3507
+                               fixed (byte *target = &dest [destIdx]){
 
3508
+                                       uint *source = (uint *) &value;
 
3509
+
 
3510
+                                       *((uint *)target) = *source;
 
3511
+                               }
 
3512
+                       }
 
3513
+
 
3514
+                       public override void PutBytes (byte [] dest, int destIdx, uint value)
 
3515
+                       {
 
3516
+                               Check (dest, destIdx, 4);
 
3517
+                               fixed (byte *target = &dest [destIdx]){
 
3518
+                                       uint *source = (uint *) &value;
 
3519
+
 
3520
+                                       *((uint *)target) = *source;
 
3521
+                               }
 
3522
+                       }
 
3523
+                       
 
3524
+                       public override void PutBytes (byte [] dest, int destIdx, long value)
 
3525
+                       {
 
3526
+                               Check (dest, destIdx, 8);
 
3527
+                               fixed (byte *target = &dest [destIdx]){
 
3528
+                                       long *source = (long *) &value;
 
3529
+
 
3530
+                                       *((long*)target) = *source;
 
3531
+                               }
 
3532
+                       }
 
3533
+                       
 
3534
+                       public override void PutBytes (byte [] dest, int destIdx, ulong value)
 
3535
+                       {
 
3536
+                               Check (dest, destIdx, 8);
 
3537
+                               fixed (byte *target = &dest [destIdx]){
 
3538
+                                       ulong *source = (ulong *) &value;
 
3539
+
 
3540
+                                       *((ulong *) target) = *source;
 
3541
+                               }
 
3542
+                       }
 
3543
+                       
 
3544
+                       public override void PutBytes (byte [] dest, int destIdx, short value)
 
3545
+                       {
 
3546
+                               Check (dest, destIdx, 2);
 
3547
+                               fixed (byte *target = &dest [destIdx]){
 
3548
+                                       ushort *source = (ushort *) &value;
 
3549
+
 
3550
+                                       *((ushort *)target) = *source;
 
3551
+                               }
 
3552
+                       }
 
3553
+                       
 
3554
+                       public override void PutBytes (byte [] dest, int destIdx, ushort value)
 
3555
+                       {
 
3556
+                               Check (dest, destIdx, 2);
 
3557
+                               fixed (byte *target = &dest [destIdx]){
 
3558
+                                       ushort *source = (ushort *) &value;
 
3559
+
 
3560
+                                       *((ushort *)target) = *source;
 
3561
+                               }
 
3562
+                       }
 
3563
+               }
 
3564
+
 
3565
+               class SwapConverter : DataConverter {
 
3566
+                       public override double GetDouble (byte [] data, int index)
 
3567
+                       {
 
3568
+                               if (data == null)
 
3569
+                                       throw new ArgumentNullException ("data");
 
3570
+                               if (data.Length - index < 8)
 
3571
+                                       throw new ArgumentException ("index");
 
3572
+                               if (index < 0)
 
3573
+                                       throw new ArgumentException ("index");
 
3574
+
 
3575
+                               double ret;
 
3576
+                               byte *b = (byte *)&ret;
 
3577
+
 
3578
+                               for (int i = 0; i < 8; i++)
 
3579
+                                       b [7-i] = data [index+i];
 
3580
+
 
3581
+                               return ret;
 
3582
+                       }
 
3583
+
 
3584
+                       public override ulong GetUInt64 (byte [] data, int index)
 
3585
+                       {
 
3586
+                               if (data == null)
 
3587
+                                       throw new ArgumentNullException ("data");
 
3588
+                               if (data.Length - index < 8)
 
3589
+                                       throw new ArgumentException ("index");
 
3590
+                               if (index < 0)
 
3591
+                                       throw new ArgumentException ("index");
 
3592
+
 
3593
+                               ulong ret;
 
3594
+                               byte *b = (byte *)&ret;
 
3595
+
 
3596
+                               for (int i = 0; i < 8; i++)
 
3597
+                                       b [7-i] = data [index+i];
 
3598
+
 
3599
+                               return ret;
 
3600
+                       }
 
3601
+
 
3602
+                       public override long GetInt64 (byte [] data, int index)
 
3603
+                       {
 
3604
+                               if (data == null)
 
3605
+                                       throw new ArgumentNullException ("data");
 
3606
+                               if (data.Length - index < 8)
 
3607
+                                       throw new ArgumentException ("index");
 
3608
+                               if (index < 0)
 
3609
+                                       throw new ArgumentException ("index");
 
3610
+
 
3611
+                               long ret;
 
3612
+                               byte *b = (byte *)&ret;
 
3613
+
 
3614
+                               for (int i = 0; i < 8; i++)
 
3615
+                                       b [7-i] = data [index+i];
 
3616
+
 
3617
+                               return ret;
 
3618
+                       }
 
3619
+                       
 
3620
+                       public override float GetFloat  (byte [] data, int index)
 
3621
+                       {
 
3622
+                               if (data == null)
 
3623
+                                       throw new ArgumentNullException ("data");
 
3624
+                               if (data.Length - index < 4)
 
3625
+                                       throw new ArgumentException ("index");
 
3626
+                               if (index < 0)
 
3627
+                                       throw new ArgumentException ("index");
 
3628
+
 
3629
+                               float ret;
 
3630
+                               byte *b = (byte *)&ret;
 
3631
+
 
3632
+                               for (int i = 0; i < 4; i++)
 
3633
+                                       b [3-i] = data [index+i];
 
3634
+
 
3635
+                               return ret;
 
3636
+                       }
 
3637
+                       
 
3638
+                       public override int GetInt32  (byte [] data, int index)
 
3639
+                       {
 
3640
+                               if (data == null)
 
3641
+                                       throw new ArgumentNullException ("data");
 
3642
+                               if (data.Length - index < 4)
 
3643
+                                       throw new ArgumentException ("index");
 
3644
+                               if (index < 0)
 
3645
+                                       throw new ArgumentException ("index");
 
3646
+
 
3647
+                               int ret;
 
3648
+                               byte *b = (byte *)&ret;
 
3649
+
 
3650
+                               for (int i = 0; i < 4; i++)
 
3651
+                                       b [3-i] = data [index+i];
 
3652
+
 
3653
+                               return ret;
 
3654
+                       }
 
3655
+                       
 
3656
+                       public override uint GetUInt32 (byte [] data, int index)
 
3657
+                       {
 
3658
+                               if (data == null)
 
3659
+                                       throw new ArgumentNullException ("data");
 
3660
+                               if (data.Length - index < 4)
 
3661
+                                       throw new ArgumentException ("index");
 
3662
+                               if (index < 0)
 
3663
+                                       throw new ArgumentException ("index");
 
3664
+
 
3665
+                               uint ret;
 
3666
+                               byte *b = (byte *)&ret;
 
3667
+
 
3668
+                               for (int i = 0; i < 4; i++)
 
3669
+                                       b [3-i] = data [index+i];
 
3670
+
 
3671
+                               return ret;
 
3672
+                       }
 
3673
+                       
 
3674
+                       public override short GetInt16 (byte [] data, int index)
 
3675
+                       {
 
3676
+                               if (data == null)
 
3677
+                                       throw new ArgumentNullException ("data");
 
3678
+                               if (data.Length - index < 2)
 
3679
+                                       throw new ArgumentException ("index");
 
3680
+                               if (index < 0)
 
3681
+                                       throw new ArgumentException ("index");
 
3682
+
 
3683
+                               short ret;
 
3684
+                               byte *b = (byte *)&ret;
 
3685
+
 
3686
+                               for (int i = 0; i < 2; i++)
 
3687
+                                       b [1-i] = data [index+i];
 
3688
+
 
3689
+                               return ret;
 
3690
+                       }
 
3691
+                       
 
3692
+                       public override ushort GetUInt16 (byte [] data, int index)
 
3693
+                       {
 
3694
+                               if (data == null)
 
3695
+                                       throw new ArgumentNullException ("data");
 
3696
+                               if (data.Length - index < 2)
 
3697
+                                       throw new ArgumentException ("index");
 
3698
+                               if (index < 0)
 
3699
+                                       throw new ArgumentException ("index");
 
3700
+
 
3701
+                               ushort ret;
 
3702
+                               byte *b = (byte *)&ret;
 
3703
+
 
3704
+                               for (int i = 0; i < 2; i++)
 
3705
+                                       b [1-i] = data [index+i];
 
3706
+
 
3707
+                               return ret;
 
3708
+                       }
 
3709
+
 
3710
+                       public override void PutBytes (byte [] dest, int destIdx, double value)
 
3711
+                       {
 
3712
+                               Check (dest, destIdx, 8);
 
3713
+
 
3714
+                               fixed (byte *target = &dest [destIdx]){
 
3715
+                                       byte *source = (byte *) &value;
 
3716
+
 
3717
+                                       for (int i = 0; i < 8; i++)
 
3718
+                                               target [i] = source [7-i];
 
3719
+                               }
 
3720
+                       }
 
3721
+                       
 
3722
+                       public override void PutBytes (byte [] dest, int destIdx, float value)
 
3723
+                       {
 
3724
+                               Check (dest, destIdx, 4);
 
3725
+
 
3726
+                               fixed (byte *target = &dest [destIdx]){
 
3727
+                                       byte *source = (byte *) &value;
 
3728
+
 
3729
+                                       for (int i = 0; i < 4; i++)
 
3730
+                                               target [i] = source [3-i];
 
3731
+                               }
 
3732
+                       }
 
3733
+                       
 
3734
+                       public override void PutBytes (byte [] dest, int destIdx, int value)
 
3735
+                       {
 
3736
+                               Check (dest, destIdx, 4);
 
3737
+
 
3738
+                               fixed (byte *target = &dest [destIdx]){
 
3739
+                                       byte *source = (byte *) &value;
 
3740
+
 
3741
+                                       for (int i = 0; i < 4; i++)
 
3742
+                                               target [i] = source [3-i];
 
3743
+                               }
 
3744
+                       }
 
3745
+                       
 
3746
+                       public override void PutBytes (byte [] dest, int destIdx, uint value)
 
3747
+                       {
 
3748
+                               Check (dest, destIdx, 4);
 
3749
+
 
3750
+                               fixed (byte *target = &dest [destIdx]){
 
3751
+                                       byte *source = (byte *) &value;
 
3752
+
 
3753
+                                       for (int i = 0; i < 4; i++)
 
3754
+                                               target [i] = source [3-i];
 
3755
+                               }
 
3756
+                       }
 
3757
+                       
 
3758
+                       public override void PutBytes (byte [] dest, int destIdx, long value)
 
3759
+                       {
 
3760
+                               Check (dest, destIdx, 8);
 
3761
+
 
3762
+                               fixed (byte *target = &dest [destIdx]){
 
3763
+                                       byte *source = (byte *) &value;
 
3764
+
 
3765
+                                       for (int i = 0; i < 8; i++)
 
3766
+                                               target [i] = source [7-i];
 
3767
+                               }
 
3768
+                       }
 
3769
+                       
 
3770
+                       public override void PutBytes (byte [] dest, int destIdx, ulong value)
 
3771
+                       {
 
3772
+                               Check (dest, destIdx, 8);
 
3773
+
 
3774
+                               fixed (byte *target = &dest [destIdx]){
 
3775
+                                       byte *source = (byte *) &value;
 
3776
+
 
3777
+                                       for (int i = 0; i < 4; i++)
 
3778
+                                               target [i] = source [7-i];
 
3779
+                               }
 
3780
+                       }
 
3781
+                       
 
3782
+                       public override void PutBytes (byte [] dest, int destIdx, short value)
 
3783
+                       {
 
3784
+                               Check (dest, destIdx, 2);
 
3785
+
 
3786
+                               fixed (byte *target = &dest [destIdx]){
 
3787
+                                       byte *source = (byte *) &value;
 
3788
+
 
3789
+                                       for (int i = 0; i < 2; i++)
 
3790
+                                               target [i] = source [1-i];
 
3791
+                               }
 
3792
+                       }
 
3793
+                       
 
3794
+                       public override void PutBytes (byte [] dest, int destIdx, ushort value)
 
3795
+                       {
 
3796
+                               Check (dest, destIdx, 2);
 
3797
+
 
3798
+                               fixed (byte *target = &dest [destIdx]){
 
3799
+                                       byte *source = (byte *) &value;
 
3800
+
 
3801
+                                       for (int i = 0; i < 2; i++)
 
3802
+                                               target [i] = source [1-i];
 
3803
+                               }
 
3804
+                       }
 
3805
+               }
 
3806
+               
 
3807
+#if MONO_DATACONVERTER_STATIC_METHODS
 
3808
+               static unsafe void PutBytesLE (byte *dest, byte *src, int count)
 
3809
+               {
 
3810
+                       int i = 0;
 
3811
+                       
 
3812
+                       if (BitConverter.IsLittleEndian){
 
3813
+                               for (; i < count; i++)
 
3814
+                                       *dest++ = *src++;
 
3815
+                       } else {
 
3816
+                               dest += count;
 
3817
+                               for (; i < count; i++)
 
3818
+                                       *(--dest) = *src++;
 
3819
+                       }
 
3820
+               }
 
3821
+
 
3822
+               static unsafe void PutBytesBE (byte *dest, byte *src, int count)
 
3823
+               {
 
3824
+                       int i = 0;
 
3825
+                       
 
3826
+                       if (BitConverter.IsLittleEndian){
 
3827
+                               dest += count;
 
3828
+                               for (; i < count; i++)
 
3829
+                                       *(--dest) = *src++;
 
3830
+                       } else {
 
3831
+                               for (; i < count; i++)
 
3832
+                                       *dest++ = *src++;
 
3833
+                       }
 
3834
+               }
 
3835
+
 
3836
+               static unsafe void PutBytesNative (byte *dest, byte *src, int count)
 
3837
+               {
 
3838
+                       int i = 0;
 
3839
+                       
 
3840
+                       for (; i < count; i++)
 
3841
+                               dest [i-count] = *src++;
 
3842
+               }
 
3843
+               
 
3844
+               static public unsafe double DoubleFromLE (byte[] data, int index)
 
3845
+               {
 
3846
+                       if (data == null)
 
3847
+                               throw new ArgumentNullException ("data");
 
3848
+                       if (data.Length - index < 8)
 
3849
+                               throw new ArgumentException ("index");
 
3850
+                       if (index < 0)
 
3851
+                               throw new ArgumentException ("index");
 
3852
+                       
 
3853
+                       double ret;
 
3854
+                       fixed (byte *src = &data[index]){
 
3855
+                               PutBytesLE ((byte *) &ret, src, 8);
 
3856
+                       }
 
3857
+                       return ret;
 
3858
+               }
 
3859
+
 
3860
+               static public unsafe float FloatFromLE (byte [] data, int index)
 
3861
+               {
 
3862
+                       if (data == null)
 
3863
+                               throw new ArgumentNullException ("data");
 
3864
+                       if (data.Length - index < 4)
 
3865
+                               throw new ArgumentException ("index");
 
3866
+                       if (index < 0)
 
3867
+                               throw new ArgumentException ("index");
 
3868
+                       
 
3869
+                       float ret;
 
3870
+                       fixed (byte *src = &data[index]){
 
3871
+                               PutBytesLE ((byte *) &ret, src, 4);
 
3872
+                       }
 
3873
+                       return ret;
 
3874
+               }
 
3875
+
 
3876
+               static public unsafe long Int64FromLE (byte [] data, int index)
 
3877
+               {
 
3878
+                       if (data == null)
 
3879
+                               throw new ArgumentNullException ("data");
 
3880
+                       if (data.Length - index < 8)
 
3881
+                               throw new ArgumentException ("index");
 
3882
+                       if (index < 0)
 
3883
+                               throw new ArgumentException ("index");
 
3884
+                       
 
3885
+                       long ret;
 
3886
+                       fixed (byte *src = &data[index]){
 
3887
+                               PutBytesLE ((byte *) &ret, src, 8);
 
3888
+                       }
 
3889
+                       return ret;
 
3890
+               }
 
3891
+               
 
3892
+               static public unsafe ulong UInt64FromLE (byte [] data, int index)
 
3893
+               {
 
3894
+                       if (data == null)
 
3895
+                               throw new ArgumentNullException ("data");
 
3896
+                       if (data.Length - index < 8)
 
3897
+                               throw new ArgumentException ("index");
 
3898
+                       if (index < 0)
 
3899
+                               throw new ArgumentException ("index");
 
3900
+                       
 
3901
+                       ulong ret;
 
3902
+                       fixed (byte *src = &data[index]){
 
3903
+                               PutBytesLE ((byte *) &ret, src, 8);
 
3904
+                       }
 
3905
+                       return ret;
 
3906
+               }
 
3907
+
 
3908
+               static public unsafe int Int32FromLE (byte [] data, int index)
 
3909
+               {
 
3910
+                       if (data == null)
 
3911
+                               throw new ArgumentNullException ("data");
 
3912
+                       if (data.Length - index < 4)
 
3913
+                               throw new ArgumentException ("index");
 
3914
+                       if (index < 0)
 
3915
+                               throw new ArgumentException ("index");
 
3916
+                       
 
3917
+                       int ret;
 
3918
+                       fixed (byte *src = &data[index]){
 
3919
+                               PutBytesLE ((byte *) &ret, src, 4);
 
3920
+                       }
 
3921
+                       return ret;
 
3922
+               }
 
3923
+               
 
3924
+               static public unsafe uint UInt32FromLE (byte [] data, int index)
 
3925
+               {
 
3926
+                       if (data == null)
 
3927
+                               throw new ArgumentNullException ("data");
 
3928
+                       if (data.Length - index < 4)
 
3929
+                               throw new ArgumentException ("index");
 
3930
+                       if (index < 0)
 
3931
+                               throw new ArgumentException ("index");
 
3932
+                       
 
3933
+                       uint ret;
 
3934
+                       fixed (byte *src = &data[index]){
 
3935
+                               PutBytesLE ((byte *) &ret, src, 4);
 
3936
+                       }
 
3937
+                       return ret;
 
3938
+               }
 
3939
+
 
3940
+               static public unsafe short Int16FromLE (byte [] data, int index)
 
3941
+               {
 
3942
+                       if (data == null)
 
3943
+                               throw new ArgumentNullException ("data");
 
3944
+                       if (data.Length - index < 2)
 
3945
+                               throw new ArgumentException ("index");
 
3946
+                       if (index < 0)
 
3947
+                               throw new ArgumentException ("index");
 
3948
+
 
3949
+                       short ret;
 
3950
+                       fixed (byte *src = &data[index]){
 
3951
+                               PutBytesLE ((byte *) &ret, src, 2);
 
3952
+                       }
 
3953
+                       return ret;
 
3954
+               }
 
3955
+               
 
3956
+               static public unsafe ushort UInt16FromLE (byte [] data, int index)
 
3957
+               {
 
3958
+                       if (data == null)
 
3959
+                               throw new ArgumentNullException ("data");
 
3960
+                       if (data.Length - index < 2)
 
3961
+                               throw new ArgumentException ("index");
 
3962
+                       if (index < 0)
 
3963
+                               throw new ArgumentException ("index");
 
3964
+                       
 
3965
+                       ushort ret;
 
3966
+                       fixed (byte *src = &data[index]){
 
3967
+                               PutBytesLE ((byte *) &ret, src, 2);
 
3968
+                       }
 
3969
+                       return ret;
 
3970
+               }
 
3971
+
 
3972
+               static public unsafe double DoubleFromBE (byte[] data, int index)
 
3973
+               {
 
3974
+                       if (data == null)
 
3975
+                               throw new ArgumentNullException ("data");
 
3976
+                       if (data.Length - index < 8)
 
3977
+                               throw new ArgumentException ("index");
 
3978
+                       if (index < 0)
 
3979
+                               throw new ArgumentException ("index");
 
3980
+                       
 
3981
+                       double ret;
 
3982
+                       fixed (byte *src = &data[index]){
 
3983
+                               PutBytesBE ((byte *) &ret, src, 8);
 
3984
+                       }
 
3985
+                       return ret;
 
3986
+               }
 
3987
+
 
3988
+               static public unsafe float FloatFromBE (byte [] data, int index)
 
3989
+               {
 
3990
+                       if (data == null)
 
3991
+                               throw new ArgumentNullException ("data");
 
3992
+                       if (data.Length - index < 4)
 
3993
+                               throw new ArgumentException ("index");
 
3994
+                       if (index < 0)
 
3995
+                               throw new ArgumentException ("index");
 
3996
+                       
 
3997
+                       float ret;
 
3998
+                       fixed (byte *src = &data[index]){
 
3999
+                               PutBytesBE ((byte *) &ret, src, 4);
 
4000
+                       }
 
4001
+                       return ret;
 
4002
+               }
 
4003
+
 
4004
+               static public unsafe long Int64FromBE (byte [] data, int index)
 
4005
+               {
 
4006
+                       if (data == null)
 
4007
+                               throw new ArgumentNullException ("data");
 
4008
+                       if (data.Length - index < 8)
 
4009
+                               throw new ArgumentException ("index");
 
4010
+                       if (index < 0)
 
4011
+                               throw new ArgumentException ("index");
 
4012
+                       
 
4013
+                       long ret;
 
4014
+                       fixed (byte *src = &data[index]){
 
4015
+                               PutBytesBE ((byte *) &ret, src, 8);
 
4016
+                       }
 
4017
+                       return ret;
 
4018
+               }
 
4019
+               
 
4020
+               static public unsafe ulong UInt64FromBE (byte [] data, int index)
 
4021
+               {
 
4022
+                       if (data == null)
 
4023
+                               throw new ArgumentNullException ("data");
 
4024
+                       if (data.Length - index < 8)
 
4025
+                               throw new ArgumentException ("index");
 
4026
+                       if (index < 0)
 
4027
+                               throw new ArgumentException ("index");
 
4028
+                       
 
4029
+                       ulong ret;
 
4030
+                       fixed (byte *src = &data[index]){
 
4031
+                               PutBytesBE ((byte *) &ret, src, 8);
 
4032
+                       }
 
4033
+                       return ret;
 
4034
+               }
 
4035
+
 
4036
+               static public unsafe int Int32FromBE (byte [] data, int index)
 
4037
+               {
 
4038
+                       if (data == null)
 
4039
+                               throw new ArgumentNullException ("data");
 
4040
+                       if (data.Length - index < 4)
 
4041
+                               throw new ArgumentException ("index");
 
4042
+                       if (index < 0)
 
4043
+                               throw new ArgumentException ("index");
 
4044
+                       
 
4045
+                       int ret;
 
4046
+                       fixed (byte *src = &data[index]){
 
4047
+                               PutBytesBE ((byte *) &ret, src, 4);
 
4048
+                       }
 
4049
+                       return ret;
 
4050
+               }
 
4051
+               
 
4052
+               static public unsafe uint UInt32FromBE (byte [] data, int index)
 
4053
+               {
 
4054
+                       if (data == null)
 
4055
+                               throw new ArgumentNullException ("data");
 
4056
+                       if (data.Length - index < 4)
 
4057
+                               throw new ArgumentException ("index");
 
4058
+                       if (index < 0)
 
4059
+                               throw new ArgumentException ("index");
 
4060
+                       
 
4061
+                       uint ret;
 
4062
+                       fixed (byte *src = &data[index]){
 
4063
+                               PutBytesBE ((byte *) &ret, src, 4);
 
4064
+                       }
 
4065
+                       return ret;
 
4066
+               }
 
4067
+
 
4068
+               static public unsafe short Int16FromBE (byte [] data, int index)
 
4069
+               {
 
4070
+                       if (data == null)
 
4071
+                               throw new ArgumentNullException ("data");
 
4072
+                       if (data.Length - index < 2)
 
4073
+                               throw new ArgumentException ("index");
 
4074
+                       if (index < 0)
 
4075
+                               throw new ArgumentException ("index");
 
4076
+
 
4077
+                       short ret;
 
4078
+                       fixed (byte *src = &data[index]){
 
4079
+                               PutBytesBE ((byte *) &ret, src, 2);
 
4080
+                       }
 
4081
+                       return ret;
 
4082
+               }
 
4083
+               
 
4084
+               static public unsafe ushort UInt16FromBE (byte [] data, int index)
 
4085
+               {
 
4086
+                       if (data == null)
 
4087
+                               throw new ArgumentNullException ("data");
 
4088
+                       if (data.Length - index < 2)
 
4089
+                               throw new ArgumentException ("index");
 
4090
+                       if (index < 0)
 
4091
+                               throw new ArgumentException ("index");
 
4092
+                       
 
4093
+                       ushort ret;
 
4094
+                       fixed (byte *src = &data[index]){
 
4095
+                               PutBytesBE ((byte *) &ret, src, 2);
 
4096
+                       }
 
4097
+                       return ret;
 
4098
+               }
 
4099
+
 
4100
+               static public unsafe double DoubleFromNative (byte[] data, int index)
 
4101
+               {
 
4102
+                       if (data == null)
 
4103
+                               throw new ArgumentNullException ("data");
 
4104
+                       if (data.Length - index < 8)
 
4105
+                               throw new ArgumentException ("index");
 
4106
+                       if (index < 0)
 
4107
+                               throw new ArgumentException ("index");
 
4108
+                       
 
4109
+                       double ret;
 
4110
+                       fixed (byte *src = &data[index]){
 
4111
+                               PutBytesNative ((byte *) &ret, src, 8);
 
4112
+                       }
 
4113
+                       return ret;
 
4114
+               }
 
4115
+
 
4116
+               static public unsafe float FloatFromNative (byte [] data, int index)
 
4117
+               {
 
4118
+                       if (data == null)
 
4119
+                               throw new ArgumentNullException ("data");
 
4120
+                       if (data.Length - index < 4)
 
4121
+                               throw new ArgumentException ("index");
 
4122
+                       if (index < 0)
 
4123
+                               throw new ArgumentException ("index");
 
4124
+                       
 
4125
+                       float ret;
 
4126
+                       fixed (byte *src = &data[index]){
 
4127
+                               PutBytesNative ((byte *) &ret, src, 4);
 
4128
+                       }
 
4129
+                       return ret;
 
4130
+               }
 
4131
+
 
4132
+               static public unsafe long Int64FromNative (byte [] data, int index)
 
4133
+               {
 
4134
+                       if (data == null)
 
4135
+                               throw new ArgumentNullException ("data");
 
4136
+                       if (data.Length - index < 8)
 
4137
+                               throw new ArgumentException ("index");
 
4138
+                       if (index < 0)
 
4139
+                               throw new ArgumentException ("index");
 
4140
+                       
 
4141
+                       long ret;
 
4142
+                       fixed (byte *src = &data[index]){
 
4143
+                               PutBytesNative ((byte *) &ret, src, 8);
 
4144
+                       }
 
4145
+                       return ret;
 
4146
+               }
 
4147
+               
 
4148
+               static public unsafe ulong UInt64FromNative (byte [] data, int index)
 
4149
+               {
 
4150
+                       if (data == null)
 
4151
+                               throw new ArgumentNullException ("data");
 
4152
+                       if (data.Length - index < 8)
 
4153
+                               throw new ArgumentException ("index");
 
4154
+                       if (index < 0)
 
4155
+                               throw new ArgumentException ("index");
 
4156
+                       
 
4157
+                       ulong ret;
 
4158
+                       fixed (byte *src = &data[index]){
 
4159
+                               PutBytesNative ((byte *) &ret, src, 8);
 
4160
+                       }
 
4161
+                       return ret;
 
4162
+               }
 
4163
+
 
4164
+               static public unsafe int Int32FromNative (byte [] data, int index)
 
4165
+               {
 
4166
+                       if (data == null)
 
4167
+                               throw new ArgumentNullException ("data");
 
4168
+                       if (data.Length - index < 4)
 
4169
+                               throw new ArgumentException ("index");
 
4170
+                       if (index < 0)
 
4171
+                               throw new ArgumentException ("index");
 
4172
+                       
 
4173
+                       int ret;
 
4174
+                       fixed (byte *src = &data[index]){
 
4175
+                               PutBytesNative ((byte *) &ret, src, 4);
 
4176
+                       }
 
4177
+                       return ret;
 
4178
+               }
 
4179
+               
 
4180
+               static public unsafe uint UInt32FromNative (byte [] data, int index)
 
4181
+               {
 
4182
+                       if (data == null)
 
4183
+                               throw new ArgumentNullException ("data");
 
4184
+                       if (data.Length - index < 4)
 
4185
+                               throw new ArgumentException ("index");
 
4186
+                       if (index < 0)
 
4187
+                               throw new ArgumentException ("index");
 
4188
+                       
 
4189
+                       uint ret;
 
4190
+                       fixed (byte *src = &data[index]){
 
4191
+                               PutBytesNative ((byte *) &ret, src, 4);
 
4192
+                       }
 
4193
+                       return ret;
 
4194
+               }
 
4195
+
 
4196
+               static public unsafe short Int16FromNative (byte [] data, int index)
 
4197
+               {
 
4198
+                       if (data == null)
 
4199
+                               throw new ArgumentNullException ("data");
 
4200
+                       if (data.Length - index < 2)
 
4201
+                               throw new ArgumentException ("index");
 
4202
+                       if (index < 0)
 
4203
+                               throw new ArgumentException ("index");
 
4204
+
 
4205
+                       short ret;
 
4206
+                       fixed (byte *src = &data[index]){
 
4207
+                               PutBytesNative ((byte *) &ret, src, 2);
 
4208
+                       }
 
4209
+                       return ret;
 
4210
+               }
 
4211
+               
 
4212
+               static public unsafe ushort UInt16FromNative (byte [] data, int index)
 
4213
+               {
 
4214
+                       if (data == null)
 
4215
+                               throw new ArgumentNullException ("data");
 
4216
+                       if (data.Length - index < 2)
 
4217
+                               throw new ArgumentException ("index");
 
4218
+                       if (index < 0)
 
4219
+                               throw new ArgumentException ("index");
 
4220
+                       
 
4221
+                       ushort ret;
 
4222
+                       fixed (byte *src = &data[index]){
 
4223
+                               PutBytesNative ((byte *) &ret, src, 2);
 
4224
+                       }
 
4225
+                       return ret;
 
4226
+               }
 
4227
+
 
4228
+                unsafe static byte[] GetBytesPtr (byte *ptr, int count)
 
4229
+                {
 
4230
+                        byte [] ret = new byte [count];
 
4231
+
 
4232
+                        for (int i = 0; i < count; i++) {
 
4233
+                                ret [i] = ptr [i];
 
4234
+                        }
 
4235
+
 
4236
+                        return ret;
 
4237
+                }
 
4238
+
 
4239
+                unsafe static byte[] GetBytesSwap (bool swap, byte *ptr, int count)
 
4240
+                {
 
4241
+                        byte [] ret = new byte [count];
 
4242
+
 
4243
+                       if (swap){
 
4244
+                               int t = count-1;
 
4245
+                               for (int i = 0; i < count; i++) {
 
4246
+                                       ret [t-i] = ptr [i];
 
4247
+                               }
 
4248
+                       } else {
 
4249
+                               for (int i = 0; i < count; i++) {
 
4250
+                                       ret [i] = ptr [i];
 
4251
+                               }
 
4252
+                       }
 
4253
+                        return ret;
 
4254
+                }
 
4255
+               
 
4256
+                unsafe public static byte[] GetBytesNative (bool value)
 
4257
+                {
 
4258
+                        return GetBytesPtr ((byte *) &value, 1);
 
4259
+                }
 
4260
+
 
4261
+                unsafe public static byte[] GetBytesNative (char value)
 
4262
+                {
 
4263
+                        return GetBytesPtr ((byte *) &value, 2);
 
4264
+                }
 
4265
+
 
4266
+                unsafe public static byte[] GetBytesNative (short value)
 
4267
+                {
 
4268
+                        return GetBytesPtr ((byte *) &value, 2);
 
4269
+                }
 
4270
+
 
4271
+                unsafe public static byte[] GetBytesNative (int value)
 
4272
+                {
 
4273
+                        return GetBytesPtr ((byte *) &value, 4);
 
4274
+                }
 
4275
+
 
4276
+                unsafe public static byte[] GetBytesNative (long value)
 
4277
+                {
 
4278
+                        return GetBytesPtr ((byte *) &value, 8);
 
4279
+                }
 
4280
+
 
4281
+                [CLSCompliant (false)]
 
4282
+                unsafe public static byte[] GetBytesNative (ushort value)
 
4283
+                {
 
4284
+                        return GetBytesPtr ((byte *) &value, 2);
 
4285
+                }
 
4286
+
 
4287
+                [CLSCompliant (false)]
 
4288
+                unsafe public static byte[] GetBytesNative (uint value)
 
4289
+                {
 
4290
+                        return GetBytesPtr ((byte *) &value, 4);
 
4291
+                }
 
4292
+
 
4293
+                [CLSCompliant (false)]
 
4294
+                unsafe public static byte[] GetBytesNative (ulong value)
 
4295
+                {
 
4296
+                        return GetBytesPtr ((byte *) &value, 8);
 
4297
+                }
 
4298
+
 
4299
+                unsafe public static byte[] GetBytesNative (float value)
 
4300
+                {
 
4301
+                        return GetBytesPtr ((byte *) &value, 4);
 
4302
+                }
 
4303
+
 
4304
+                unsafe public static byte[] GetBytesNative (double value)
 
4305
+                {
 
4306
+                       return GetBytesPtr ((byte *) &value, 8);
 
4307
+                }
 
4308
+
 
4309
+                unsafe public static byte[] GetBytesLE (bool value)
 
4310
+                {
 
4311
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 1);
 
4312
+                }
 
4313
+
 
4314
+                unsafe public static byte[] GetBytesLE (char value)
 
4315
+                {
 
4316
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4317
+                }
 
4318
+
 
4319
+                unsafe public static byte[] GetBytesLE (short value)
 
4320
+                {
 
4321
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4322
+                }
 
4323
+
 
4324
+                unsafe public static byte[] GetBytesLE (int value)
 
4325
+                {
 
4326
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4327
+                }
 
4328
+
 
4329
+                unsafe public static byte[] GetBytesLE (long value)
 
4330
+                {
 
4331
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4332
+                }
 
4333
+
 
4334
+                [CLSCompliant (false)]
 
4335
+                unsafe public static byte[] GetBytesLE (ushort value)
 
4336
+                {
 
4337
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4338
+                }
 
4339
+
 
4340
+                [CLSCompliant (false)]
 
4341
+                unsafe public static byte[] GetBytesLE (uint value)
 
4342
+                {
 
4343
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4344
+                }
 
4345
+
 
4346
+                [CLSCompliant (false)]
 
4347
+                unsafe public static byte[] GetBytesLE (ulong value)
 
4348
+                {
 
4349
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4350
+                }
 
4351
+
 
4352
+                unsafe public static byte[] GetBytesLE (float value)
 
4353
+                {
 
4354
+                        return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4355
+                }
 
4356
+
 
4357
+                unsafe public static byte[] GetBytesLE (double value)
 
4358
+                {
 
4359
+                       return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4360
+                }
 
4361
+               
 
4362
+                unsafe public static byte[] GetBytesBE (bool value)
 
4363
+                {
 
4364
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 1);
 
4365
+                }
 
4366
+
 
4367
+                unsafe public static byte[] GetBytesBE (char value)
 
4368
+                {
 
4369
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4370
+                }
 
4371
+
 
4372
+                unsafe public static byte[] GetBytesBE (short value)
 
4373
+                {
 
4374
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4375
+                }
 
4376
+
 
4377
+                unsafe public static byte[] GetBytesBE (int value)
 
4378
+                {
 
4379
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4380
+                }
 
4381
+
 
4382
+                unsafe public static byte[] GetBytesBE (long value)
 
4383
+                {
 
4384
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4385
+                }
 
4386
+
 
4387
+                [CLSCompliant (false)]
 
4388
+                unsafe public static byte[] GetBytesBE (ushort value)
 
4389
+                {
 
4390
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
 
4391
+                }
 
4392
+
 
4393
+                [CLSCompliant (false)]
 
4394
+                unsafe public static byte[] GetBytesBE (uint value)
 
4395
+                {
 
4396
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4397
+                }
 
4398
+
 
4399
+                [CLSCompliant (false)]
 
4400
+                unsafe public static byte[] GetBytesBE (ulong value)
 
4401
+                {
 
4402
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4403
+                }
 
4404
+
 
4405
+                unsafe public static byte[] GetBytesBE (float value)
 
4406
+                {
 
4407
+                        return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
 
4408
+                }
 
4409
+
 
4410
+                unsafe public static byte[] GetBytesBE (double value)
 
4411
+                {
 
4412
+                       return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
 
4413
+                }
 
4414
+#endif
 
4415
+               
 
4416
+       }
 
4417
+}
 
4418
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EnumMirror.cs
 
4419
===================================================================
 
4420
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4421
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EnumMirror.cs       2010-06-16 12:45:23.061079066 +0100
 
4422
@@ -0,0 +1,48 @@
 
4423
+using System;
 
4424
+using System.Collections.Generic;
 
4425
+
 
4426
+namespace Mono.Debugger.Soft
 
4427
+{
 
4428
+       /*
 
4429
+        * Represents an enum value in the debuggee
 
4430
+        */
 
4431
+       public class EnumMirror : StructMirror {
 
4432
+       
 
4433
+               internal EnumMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, type, fields) {
 
4434
+               }
 
4435
+
 
4436
+               internal EnumMirror (VirtualMachine vm, TypeMirror type, PrimitiveValue value) : base (vm, type, new Value[] { value }) {
 
4437
+                       if (type == null)
 
4438
+                               throw new ArgumentNullException ("type");
 
4439
+                       if (value == null)
 
4440
+                               throw new ArgumentNullException ("value");
 
4441
+                       if (!type.IsEnum)
 
4442
+                               throw new ArgumentException ("type must be an enum type", "type");
 
4443
+                       TypeMirror t = type.EnumUnderlyingType;
 
4444
+                       if (value.Value == null || !value.Value.GetType ().IsPrimitive || t != vm.RootDomain.GetCorrespondingType (value.Value.GetType ()))
 
4445
+                               throw new ArgumentException ("Value '" + value.Value + "' does not match the type of the enum.");
 
4446
+               }
 
4447
+
 
4448
+               public object Value {
 
4449
+                       get {
 
4450
+                               return ((PrimitiveValue)Fields [0]).Value;
 
4451
+                       }
 
4452
+                       set {
 
4453
+                               SetField (0, vm.CreateValue (value));
 
4454
+                       }
 
4455
+               }
 
4456
+
 
4457
+               public string StringValue {
 
4458
+                       get {
 
4459
+                               foreach (FieldInfoMirror f in Type.GetFields ()) {
 
4460
+                                       if (f.IsStatic) {
 
4461
+                                               object v = (Type.GetValue (f) as EnumMirror).Value;
 
4462
+                                               if (f.IsStatic && v.Equals (Value))
 
4463
+                                                       return f.Name;
 
4464
+                                       }
 
4465
+                               }
 
4466
+                               return Value.ToString ();
 
4467
+                       }
 
4468
+               }
 
4469
+       }
 
4470
+}
 
4471
\ No newline at end of file
 
4472
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Event.cs
 
4473
===================================================================
 
4474
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4475
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Event.cs    2010-06-16 12:45:23.061079066 +0100
 
4476
@@ -0,0 +1,50 @@
 
4477
+
 
4478
+namespace Mono.Debugger.Soft
 
4479
+{
 
4480
+       public abstract class Event {
 
4481
+               protected VirtualMachine vm;
 
4482
+               EventType evtype;
 
4483
+               ThreadMirror thread;
 
4484
+               int req_id;
 
4485
+               long thread_id;
 
4486
+
 
4487
+               internal Event (EventType evtype, VirtualMachine vm, int req_id, long thread_id) {
 
4488
+                       this.evtype = evtype;
 
4489
+                       this.vm = vm;
 
4490
+                       this.req_id = req_id;
 
4491
+                       this.thread_id = thread_id;
 
4492
+               }
 
4493
+
 
4494
+               internal Event (EventType evtype, VirtualMachine vm) {
 
4495
+                       this.evtype = evtype;
 
4496
+                       this.vm = vm;
 
4497
+                       this.thread_id = -1;
 
4498
+               }
 
4499
+
 
4500
+               public EventType EventType {
 
4501
+                       get {
 
4502
+                               return evtype;
 
4503
+                       }
 
4504
+               }
 
4505
+
 
4506
+               public override string ToString () {
 
4507
+                       return evtype.ToString ();
 
4508
+               }
 
4509
+
 
4510
+               public ThreadMirror Thread {
 
4511
+                       get {
 
4512
+                               if (thread_id == -1)
 
4513
+                                       return null;
 
4514
+                               if (thread == null)
 
4515
+                                       thread = vm.GetThread (thread_id);
 
4516
+                               return thread;
 
4517
+                       }
 
4518
+           }
 
4519
+
 
4520
+               public EventRequest Request {
 
4521
+                       get {
 
4522
+                               return vm.GetRequest (req_id);
 
4523
+                       }
 
4524
+               }
 
4525
+       }
 
4526
+}
 
4527
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventQueueImpl.cs
 
4528
===================================================================
 
4529
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4530
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventQueueImpl.cs   2010-06-16 12:45:23.061079066 +0100
 
4531
@@ -0,0 +1,133 @@
 
4532
+#if FALSE
 
4533
+using System;
 
4534
+using System.Collections;
 
4535
+using System.Collections.Generic;
 
4536
+using System.IO;
 
4537
+using System.Threading;
 
4538
+using Mono.Debugger;
 
4539
+using Mono.Debugger.Requests;
 
4540
+using Mono.Debugger.Events;
 
4541
+
 
4542
+namespace Mono.Debugger.Soft
 
4543
+{
 
4544
+       class EventQueueImpl : MirrorImpl, EventQueue
 
4545
+       {
 
4546
+               bool disconnected;
 
4547
+               Dictionary<int, byte[]> reply_packets;
 
4548
+               Thread receiver_thread;
 
4549
+               Queue queue;
 
4550
+               object queue_monitor;
 
4551
+               object reply_packets_monitor;
 
4552
+
 
4553
+               public EventQueueImpl (VirtualMachineImpl vm) : base (vm) {
 
4554
+                       reply_packets = new Dictionary<int, byte[]> ();
 
4555
+                       reply_packets_monitor = new Object ();
 
4556
+
 
4557
+                       queue = new Queue ();
 
4558
+                       queue_monitor = new Object ();
 
4559
+                       receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
 
4560
+                       receiver_thread.Start ();
 
4561
+               }
 
4562
+
 
4563
+               public EventSet Remove () {
 
4564
+                       if (disconnected)
 
4565
+                               // FIXME: VMDisconnectedException
 
4566
+                               throw new IOException ();
 
4567
+
 
4568
+                       lock (queue_monitor) {
 
4569
+                               if (queue.Count == 0)
 
4570
+                                       Monitor.Wait (queue_monitor);
 
4571
+                               return (EventSet)queue.Dequeue ();
 
4572
+                       }
 
4573
+               }
 
4574
+
 
4575
+               public EventSet Remove (int timeout) {
 
4576
+                       throw new NotImplementedException ();
 
4577
+               }
 
4578
+
 
4579
+               Event DecodeEventInfo (WireProtocol.EventInfo info) {
 
4580
+                       EventRequest req = FindRequest (info.requestId);
 
4581
+                       if (info.eventKind == WireProtocol.EVENT_VM_START) {
 
4582
+                               WireProtocol.VMStartEventInfo einfo = (WireProtocol.VMStartEventInfo)info;
 
4583
+                               return new VMStartEventImpl (vm, req, new ThreadReferenceImpl (vm, einfo.thread), new AppDomainMirrorImpl (vm, einfo.domain));
 
4584
+                       } else if (info.eventKind == WireProtocol.EVENT_VM_DEATH) {
 
4585
+                               return new VMDeathEventImpl (vm, req);
 
4586
+                       } else if (info.eventKind == WireProtocol.EVENT_THREAD_START) {
 
4587
+                               WireProtocol.ThreadStartEventInfo einfo = (WireProtocol.ThreadStartEventInfo)info;
 
4588
+                               return new ThreadStartEventImpl (vm, req, new ThreadReferenceImpl (vm, einfo.thread));
 
4589
+                       } else if (info.eventKind == WireProtocol.EVENT_THREAD_DEATH) {
 
4590
+                               WireProtocol.ThreadDeathEventInfo einfo = (WireProtocol.ThreadDeathEventInfo)info;
 
4591
+                               return new ThreadDeathEventImpl (vm, req, new ThreadReferenceImpl (vm, einfo.thread));
 
4592
+                       } else {
 
4593
+                               throw new NotImplementedException ();
 
4594
+                       }
 
4595
+               }
 
4596
+
 
4597
+               EventRequest FindRequest (int requestId) {
 
4598
+                       if (requestId == 0)
 
4599
+                               return null;
 
4600
+                       else
 
4601
+                               return ((EventRequestManagerImpl)vm.EventRequestManager).FindRequest (requestId);
 
4602
+               }
 
4603
+
 
4604
+               // Wait for the reply for a command packet
 
4605
+               public byte[] WaitForReply (int packetId) {
 
4606
+                       while (true) {
 
4607
+                               lock (reply_packets_monitor) {
 
4608
+                                       if (reply_packets.ContainsKey (packetId)) {
 
4609
+                                               byte[] reply = reply_packets [packetId];
 
4610
+                                               reply_packets.Remove (packetId);
 
4611
+                                               return reply;
 
4612
+                                       } else {
 
4613
+                                               Monitor.Wait (reply_packets_monitor);
 
4614
+                                       }
 
4615
+                               }
 
4616
+                       }
 
4617
+               }
 
4618
+
 
4619
+               void add_event_set (EventSet set) {
 
4620
+                       lock (queue_monitor) {
 
4621
+                               queue.Enqueue (set);
 
4622
+                               Monitor.Pulse (queue_monitor);
 
4623
+                       }
 
4624
+               }
 
4625
+
 
4626
+               void receiver_thread_main () {
 
4627
+
 
4628
+                       Connection conn = vm.Connection;
 
4629
+
 
4630
+                       while (true) {
 
4631
+                               byte[] packet = conn.ReadPacket ();
 
4632
+
 
4633
+                               if (packet.Length == 0) {
 
4634
+                                       disconnected = true;
 
4635
+                               
 
4636
+                                       VMDisconnectEventImpl ev = new VMDisconnectEventImpl (vm, null);
 
4637
+                                       add_event_set (new EventSetImpl (vm, new Event [] { ev }, SuspendPolicy.SuspendNone));
 
4638
+                                       break;
 
4639
+                               }
 
4640
+
 
4641
+                               if (WireProtocol.IsReplyPacket (packet)) {
 
4642
+                                       /* Reply packet */
 
4643
+                                       int id = WireProtocol.GetPacketId (packet);
 
4644
+                                       lock (reply_packets_monitor) {
 
4645
+                                               reply_packets [id] = packet;
 
4646
+                                               Monitor.PulseAll (reply_packets_monitor);
 
4647
+                                       }
 
4648
+                               } else {
 
4649
+                                       WireProtocol.Packet decoded = WireProtocol.DecodePacket (packet);
 
4650
+                                       if (decoded is WireProtocol.Event.CompositePacket) {
 
4651
+                                               WireProtocol.Event.CompositePacket p = (WireProtocol.Event.CompositePacket)decoded;
 
4652
+                                               Event[] events = new Event [p.events.Length];
 
4653
+                                               for (int i = 0; i < p.events.Length; ++i) {
 
4654
+                                                       events [i] = DecodeEventInfo (p.events [i]);
 
4655
+                                               }
 
4656
+
 
4657
+                                               add_event_set (new EventSetImpl (vm, events, p.suspendPolicy));
 
4658
+                                       }
 
4659
+                               }
 
4660
+                       }
 
4661
+               }
 
4662
+    }
 
4663
+}
 
4664
+#endif
 
4665
\ No newline at end of file
 
4666
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventRequest.cs
 
4667
===================================================================
 
4668
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4669
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventRequest.cs     2010-06-16 12:45:23.061079066 +0100
 
4670
@@ -0,0 +1,142 @@
 
4671
+using System;
 
4672
+using System.Collections.Generic;
 
4673
+using System.Linq;
 
4674
+
 
4675
+namespace Mono.Debugger.Soft
 
4676
+{
 
4677
+       public abstract class EventRequest {
 
4678
+               protected int id;
 
4679
+               protected EventType etype;
 
4680
+               protected bool enabled;
 
4681
+               protected VirtualMachine vm;
 
4682
+               protected SuspendPolicy suspend;
 
4683
+               protected int count;
 
4684
+               protected ThreadMirror thread;
 
4685
+               protected IList<AssemblyMirror> assembly_filter;
 
4686
+
 
4687
+               internal EventRequest (VirtualMachine vm, EventType etype) {
 
4688
+                       this.vm = vm;
 
4689
+                       this.etype = etype;
 
4690
+                       this.suspend = SuspendPolicy.All;
 
4691
+               }
 
4692
+
 
4693
+               internal EventRequest (EventType etype, int id) {
 
4694
+                       this.id = id;
 
4695
+                       this.etype = etype;
 
4696
+               }
 
4697
+
 
4698
+               internal int Id {
 
4699
+                       get {
 
4700
+                               return id;
 
4701
+                       }
 
4702
+                       set {
 
4703
+                               id = value;
 
4704
+                       }
 
4705
+               }
 
4706
+
 
4707
+               public EventType EventType {
 
4708
+                       get {
 
4709
+                               return etype;
 
4710
+                       }
 
4711
+               }
 
4712
+
 
4713
+               public bool Enabled {
 
4714
+                       get {
 
4715
+                               return enabled;
 
4716
+                       }
 
4717
+                       set {
 
4718
+                               if (value != enabled) {
 
4719
+                                       if (value)
 
4720
+                                               Enable ();
 
4721
+                                       else
 
4722
+                                               Disable ();
 
4723
+                               }
 
4724
+                       }
 
4725
+               }
 
4726
+
 
4727
+               public int Count {
 
4728
+                       get {
 
4729
+                               return count;
 
4730
+                       }
 
4731
+                       set {
 
4732
+                               CheckDisabled ();
 
4733
+                               count = value;
 
4734
+                       }
 
4735
+               }
 
4736
+
 
4737
+               public ThreadMirror Thread {
 
4738
+                       get {
 
4739
+                               return thread;
 
4740
+                       }
 
4741
+                       set {
 
4742
+                               CheckDisabled ();
 
4743
+                               if (value != null && value.VirtualMachine != vm)
 
4744
+                                       throw new VMMismatchException ();
 
4745
+                               thread = value;
 
4746
+                       }
 
4747
+               }
 
4748
+
 
4749
+               public IList<AssemblyMirror> AssemblyFilter {
 
4750
+                       get {
 
4751
+                               return assembly_filter;
 
4752
+                       }
 
4753
+                       set {
 
4754
+                               CheckDisabled ();
 
4755
+                               if (value != null) {
 
4756
+                                       foreach (var ass in value)
 
4757
+                                               if (ass == null)
 
4758
+                                                       throw new ArgumentException ("one of the elements of the array is null.");
 
4759
+                               }
 
4760
+                               assembly_filter = value;
 
4761
+                       }
 
4762
+               }
 
4763
+
 
4764
+               /*
 
4765
+                * Every time an EventRequest object is enabled, a new JDWP event request
 
4766
+                * is created, and the event request's id changes.
 
4767
+                */
 
4768
+               internal void SendReq (List<Modifier> mods) {
 
4769
+                       if (!enabled) {
 
4770
+                               if (Count > 0)
 
4771
+                                       mods.Add (new CountModifier () { Count = Count });
 
4772
+                               if (Thread != null)
 
4773
+                                       mods.Add (new ThreadModifier () { Thread = Thread.Id });
 
4774
+                               if (AssemblyFilter != null)
 
4775
+                                       mods.Add (new AssemblyModifier () { Assemblies = AssemblyFilter.Select (x => x.Id ).ToArray () });
 
4776
+                               id = vm.conn.EnableEvent (EventType, suspend, mods);
 
4777
+                               SetEnabled (id);
 
4778
+                       }
 
4779
+               }
 
4780
+                               
 
4781
+               public virtual void Enable () {
 
4782
+                       SendReq (new List<Modifier> ());
 
4783
+               }
 
4784
+
 
4785
+               public void Disable () {
 
4786
+                       if (enabled) {
 
4787
+                               vm.conn.ClearEventRequest (etype, id);
 
4788
+                               enabled = false;
 
4789
+                               // FIXME: This causes problems because Events can still reference
 
4790
+                               // the old id
 
4791
+                               //vm.RemoveRequest (this, id);
 
4792
+                               id = -1;
 
4793
+                       }
 
4794
+               }
 
4795
+
 
4796
+               protected void SetEnabled (int id) {
 
4797
+                       this.id = id;
 
4798
+                       enabled = true;
 
4799
+                       vm.AddRequest (this, id);
 
4800
+               }
 
4801
+
 
4802
+               protected void CheckDisabled () {
 
4803
+                       if (Enabled)
 
4804
+                               throw new InvalidOperationException ("Request objects can only be modified while they are disabled.");
 
4805
+               }
 
4806
+
 
4807
+               protected void CheckMirror (VirtualMachine vm, Mirror m) {
 
4808
+                       if (vm != m.VirtualMachine)
 
4809
+                               throw new VMMismatchException ();
 
4810
+               }
 
4811
+       }
 
4812
+}
 
4813
\ No newline at end of file
 
4814
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventType.cs
 
4815
===================================================================
 
4816
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4817
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/EventType.cs        2010-06-16 12:45:23.061079066 +0100
 
4818
@@ -0,0 +1,23 @@
 
4819
+
 
4820
+namespace Mono.Debugger.Soft
 
4821
+{
 
4822
+       // Keep it in sync with debugger-agent.h
 
4823
+       public enum EventType {
 
4824
+               VMStart = 0,
 
4825
+               VMDeath = 1,
 
4826
+               ThreadStart = 2,
 
4827
+               ThreadDeath = 3,
 
4828
+               AppDomainCreate = 4,
 
4829
+               AppDomainUnload = 5,
 
4830
+               MethodEntry = 6,
 
4831
+               MethodExit = 7,
 
4832
+               AssemblyLoad = 8,
 
4833
+               AssemblyUnload = 9,
 
4834
+               Breakpoint = 10,
 
4835
+               Step = 11,
 
4836
+               TypeLoad = 12,
 
4837
+               Exception = 13,
 
4838
+               // Not part of the wire protocol
 
4839
+               VMDisconnect = 99
 
4840
+       }
 
4841
+}
 
4842
\ No newline at end of file
 
4843
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ExceptionEvent.cs
 
4844
===================================================================
 
4845
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4846
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ExceptionEvent.cs   2010-06-16 12:45:23.061079066 +0100
 
4847
@@ -0,0 +1,20 @@
 
4848
+
 
4849
+namespace Mono.Debugger.Soft
 
4850
+{
 
4851
+       public class ExceptionEvent : Event {
 
4852
+               ObjectMirror exc;
 
4853
+               long exc_id;
 
4854
+
 
4855
+               internal ExceptionEvent (VirtualMachine vm, int req_id, long thread_id, long exc_id, long loc) : base (EventType.Exception, vm, req_id, thread_id) {
 
4856
+                       this.exc_id = exc_id;
 
4857
+               }
 
4858
+
 
4859
+               public ObjectMirror Exception {
 
4860
+                       get {
 
4861
+                               if (exc == null)
 
4862
+                                       exc = vm.GetObject (exc_id);
 
4863
+                               return exc;
 
4864
+                       }
 
4865
+               }
 
4866
+       }
 
4867
+}
 
4868
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ExceptionEventRequest.cs
 
4869
===================================================================
 
4870
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4871
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ExceptionEventRequest.cs    2010-06-16 12:45:23.061079066 +0100
 
4872
@@ -0,0 +1,35 @@
 
4873
+using System;
 
4874
+using System.Collections.Generic;
 
4875
+
 
4876
+namespace Mono.Debugger.Soft
 
4877
+{
 
4878
+       public sealed class ExceptionEventRequest : EventRequest {
 
4879
+
 
4880
+               TypeMirror exc_type;
 
4881
+               bool caught, uncaught;
 
4882
+               
 
4883
+               internal ExceptionEventRequest (VirtualMachine vm, TypeMirror exc_type, bool caught, bool uncaught) : base (vm, EventType.Exception) {
 
4884
+                       if (exc_type != null) {
 
4885
+                               CheckMirror (vm, exc_type);
 
4886
+                               TypeMirror exception_type = vm.RootDomain.Corlib.GetType ("System.Exception", false, false);
 
4887
+                               if (!exception_type.IsAssignableFrom (exc_type))
 
4888
+                                       throw new ArgumentException ("The exception type does not inherit from System.Exception", "exc_type");
 
4889
+                       }
 
4890
+                       this.exc_type = exc_type;
 
4891
+                       this.caught = caught;
 
4892
+                       this.uncaught = uncaught;
 
4893
+               }
 
4894
+
 
4895
+               public TypeMirror ExceptionType {
 
4896
+                       get {
 
4897
+                               return exc_type;
 
4898
+                       }
 
4899
+               }
 
4900
+
 
4901
+               public override void Enable () {
 
4902
+                       var mods = new List <Modifier> ();
 
4903
+                       mods.Add (new ExceptionModifier () { Type = exc_type != null ? exc_type.Id : 0, Caught = caught, Uncaught = uncaught });
 
4904
+                       SendReq (mods);
 
4905
+               }
 
4906
+       }
 
4907
+}
 
4908
\ No newline at end of file
 
4909
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/FieldInfoMirror.cs
 
4910
===================================================================
 
4911
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
4912
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/FieldInfoMirror.cs  2010-06-16 12:45:23.061079066 +0100
 
4913
@@ -0,0 +1,159 @@
 
4914
+using System;
 
4915
+using System.Collections.Generic;
 
4916
+using System.Text;
 
4917
+using System.Reflection;
 
4918
+using C = Mono.Cecil;
 
4919
+using Mono.Cecil.Metadata;
 
4920
+
 
4921
+namespace Mono.Debugger.Soft
 
4922
+{
 
4923
+       public class FieldInfoMirror : Mirror {
 
4924
+
 
4925
+               TypeMirror parent;
 
4926
+               string name;
 
4927
+               TypeMirror type;
 
4928
+               FieldAttributes attrs;
 
4929
+               CustomAttributeDataMirror[] cattrs;
 
4930
+
 
4931
+               public FieldInfoMirror (TypeMirror parent, long id, string name, TypeMirror type, FieldAttributes attrs) : base (parent.VirtualMachine, id) {
 
4932
+                       this.parent = parent;
 
4933
+                       this.name = name;
 
4934
+                       this.type = type;
 
4935
+                       this.attrs = attrs;
 
4936
+               }
 
4937
+
 
4938
+               public TypeMirror DeclaringType {
 
4939
+                       get {
 
4940
+                               return parent;
 
4941
+                       }
 
4942
+               }
 
4943
+
 
4944
+               public string Name {
 
4945
+                       get {
 
4946
+                               return name;
 
4947
+                       }
 
4948
+               }
 
4949
+
 
4950
+               public TypeMirror FieldType {
 
4951
+                       get {
 
4952
+                               return type;
 
4953
+                       }
 
4954
+               }
 
4955
+
 
4956
+               public FieldAttributes Attributes {
 
4957
+                       get {
 
4958
+                               return attrs;
 
4959
+                       }
 
4960
+               }
 
4961
+
 
4962
+               public bool IsLiteral
 
4963
+               {
 
4964
+                       get {return (Attributes & FieldAttributes.Literal) != 0;}
 
4965
+               } 
 
4966
+
 
4967
+               public bool IsStatic
 
4968
+               {
 
4969
+                       get {return (Attributes & FieldAttributes.Static) != 0;}
 
4970
+               } 
 
4971
+
 
4972
+               public bool IsInitOnly
 
4973
+               {
 
4974
+                       get {return (Attributes & FieldAttributes.InitOnly) != 0;}
 
4975
+               }
 
4976
 
4977
+               public Boolean IsPublic
 
4978
+               { 
 
4979
+                       get
 
4980
+                       {
 
4981
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
 
4982
+                       }
 
4983
+               }
 
4984
+
 
4985
+               public Boolean IsPrivate
 
4986
+               {
 
4987
+                       get
 
4988
+                       {
 
4989
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
 
4990
+                       }
 
4991
+               }
 
4992
+
 
4993
+               public Boolean IsFamily
 
4994
+               {
 
4995
+                       get
 
4996
+                       {
 
4997
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
 
4998
+                       }
 
4999
+               }
 
5000
+
 
5001
+               public Boolean IsAssembly
 
5002
+               {
 
5003
+                       get
 
5004
+                       {
 
5005
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
 
5006
+                       }
 
5007
+               }
 
5008
+
 
5009
+               public Boolean IsFamilyAndAssembly
 
5010
+               {
 
5011
+                       get {
 
5012
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
 
5013
+                       }
 
5014
+               }
 
5015
+
 
5016
+               public Boolean IsFamilyOrAssembly
 
5017
+               {
 
5018
+                       get
 
5019
+                       {
 
5020
+                               return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
 
5021
+                       }
 
5022
+               }
 
5023
+
 
5024
+               public Boolean IsPinvokeImpl
 
5025
+               {
 
5026
+                       get
 
5027
+                       {
 
5028
+                               return (Attributes & FieldAttributes.PinvokeImpl) == FieldAttributes.PinvokeImpl;
 
5029
+                       }
 
5030
+               }
 
5031
+
 
5032
+               public Boolean IsSpecialName
 
5033
+               {
 
5034
+                       get
 
5035
+                       {
 
5036
+                               return (Attributes & FieldAttributes.SpecialName) == FieldAttributes.SpecialName;
 
5037
+                       }
 
5038
+               }
 
5039
+
 
5040
+               public Boolean IsNotSerialized
 
5041
+               {
 
5042
+                       get
 
5043
+                       {
 
5044
+                               return (Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized;
 
5045
+                       }
 
5046
+               }
 
5047
+
 
5048
+               public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
 
5049
+                       return GetCAttrs (null, inherit);
 
5050
+               }
 
5051
+
 
5052
+               public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
 
5053
+                       if (attributeType == null)
 
5054
+                               throw new ArgumentNullException ("attributeType");
 
5055
+                       return GetCAttrs (attributeType, inherit);
 
5056
+               }
 
5057
+
 
5058
+               CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
 
5059
+                       // FIXME: Handle inherit
 
5060
+                       if (cattrs == null) {
 
5061
+                               CattrInfo[] info = vm.conn.Type_GetFieldCustomAttributes (DeclaringType.Id, id, 0, false);
 
5062
+                               cattrs = CustomAttributeDataMirror.Create (vm, info);
 
5063
+                       }
 
5064
+                       var res = new List<CustomAttributeDataMirror> ();
 
5065
+                       foreach (var attr in cattrs)
 
5066
+                               if (type == null || attr.Constructor.DeclaringType == type)
 
5067
+                                       res.Add (attr);
 
5068
+                       return res.ToArray ();
 
5069
+               }
 
5070
+       }
 
5071
+}
 
5072
+
 
5073
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/IInvokeAsyncResult.cs
 
5074
===================================================================
 
5075
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5076
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/IInvokeAsyncResult.cs       2010-06-16 12:45:23.061079066 +0100
 
5077
@@ -0,0 +1,10 @@
 
5078
+using System;
 
5079
+using System.Collections.Generic;
 
5080
+
 
5081
+namespace Mono.Debugger.Soft
 
5082
+{
 
5083
+       public interface IInvokeAsyncResult : IAsyncResult
 
5084
+       {
 
5085
+               void Abort ();
 
5086
+       }
 
5087
+}
 
5088
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ILInstruction.cs
 
5089
===================================================================
 
5090
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5091
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ILInstruction.cs    2010-06-16 12:45:23.061079066 +0100
 
5092
@@ -0,0 +1,67 @@
 
5093
+using System;
 
5094
+using System.Collections.Generic;
 
5095
+using System.Text;
 
5096
+using Mono.Cecil.Cil;
 
5097
+using Mono.Cecil.Metadata;
 
5098
+using System.IO;
 
5099
+using System.Reflection;
 
5100
+
 
5101
+namespace Mono.Debugger.Soft
 
5102
+{
 
5103
+       /*
 
5104
+        * This is similar to the Instruction class in Cecil, we can't use that
 
5105
+        * as its constructor is internal.
 
5106
+        */
 
5107
+       public class ILInstruction
 
5108
+       {
 
5109
+               int offset;
 
5110
+               OpCode opcode;
 
5111
+               object operand;
 
5112
+               ILInstruction prev, next;
 
5113
+
 
5114
+               internal ILInstruction (int offset, OpCode opcode, object operand) {
 
5115
+                       this.offset = offset;
 
5116
+                       this.opcode = opcode;
 
5117
+                       this.operand = operand;
 
5118
+               }
 
5119
+
 
5120
+               public int Offset {
 
5121
+                       get {
 
5122
+                               return offset;
 
5123
+                       }
 
5124
+               }
 
5125
+
 
5126
+               public OpCode OpCode {
 
5127
+                       get {
 
5128
+                               return opcode;
 
5129
+                       }
 
5130
+               }
 
5131
+
 
5132
+               public Object Operand {
 
5133
+                       get {
 
5134
+                               return operand;
 
5135
+                       }
 
5136
+                       set {
 
5137
+                               operand = value;
 
5138
+                       }
 
5139
+               }
 
5140
+
 
5141
+               public ILInstruction Next {
 
5142
+                       get {
 
5143
+                               return next;
 
5144
+                       }
 
5145
+                       set {
 
5146
+                               next = value;
 
5147
+                       }
 
5148
+               }
 
5149
+
 
5150
+               public ILInstruction Previous {
 
5151
+                       get {
 
5152
+                               return prev;
 
5153
+                       }
 
5154
+                       set {
 
5155
+                               prev = value;
 
5156
+                       }
 
5157
+               }
 
5158
+       }
 
5159
+}
 
5160
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/IMirror.cs
 
5161
===================================================================
 
5162
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5163
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/IMirror.cs  2010-06-16 12:45:23.061079066 +0100
 
5164
@@ -0,0 +1,20 @@
 
5165
+using System;
 
5166
+
 
5167
+namespace Mono.Debugger.Soft
 
5168
+{
 
5169
+       /*
 
5170
+        * A Mirror represents a runtime object in the remote virtual machine. Calling
 
5171
+        * methods/properties of mirror objects potentially involves a remoting call, 
 
5172
+        * which
 
5173
+        * has some overhead, and may also fail. Values of properties which are 
 
5174
+        * constant (like Type.Name) are cached locally, so only the first call is 
 
5175
+        * affected.
 
5176
+        * FIXME: Thread safety in the api ? 
 
5177
+        */
 
5178
+       public interface IMirror
 
5179
+       {
 
5180
+               VirtualMachine VirtualMachine {
 
5181
+                       get;
 
5182
+               }
 
5183
+       }
 
5184
+}
 
5185
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ITargetProcess.cs
 
5186
===================================================================
 
5187
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5188
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ITargetProcess.cs   2010-06-16 12:45:23.061079066 +0100
 
5189
@@ -0,0 +1,74 @@
 
5190
+using System;
 
5191
+using System.Diagnostics;
 
5192
+using System.IO;
 
5193
+
 
5194
+namespace Mono.Debugger.Soft
 
5195
+{
 
5196
+       public interface ITargetProcess
 
5197
+       {
 
5198
+               event System.EventHandler Exited;
 
5199
+               StreamReader StandardOutput { get; }
 
5200
+               StreamReader StandardError { get; }
 
5201
+               bool HasExited { get; }
 
5202
+               void Kill ();
 
5203
+               int Id { get; }
 
5204
+               string ProcessName { get; }
 
5205
+       }
 
5206
+       
 
5207
+       internal class ProcessWrapper: ITargetProcess
 
5208
+       {
 
5209
+               Process process;
 
5210
+
 
5211
+               public ProcessWrapper (Process process)
 
5212
+               {
 
5213
+                       this.process = process;
 
5214
+               }
 
5215
+               
 
5216
+               public Process Process {
 
5217
+                       get { return process; }
 
5218
+               }
 
5219
+               
 
5220
+               public event System.EventHandler Exited {
 
5221
+                       add { process.Exited += value; }
 
5222
+                       remove { process.Exited -= value; }
 
5223
+               }
 
5224
+               
 
5225
+               public StreamReader StandardOutput {
 
5226
+                       get {
 
5227
+                               return process.StandardOutput;
 
5228
+                       }
 
5229
+               }
 
5230
+               
 
5231
+               public StreamReader StandardError {
 
5232
+                       get {
 
5233
+                               return process.StandardError;
 
5234
+                       }
 
5235
+               }
 
5236
+               
 
5237
+               public bool HasExited {
 
5238
+                       get {
 
5239
+                               return process.HasExited;
 
5240
+                       }
 
5241
+               }
 
5242
+               
 
5243
+               public void Kill ()
 
5244
+               {
 
5245
+                       process.Kill ();
 
5246
+               }
 
5247
+
 
5248
+               public int Id {
 
5249
+                       get {
 
5250
+                               return process.Id;
 
5251
+                       }
 
5252
+               }
 
5253
+               
 
5254
+               public string ProcessName {
 
5255
+                       get {
 
5256
+                               return process.ProcessName;
 
5257
+                       }
 
5258
+               }
 
5259
+               
 
5260
+               
 
5261
+               
 
5262
+       }
 
5263
+}
 
5264
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvalidStackFrameException.cs
 
5265
===================================================================
 
5266
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5267
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvalidStackFrameException.cs       2010-06-16 12:45:23.061079066 +0100
 
5268
@@ -0,0 +1,10 @@
 
5269
+using System;
 
5270
+
 
5271
+namespace Mono.Debugger.Soft
 
5272
+{
 
5273
+       public class InvalidStackFrameException : Exception {
 
5274
+               
 
5275
+               public InvalidStackFrameException () : base ("The requested operation cannot be completed because the specified stack frame is no longer valid.") {
 
5276
+               }
 
5277
+       }
 
5278
+}
 
5279
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvocationException.cs
 
5280
===================================================================
 
5281
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5282
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvocationException.cs      2010-06-16 12:45:23.071079918 +0100
 
5283
@@ -0,0 +1,20 @@
 
5284
+using System;
 
5285
+using System.Collections.Generic;
 
5286
+
 
5287
+namespace Mono.Debugger.Soft
 
5288
+{
 
5289
+       public class InvocationException : Exception {
 
5290
+
 
5291
+               ObjectMirror exception;
 
5292
+
 
5293
+               public InvocationException (ObjectMirror exception) {
 
5294
+                       this.exception = exception;
 
5295
+               }
 
5296
+
 
5297
+               public ObjectMirror Exception {
 
5298
+                       get {
 
5299
+                               return exception;
 
5300
+                       }
 
5301
+               }
 
5302
+       }
 
5303
+}
 
5304
\ No newline at end of file
 
5305
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvokeOptions.cs
 
5306
===================================================================
 
5307
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5308
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/InvokeOptions.cs    2010-06-16 12:45:23.071079918 +0100
 
5309
@@ -0,0 +1,18 @@
 
5310
+using System;
 
5311
+using System.Collections.Generic;
 
5312
+
 
5313
+namespace Mono.Debugger.Soft
 
5314
+{
 
5315
+       [Flags]
 
5316
+       public enum InvokeOptions {
 
5317
+               None = 0,
 
5318
+               /*
 
5319
+                * Disable breakpoints on the thread doing the invoke
 
5320
+                */
 
5321
+               DisableBreakpoints = 1,
 
5322
+               /*
 
5323
+                * Only resume the target thread during the invoke
 
5324
+                */
 
5325
+               SingleThreaded = 2
 
5326
+       }
 
5327
+}
 
5328
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/LocalVariable.cs
 
5329
===================================================================
 
5330
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5331
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/LocalVariable.cs    2010-06-16 12:45:23.071079918 +0100
 
5332
@@ -0,0 +1,79 @@
 
5333
+using System;
 
5334
+
 
5335
+namespace Mono.Debugger.Soft
 
5336
+{
 
5337
+       public class LocalVariable : Mirror {
 
5338
+
 
5339
+               MethodMirror method;
 
5340
+               string name;
 
5341
+               int index;
 
5342
+               long type_id;
 
5343
+               TypeMirror t;
 
5344
+               bool is_arg;
 
5345
+               int live_range_start, live_range_end;
 
5346
+
 
5347
+           internal LocalVariable (VirtualMachine vm, MethodMirror method, int index, long type_id, string name, int live_range_start, int live_range_end, bool is_arg) : base (vm, 0) {
 
5348
+                       this.method = method;
 
5349
+                       this.index = index;
 
5350
+                       this.name = name;
 
5351
+                       this.type_id = type_id;
 
5352
+                       this.is_arg = is_arg;
 
5353
+                       this.live_range_start = live_range_start;
 
5354
+                       this.live_range_end = live_range_end;
 
5355
+               }
 
5356
+
 
5357
+               public string Name {
 
5358
+                       get {
 
5359
+                               return name;
 
5360
+                       }
 
5361
+               }
 
5362
+
 
5363
+               public int Index {
 
5364
+                       get {
 
5365
+                               return index;
 
5366
+                       }
 
5367
+               }
 
5368
+
 
5369
+               public TypeMirror Type {
 
5370
+                       get {
 
5371
+                               if (t == null)
 
5372
+                                       t = vm.GetType (type_id);
 
5373
+                               return t;
 
5374
+                       }
 
5375
+               }
 
5376
+
 
5377
+               public bool IsArg {
 
5378
+                       get {
 
5379
+                               return is_arg;
 
5380
+                       }
 
5381
+               }
 
5382
+
 
5383
+               public MethodMirror Method {
 
5384
+                       get {
 
5385
+                               return method;
 
5386
+                       }
 
5387
+               }
 
5388
+
 
5389
+               internal int LiveRangeStart {
 
5390
+                       get {
 
5391
+                               return live_range_start;
 
5392
+                       }
 
5393
+               }
 
5394
+
 
5395
+               internal int LiveRangeEnd {
 
5396
+                       get {
 
5397
+                               return live_range_end;
 
5398
+                       }
 
5399
+               }
 
5400
+
 
5401
+               internal int GetValueIndex {
 
5402
+                       get {
 
5403
+                               if (IsArg)
 
5404
+                                       return (-Index) - 1;
 
5405
+                               else
 
5406
+                                       return Index;
 
5407
+                       }
 
5408
+               }
 
5409
+       }
 
5410
+}
 
5411
+
 
5412
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Location.cs
 
5413
===================================================================
 
5414
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5415
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Location.cs 2010-06-16 12:45:23.071079918 +0100
 
5416
@@ -0,0 +1,51 @@
 
5417
+using System;
 
5418
+
 
5419
+namespace Mono.Debugger.Soft
 
5420
+{
 
5421
+       public class Location : Mirror
 
5422
+       {
 
5423
+               MethodMirror method;
 
5424
+               //long native_addr;
 
5425
+               int il_offset;
 
5426
+               string source_file;
 
5427
+               int line_number;
 
5428
+               //int column_number;
 
5429
+               
 
5430
+               internal Location (VirtualMachine vm, MethodMirror method, long native_addr, int il_offset, string source_file, int line_number, int column_number) : base (vm, 0) {
 
5431
+                       this.method = method;
 
5432
+                       //this.native_addr = native_addr;
 
5433
+                       this.il_offset = il_offset;
 
5434
+                       this.source_file = source_file;
 
5435
+                       this.line_number = line_number;
 
5436
+                       //this.column_number = column_number;
 
5437
+               }
 
5438
+
 
5439
+               public MethodMirror Method {
 
5440
+                       get {
 
5441
+                               return method;
 
5442
+                       }
 
5443
+               }
 
5444
+
 
5445
+               public int ILOffset {
 
5446
+                       get {
 
5447
+                               return il_offset;
 
5448
+                       }
 
5449
+               }
 
5450
+
 
5451
+               public string SourceFile {
 
5452
+                       get {
 
5453
+                               return source_file;
 
5454
+                       }
 
5455
+           }
 
5456
+
 
5457
+               public int LineNumber {
 
5458
+                       get {
 
5459
+                               return line_number;
 
5460
+                       }
 
5461
+           }
 
5462
+
 
5463
+               public override string ToString () {
 
5464
+                       return String.Format ("{0}+0x{1:x} at {2}:{3}", Method.FullName, ILOffset, SourceFile, LineNumber);
 
5465
+               }
 
5466
+    }
 
5467
+}
 
5468
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodBodyMirror.cs
 
5469
===================================================================
 
5470
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5471
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodBodyMirror.cs 2010-06-16 12:45:23.071079918 +0100
 
5472
@@ -0,0 +1,203 @@
 
5473
+using System;
 
5474
+using System.Collections.Generic;
 
5475
+using System.Text;
 
5476
+using Mono.Cecil.Cil;
 
5477
+using Mono.Cecil.Metadata;
 
5478
+using System.IO;
 
5479
+using System.Reflection;
 
5480
+
 
5481
+namespace Mono.Debugger.Soft
 
5482
+{
 
5483
+       public class MethodBodyMirror : Mirror
 
5484
+       {
 
5485
+               MethodMirror method;
 
5486
+               byte[] il;
 
5487
+
 
5488
+               internal MethodBodyMirror (VirtualMachine vm, MethodMirror method, byte[] il) : base (vm, 0) {
 
5489
+                       this.method = method;
 
5490
+                       this.il = il;
 
5491
+               }
 
5492
+
 
5493
+               public MethodMirror Method {
 
5494
+                       get {
 
5495
+                               return method;
 
5496
+                       }
 
5497
+               }
 
5498
+
 
5499
+               public byte[] GetILAsByteArray () {
 
5500
+                       return il;
 
5501
+               }
 
5502
+
 
5503
+               public List<ILInstruction> Instructions {
 
5504
+                       get {
 
5505
+                               return ReadCilBody (new BinaryReader (new MemoryStream (il)), il.Length);
 
5506
+                       }
 
5507
+               }
 
5508
+
 
5509
+               static bool opcodes_inited;
 
5510
+
 
5511
+               static OpCode [] OneByteOpCode = new OpCode [0xe0 + 1];
 
5512
+               static OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1];
 
5513
+
 
5514
+               // Adapted from Cecil
 
5515
+           List<ILInstruction> ReadCilBody (BinaryReader br, int code_size)
 
5516
+               {
 
5517
+                       long start = br.BaseStream.Position;
 
5518
+                       ILInstruction last = null;
 
5519
+                       //GenericContext context = new GenericContext (body.Method);
 
5520
+                       List<ILInstruction> code = new List<ILInstruction> ();
 
5521
+
 
5522
+                       var by_offset = new Dictionary<int, ILInstruction> ();
 
5523
+
 
5524
+                       if (!opcodes_inited) {
 
5525
+                               foreach (FieldInfo fi in typeof (OpCodes).GetFields (BindingFlags.Static|BindingFlags.Public)) {
 
5526
+                                       var val = (OpCode)fi.GetValue (null);
 
5527
+
 
5528
+                                       if (val.Op1 == 0xff)
 
5529
+                                               OneByteOpCode [val.Op2] = val;
 
5530
+                                       else
 
5531
+                                               TwoBytesOpCode [val.Op2] = val;
 
5532
+                               }
 
5533
+                               opcodes_inited = true;
 
5534
+                       }
 
5535
+
 
5536
+                       while (br.BaseStream.Position < start + code_size) {
 
5537
+                               OpCode op;
 
5538
+                               long offset = br.BaseStream.Position - start;
 
5539
+                               int cursor = br.ReadByte ();
 
5540
+                               int token;
 
5541
+                               ResolvedToken t;
 
5542
+
 
5543
+                               if (cursor == 0xfe)
 
5544
+                                       op = TwoBytesOpCode [br.ReadByte ()];
 
5545
+                               else
 
5546
+                                       op = OneByteOpCode [cursor];
 
5547
+
 
5548
+                               ILInstruction instr = new ILInstruction ((int)offset, op, null);
 
5549
+
 
5550
+                               by_offset [instr.Offset] = instr;
 
5551
+
 
5552
+                               switch (op.OperandType) {
 
5553
+                               case OperandType.InlineNone :
 
5554
+                                       break;
 
5555
+                               case OperandType.InlineSwitch :
 
5556
+                                       uint length = br.ReadUInt32 ();
 
5557
+                                       int [] branches = new int [length];
 
5558
+                                       int [] buf = new int [length];
 
5559
+                                       for (int i = 0; i < length; i++)
 
5560
+                                               buf [i] = br.ReadInt32 ();
 
5561
+                                       for (int i = 0; i < length; i++)
 
5562
+                                               branches [i] = Convert.ToInt32 (br.BaseStream.Position - start + buf [i]);
 
5563
+                                       instr.Operand = branches;
 
5564
+                                       break;
 
5565
+                               case OperandType.ShortInlineBrTarget :
 
5566
+                                       sbyte sbrtgt = br.ReadSByte ();
 
5567
+                                       instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt);
 
5568
+                                       break;
 
5569
+                               case OperandType.InlineBrTarget :
 
5570
+                                       int brtgt = br.ReadInt32 ();
 
5571
+                                       instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt);
 
5572
+                                       break;
 
5573
+                               case OperandType.ShortInlineI :
 
5574
+                                       if (op == OpCodes.Ldc_I4_S)
 
5575
+                                               instr.Operand = br.ReadSByte ();
 
5576
+                                       else
 
5577
+                                               instr.Operand = br.ReadByte ();
 
5578
+                                       break;
 
5579
+                               case OperandType.ShortInlineVar :
 
5580
+                                       br.ReadByte ();
 
5581
+                                       //instr.Operand = GetVariable (body, br.ReadByte ());
 
5582
+                                       break;
 
5583
+                               case OperandType.ShortInlineParam :
 
5584
+                                       br.ReadByte ();
 
5585
+                                       //instr.Operand = GetParameter (body, br.ReadByte ());
 
5586
+                                       break;
 
5587
+                               case OperandType.InlineSig :
 
5588
+                                       br.ReadInt32 ();
 
5589
+                                       //instr.Operand = GetCallSiteAt (br.ReadInt32 (), context);
 
5590
+                                       break;
 
5591
+                               case OperandType.InlineI :
 
5592
+                                       br.ReadInt32 ();
 
5593
+                                       //instr.Operand = br.ReadInt32 ();
 
5594
+                                       break;
 
5595
+                               case OperandType.InlineVar :
 
5596
+                                       br.ReadInt16 ();
 
5597
+                                       //instr.Operand = GetVariable (body, br.ReadInt16 ());
 
5598
+                                       break;
 
5599
+                               case OperandType.InlineParam :
 
5600
+                                       br.ReadInt16 ();
 
5601
+                                       //instr.Operand = GetParameter (body, br.ReadInt16 ());
 
5602
+                                       break;
 
5603
+                               case OperandType.InlineI8 :
 
5604
+                                       instr.Operand = br.ReadInt64 ();
 
5605
+                                       break;
 
5606
+                               case OperandType.ShortInlineR :
 
5607
+                                       instr.Operand = br.ReadSingle ();
 
5608
+                                       break;
 
5609
+                               case OperandType.InlineR :
 
5610
+                                       instr.Operand = br.ReadDouble ();
 
5611
+                                       break;
 
5612
+                               case OperandType.InlineString :
 
5613
+                                       token = br.ReadInt32 ();
 
5614
+                                       t = vm.conn.Method_ResolveToken (Method.Id, token);
 
5615
+                                       if (t.Type == TokenType.STRING)
 
5616
+                                               instr.Operand = t.Str;
 
5617
+                                       break;
 
5618
+                               case OperandType.InlineField :
 
5619
+                               case OperandType.InlineMethod :
 
5620
+                               case OperandType.InlineType :
 
5621
+                               case OperandType.InlineTok :
 
5622
+                                       token = br.ReadInt32 ();
 
5623
+
 
5624
+                                       t = vm.conn.Method_ResolveToken (Method.Id, token);
 
5625
+
 
5626
+                                       switch (t.Type) {
 
5627
+                                       case TokenType.TYPE:
 
5628
+                                               instr.Operand = vm.GetType (t.Id);
 
5629
+                                               break;
 
5630
+                                       case TokenType.FIELD:
 
5631
+                                               // FIXME: No vm.GetField ()
 
5632
+                                               //instr.Operand = vm.GetField (t.Id);
 
5633
+                                               break;
 
5634
+                                       case TokenType.METHOD:
 
5635
+                                               instr.Operand = vm.GetMethod (t.Id);
 
5636
+                                               break;
 
5637
+                                       case TokenType.UNKNOWN:
 
5638
+                                               break;
 
5639
+                                       default:
 
5640
+                                               throw new NotImplementedException ("Unknown token type: " + t.Type);
 
5641
+                                       }
 
5642
+                                       break;
 
5643
+                               }
 
5644
+
 
5645
+                               if (last != null) {
 
5646
+                                       last.Next = instr;
 
5647
+                                       instr.Previous = last;
 
5648
+                               }
 
5649
+
 
5650
+                               last = instr;
 
5651
+
 
5652
+                               code.Add (instr);
 
5653
+                       }
 
5654
+
 
5655
+                       // resolve branches
 
5656
+                       foreach (ILInstruction i in code) {
 
5657
+                               switch (i.OpCode.OperandType) {
 
5658
+                               case OperandType.ShortInlineBrTarget:
 
5659
+                               case OperandType.InlineBrTarget:
 
5660
+                                       i.Operand = by_offset [(int)i.Operand];
 
5661
+                                       break;
 
5662
+                               case OperandType.InlineSwitch:
 
5663
+                                       int [] lbls = (int []) i.Operand;
 
5664
+                                       ILInstruction [] instrs = new ILInstruction [lbls.Length];
 
5665
+                                       for (int j = 0; j < lbls.Length; j++)
 
5666
+                                               instrs [j] = by_offset [lbls [j]];
 
5667
+                                       i.Operand = instrs;
 
5668
+                                       break;
 
5669
+                               }
 
5670
+                       }
 
5671
+
 
5672
+                       return code;
 
5673
+               }
 
5674
+       }
 
5675
+}
 
5676
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodEntryEvent.cs
 
5677
===================================================================
 
5678
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5679
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodEntryEvent.cs 2010-06-16 12:45:23.071079918 +0100
 
5680
@@ -0,0 +1,20 @@
 
5681
+
 
5682
+namespace Mono.Debugger.Soft
 
5683
+{
 
5684
+       public class MethodEntryEvent : Event {
 
5685
+               MethodMirror method;
 
5686
+               long id;
 
5687
+
 
5688
+               internal MethodEntryEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.MethodEntry, vm, req_id, thread_id) {
 
5689
+                       this.id = id;
 
5690
+               }
 
5691
+
 
5692
+               public MethodMirror Method {
 
5693
+                       get {
 
5694
+                               if (method == null)
 
5695
+                                       method = vm.GetMethod (id);
 
5696
+                               return method;
 
5697
+                       }
 
5698
+               }
 
5699
+       }
 
5700
+}
 
5701
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodEntryEventRequest.cs
 
5702
===================================================================
 
5703
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5704
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodEntryEventRequest.cs  2010-06-16 12:45:23.071079918 +0100
 
5705
@@ -0,0 +1,10 @@
 
5706
+using System;
 
5707
+
 
5708
+namespace Mono.Debugger.Soft
 
5709
+{
 
5710
+       public sealed class MethodEntryEventRequest : EventRequest {
 
5711
+
 
5712
+               internal MethodEntryEventRequest (VirtualMachine vm) : base (vm, EventType.MethodEntry) {
 
5713
+               }
 
5714
+       }
 
5715
+}
 
5716
\ No newline at end of file
 
5717
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodExitEvent.cs
 
5718
===================================================================
 
5719
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5720
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodExitEvent.cs  2010-06-16 12:45:23.071079918 +0100
 
5721
@@ -0,0 +1,20 @@
 
5722
+
 
5723
+namespace Mono.Debugger.Soft
 
5724
+{
 
5725
+       public class MethodExitEvent : Event {
 
5726
+               MethodMirror method;
 
5727
+               long id;
 
5728
+
 
5729
+               internal MethodExitEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.MethodExit, vm, req_id, thread_id) {
 
5730
+                       this.id = id;
 
5731
+               }
 
5732
+
 
5733
+               public MethodMirror Method {
 
5734
+                       get {
 
5735
+                               if (method == null)
 
5736
+                                       method = vm.GetMethod (id);
 
5737
+                               return method;
 
5738
+                       }
 
5739
+               }
 
5740
+       }
 
5741
+}
 
5742
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodExitEventRequest.cs
 
5743
===================================================================
 
5744
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5745
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodExitEventRequest.cs   2010-06-16 12:45:23.071079918 +0100
 
5746
@@ -0,0 +1,10 @@
 
5747
+using System;
 
5748
+
 
5749
+namespace Mono.Debugger.Soft
 
5750
+{
 
5751
+       public sealed class MethodExitEventRequest : EventRequest {
 
5752
+
 
5753
+               internal MethodExitEventRequest (VirtualMachine vm) : base (vm, EventType.MethodExit) {
 
5754
+               }
 
5755
+       }
 
5756
+}
 
5757
\ No newline at end of file
 
5758
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodMirror.cs
 
5759
===================================================================
 
5760
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
5761
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/MethodMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
5762
@@ -0,0 +1,290 @@
 
5763
+using System;
 
5764
+using System.Collections.Generic;
 
5765
+using System.Text;
 
5766
+using System.Reflection;
 
5767
+using C = Mono.Cecil;
 
5768
+using Mono.Cecil.Metadata;
 
5769
+
 
5770
+namespace Mono.Debugger.Soft
 
5771
+{
 
5772
+       public class MethodMirror : Mirror
 
5773
+       {
 
5774
+               string name;
 
5775
+               MethodInfo info;
 
5776
+               TypeMirror declaring_type;
 
5777
+               DebugInfo debug_info;
 
5778
+               C.MethodDefinition meta;
 
5779
+               ParameterInfoMirror[] param_info;
 
5780
+               ParameterInfoMirror ret_param;
 
5781
+               LocalVariable[] locals;
 
5782
+               IList<Location> locations;
 
5783
+               MethodBodyMirror body;
 
5784
+
 
5785
+               internal MethodMirror (VirtualMachine vm, long id) : base (vm, id) {
 
5786
+               }
 
5787
+
 
5788
+               public string Name {
 
5789
+                       get {
 
5790
+                               if (name == null)
 
5791
+                                       name = vm.conn.Method_GetName (id);
 
5792
+                               return name;
 
5793
+                       }
 
5794
+           }
 
5795
+
 
5796
+               public TypeMirror DeclaringType {
 
5797
+                       get {
 
5798
+                               if (declaring_type == null)
 
5799
+                                       declaring_type = vm.GetType (vm.conn.Method_GetDeclaringType (id));
 
5800
+                               return declaring_type;
 
5801
+                       }
 
5802
+           }
 
5803
+
 
5804
+               public TypeMirror ReturnType {
 
5805
+                       get {
 
5806
+                               return ReturnParameter.ParameterType;
 
5807
+                       }
 
5808
+               }
 
5809
+
 
5810
+               // FIXME:
 
5811
+               public string FullName {
 
5812
+                       get {
 
5813
+                               string type_namespace = DeclaringType.Namespace;
 
5814
+                               string type_name = DeclaringType.Name;
 
5815
+                               StringBuilder sb = new StringBuilder ();
 
5816
+                               sb.Append (ReturnType.Name);
 
5817
+                               sb.Append (' ');
 
5818
+                               if (type_namespace == String.Empty)
 
5819
+                                       sb.Append (type_name + ":" + Name + " ()");
 
5820
+                               else
 
5821
+                                       sb.Append (type_namespace + "." + type_name + ":" + Name + " ()");
 
5822
+                               return sb.ToString ();
 
5823
+                       }
 
5824
+           }
 
5825
+
 
5826
+               void GetInfo () {
 
5827
+                       if (info == null)
 
5828
+                               info = vm.conn.Method_GetInfo (id);
 
5829
+               }
 
5830
+
 
5831
+               public int MetadataToken {
 
5832
+                       get {
 
5833
+                               GetInfo ();
 
5834
+                               return info.token;
 
5835
+                       }
 
5836
+               }
 
5837
+
 
5838
+               public MethodAttributes Attributes {
 
5839
+                       get {
 
5840
+                               GetInfo ();
 
5841
+                               return (MethodAttributes)info.attributes;
 
5842
+                       }
 
5843
+               }
 
5844
+
 
5845
+               public bool IsPublic { 
 
5846
+                       get {
 
5847
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
 
5848
+                       }
 
5849
+               }
 
5850
+               public bool IsPrivate {
 
5851
+                       get {
 
5852
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
 
5853
+                       }
 
5854
+               }
 
5855
+               public bool IsFamily {
 
5856
+                       get {
 
5857
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
 
5858
+                       }
 
5859
+               }
 
5860
+               public bool IsAssembly {
 
5861
+                       get {
 
5862
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
 
5863
+                       }
 
5864
+               }
 
5865
+               public bool IsFamilyAndAssembly {
 
5866
+                       get {
 
5867
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
 
5868
+                       }
 
5869
+               }
 
5870
+               public bool IsFamilyOrAssembly {
 
5871
+                       get {
 
5872
+                               return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
 
5873
+                       }
 
5874
+               }
 
5875
+               public bool IsStatic {
 
5876
+                       get {
 
5877
+                               return (Attributes & MethodAttributes.Static) != 0;
 
5878
+                       }
 
5879
+               }
 
5880
+               public bool IsFinal {
 
5881
+                       get {
 
5882
+                               return (Attributes & MethodAttributes.Final) != 0;
 
5883
+                       }
 
5884
+               }
 
5885
+               public bool IsVirtual {
 
5886
+                       get {
 
5887
+                               return (Attributes & MethodAttributes.Virtual) != 0;
 
5888
+                       }
 
5889
+               }
 
5890
+               public bool IsHideBySig {
 
5891
+                       get {
 
5892
+                               return (Attributes & MethodAttributes.HideBySig) != 0;
 
5893
+                       }
 
5894
+               }
 
5895
+               public bool IsAbstract {
 
5896
+                       get {
 
5897
+                               return (Attributes & MethodAttributes.Abstract) != 0;
 
5898
+                       }
 
5899
+               }
 
5900
+               public bool IsSpecialName {
 
5901
+                       get {
 
5902
+                               return (Attributes & MethodAttributes.SpecialName) != 0;
 
5903
+                       }
 
5904
+               }
 
5905
+
 
5906
+               public bool IsConstructor {
 
5907
+                       get {
 
5908
+                               int attr = (int)Attributes;
 
5909
+                               return ((attr & (int)MethodAttributes.RTSpecialName) != 0
 
5910
+                                       && (Name == ".ctor"));
 
5911
+                       }
 
5912
+               }
 
5913
+
 
5914
+           public ParameterInfoMirror[] GetParameters () {
 
5915
+                       if (param_info == null) {
 
5916
+                               var pi = vm.conn.Method_GetParamInfo (id);
 
5917
+                               param_info = new ParameterInfoMirror [pi.param_count];
 
5918
+                               // Return
 
5919
+                               ret_param = new ParameterInfoMirror (this, -1, vm.GetType (pi.ret_type), null, ParameterAttributes.Retval);
 
5920
+                               // FIXME: this
 
5921
+                               // FIXME: Attributes
 
5922
+                               for (int i = 0; i < pi.param_count; ++i) {
 
5923
+                                       param_info [i] = new ParameterInfoMirror (this, i, vm.GetType (pi.param_types [i]), pi.param_names [i], 0);
 
5924
+                               }
 
5925
+                       }
 
5926
+
 
5927
+                       return param_info;
 
5928
+               }
 
5929
+
 
5930
+           public ParameterInfoMirror ReturnParameter {
 
5931
+                       get {
 
5932
+                               if (ret_param == null)
 
5933
+                                       GetParameters ();
 
5934
+                               return ret_param;
 
5935
+                       }
 
5936
+               }
 
5937
+
 
5938
+               public LocalVariable[] GetLocals () {
 
5939
+                       if (locals == null) {
 
5940
+                               var li = vm.conn.Method_GetLocalsInfo (id);
 
5941
+                               // Add the arguments as well
 
5942
+                               var pi = vm.conn.Method_GetParamInfo (id);
 
5943
+
 
5944
+                               locals = new LocalVariable [pi.param_count + li.names.Length];
 
5945
+
 
5946
+                               for (int i = 0; i < pi.param_count; ++i)
 
5947
+                                       locals [i] = new LocalVariable (vm, this, i, pi.param_types [i], pi.param_names [i], -1, -1, true);
 
5948
+
 
5949
+                               for (int i = 0; i < li.names.Length; ++i)
 
5950
+                                       locals [i + pi.param_count] = new LocalVariable (vm, this, i, li.types [i], li.names [i], li.live_range_start [i], li.live_range_end [i], false);
 
5951
+                       }
 
5952
+                       return locals;
 
5953
+               }
 
5954
+
 
5955
+               public LocalVariable GetLocal (string name) {
 
5956
+                       if (name == null)
 
5957
+                               throw new ArgumentNullException ("name");
 
5958
+
 
5959
+                       GetLocals ();
 
5960
+
 
5961
+                       LocalVariable res = null;
 
5962
+                       for (int i = 0; i < locals.Length; ++i) {
 
5963
+                               if (locals [i].Name == name) {
 
5964
+                                       if (res != null)
 
5965
+                                               throw new AmbiguousMatchException ("More that one local has the name '" + name + "'.");
 
5966
+                                       res = locals [i];
 
5967
+                               }
 
5968
+                       }
 
5969
+
 
5970
+                       return res;
 
5971
+               }
 
5972
+
 
5973
+               public MethodBodyMirror GetMethodBody () {
 
5974
+                       if (body == null) {
 
5975
+                               MethodBodyInfo info = vm.conn.Method_GetBody (id);
 
5976
+
 
5977
+                               body = new MethodBodyMirror (vm, this, info.il);
 
5978
+                       }
 
5979
+                       return body;
 
5980
+               }
 
5981
+
 
5982
+               public IList<int> ILOffsets {
 
5983
+                       get {
 
5984
+                               if (debug_info == null)
 
5985
+                                       debug_info = vm.conn.Method_GetDebugInfo (id);
 
5986
+                               return Array.AsReadOnly (debug_info.il_offsets);
 
5987
+                       }
 
5988
+           }
 
5989
+
 
5990
+               public IList<int> LineNumbers {
 
5991
+                       get {
 
5992
+                               if (debug_info == null)
 
5993
+                                       debug_info = vm.conn.Method_GetDebugInfo (id);
 
5994
+                               return Array.AsReadOnly (debug_info.line_numbers);
 
5995
+                       }
 
5996
+           }
 
5997
+
 
5998
+               public string SourceFile {
 
5999
+                       get {
 
6000
+                               if (debug_info == null)
 
6001
+                                       debug_info = vm.conn.Method_GetDebugInfo (id);
 
6002
+                               return debug_info.filename;
 
6003
+                       }
 
6004
+           }
 
6005
+
 
6006
+               public IList<Location> Locations {
 
6007
+                       get {
 
6008
+                               if (locations == null) {
 
6009
+                                       var il_offsets = ILOffsets;
 
6010
+                                       var line_numbers = LineNumbers;
 
6011
+                                       IList<Location> res = new Location [ILOffsets.Count];
 
6012
+                                       for (int i = 0; i < il_offsets.Count; ++i)
 
6013
+                                               res [i] = new Location (vm, this, -1, il_offsets [i], SourceFile, line_numbers [i], 0);
 
6014
+                                       locations = res;
 
6015
+                               }
 
6016
+                               return locations;
 
6017
+                       }
 
6018
+               }                               
 
6019
+
 
6020
+               internal int il_offset_to_line_number (int il_offset) {
 
6021
+                       if (debug_info == null)
 
6022
+                               debug_info = vm.conn.Method_GetDebugInfo (id);
 
6023
+
 
6024
+                       // FIXME: Optimize this
 
6025
+                       for (int i = debug_info.il_offsets.Length - 1; i >= 0; --i) {
 
6026
+                               if (debug_info.il_offsets [i] <= il_offset)
 
6027
+                                       return debug_info.line_numbers [i];
 
6028
+                       }
 
6029
+                       return -1;
 
6030
+           }
 
6031
+
 
6032
+               public Location LocationAtILOffset (int il_offset) {
 
6033
+                       IList<Location> locs = Locations;
 
6034
+
 
6035
+                       // FIXME: Optimize this
 
6036
+                       for (int i = locs.Count - 1; i >= 0; --i) {
 
6037
+                               if (locs [i].ILOffset <= il_offset)
 
6038
+                                       return locs [i];
 
6039
+                       }
 
6040
+
 
6041
+                       return null;
 
6042
+               }
 
6043
+
 
6044
+               public C.MethodDefinition Metadata {
 
6045
+                       get {
 
6046
+                               if (meta == null)
 
6047
+                                       meta = (C.MethodDefinition)DeclaringType.Assembly.Metadata.MainModule.LookupByToken (new MetadataToken (MetadataToken));
 
6048
+                               return meta;
 
6049
+                       }
 
6050
+               }
 
6051
+    }
 
6052
+}
 
6053
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Mirror.cs
 
6054
===================================================================
 
6055
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6056
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Mirror.cs   2010-06-16 12:45:23.071079918 +0100
 
6057
@@ -0,0 +1,39 @@
 
6058
+using System;
 
6059
+
 
6060
+namespace Mono.Debugger.Soft
 
6061
+{
 
6062
+       public abstract class Mirror : IMirror
 
6063
+       {
 
6064
+               protected VirtualMachine vm;
 
6065
+               protected long id; // The id used in the protocol
 
6066
+
 
6067
+               internal Mirror (VirtualMachine vm, long id) {
 
6068
+                       this.vm = vm;
 
6069
+                       this.id = id;
 
6070
+               }
 
6071
+
 
6072
+               internal Mirror () {
 
6073
+               }
 
6074
+
 
6075
+               public VirtualMachine VirtualMachine {
 
6076
+                       get {
 
6077
+                               return vm;
 
6078
+                       }
 
6079
+               }
 
6080
+
 
6081
+               internal long Id {
 
6082
+                       get {
 
6083
+                               return id;
 
6084
+                       }
 
6085
+               }
 
6086
+
 
6087
+               protected void SetVirtualMachine (VirtualMachine vm) {
 
6088
+                       this.vm = vm;
 
6089
+               }
 
6090
+
 
6091
+               protected void CheckMirror (Mirror m) {
 
6092
+                       if (vm != m.VirtualMachine)
 
6093
+                               throw new VMMismatchException ();
 
6094
+               }
 
6095
+       }
 
6096
+}
 
6097
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs
 
6098
===================================================================
 
6099
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6100
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ModuleMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
6101
@@ -0,0 +1,66 @@
 
6102
+using System;
 
6103
+using Mono.Debugger;
 
6104
+using Mono.Cecil;
 
6105
+
 
6106
+namespace Mono.Debugger.Soft
 
6107
+{
 
6108
+       public class ModuleMirror : Mirror
 
6109
+       {
 
6110
+               ModuleInfo info;
 
6111
+               Guid guid;
 
6112
+               AssemblyMirror assembly;
 
6113
+
 
6114
+               internal ModuleMirror (VirtualMachine vm, long id) : base (vm, id) {
 
6115
+               }
 
6116
+
 
6117
+               void ReadInfo () {
 
6118
+                       if (info == null)
 
6119
+                               info = vm.conn.Module_GetInfo (id);
 
6120
+               }
 
6121
+
 
6122
+               public string Name {
 
6123
+                       get {
 
6124
+                               ReadInfo ();
 
6125
+                               return info.Name;
 
6126
+                       }
 
6127
+               }
 
6128
+
 
6129
+               public string ScopeName {
 
6130
+                       get {
 
6131
+                               ReadInfo ();
 
6132
+                               return info.ScopeName;
 
6133
+                       }
 
6134
+               }
 
6135
+
 
6136
+               public string FullyQualifiedName {
 
6137
+                       get {
 
6138
+                               ReadInfo ();
 
6139
+                               return info.FQName;
 
6140
+                       }
 
6141
+               }
 
6142
+
 
6143
+               public Guid ModuleVersionId {
 
6144
+                       get {
 
6145
+                               if (guid == Guid.Empty) {
 
6146
+                                       ReadInfo ();
 
6147
+                                       guid = new Guid (info.Guid);
 
6148
+                               }
 
6149
+                               return guid;
 
6150
+                       }
 
6151
+               }
 
6152
+
 
6153
+               public AssemblyMirror Assembly {
 
6154
+                       get {
 
6155
+                               if (assembly == null) {
 
6156
+                                       ReadInfo ();
 
6157
+                                       if (info.Assembly == 0)
 
6158
+                                               return null;
 
6159
+                                       assembly = vm.GetAssembly (info.Assembly);
 
6160
+                               }
 
6161
+                               return assembly;
 
6162
+                       }
 
6163
+               }
 
6164
+
 
6165
+               // FIXME: Add function to query the guid, check in Metadata
 
6166
+    }
 
6167
+}
 
6168
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ObjectCollectedException.cs
 
6169
===================================================================
 
6170
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6171
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ObjectCollectedException.cs 2010-06-16 12:45:23.071079918 +0100
 
6172
@@ -0,0 +1,10 @@
 
6173
+using System;
 
6174
+
 
6175
+namespace Mono.Debugger.Soft
 
6176
+{
 
6177
+       public class ObjectCollectedException : Exception {
 
6178
+               
 
6179
+               public ObjectCollectedException () : base ("The requested operation cannot be completed because the object has been garbage collected.") {
 
6180
+               }
 
6181
+       }
 
6182
+}
 
6183
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs
 
6184
===================================================================
 
6185
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6186
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ObjectMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
6187
@@ -0,0 +1,259 @@
 
6188
+using System;
 
6189
+using System.Collections.Generic;
 
6190
+using System.Runtime.Remoting.Messaging;
 
6191
+using System.Threading;
 
6192
+
 
6193
+namespace Mono.Debugger.Soft
 
6194
+{
 
6195
+       public class ObjectMirror : Value {
 
6196
+       
 
6197
+               internal ObjectMirror (VirtualMachine vm, long id) : base (vm, id) {
 
6198
+               }
 
6199
+       
 
6200
+               public TypeMirror Type {
 
6201
+                       get {
 
6202
+                               return vm.GetType (vm.conn.Object_GetType (id));
 
6203
+                       }
 
6204
+               }
 
6205
+
 
6206
+               public AppDomainMirror Domain {
 
6207
+                       get {
 
6208
+                               return vm.GetDomain (vm.conn.Object_GetDomain (id));
 
6209
+                       }
 
6210
+               }
 
6211
+
 
6212
+               public bool IsCollected {
 
6213
+                       get {
 
6214
+                               return vm.conn.Object_IsCollected (id);
 
6215
+                       }
 
6216
+               }
 
6217
+
 
6218
+               public Value GetValue (FieldInfoMirror field) {
 
6219
+                       return GetValues (new FieldInfoMirror [] { field }) [0];
 
6220
+               }
 
6221
+
 
6222
+               public Value[] GetValues (IList<FieldInfoMirror> fields) {
 
6223
+                       if (fields == null)
 
6224
+                               throw new ArgumentNullException ("fields");
 
6225
+                       foreach (FieldInfoMirror f in fields) {
 
6226
+                               if (f == null)
 
6227
+                                       throw new ArgumentNullException ("field");
 
6228
+                               CheckMirror (f);
 
6229
+                       }
 
6230
+                       long[] ids = new long [fields.Count];
 
6231
+                       for (int i = 0; i < fields.Count; ++i)
 
6232
+                               ids [i] = fields [i].Id;
 
6233
+                       try {
 
6234
+                               return vm.DecodeValues (vm.conn.Object_GetValues (id, ids));
 
6235
+                       } catch (CommandException ex) {
 
6236
+                               if (ex.ErrorCode == ErrorCode.INVALID_FIELDID)
 
6237
+                                       throw new ArgumentException ("One of the fields is not valid for this type.", "fields");
 
6238
+                               else
 
6239
+                                       throw;
 
6240
+                       }
 
6241
+               }
 
6242
+
 
6243
+               public void SetValues (IList<FieldInfoMirror> fields, Value[] values) {
 
6244
+                       if (fields == null)
 
6245
+                               throw new ArgumentNullException ("fields");
 
6246
+                       if (values == null)
 
6247
+                               throw new ArgumentNullException ("values");
 
6248
+                       foreach (FieldInfoMirror f in fields) {
 
6249
+                               if (f == null)
 
6250
+                                       throw new ArgumentNullException ("field");
 
6251
+                               CheckMirror (f);
 
6252
+                       }
 
6253
+                       foreach (Value v in values) {
 
6254
+                               if (v == null)
 
6255
+                                       throw new ArgumentNullException ("values");
 
6256
+                               CheckMirror (v);
 
6257
+                       }
 
6258
+                       long[] ids = new long [fields.Count];
 
6259
+                       for (int i = 0; i < fields.Count; ++i)
 
6260
+                               ids [i] = fields [i].Id;
 
6261
+                       try {
 
6262
+                               vm.conn.Object_SetValues (id, ids, vm.EncodeValues (values));
 
6263
+                       } catch (CommandException ex) {
 
6264
+                               if (ex.ErrorCode == ErrorCode.INVALID_FIELDID)
 
6265
+                                       throw new ArgumentException ("One of the fields is not valid for this type.", "fields");
 
6266
+                               else if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
 
6267
+                                       throw new ArgumentException ("One of the values is not valid for its field.", "values");
 
6268
+                               else
 
6269
+                                       throw;
 
6270
+                       }
 
6271
+               }
 
6272
+
 
6273
+               public void SetValue (FieldInfoMirror field, Value value) {
 
6274
+                       SetValues (new FieldInfoMirror [] { field }, new Value [] { value });
 
6275
+               }
 
6276
+
 
6277
+               /*
 
6278
+                * The current address of the object. It can change during garbage 
 
6279
+                * collections. Use a long since the debuggee might have a different 
 
6280
+                * pointer size. 
 
6281
+                */
 
6282
+               public long Address {
 
6283
+                       get {
 
6284
+                               return vm.conn.Object_GetAddress (id);
 
6285
+                       }
 
6286
+               }
 
6287
+
 
6288
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
 
6289
+                       return InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
 
6290
+               }
 
6291
+
 
6292
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
 
6293
+                       return InvokeMethod (vm, thread, method, this, arguments, options);
 
6294
+               }
 
6295
+
 
6296
+               [Obsolete ("Use the overload without the 'vm' argument")]
 
6297
+               public IAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
6298
+                       return BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
 
6299
+               }
 
6300
+
 
6301
+               public IAsyncResult BeginInvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
6302
+                       return BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
 
6303
+               }
 
6304
+
 
6305
+               public Value EndInvokeMethod (IAsyncResult asyncResult) {
 
6306
+                       return EndInvokeMethodInternal (asyncResult);
 
6307
+               }
 
6308
+
 
6309
+               /*
 
6310
+                * Common implementation for invokes
 
6311
+                */
 
6312
+
 
6313
+               class InvokeAsyncResult : IInvokeAsyncResult {
 
6314
+
 
6315
+                       public object AsyncState {
 
6316
+                               get; set;
 
6317
+                       }
 
6318
+
 
6319
+                       public WaitHandle AsyncWaitHandle {
 
6320
+                               get; set;
 
6321
+                       }
 
6322
+
 
6323
+                       public bool CompletedSynchronously {
 
6324
+                               get {
 
6325
+                                       return false;
 
6326
+                               }
 
6327
+                       }
 
6328
+
 
6329
+                       public bool IsCompleted {
 
6330
+                               get; set;
 
6331
+                       }
 
6332
+
 
6333
+                       public AsyncCallback Callback {
 
6334
+                               get; set;
 
6335
+                       }
 
6336
+
 
6337
+                       public ErrorCode ErrorCode {
 
6338
+                               get; set;
 
6339
+                       }
 
6340
+
 
6341
+                       public VirtualMachine VM {
 
6342
+                               get; set;
 
6343
+                       }
 
6344
+
 
6345
+                       public ThreadMirror Thread {
 
6346
+                               get; set;
 
6347
+                       }
 
6348
+
 
6349
+                       public ValueImpl Value {
 
6350
+                               get; set;
 
6351
+                       }
 
6352
+
 
6353
+                       public ValueImpl Exception {
 
6354
+                               get; set;
 
6355
+                       }
 
6356
+
 
6357
+                       public int ID {
 
6358
+                               get; set;
 
6359
+                       }
 
6360
+
 
6361
+                       public void Abort ()
 
6362
+                       {
 
6363
+                               if (ID == 0) // Ooops
 
6364
+                                       return;
 
6365
+
 
6366
+                               ObjectMirror.AbortInvoke (VM, Thread, ID);
 
6367
+                       }
 
6368
+               }
 
6369
+
 
6370
+               internal static IInvokeAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
6371
+                       if (thread == null)
 
6372
+                               throw new ArgumentNullException ("thread");
 
6373
+                       if (method == null)
 
6374
+                               throw new ArgumentNullException ("method");
 
6375
+                       if (arguments == null)
 
6376
+                               arguments = new Value [0];
 
6377
+
 
6378
+                       InvokeFlags f = InvokeFlags.NONE;
 
6379
+
 
6380
+                       if ((options & InvokeOptions.DisableBreakpoints) != 0)
 
6381
+                               f |= InvokeFlags.DISABLE_BREAKPOINTS;
 
6382
+                       if ((options & InvokeOptions.SingleThreaded) != 0)
 
6383
+                               f |= InvokeFlags.SINGLE_THREADED;
 
6384
+
 
6385
+                       InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback };
 
6386
+
 
6387
+                       r.ID = vm.conn.VM_BeginInvokeMethod (thread.Id, method.Id, this_obj != null ? vm.EncodeValue (this_obj) : vm.EncodeValue (vm.CreateValue (null)), vm.EncodeValues (arguments), f, InvokeCB, r);
 
6388
+
 
6389
+                       return r;
 
6390
+               }
 
6391
+
 
6392
+               // This is called when the result of an invoke is received
 
6393
+               static void InvokeCB (ValueImpl v, ValueImpl exc, ErrorCode error, object state) {
 
6394
+                       InvokeAsyncResult r = (InvokeAsyncResult)state;
 
6395
+
 
6396
+                       if (error != 0) {
 
6397
+                               r.ErrorCode = error;
 
6398
+                       } else {
 
6399
+                               r.Value = v;
 
6400
+                               r.Exception = exc;
 
6401
+                       }
 
6402
+
 
6403
+                       r.IsCompleted = true;
 
6404
+                       ((ManualResetEvent)r.AsyncWaitHandle).Set ();
 
6405
+
 
6406
+                       if (r.Callback != null)
 
6407
+                               r.Callback.BeginInvoke (r, null, null);
 
6408
+               }
 
6409
+
 
6410
+           internal static Value EndInvokeMethodInternal (IAsyncResult asyncResult) {
 
6411
+                       if (asyncResult == null)
 
6412
+                               throw new ArgumentNullException ("asyncResult");
 
6413
+
 
6414
+                       InvokeAsyncResult r = (InvokeAsyncResult)asyncResult;
 
6415
+
 
6416
+                       if (!r.IsCompleted)
 
6417
+                               r.AsyncWaitHandle.WaitOne ();
 
6418
+
 
6419
+                       if (r.ErrorCode != 0) {
 
6420
+                               try {
 
6421
+                                       r.VM.ErrorHandler (null, new ErrorHandlerEventArgs () { ErrorCode = r.ErrorCode });
 
6422
+                               } catch (CommandException ex) {
 
6423
+                                       if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
 
6424
+                                               throw new ArgumentException ("Incorrect number or types of arguments", "arguments");
 
6425
+                                       else
 
6426
+                                               throw;
 
6427
+                               }
 
6428
+                               throw new NotImplementedException ();
 
6429
+                       } else {
 
6430
+                               if (r.Exception != null)
 
6431
+                                       throw new InvocationException ((ObjectMirror)r.VM.DecodeValue (r.Exception));
 
6432
+                               else
 
6433
+                                       return r.VM.DecodeValue (r.Value);
 
6434
+                       }
 
6435
+               }
 
6436
+
 
6437
+               internal static Value InvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options) {
 
6438
+                       return EndInvokeMethodInternal (BeginInvokeMethod (vm, thread, method, this_obj, arguments, options, null, null));
 
6439
+               }
 
6440
+
 
6441
+               internal static void AbortInvoke (VirtualMachine vm, ThreadMirror thread, int id)
 
6442
+               {
 
6443
+                       vm.conn.VM_AbortInvoke (thread.Id, id);
 
6444
+               }
 
6445
+       }
 
6446
+}
 
6447
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ParameterInfoMirror.cs
 
6448
===================================================================
 
6449
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6450
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ParameterInfoMirror.cs      2010-06-16 12:45:23.071079918 +0100
 
6451
@@ -0,0 +1,64 @@
 
6452
+using System;
 
6453
+using System.Collections.Generic;
 
6454
+using System.Text;
 
6455
+using System.Reflection;
 
6456
+
 
6457
+namespace Mono.Debugger.Soft
 
6458
+{
 
6459
+       public class ParameterInfoMirror : Mirror {
 
6460
+
 
6461
+               MethodMirror method;
 
6462
+               TypeMirror type;
 
6463
+               string name;
 
6464
+               int pos;
 
6465
+               ParameterAttributes attrs;
 
6466
+
 
6467
+               internal ParameterInfoMirror (MethodMirror method, int pos, TypeMirror type, string name, ParameterAttributes attrs) : base (method.VirtualMachine, 0) {
 
6468
+                       this.method = method;
 
6469
+                       this.pos = pos;
 
6470
+                       this.type = type;
 
6471
+                       this.name = name;
 
6472
+                       this.attrs = attrs;
 
6473
+               }
 
6474
+
 
6475
+               public TypeMirror ParameterType {
 
6476
+                       get {
 
6477
+                               return type;
 
6478
+                       }
 
6479
+               }
 
6480
+
 
6481
+               public MethodMirror Method {
 
6482
+                       get {
 
6483
+                               return method;
 
6484
+                       }
 
6485
+               }
 
6486
+
 
6487
+               public string Name {
 
6488
+                       get {
 
6489
+                               return name;
 
6490
+                       }
 
6491
+               }
 
6492
+
 
6493
+               public int Position {
 
6494
+                       get {
 
6495
+                               return pos;
 
6496
+                       }
 
6497
+               }
 
6498
+
 
6499
+               public ParameterAttributes Attributes {
 
6500
+                       get {
 
6501
+                               return attrs;
 
6502
+                       }
 
6503
+               }
 
6504
+
 
6505
+               public bool IsRetval {
 
6506
+                       get {
 
6507
+                               return (Attributes & ParameterAttributes.Retval) != 0;
 
6508
+                       }
 
6509
+               }
 
6510
+
 
6511
+               public override string ToString () {
 
6512
+                       return String.Format ("ParameterInfo ({0})", Name);
 
6513
+               }
 
6514
+       }
 
6515
+}
 
6516
\ No newline at end of file
 
6517
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs
 
6518
===================================================================
 
6519
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6520
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/PrimitiveValue.cs   2010-06-16 12:45:23.071079918 +0100
 
6521
@@ -0,0 +1,39 @@
 
6522
+using System;
 
6523
+using System.Collections.Generic;
 
6524
+
 
6525
+namespace Mono.Debugger.Soft
 
6526
+{
 
6527
+       /*
 
6528
+        * Represents a value of a primitive type in the debuggee
 
6529
+        */
 
6530
+       public class PrimitiveValue : Value {
 
6531
+
 
6532
+               object value;
 
6533
+
 
6534
+               public PrimitiveValue (VirtualMachine vm, object value) : base (vm, 0) {
 
6535
+                       this.value = value;
 
6536
+               }
 
6537
+
 
6538
+               public object Value {
 
6539
+                       get {
 
6540
+                               return value;
 
6541
+                       }
 
6542
+               }
 
6543
+
 
6544
+               public override bool Equals (object obj) {
 
6545
+                       if (value == obj)
 
6546
+                               return true;
 
6547
+                       if (obj != null && obj is PrimitiveValue)
 
6548
+                               return value == (obj as PrimitiveValue).Value;
 
6549
+                       return base.Equals (obj);
 
6550
+               }
 
6551
+
 
6552
+               public override int GetHashCode () {
 
6553
+                       return base.GetHashCode ();
 
6554
+               }
 
6555
+
 
6556
+               public override string ToString () {
 
6557
+                       return "PrimitiveValue<" + Value + ">";
 
6558
+               }
 
6559
+       }
 
6560
+}
 
6561
\ No newline at end of file
 
6562
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/PropertyInfoMirror.cs
 
6563
===================================================================
 
6564
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6565
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/PropertyInfoMirror.cs       2010-06-16 12:45:23.071079918 +0100
 
6566
@@ -0,0 +1,117 @@
 
6567
+using System;
 
6568
+using System.Collections.Generic;
 
6569
+using System.Text;
 
6570
+using System.Reflection;
 
6571
+using C = Mono.Cecil;
 
6572
+using Mono.Cecil.Metadata;
 
6573
+
 
6574
+namespace Mono.Debugger.Soft
 
6575
+{
 
6576
+       public class PropertyInfoMirror : Mirror {
 
6577
+
 
6578
+               TypeMirror parent;
 
6579
+               string name;
 
6580
+               PropertyAttributes attrs;
 
6581
+               MethodMirror get_method, set_method;
 
6582
+               CustomAttributeDataMirror[] cattrs;
 
6583
+
 
6584
+               public PropertyInfoMirror (TypeMirror parent, long id, string name, MethodMirror get_method, MethodMirror set_method, PropertyAttributes attrs) : base (parent.VirtualMachine, id) {
 
6585
+                       this.parent = parent;
 
6586
+                       this.name = name;
 
6587
+                       this.attrs = attrs;
 
6588
+                       this.get_method = get_method;
 
6589
+                       this.set_method = set_method;
 
6590
+               }
 
6591
+
 
6592
+               public TypeMirror DeclaringType {
 
6593
+                       get {
 
6594
+                               return parent;
 
6595
+                       }
 
6596
+               }
 
6597
+
 
6598
+               public string Name {
 
6599
+                       get {
 
6600
+                               return name;
 
6601
+                       }
 
6602
+               }
 
6603
+
 
6604
+               public TypeMirror PropertyType {
 
6605
+                       get {
 
6606
+                               if (get_method != null)
 
6607
+                                       return get_method.ReturnType;
 
6608
+                               else {
 
6609
+                                       ParameterInfoMirror[] parameters = set_method.GetParameters ();
 
6610
+                                       
 
6611
+                                       return parameters [parameters.Length - 1].ParameterType;
 
6612
+                               }
 
6613
+                       }
 
6614
+               }
 
6615
+
 
6616
+               public PropertyAttributes Attributes {
 
6617
+                       get {
 
6618
+                               return attrs;
 
6619
+                       }
 
6620
+               }
 
6621
+
 
6622
+               public bool IsSpecialName {
 
6623
+                       get {return (Attributes & PropertyAttributes.SpecialName) != 0;}
 
6624
+               }
 
6625
+
 
6626
+               public MethodMirror GetGetMethod ()
 
6627
+               {
 
6628
+                       return GetGetMethod (false);
 
6629
+               }
 
6630
+
 
6631
+               public MethodMirror GetGetMethod (bool nonPublic)
 
6632
+               {
 
6633
+                       if (get_method != null && (nonPublic || get_method.IsPublic))
 
6634
+                               return get_method;
 
6635
+                       else
 
6636
+                               return null;
 
6637
+               }
 
6638
+
 
6639
+               public MethodMirror GetSetMethod ()
 
6640
+               {
 
6641
+                       return GetSetMethod (false);
 
6642
+               }
 
6643
+
 
6644
+               public MethodMirror GetSetMethod (bool nonPublic)
 
6645
+               {
 
6646
+                       if (set_method != null && (nonPublic || set_method.IsPublic))
 
6647
+                               return set_method;
 
6648
+                       else
 
6649
+                               return null;
 
6650
+               }
 
6651
+
 
6652
+               public ParameterInfoMirror[] GetIndexParameters()
 
6653
+               {
 
6654
+                       if (get_method != null)
 
6655
+                               return get_method.GetParameters ();
 
6656
+                       return new ParameterInfoMirror [0];
 
6657
+               }
 
6658
+
 
6659
+               public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
 
6660
+                       return GetCAttrs (null, inherit);
 
6661
+               }
 
6662
+
 
6663
+               public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
 
6664
+                       if (attributeType == null)
 
6665
+                               throw new ArgumentNullException ("attributeType");
 
6666
+                       return GetCAttrs (attributeType, inherit);
 
6667
+               }
 
6668
+
 
6669
+               CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
 
6670
+                       // FIXME: Handle inherit
 
6671
+                       if (cattrs == null) {
 
6672
+                               CattrInfo[] info = vm.conn.Type_GetPropertyCustomAttributes (DeclaringType.Id, id, 0, false);
 
6673
+                               cattrs = CustomAttributeDataMirror.Create (vm, info);
 
6674
+                       }
 
6675
+                       var res = new List<CustomAttributeDataMirror> ();
 
6676
+                       foreach (var attr in cattrs)
 
6677
+                               if (type == null || attr.Constructor.DeclaringType == type)
 
6678
+                                       res.Add (attr);
 
6679
+                       return res.ToArray ();
 
6680
+               }
 
6681
+       }
 
6682
+}
 
6683
+
 
6684
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StackFrame.cs
 
6685
===================================================================
 
6686
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6687
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StackFrame.cs       2010-06-16 12:45:23.071079918 +0100
 
6688
@@ -0,0 +1,189 @@
 
6689
+using System;
 
6690
+using System.Collections.Generic;
 
6691
+using System.Linq;
 
6692
+
 
6693
+namespace Mono.Debugger.Soft
 
6694
+{
 
6695
+       public class StackFrame : Mirror
 
6696
+       {
 
6697
+               ThreadMirror thread;
 
6698
+               MethodMirror method;
 
6699
+               int il_offset;
 
6700
+               Location location;
 
6701
+               StackFrameFlags flags;
 
6702
+
 
6703
+               /*
 
6704
+                * FIXME: Decide on the way to request/handle debugging information:
 
6705
+                * - request the info in bulk for all frames/on demand for individual frames
 
6706
+                * - request the info from the runtime/request only the il offset, and compute
 
6707
+                *   everything else based on this info using the method debug info.
 
6708
+                */
 
6709
+
 
6710
+               internal StackFrame (VirtualMachine vm, long id, ThreadMirror thread, MethodMirror method, int il_offset, StackFrameFlags flags) : base (vm, id) {
 
6711
+                       this.thread = thread;
 
6712
+                       this.method = method;
 
6713
+                       this.il_offset = il_offset;
 
6714
+                       this.flags = flags;
 
6715
+               }
 
6716
+
 
6717
+               public ThreadMirror Thread {
 
6718
+                       get {
 
6719
+                               return thread;
 
6720
+                       }
 
6721
+               }
 
6722
+
 
6723
+               public MethodMirror Method {
 
6724
+                       get {
 
6725
+                               return method;
 
6726
+                       }
 
6727
+               }
 
6728
+
 
6729
+               public Location Location {
 
6730
+                       get {
 
6731
+                               if (location == null) {
 
6732
+                                       int line_number;
 
6733
+
 
6734
+                                       if (il_offset == -1)
 
6735
+                                               line_number = -1;
 
6736
+                                       else
 
6737
+                                               line_number = method.il_offset_to_line_number (il_offset);
 
6738
+
 
6739
+                                       location = new Location (vm, Method, 0, il_offset, method.SourceFile, line_number, 0);
 
6740
+                               }
 
6741
+                               return location;
 
6742
+                       }
 
6743
+               }
 
6744
+
 
6745
+               public string FileName {
 
6746
+                       get {
 
6747
+                               return Location.SourceFile;
 
6748
+                       }
 
6749
+           }
 
6750
+
 
6751
+               public int ILOffset {
 
6752
+                       get {
 
6753
+                               return Location.ILOffset;
 
6754
+                       }
 
6755
+               }
 
6756
+
 
6757
+               public int LineNumber {
 
6758
+                       get {
 
6759
+                               return Location.LineNumber;
 
6760
+                       }
 
6761
+           }
 
6762
+
 
6763
+               public bool IsDebuggerInvoke {
 
6764
+                       get {
 
6765
+                               return (flags & StackFrameFlags.DEBUGGER_INVOKE) != 0;
 
6766
+                       }
 
6767
+               }
 
6768
+
 
6769
+               public Value GetValue (ParameterInfoMirror param) {
 
6770
+                       if (param == null)
 
6771
+                               throw new ArgumentNullException ("param");
 
6772
+                       if (param.Method != Method)
 
6773
+                               throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
 
6774
+                       if (param.IsRetval)
 
6775
+                               throw new ArgumentException ("Parameter represents the method return value.");
 
6776
+
 
6777
+                       // FIXME: Liveness
 
6778
+                       // FIXME: Allow returning the frame return value if possible
 
6779
+                       return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { (- param.Position) - 1 })[0]);
 
6780
+               }
 
6781
+
 
6782
+               public Value GetValue (LocalVariable var) {
 
6783
+                       if (var == null)
 
6784
+                               throw new ArgumentNullException ("var");
 
6785
+                       if (var.Method != Method)
 
6786
+                               throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
 
6787
+
 
6788
+                       // FIXME: Liveness
 
6789
+                       // FIXME: Check for return value
 
6790
+                       // FIXME: Allow returning the frame return value if possible
 
6791
+                       return vm.DecodeValue (vm.conn.StackFrame_GetValues (thread.Id, Id, new int [] { var.GetValueIndex } )[0]);
 
6792
+               }
 
6793
+
 
6794
+               public Value[] GetValues (LocalVariable[] vars) {
 
6795
+                       if (vars == null)
 
6796
+                               throw new ArgumentNullException ("vars");
 
6797
+                       for (int i = 0; i < vars.Length; ++i) {
 
6798
+                               if (vars [i] == null)
 
6799
+                                       throw new ArgumentNullException ("vars");
 
6800
+                               if (vars [i].Method != Method)
 
6801
+                                       throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
 
6802
+                       }
 
6803
+                       int[] pos = new int [vars.Length];
 
6804
+                       for (int i = 0; i < vars.Length; ++i)
 
6805
+                               pos [i] = vars [i].GetValueIndex;
 
6806
+                       return vm.DecodeValues (vm.conn.StackFrame_GetValues (thread.Id, Id, pos));
 
6807
+               }
 
6808
+
 
6809
+               public Value GetArgument (int pos) {
 
6810
+                       return GetValue (Method.GetParameters () [pos]);
 
6811
+               }
 
6812
+
 
6813
+               public Value GetThis () {
 
6814
+                       return vm.DecodeValue (vm.conn.StackFrame_GetThis (thread.Id, Id));
 
6815
+               }
 
6816
+
 
6817
+               public void SetValue (LocalVariable var, Value value) {
 
6818
+                       if (var == null)
 
6819
+                               throw new ArgumentNullException ("var");
 
6820
+                       if (var.Method != Method)
 
6821
+                               throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
 
6822
+                       if (value == null)
 
6823
+                               throw new ArgumentNullException ("value");
 
6824
+                       CheckMirror (value);
 
6825
+                       // FIXME: Liveness
 
6826
+                       // FIXME: Check for return value
 
6827
+                       try {
 
6828
+                               vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { var.GetValueIndex }, new ValueImpl [] { vm.EncodeValue (value) });
 
6829
+                       } catch (CommandException ex) {
 
6830
+                               if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
 
6831
+                                       throw new ArgumentException ("Value does not match the type of the local variable.");
 
6832
+                               else
 
6833
+                                       throw;
 
6834
+                       }
 
6835
+               }
 
6836
+
 
6837
+               public void SetValue (ParameterInfoMirror param, Value value) {
 
6838
+                       if (param == null)
 
6839
+                               throw new ArgumentNullException ("param");
 
6840
+                       if (param.Method != Method)
 
6841
+                               throw new ArgumentException ("Parameter doesn't belong to this frame's method.");
 
6842
+                       if (param.IsRetval)
 
6843
+                               throw new ArgumentException ("Parameter represents the method return value.");
 
6844
+                       if (value == null)
 
6845
+                               throw new ArgumentNullException ("value");
 
6846
+                       CheckMirror (value);
 
6847
+
 
6848
+                       // FIXME: Liveness
 
6849
+                       // FIXME: Allow setting the frame return value if possible
 
6850
+                       try {
 
6851
+                               vm.conn.StackFrame_SetValues (thread.Id, Id, new int [] { (- param.Position) - 1 }, new ValueImpl [] { vm.EncodeValue (value) });
 
6852
+                       } catch (CommandException ex) {
 
6853
+                               if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT)
 
6854
+                                       throw new ArgumentException ("Value does not match the type of the variable.");
 
6855
+                               else
 
6856
+                                       throw;
 
6857
+                       }
 
6858
+               }
 
6859
+
 
6860
+               public IList<LocalVariable> GetVisibleVariables () {
 
6861
+                       if (Location.ILOffset == -1)
 
6862
+                               throw new AbsentInformationException ();
 
6863
+
 
6864
+                       return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset).ToList ();
 
6865
+               }
 
6866
+
 
6867
+               public LocalVariable GetVisibleVariableByName (string name) {
 
6868
+                       if (name == null)
 
6869
+                               throw new ArgumentNullException ("name");
 
6870
+
 
6871
+                       if (Location.ILOffset == -1)
 
6872
+                               throw new AbsentInformationException ();
 
6873
+
 
6874
+                       return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset && l.Name == name).FirstOrDefault ();
 
6875
+               }
 
6876
+    }
 
6877
+}
 
6878
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StepEvent.cs
 
6879
===================================================================
 
6880
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6881
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StepEvent.cs        2010-06-16 12:45:23.071079918 +0100
 
6882
@@ -0,0 +1,27 @@
 
6883
+
 
6884
+namespace Mono.Debugger.Soft
 
6885
+{
 
6886
+       public class StepEvent : Event {
 
6887
+               MethodMirror method;
 
6888
+               long id, loc;
 
6889
+
 
6890
+               internal StepEvent (VirtualMachine vm, int req_id, long thread_id, long id, long loc) : base (EventType.Step, vm, req_id, thread_id) {
 
6891
+                       this.id = id;
 
6892
+                       this.loc = loc;
 
6893
+               }
 
6894
+
 
6895
+               public MethodMirror Method {
 
6896
+                       get {
 
6897
+                               if (method == null)
 
6898
+                                       method = vm.GetMethod (id);
 
6899
+                               return method;
 
6900
+                       }
 
6901
+               }
 
6902
+
 
6903
+               public long Location {
 
6904
+                       get {
 
6905
+                               return loc;
 
6906
+                       }
 
6907
+               }
 
6908
+       }
 
6909
+}
 
6910
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StepEventRequest.cs
 
6911
===================================================================
 
6912
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6913
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StepEventRequest.cs 2010-06-16 12:45:23.071079918 +0100
 
6914
@@ -0,0 +1,64 @@
 
6915
+using System;
 
6916
+using System.Collections.Generic;
 
6917
+
 
6918
+namespace Mono.Debugger.Soft
 
6919
+{
 
6920
+       public enum StepDepth {
 
6921
+               Into = 0,
 
6922
+               Over = 1,
 
6923
+               Out = 2
 
6924
+       }
 
6925
+
 
6926
+       public enum StepSize {
 
6927
+               Min = 0,
 
6928
+               Line = 1
 
6929
+       }
 
6930
+
 
6931
+       public sealed class StepEventRequest : EventRequest {
 
6932
+
 
6933
+               ThreadMirror step_thread;
 
6934
+               StepDepth depth;
 
6935
+               StepSize size;
 
6936
+               
 
6937
+               internal StepEventRequest (VirtualMachine vm, ThreadMirror thread) : base (vm, EventType.Step) {
 
6938
+                       if (thread == null)
 
6939
+                               throw new ArgumentNullException ("thread");
 
6940
+                       CheckMirror (vm, thread);
 
6941
+                       this.step_thread = thread;
 
6942
+                       Depth = StepDepth.Into;
 
6943
+                       Size = StepSize.Min;
 
6944
+               }
 
6945
+
 
6946
+               public override void Enable () {
 
6947
+                       var mods = new List <Modifier> ();
 
6948
+                       mods.Add (new StepModifier () { Thread = step_thread.Id, Depth = (int)Depth, Size = (int)Size });
 
6949
+                       SendReq (mods);
 
6950
+               }
 
6951
+
 
6952
+               public new ThreadMirror Thread {
 
6953
+                       get {
 
6954
+                               return step_thread;
 
6955
+                       }
 
6956
+               }
 
6957
+
 
6958
+               public StepDepth Depth {
 
6959
+                       get {
 
6960
+                               return depth;
 
6961
+                       }
 
6962
+                       set {
 
6963
+                               CheckDisabled ();
 
6964
+                               depth = value;
 
6965
+                       }
 
6966
+               }
 
6967
+
 
6968
+               public StepSize Size {
 
6969
+                       get {
 
6970
+                               return size;
 
6971
+                       }
 
6972
+                       set {
 
6973
+                               CheckDisabled ();
 
6974
+                               size = value;
 
6975
+                       }
 
6976
+               }
 
6977
+       }
 
6978
+}
 
6979
\ No newline at end of file
 
6980
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StringMirror.cs
 
6981
===================================================================
 
6982
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
6983
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StringMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
6984
@@ -0,0 +1,17 @@
 
6985
+using System;
 
6986
+using System.Collections;
 
6987
+
 
6988
+namespace Mono.Debugger.Soft
 
6989
+{
 
6990
+       public class StringMirror : ObjectMirror {
 
6991
+
 
6992
+               internal StringMirror (VirtualMachine vm, long id) : base (vm, id) {
 
6993
+               }
 
6994
+
 
6995
+               public string Value {
 
6996
+                       get {
 
6997
+                               return vm.conn.String_GetValue (id);
 
6998
+                       }
 
6999
+               }
 
7000
+       }
 
7001
+}
 
7002
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs
 
7003
===================================================================
 
7004
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7005
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/StructMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
7006
@@ -0,0 +1,71 @@
 
7007
+using System;
 
7008
+using System.Collections.Generic;
 
7009
+
 
7010
+namespace Mono.Debugger.Soft
 
7011
+{
 
7012
+       /*
 
7013
+        * Represents a valuetype value in the debuggee
 
7014
+        */
 
7015
+       public class StructMirror : Value {
 
7016
+       
 
7017
+               TypeMirror type;
 
7018
+               Value[] fields;
 
7019
+
 
7020
+               internal StructMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, 0) {
 
7021
+                       this.type = type;
 
7022
+                       this.fields = fields;
 
7023
+               }
 
7024
+
 
7025
+               public TypeMirror Type {
 
7026
+                       get {
 
7027
+                               return type;
 
7028
+                       }
 
7029
+               }
 
7030
+
 
7031
+               public Value[] Fields {
 
7032
+                       get {
 
7033
+                               return fields;
 
7034
+                       }
 
7035
+               }
 
7036
+
 
7037
+               public Value this [String field] {
 
7038
+                       get {
 
7039
+                               FieldInfoMirror[] field_info = Type.GetFields ();
 
7040
+                               int nf = 0;
 
7041
+                               for (int i = 0; i < field_info.Length; ++i) {
 
7042
+                                       if (!field_info [i].IsStatic) {
 
7043
+                                               if (field_info [i].Name == field)
 
7044
+                                                       return Fields [nf];
 
7045
+                                               nf++;
 
7046
+                                       }
 
7047
+                               }
 
7048
+                               throw new ArgumentException ("Unknown struct field '" + field + "'.", "field");
 
7049
+                       }
 
7050
+               }
 
7051
+
 
7052
+               internal void SetField (int index, Value value) {
 
7053
+                       fields [index] = value;
 
7054
+               }
 
7055
+
 
7056
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
 
7057
+                       return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
 
7058
+               }
 
7059
+
 
7060
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
 
7061
+                       return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, options);
 
7062
+               }
 
7063
+
 
7064
+               [Obsolete ("Use the overload without the 'vm' argument")]
 
7065
+               public IAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
7066
+                       return ObjectMirror.BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
 
7067
+               }
 
7068
+
 
7069
+               public IAsyncResult BeginInvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
7070
+                       return ObjectMirror.BeginInvokeMethod (vm, thread, method, this, arguments, options, callback, state);
 
7071
+               }
 
7072
+
 
7073
+               public Value EndInvokeMethod (IAsyncResult asyncResult) {
 
7074
+                       return ObjectMirror.EndInvokeMethodInternal (asyncResult);
 
7075
+               }
 
7076
+       }
 
7077
+}
 
7078
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/SuspendPolicy.cs
 
7079
===================================================================
 
7080
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7081
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/SuspendPolicy.cs    2010-06-16 12:45:23.071079918 +0100
 
7082
@@ -0,0 +1,10 @@
 
7083
+
 
7084
+namespace Mono.Debugger.Soft
 
7085
+{
 
7086
+       // Keep it in sync with debugger-agent.h
 
7087
+       public enum SuspendPolicy {
 
7088
+               None = 0,
 
7089
+               EventThread = 1,
 
7090
+               All = 2
 
7091
+       }
 
7092
+}
 
7093
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadDeathEvent.cs
 
7094
===================================================================
 
7095
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7096
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadDeathEvent.cs 2010-06-16 12:45:23.071079918 +0100
 
7097
@@ -0,0 +1,8 @@
 
7098
+
 
7099
+namespace Mono.Debugger.Soft
 
7100
+{
 
7101
+       public class ThreadDeathEvent : Event {
 
7102
+               internal ThreadDeathEvent (VirtualMachine vm, int req_id, long id) : base (EventType.ThreadDeath, vm, req_id, id) {
 
7103
+               }
 
7104
+       }
 
7105
+}
 
7106
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadMirror.cs
 
7107
===================================================================
 
7108
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7109
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadMirror.cs     2010-06-16 12:45:23.071079918 +0100
 
7110
@@ -0,0 +1,65 @@
 
7111
+using System;
 
7112
+using System.Threading;
 
7113
+
 
7114
+namespace Mono.Debugger.Soft
 
7115
+{
 
7116
+       public class ThreadMirror : ObjectMirror
 
7117
+       {
 
7118
+               string name;
 
7119
+
 
7120
+               internal ThreadMirror (VirtualMachine vm, long id) : base (vm, id) {
 
7121
+               }
 
7122
+
 
7123
+               // FIXME: Cache, invalidate when the thread/runtime is resumed
 
7124
+               public StackFrame[] GetFrames () {
 
7125
+                       FrameInfo[] frame_info = vm.conn.Thread_GetFrameInfo (id, 0, -1);
 
7126
+
 
7127
+                       StackFrame[] frames = new StackFrame [frame_info.Length];
 
7128
+                       for (int i = 0; i < frame_info.Length; ++i) {
 
7129
+                               FrameInfo info = (FrameInfo)frame_info [i];
 
7130
+                               MethodMirror method = vm.GetMethod (info.method);
 
7131
+                               frames [i] = new StackFrame (vm, info.id, this, method, info.il_offset, info.flags);
 
7132
+                       }
 
7133
+
 
7134
+                       return frames;
 
7135
+           }
 
7136
+
 
7137
+               public string Name {
 
7138
+                       get {
 
7139
+                               if (name == null)
 
7140
+                                       name = vm.conn.Thread_GetName (id);
 
7141
+                               return name;
 
7142
+                       }
 
7143
+           }
 
7144
+
 
7145
+               public new long Id {
 
7146
+                       get {
 
7147
+                               return id;
 
7148
+                       }
 
7149
+               }
 
7150
+
 
7151
+               public ThreadState ThreadState {
 
7152
+                       get {
 
7153
+                               return (ThreadState)vm.conn.Thread_GetState (id);
 
7154
+                       }
 
7155
+               }
 
7156
+
 
7157
+               public bool IsThreadPoolThread {
 
7158
+                       get {
 
7159
+                               ThreadInfo info = vm.conn.Thread_GetInfo (id);
 
7160
+
 
7161
+                               return info.is_thread_pool;
 
7162
+                       }
 
7163
+               }
 
7164
+
 
7165
+               /*
 
7166
+                * Return a unique identifier for this thread, multiple ThreadMirror objects
 
7167
+                * may have the same ThreadId because of appdomains.
 
7168
+                */
 
7169
+               public long ThreadId {
 
7170
+                       get {
 
7171
+                               return vm.conn.Thread_GetId (id);
 
7172
+                       }
 
7173
+               }
 
7174
+    }
 
7175
+}
 
7176
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadStartEvent.cs
 
7177
===================================================================
 
7178
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7179
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/ThreadStartEvent.cs 2010-06-16 12:45:23.071079918 +0100
 
7180
@@ -0,0 +1,8 @@
 
7181
+
 
7182
+namespace Mono.Debugger.Soft
 
7183
+{
 
7184
+       public class ThreadStartEvent : Event {
 
7185
+               internal ThreadStartEvent (VirtualMachine vm, int req_id, long id) : base (EventType.ThreadStart, vm, req_id, id) {
 
7186
+               }
 
7187
+       }
 
7188
+}
 
7189
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/TypeLoadEvent.cs
 
7190
===================================================================
 
7191
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7192
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/TypeLoadEvent.cs    2010-06-16 12:45:23.071079918 +0100
 
7193
@@ -0,0 +1,20 @@
 
7194
+
 
7195
+namespace Mono.Debugger.Soft
 
7196
+{
 
7197
+       public class TypeLoadEvent : Event {
 
7198
+               TypeMirror type;
 
7199
+               long id;
 
7200
+
 
7201
+               internal TypeLoadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.TypeLoad, vm, req_id, thread_id) {
 
7202
+                       this.id = id;
 
7203
+               }
 
7204
+
 
7205
+               public TypeMirror Type {
 
7206
+                       get {
 
7207
+                               if (type == null)
 
7208
+                                       type = vm.GetType (id);
 
7209
+                               return type;
 
7210
+                       }
 
7211
+               }
 
7212
+       }
 
7213
+}
 
7214
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
 
7215
===================================================================
 
7216
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7217
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs       2010-06-16 12:45:23.071079918 +0100
 
7218
@@ -0,0 +1,650 @@
 
7219
+using System;
 
7220
+using System.Collections.Generic;
 
7221
+using System.Reflection;
 
7222
+using C = Mono.Cecil;
 
7223
+using Mono.Cecil.Metadata;
 
7224
+
 
7225
+namespace Mono.Debugger.Soft
 
7226
+{
 
7227
+       /*
 
7228
+        * Represents a type in the remote virtual machine.
 
7229
+        * It might be better to make this a subclass of Type, but that could be
 
7230
+        * difficult as some of our methods like GetMethods () return Mirror objects.
 
7231
+        */
 
7232
+       public class TypeMirror : Mirror
 
7233
+       {
 
7234
+               MethodMirror[] methods;
 
7235
+               AssemblyMirror ass;
 
7236
+               ModuleMirror module;
 
7237
+               C.TypeDefinition meta;
 
7238
+               FieldInfoMirror[] fields;
 
7239
+               PropertyInfoMirror[] properties;
 
7240
+               TypeInfo info;
 
7241
+               TypeMirror base_type, element_type;
 
7242
+               TypeMirror[] nested;
 
7243
+               CustomAttributeDataMirror[] cattrs;
 
7244
+
 
7245
+               internal const BindingFlags DefaultBindingFlags =
 
7246
+               BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
 
7247
+
 
7248
+               internal TypeMirror (VirtualMachine vm, long id) : base (vm, id) {
 
7249
+               }
 
7250
+
 
7251
+               public string Name {
 
7252
+                       get {
 
7253
+                               return GetInfo ().name;
 
7254
+                       }
 
7255
+           }
 
7256
+
 
7257
+               public string Namespace {
 
7258
+                       get {
 
7259
+                               return GetInfo ().ns;
 
7260
+                       }
 
7261
+           }
 
7262
+
 
7263
+               public AssemblyMirror Assembly {
 
7264
+                       get {
 
7265
+                               if (ass == null) {
 
7266
+                                       ass = vm.GetAssembly (GetInfo ().assembly);
 
7267
+                               }
 
7268
+                               return ass;
 
7269
+                       }
 
7270
+               }
 
7271
+
 
7272
+               public ModuleMirror Module {
 
7273
+                       get {
 
7274
+                               if (module == null) {
 
7275
+                                       module = vm.GetModule (GetInfo ().module);
 
7276
+                               }                                                                                  
 
7277
+                               return module;
 
7278
+                       }
 
7279
+               }
 
7280
+
 
7281
+               public int MetadataToken {
 
7282
+                       get {
 
7283
+                               return GetInfo ().token;
 
7284
+                       }
 
7285
+               }
 
7286
+
 
7287
+               public TypeAttributes Attributes {
 
7288
+                       get {
 
7289
+                               return (TypeAttributes)GetInfo ().attributes;
 
7290
+                       }
 
7291
+               }
 
7292
+
 
7293
+               public TypeMirror BaseType {
 
7294
+                       get {
 
7295
+                               // FIXME: base_type could be null for object/interfaces
 
7296
+                               if (base_type == null) {
 
7297
+                                       base_type = vm.GetType (GetInfo ().base_type);
 
7298
+                               }
 
7299
+                               return base_type;
 
7300
+                       }
 
7301
+               }
 
7302
+
 
7303
+               public int GetArrayRank () {
 
7304
+                       GetInfo ();
 
7305
+                       if (info.rank == 0)
 
7306
+                               throw new ArgumentException ("Type must be an array type.");
 
7307
+                       return info.rank;
 
7308
+               }
 
7309
+
 
7310
+
 
7311
+               public bool IsAbstract {
 
7312
+                       get {
 
7313
+                               return (Attributes & TypeAttributes.Abstract) != 0;
 
7314
+                       }
 
7315
+               }
 
7316
+
 
7317
+               public bool IsAnsiClass {
 
7318
+                       get {
 
7319
+                               return (Attributes & TypeAttributes.StringFormatMask)
 
7320
+                               == TypeAttributes.AnsiClass;
 
7321
+                       }
 
7322
+               }
 
7323
+
 
7324
+               public bool IsArray {
 
7325
+                       get {
 
7326
+                               return IsArrayImpl ();
 
7327
+                       }
 
7328
+               }
 
7329
+
 
7330
+               public bool IsAutoClass {
 
7331
+                       get {
 
7332
+                               return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
 
7333
+                       }
 
7334
+               }
 
7335
+
 
7336
+               public bool IsAutoLayout {
 
7337
+                       get {
 
7338
+                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
 
7339
+                       }
 
7340
+               }
 
7341
+
 
7342
+               public bool IsByRef {
 
7343
+                       get {
 
7344
+                               return IsByRefImpl ();
 
7345
+                       }
 
7346
+               }
 
7347
+
 
7348
+               public bool IsClass {
 
7349
+                       get {
 
7350
+                               if (IsInterface)
 
7351
+                                       return false;
 
7352
+
 
7353
+                               return !IsValueType;
 
7354
+                       }
 
7355
+               }
 
7356
+
 
7357
+               public bool IsCOMObject {
 
7358
+                       get {
 
7359
+                               return IsCOMObjectImpl ();
 
7360
+                       }
 
7361
+               }
 
7362
+
 
7363
+               public bool IsContextful {
 
7364
+                       get {
 
7365
+                               return IsContextfulImpl ();
 
7366
+                       }
 
7367
+               }
 
7368
+
 
7369
+               public bool IsEnum {
 
7370
+                       get {
 
7371
+                               return GetInfo ().is_enum;
 
7372
+                       }
 
7373
+               }
 
7374
+
 
7375
+               public bool IsExplicitLayout {
 
7376
+                       get {
 
7377
+                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
 
7378
+                       }
 
7379
+               }
 
7380
+
 
7381
+               public bool IsImport {
 
7382
+                       get {
 
7383
+                               return (Attributes & TypeAttributes.Import) != 0;
 
7384
+                       }
 
7385
+               }
 
7386
+
 
7387
+               public bool IsInterface {
 
7388
+                       get {
 
7389
+                               return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
 
7390
+                       }
 
7391
+               }
 
7392
+
 
7393
+               public bool IsLayoutSequential {
 
7394
+                       get {
 
7395
+                               return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
 
7396
+                       }
 
7397
+               }
 
7398
+
 
7399
+               public bool IsMarshalByRef {
 
7400
+                       get {
 
7401
+                               return IsMarshalByRefImpl ();
 
7402
+                       }
 
7403
+               }
 
7404
+
 
7405
+               public bool IsNestedAssembly {
 
7406
+                       get {
 
7407
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
 
7408
+                       }
 
7409
+               }
 
7410
+
 
7411
+               public bool IsNestedFamANDAssem {
 
7412
+                       get {
 
7413
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
 
7414
+                       }
 
7415
+               }
 
7416
+
 
7417
+               public bool IsNestedFamily {
 
7418
+                       get {
 
7419
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
 
7420
+                       }
 
7421
+               }
 
7422
+
 
7423
+               public bool IsNestedFamORAssem {
 
7424
+                       get {
 
7425
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
 
7426
+                       }
 
7427
+               }
 
7428
+
 
7429
+               public bool IsNestedPrivate {
 
7430
+                       get {
 
7431
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
 
7432
+                       }
 
7433
+               }
 
7434
+
 
7435
+               public bool IsNestedPublic {
 
7436
+                       get {
 
7437
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
 
7438
+                       }
 
7439
+               }
 
7440
+
 
7441
+               public bool IsNotPublic {
 
7442
+                       get {
 
7443
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
 
7444
+                       }
 
7445
+               }
 
7446
+
 
7447
+               public bool IsPointer {
 
7448
+                       get {
 
7449
+                               return IsPointerImpl ();
 
7450
+                       }
 
7451
+               }
 
7452
+
 
7453
+               public bool IsPrimitive {
 
7454
+                       get {
 
7455
+                               return IsPrimitiveImpl ();
 
7456
+                       }
 
7457
+               }
 
7458
+
 
7459
+               public bool IsPublic {
 
7460
+                       get {
 
7461
+                               return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
 
7462
+                       }
 
7463
+               }
 
7464
+
 
7465
+               public bool IsSealed {
 
7466
+                       get {
 
7467
+                               return (Attributes & TypeAttributes.Sealed) != 0;
 
7468
+                       }
 
7469
+               }
 
7470
+
 
7471
+               public bool IsSerializable {
 
7472
+                       get {
 
7473
+                               if ((Attributes & TypeAttributes.Serializable) != 0)
 
7474
+                                       return true;
 
7475
+
 
7476
+                               // FIXME:
 
7477
+                               return false;
 
7478
+                       }
 
7479
+               }
 
7480
+
 
7481
+               public bool IsSpecialName {
 
7482
+                       get {
 
7483
+                               return (Attributes & TypeAttributes.SpecialName) != 0;
 
7484
+                       }
 
7485
+               }
 
7486
+
 
7487
+               public bool IsUnicodeClass {
 
7488
+                       get {
 
7489
+                               return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
 
7490
+                       }
 
7491
+               }
 
7492
+
 
7493
+               public bool IsValueType {
 
7494
+                       get {
 
7495
+                               return IsValueTypeImpl ();
 
7496
+                       }
 
7497
+               }
 
7498
+
 
7499
+               public bool HasElementType {
 
7500
+                       get {
 
7501
+                               return HasElementTypeImpl ();
 
7502
+                       }
 
7503
+               }
 
7504
+
 
7505
+               public TypeMirror GetElementType () {
 
7506
+                       GetInfo ();
 
7507
+                       if (element_type == null && info.element_type != 0)
 
7508
+                               element_type = vm.GetType (info.element_type);
 
7509
+                       return element_type;
 
7510
+               }
 
7511
+
 
7512
+               public string FullName {
 
7513
+                       get {
 
7514
+                               return GetInfo ().full_name;
 
7515
+                       }
 
7516
+               }
 
7517
+
 
7518
+               public string CSharpName {
 
7519
+                       get {
 
7520
+                               if (IsArray) {
 
7521
+                                       if (GetArrayRank () == 1)
 
7522
+                                               return GetElementType ().CSharpName + "[]";
 
7523
+                                       else {
 
7524
+                                               string ranks = "";
 
7525
+                                               for (int i = 0; i < GetArrayRank (); ++i)
 
7526
+                                                       ranks += ',';
 
7527
+                                               return GetElementType ().CSharpName + "[" + ranks + "]";
 
7528
+                                       }
 
7529
+                               }
 
7530
+                               if (IsPrimitive) {
 
7531
+                                       switch (Name) {
 
7532
+                                       case "Byte":
 
7533
+                                               return "byte";
 
7534
+                                       case "Int32":
 
7535
+                                               return "int";
 
7536
+                                       case "Boolean":
 
7537
+                                               return "bool";
 
7538
+                                       default:
 
7539
+                                               return FullName;
 
7540
+                                       }
 
7541
+                               }
 
7542
+                               // FIXME: Only do this for real corlib types
 
7543
+                               if (Namespace == "System") {
 
7544
+                                       string s = Name;
 
7545
+                                       switch (s) {
 
7546
+                                       case "String":
 
7547
+                                               return "string";
 
7548
+                                       default:
 
7549
+                                               return FullName;
 
7550
+                                       }
 
7551
+                               } else {
 
7552
+                                       return FullName;
 
7553
+                               }
 
7554
+                       }
 
7555
+               }
 
7556
+
 
7557
+               public MethodMirror[] GetMethods () {
 
7558
+                       if (methods == null) {
 
7559
+                               long[] ids = vm.conn.Type_GetMethods (id);
 
7560
+                               MethodMirror[] m = new MethodMirror [ids.Length];
 
7561
+                               for (int i = 0; i < ids.Length; ++i) {
 
7562
+                                       m [i] = vm.GetMethod (ids [i]);
 
7563
+                               }
 
7564
+                               methods = m;
 
7565
+                       }
 
7566
+                       return methods;
 
7567
+               }
 
7568
+
 
7569
+               // FIXME: Sync this with Type
 
7570
+               public MethodMirror GetMethod (string name) {
 
7571
+                       foreach (var m in GetMethods ())
 
7572
+                               if (m.Name == name)
 
7573
+                                       return m;
 
7574
+                       return null;
 
7575
+               }
 
7576
+
 
7577
+               public FieldInfoMirror[] GetFields () {
 
7578
+                       if (fields != null)
 
7579
+                               return fields;
 
7580
+
 
7581
+                       string[] names;
 
7582
+                       long[] types;
 
7583
+                       int[] attrs;
 
7584
+                       long[] ids = vm.conn.Type_GetFields (id, out names, out types, out attrs);
 
7585
+
 
7586
+                       FieldInfoMirror[] res = new FieldInfoMirror [ids.Length];
 
7587
+                       for (int i = 0; i < res.Length; ++i)
 
7588
+                               res [i] = new FieldInfoMirror (this, ids [i], names [i], vm.GetType (types [i]), (FieldAttributes)attrs [i]);
 
7589
+
 
7590
+                       fields = res;
 
7591
+                       return fields;
 
7592
+               }
 
7593
+
 
7594
+               public FieldInfoMirror GetField (string name) {
 
7595
+                       if (name == null)
 
7596
+                               throw new ArgumentNullException ("name");
 
7597
+                       foreach (var f in GetFields ())
 
7598
+                               if (f.Name == name)
 
7599
+                                       return f;
 
7600
+                       return null;
 
7601
+               }
 
7602
+
 
7603
+               public TypeMirror[] GetNestedTypes ()
 
7604
+               {
 
7605
+                       return GetNestedTypes (DefaultBindingFlags);
 
7606
+               }
 
7607
+
 
7608
+               public TypeMirror[] GetNestedTypes (BindingFlags bindingAttr) {
 
7609
+                       if (nested != null)
 
7610
+                               return nested;
 
7611
+
 
7612
+                       // FIXME: bindingAttr
 
7613
+                       GetInfo ();
 
7614
+                       var arr = new TypeMirror [info.nested.Length];
 
7615
+                       for (int i = 0; i < arr.Length; ++i)
 
7616
+                               arr [i] = vm.GetType (info.nested [i]);
 
7617
+                       nested = arr;
 
7618
+
 
7619
+                       return nested;
 
7620
+               }
 
7621
+
 
7622
+               public PropertyInfoMirror[] GetProperties () {
 
7623
+                       return GetProperties (DefaultBindingFlags);
 
7624
+               }
 
7625
+
 
7626
+               public PropertyInfoMirror[] GetProperties (BindingFlags bindingAttr) {
 
7627
+                       if (properties != null)
 
7628
+                               return properties;
 
7629
+
 
7630
+                       PropInfo[] info = vm.conn.Type_GetProperties (id);
 
7631
+
 
7632
+                       PropertyInfoMirror[] res = new PropertyInfoMirror [info.Length];
 
7633
+                       for (int i = 0; i < res.Length; ++i)
 
7634
+                               res [i] = new PropertyInfoMirror (this, info [i].id, info [i].name, vm.GetMethod (info [i].get_method), vm.GetMethod (info [i].set_method), (PropertyAttributes)info [i].attrs);
 
7635
+
 
7636
+                       properties = res;
 
7637
+                       return properties;
 
7638
+               }
 
7639
+
 
7640
+               public PropertyInfoMirror GetProperty (string name) {
 
7641
+                       if (name == null)
 
7642
+                               throw new ArgumentNullException ("name");
 
7643
+                       foreach (var p in GetProperties ())
 
7644
+                               if (p.Name == name)
 
7645
+                                       return p;
 
7646
+                       return null;
 
7647
+               }
 
7648
+
 
7649
+               public virtual bool IsAssignableFrom (TypeMirror c) {
 
7650
+                       if (c == null)
 
7651
+                               throw new ArgumentNullException ("c");
 
7652
+
 
7653
+                       CheckMirror (c);
 
7654
+
 
7655
+                       // This is complex so do it in the debuggee
 
7656
+                       return vm.conn.Type_IsAssignableFrom (id, c.Id);
 
7657
+               }
 
7658
+
 
7659
+               public Value GetValue (FieldInfoMirror field) {
 
7660
+                       return GetValues (new FieldInfoMirror [] { field }) [0];
 
7661
+               }
 
7662
+
 
7663
+               public Value[] GetValues (IList<FieldInfoMirror> fields) {
 
7664
+                       if (fields == null)
 
7665
+                               throw new ArgumentNullException ("fields");
 
7666
+                       foreach (FieldInfoMirror f in fields) {
 
7667
+                               if (f == null)
 
7668
+                                       throw new ArgumentNullException ("field");
 
7669
+                               CheckMirror (f);
 
7670
+                       }
 
7671
+                       long[] ids = new long [fields.Count];
 
7672
+                       for (int i = 0; i < fields.Count; ++i)
 
7673
+                               ids [i] = fields [i].Id;
 
7674
+                       try {
 
7675
+                               return vm.DecodeValues (vm.conn.Type_GetValues (id, ids));
 
7676
+                       } catch (CommandException ex) {
 
7677
+                               if (ex.ErrorCode == ErrorCode.INVALID_FIELDID)
 
7678
+                                       throw new ArgumentException ("One of the fields is not valid for this type.", "fields");
 
7679
+                               else
 
7680
+                                       throw;
 
7681
+                       }
 
7682
+               }
 
7683
+
 
7684
+               public void SetValues (IList<FieldInfoMirror> fields, Value[] values) {
 
7685
+                       if (fields == null)
 
7686
+                               throw new ArgumentNullException ("fields");
 
7687
+                       if (values == null)
 
7688
+                               throw new ArgumentNullException ("values");
 
7689
+                       foreach (FieldInfoMirror f in fields) {
 
7690
+                               if (f == null)
 
7691
+                                       throw new ArgumentNullException ("field");
 
7692
+                               CheckMirror (f);
 
7693
+                       }
 
7694
+                       foreach (Value v in values) {
 
7695
+                               if (v == null)
 
7696
+                                       throw new ArgumentNullException ("values");
 
7697
+                               CheckMirror (v);
 
7698
+                       }
 
7699
+                       long[] ids = new long [fields.Count];
 
7700
+                       for (int i = 0; i < fields.Count; ++i)
 
7701
+                               ids [i] = fields [i].Id;
 
7702
+                       try {
 
7703
+                               vm.conn.Type_SetValues (id, ids, vm.EncodeValues (values));
 
7704
+                       } catch (CommandException ex) {
 
7705
+                               if (ex.ErrorCode == ErrorCode.INVALID_FIELDID)
 
7706
+                                       throw new ArgumentException ("One of the fields is not valid for this type.", "fields");
 
7707
+                               else
 
7708
+                                       throw;
 
7709
+                       }
 
7710
+               }
 
7711
+
 
7712
+               public void SetValue (FieldInfoMirror field, Value value) {
 
7713
+                       SetValues (new FieldInfoMirror [] { field }, new Value [] { value });
 
7714
+               }
 
7715
+
 
7716
+               public ObjectMirror GetTypeObject () {
 
7717
+                       return vm.GetObject (vm.conn.Type_GetObject (id));
 
7718
+               }
 
7719
+
 
7720
+               /*
 
7721
+                * Return a list of source files without path info, where methods of 
 
7722
+                * this type are defined. Return an empty list if the information is not 
 
7723
+                * available. 
 
7724
+                * This can be used by a debugger to find out which types occur in a 
 
7725
+                * given source file, to filter the list of methods whose locations
 
7726
+                * have to be checked when placing breakpoints.
 
7727
+                */
 
7728
+               public string[] GetSourceFiles () {
 
7729
+                       return GetSourceFiles (false);
 
7730
+               }
 
7731
+
 
7732
+               public string[] GetSourceFiles (bool return_full_paths) {
 
7733
+                       return vm.conn.Type_GetSourceFiles (id, return_full_paths);
 
7734
+               }
 
7735
+
 
7736
+               public C.TypeDefinition Metadata {
 
7737
+                       get {
 
7738
+                               if (meta == null) {
 
7739
+                                       if (Assembly.Metadata == null || MetadataToken == 0)
 
7740
+                                               return null;
 
7741
+                                       meta = (C.TypeDefinition)Assembly.Metadata.MainModule.LookupByToken (new MetadataToken (MetadataToken));
 
7742
+                               }
 
7743
+                               return meta;
 
7744
+                       }
 
7745
+               }
 
7746
+
 
7747
+               TypeInfo GetInfo () {
 
7748
+                       if (info == null)
 
7749
+                               info = vm.conn.Type_GetInfo (id);
 
7750
+                       return info;
 
7751
+               }
 
7752
+
 
7753
+               protected virtual TypeAttributes GetAttributeFlagsImpl () {
 
7754
+                       return (TypeAttributes)GetInfo ().attributes;
 
7755
+               }
 
7756
+
 
7757
+               protected virtual bool HasElementTypeImpl () {
 
7758
+                       return IsArray || IsByRef || IsPointer;
 
7759
+               }
 
7760
+
 
7761
+               protected virtual bool IsArrayImpl () {
 
7762
+                       return GetInfo ().rank > 0;
 
7763
+               }
 
7764
+
 
7765
+               protected virtual bool IsByRefImpl () {
 
7766
+                       return GetInfo ().is_byref;
 
7767
+               }
 
7768
+
 
7769
+               protected virtual bool IsCOMObjectImpl () {
 
7770
+                       return false;
 
7771
+               }
 
7772
+
 
7773
+               protected virtual bool IsPointerImpl () {
 
7774
+                       return GetInfo ().is_pointer;
 
7775
+               }
 
7776
+
 
7777
+               protected virtual bool IsPrimitiveImpl () {
 
7778
+                       return GetInfo ().is_primitive;
 
7779
+               }
 
7780
+
 
7781
+               protected virtual bool IsValueTypeImpl ()
 
7782
+               {
 
7783
+                       return GetInfo ().is_valuetype;
 
7784
+               }
 
7785
+               
 
7786
+               protected virtual bool IsContextfulImpl ()
 
7787
+               {
 
7788
+                       // FIXME:
 
7789
+                       return false;
 
7790
+               }
 
7791
+
 
7792
+               protected virtual bool IsMarshalByRefImpl ()
 
7793
+               {
 
7794
+                       // FIXME:
 
7795
+                       return false;
 
7796
+               }
 
7797
+
 
7798
+               // Same as Enum.GetUnderlyingType ()
 
7799
+               public TypeMirror EnumUnderlyingType {
 
7800
+                       get {
 
7801
+                               if (!IsEnum)
 
7802
+                                       throw new ArgumentException ("Type is not an enum type.");
 
7803
+                               foreach (FieldInfoMirror f in GetFields ()) {
 
7804
+                                       if (!f.IsStatic)
 
7805
+                                               return f.FieldType;
 
7806
+                               }
 
7807
+                               throw new NotImplementedException ();
 
7808
+                       }
 
7809
+               }
 
7810
+
 
7811
+               /*
 
7812
+                * Creating the custom attributes themselves could modify the behavior of the
 
7813
+                * debuggee, so we return objects similar to the CustomAttributeData objects
 
7814
+                * used by the reflection-only functionality on .net.
 
7815
+                */
 
7816
+               public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
 
7817
+                       return GetCAttrs (null, inherit);
 
7818
+               }
 
7819
+
 
7820
+               public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
 
7821
+                       if (attributeType == null)
 
7822
+                               throw new ArgumentNullException ("attributeType");
 
7823
+                       return GetCAttrs (attributeType, inherit);
 
7824
+               }
 
7825
+
 
7826
+               CustomAttributeDataMirror[] GetCAttrs (TypeMirror type, bool inherit) {
 
7827
+                       // FIXME: Handle inherit
 
7828
+                       if (cattrs == null) {
 
7829
+                               CattrInfo[] info = vm.conn.Type_GetCustomAttributes (id, 0, false);
 
7830
+                               cattrs = CustomAttributeDataMirror.Create (vm, info);
 
7831
+                       }
 
7832
+                       var res = new List<CustomAttributeDataMirror> ();
 
7833
+                       foreach (var attr in cattrs)
 
7834
+                               if (type == null || attr.Constructor.DeclaringType == type)
 
7835
+                                       res.Add (attr);
 
7836
+                       return res.ToArray ();
 
7837
+               }
 
7838
+
 
7839
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
 
7840
+                       return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, InvokeOptions.None);
 
7841
+               }
 
7842
+
 
7843
+               public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
 
7844
+                       return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
 
7845
+               }
 
7846
+
 
7847
+               [Obsolete ("Use the overload without the 'vm' argument")]
 
7848
+               public IAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
7849
+                       return ObjectMirror.BeginInvokeMethod (vm, thread, method, null, arguments, options, callback, state);
 
7850
+               }
 
7851
+
 
7852
+               public IAsyncResult BeginInvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) {
 
7853
+                       return ObjectMirror.BeginInvokeMethod (vm, thread, method, null, arguments, options, callback, state);
 
7854
+               }
 
7855
+
 
7856
+               public Value EndInvokeMethod (IAsyncResult asyncResult) {
 
7857
+                       return ObjectMirror.EndInvokeMethodInternal (asyncResult);
 
7858
+               }
 
7859
+
 
7860
+               public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
 
7861
+                       return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, InvokeOptions.None);
 
7862
+               }                       
 
7863
+
 
7864
+               public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
 
7865
+                       return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
 
7866
+               }                       
 
7867
+    }
 
7868
+}
 
7869
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDeathEvent.cs
 
7870
===================================================================
 
7871
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7872
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDeathEvent.cs     2010-06-16 12:45:23.071079918 +0100
 
7873
@@ -0,0 +1,10 @@
 
7874
+using System;
 
7875
+
 
7876
+namespace Mono.Debugger.Soft
 
7877
+{
 
7878
+       public class VMDeathEvent : Event
 
7879
+       {
 
7880
+               public VMDeathEvent (VirtualMachine vm, int req_id) : base (EventType.VMDeath, vm, req_id, -1) {
 
7881
+               }
 
7882
+    }
 
7883
+}
 
7884
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDisconnectEvent.cs
 
7885
===================================================================
 
7886
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7887
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDisconnectEvent.cs        2010-06-16 12:45:23.071079918 +0100
 
7888
@@ -0,0 +1,10 @@
 
7889
+using System;
 
7890
+
 
7891
+namespace Mono.Debugger.Soft
 
7892
+{
 
7893
+       public class VMDisconnectEvent : Event
 
7894
+       {
 
7895
+               public VMDisconnectEvent (VirtualMachine vm, int req_id) : base (EventType.VMDisconnect, vm, req_id, -1) {
 
7896
+               }
 
7897
+    }
 
7898
+}
 
7899
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDisconnectedException.cs
 
7900
===================================================================
 
7901
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7902
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMDisconnectedException.cs  2010-06-16 12:45:23.071079918 +0100
 
7903
@@ -0,0 +1,10 @@
 
7904
+using System;
 
7905
+
 
7906
+namespace Mono.Debugger.Soft
 
7907
+{
 
7908
+       public class VMDisconnectedException : Exception {
 
7909
+               
 
7910
+               public VMDisconnectedException () : base () {
 
7911
+               }
 
7912
+       }
 
7913
+}
 
7914
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMMismatchException.cs
 
7915
===================================================================
 
7916
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7917
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMMismatchException.cs      2010-06-16 12:45:23.071079918 +0100
 
7918
@@ -0,0 +1,10 @@
 
7919
+using System;
 
7920
+
 
7921
+namespace Mono.Debugger.Soft
 
7922
+{
 
7923
+       public class VMMismatchException : Exception
 
7924
+       {
 
7925
+               public VMMismatchException () : base () {
 
7926
+               }
 
7927
+       }
 
7928
+}
 
7929
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMStartEvent.cs
 
7930
===================================================================
 
7931
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7932
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VMStartEvent.cs     2010-06-16 12:45:23.071079918 +0100
 
7933
@@ -0,0 +1,10 @@
 
7934
+using System;
 
7935
+
 
7936
+namespace Mono.Debugger.Soft
 
7937
+{
 
7938
+       public class VMStartEvent : Event
 
7939
+       {
 
7940
+               public VMStartEvent (VirtualMachine vm, int req_id, long thread_id) : base (EventType.VMStart, vm, req_id, thread_id) {
 
7941
+               }
 
7942
+    }
 
7943
+}
 
7944
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Value.cs
 
7945
===================================================================
 
7946
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7947
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Value.cs    2010-06-16 12:45:23.071079918 +0100
 
7948
@@ -0,0 +1,14 @@
 
7949
+using System;
 
7950
+using System.Collections.Generic;
 
7951
+
 
7952
+namespace Mono.Debugger.Soft
 
7953
+{
 
7954
+       public abstract class Value : Mirror {
 
7955
+
 
7956
+               // FIXME: Add a 'Value' field
 
7957
+
 
7958
+               internal Value (VirtualMachine vm, long id) : base (vm, id) {
 
7959
+               }
 
7960
+       }
 
7961
+}
 
7962
+
 
7963
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
 
7964
===================================================================
 
7965
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
7966
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs   2010-06-16 12:45:23.071079918 +0100
 
7967
@@ -0,0 +1,571 @@
 
7968
+using System;
 
7969
+using System.IO;
 
7970
+using System.Threading;
 
7971
+using System.Net;
 
7972
+using System.Diagnostics;
 
7973
+using System.Collections;
 
7974
+using System.Collections.Generic;
 
7975
+using Mono.Cecil.Metadata;
 
7976
+
 
7977
+namespace Mono.Debugger.Soft
 
7978
+{
 
7979
+       public class VirtualMachine : Mirror
 
7980
+       {
 
7981
+               Queue queue;
 
7982
+               object queue_monitor;
 
7983
+               object startup_monitor;
 
7984
+               AppDomainMirror root_domain;
 
7985
+               Dictionary<int, EventRequest> requests;
 
7986
+               ITargetProcess process;
 
7987
+
 
7988
+               internal Connection conn;
 
7989
+
 
7990
+               VersionInfo version;
 
7991
+
 
7992
+               internal VirtualMachine (ITargetProcess process, Connection conn) : base () {
 
7993
+                       SetVirtualMachine (this);
 
7994
+                       queue = new Queue ();
 
7995
+                       queue_monitor = new Object ();
 
7996
+                       startup_monitor = new Object ();
 
7997
+                       requests = new Dictionary <int, EventRequest> ();
 
7998
+                       this.conn = conn;
 
7999
+                       this.process = process;
 
8000
+                       conn.ErrorHandler += ErrorHandler;
 
8001
+               }
 
8002
+
 
8003
+               // The standard output of the process is available normally through Process
 
8004
+               public StreamReader StandardOutput { get; set; }
 
8005
+               public StreamReader StandardError { get; set; }
 
8006
+
 
8007
+               
 
8008
+               public Process Process {
 
8009
+                       get {
 
8010
+                               ProcessWrapper pw = process as ProcessWrapper;
 
8011
+                               if (pw == null)
 
8012
+                                   throw new InvalidOperationException ("Process instance not available");
 
8013
+                               return pw.Process;
 
8014
+                       }
 
8015
+               }
 
8016
+
 
8017
+               public ITargetProcess TargetProcess {
 
8018
+                       get {
 
8019
+                               return process;
 
8020
+                       }
 
8021
+               }
 
8022
+
 
8023
+               public AppDomainMirror RootDomain {
 
8024
+                       get {
 
8025
+                               return root_domain;
 
8026
+                       }
 
8027
+           }
 
8028
+
 
8029
+               public EndPoint EndPoint {
 
8030
+                       get {
 
8031
+                               return conn.EndPoint;
 
8032
+                       }
 
8033
+               }
 
8034
+
 
8035
+               public VersionInfo Version {
 
8036
+                       get {
 
8037
+                               return version;
 
8038
+                       }
 
8039
+               }
 
8040
+
 
8041
+               public Event GetNextEvent () {
 
8042
+                       lock (queue_monitor) {
 
8043
+                               if (queue.Count == 0)
 
8044
+                                       Monitor.Wait (queue_monitor);
 
8045
+                               return (Event)queue.Dequeue ();
 
8046
+                       }
 
8047
+               }
 
8048
+
 
8049
+               public Event GetNextEvent (int timeout) {
 
8050
+                       throw new NotImplementedException ();
 
8051
+               }
 
8052
+
 
8053
+               public T GetNextEvent<T> () where T : Event {
 
8054
+                       return GetNextEvent () as T;
 
8055
+               }
 
8056
+
 
8057
+               public void Suspend () {
 
8058
+                       conn.VM_Suspend ();
 
8059
+           }
 
8060
+
 
8061
+               public void Resume () {
 
8062
+                       try {
 
8063
+                               conn.VM_Resume ();
 
8064
+                       } catch (CommandException ex) {
 
8065
+                               if (ex.ErrorCode == ErrorCode.NOT_SUSPENDED)
 
8066
+                                       throw new InvalidOperationException ("The vm is not suspended.");
 
8067
+                               else
 
8068
+                                       throw;
 
8069
+                       }
 
8070
+           }
 
8071
+
 
8072
+               public void Exit (int exitCode) {
 
8073
+                       conn.VM_Exit (exitCode);
 
8074
+               }
 
8075
+
 
8076
+               public void Dispose () {
 
8077
+                       conn.VM_Dispose ();
 
8078
+                       conn.Close ();
 
8079
+                       notify_vm_event (EventType.VMDisconnect, 0, 0, null);
 
8080
+               }
 
8081
+
 
8082
+               public IList<ThreadMirror> GetThreads () {
 
8083
+                       long[] ids = vm.conn.VM_GetThreads ();
 
8084
+                       ThreadMirror[] res = new ThreadMirror [ids.Length];
 
8085
+                       for (int i = 0; i < ids.Length; ++i)
 
8086
+                               res [i] = GetThread (ids [i]);
 
8087
+                       return res;
 
8088
+               }
 
8089
+
 
8090
+               // Same as the mirrorOf methods in JDI
 
8091
+               public PrimitiveValue CreateValue (object value) {
 
8092
+                       if (value == null)
 
8093
+                               return new PrimitiveValue (vm, null);
 
8094
+
 
8095
+                       if (!value.GetType ().IsPrimitive)
 
8096
+                               throw new ArgumentException ("value must be of a primitive type instead of '" + value.GetType () + "'", "value");
 
8097
+
 
8098
+                       return new PrimitiveValue (vm, value);
 
8099
+               }
 
8100
+
 
8101
+               public EnumMirror CreateEnumMirror (TypeMirror type, PrimitiveValue value) {
 
8102
+                       return new EnumMirror (this, type, value);
 
8103
+               }
 
8104
+
 
8105
+               //
 
8106
+               // Methods to create event request objects
 
8107
+               //
 
8108
+               public BreakpointEventRequest CreateBreakpointRequest (MethodMirror method, long il_offset) {
 
8109
+                       return new BreakpointEventRequest (this, method, il_offset);
 
8110
+               }
 
8111
+
 
8112
+               public BreakpointEventRequest CreateBreakpointRequest (Location loc) {
 
8113
+                       if (loc == null)
 
8114
+                               throw new ArgumentNullException ("loc");
 
8115
+                       CheckMirror (loc);
 
8116
+                       return new BreakpointEventRequest (this, loc.Method, loc.ILOffset);
 
8117
+               }
 
8118
+
 
8119
+               public StepEventRequest CreateStepRequest (ThreadMirror thread) {
 
8120
+                       return new StepEventRequest (this, thread);
 
8121
+               }
 
8122
+
 
8123
+               public MethodEntryEventRequest CreateMethodEntryRequest () {
 
8124
+                       return new MethodEntryEventRequest (this);
 
8125
+               }
 
8126
+
 
8127
+               public MethodExitEventRequest CreateMethodExitRequest () {
 
8128
+                       return new MethodExitEventRequest (this);
 
8129
+               }
 
8130
+
 
8131
+               public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type) {
 
8132
+                       return new ExceptionEventRequest (this, exc_type, true, true);
 
8133
+               }
 
8134
+
 
8135
+               public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type, bool caught, bool uncaught) {
 
8136
+                       return new ExceptionEventRequest (this, exc_type, caught, uncaught);
 
8137
+               }
 
8138
+
 
8139
+               public void EnableEvents (params EventType[] events) {
 
8140
+                       foreach (EventType etype in events)
 
8141
+                               conn.EnableEvent (etype, SuspendPolicy.All, null);
 
8142
+               }
 
8143
+
 
8144
+               public BreakpointEventRequest SetBreakpoint (MethodMirror method, long il_offset) {
 
8145
+                       BreakpointEventRequest req = CreateBreakpointRequest (method, il_offset);
 
8146
+
 
8147
+                       req.Enable ();
 
8148
+
 
8149
+                       return req;
 
8150
+               }
 
8151
+
 
8152
+               public void ClearAllBreakpoints () {
 
8153
+                       conn.ClearAllBreakpoints ();
 
8154
+               }
 
8155
+
 
8156
+               internal void queue_event (Event e) {
 
8157
+                       lock (queue_monitor) {
 
8158
+                               queue.Enqueue (e);
 
8159
+                               Monitor.Pulse (queue_monitor);
 
8160
+                       }
 
8161
+               }
 
8162
+
 
8163
+               internal void ErrorHandler (object sender, ErrorHandlerEventArgs args) {
 
8164
+                       switch (args.ErrorCode) {
 
8165
+                       case ErrorCode.INVALID_OBJECT:
 
8166
+                               throw new ObjectCollectedException ();
 
8167
+                       case ErrorCode.INVALID_FRAMEID:
 
8168
+                               throw new InvalidStackFrameException ();
 
8169
+                       case ErrorCode.NOT_SUSPENDED:
 
8170
+                               throw new InvalidOperationException ("The vm is not suspended.");
 
8171
+                       case ErrorCode.NOT_IMPLEMENTED:
 
8172
+                               throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
 
8173
+                       case ErrorCode.ABSENT_INFORMATION:
 
8174
+                               throw new AbsentInformationException ();
 
8175
+                       default:
 
8176
+                               throw new CommandException (args.ErrorCode);
 
8177
+                       }
 
8178
+               }
 
8179
+
 
8180
+               /* Wait for the debuggee to start up and connect to it */
 
8181
+               internal void connect () {
 
8182
+                       conn.Connect ();
 
8183
+
 
8184
+                       // Test the connection
 
8185
+                       version = conn.Version;
 
8186
+                       if (version.MajorVersion != Connection.MAJOR_VERSION)
 
8187
+                               throw new NotSupportedException (String.Format ("The debuggee implements protocol version {0}.{1}, while {2}.{3} is required.", version.MajorVersion, version.MinorVersion, Connection.MAJOR_VERSION, Connection.MINOR_VERSION));
 
8188
+
 
8189
+                       long root_domain_id = conn.RootDomain;
 
8190
+                       root_domain = GetDomain (root_domain_id);
 
8191
+               }
 
8192
+
 
8193
+               internal void notify_vm_event (EventType evtype, int req_id, long thread_id, string vm_uri) {
 
8194
+                       //Console.WriteLine ("Event: " + evtype + "(" + vm_uri + ")");
 
8195
+
 
8196
+                       switch (evtype) {
 
8197
+                       case EventType.VMStart:
 
8198
+                               /* Notify the main thread that the debuggee started up */
 
8199
+                               lock (startup_monitor) {
 
8200
+                                       Monitor.Pulse (startup_monitor);
 
8201
+                               }
 
8202
+                               queue_event (new VMStartEvent (vm, req_id, thread_id));
 
8203
+                               break;
 
8204
+                       case EventType.VMDeath:
 
8205
+                               queue_event (new VMDeathEvent (vm, req_id));
 
8206
+                               break;
 
8207
+                       case EventType.VMDisconnect:
 
8208
+                               queue_event (new VMDisconnectEvent (vm, req_id));
 
8209
+                               break;
 
8210
+                       default:
 
8211
+                               throw new Exception ();
 
8212
+                       }
 
8213
+               }
 
8214
+
 
8215
+               //
 
8216
+               // Methods to create instances of mirror objects
 
8217
+               //
 
8218
+
 
8219
+               /*
 
8220
+               class MirrorCache<T> {
 
8221
+                       static Dictionary <long, T> mirrors;
 
8222
+                       static object mirror_lock = new object ();
 
8223
+
 
8224
+                       internal static T GetMirror (VirtualMachine vm, long id) {
 
8225
+                               lock (mirror_lock) {
 
8226
+                               if (mirrors == null)
 
8227
+                                       mirrors = new Dictionary <long, T> ();
 
8228
+                               T obj;
 
8229
+                               if (!mirrors.TryGetValue (id, out obj)) {
 
8230
+                                       obj = CreateMirror (vm, id);
 
8231
+                                       mirrors [id] = obj;
 
8232
+                               }
 
8233
+                               return obj;
 
8234
+                               }
 
8235
+                       }
 
8236
+
 
8237
+                       internal static T CreateMirror (VirtualMachine vm, long id) {
 
8238
+                       }
 
8239
+               }
 
8240
+               */
 
8241
+
 
8242
+               // FIXME: When to remove items from the cache ?
 
8243
+
 
8244
+               Dictionary <long, MethodMirror> methods;
 
8245
+               object methods_lock = new object ();
 
8246
+
 
8247
+               internal MethodMirror GetMethod (long id) {
 
8248
+                       lock (methods_lock) {
 
8249
+                               if (methods == null)
 
8250
+                                       methods = new Dictionary <long, MethodMirror> ();
 
8251
+                               MethodMirror obj;
 
8252
+                               if (id == 0)
 
8253
+                                       return null;
 
8254
+                               if (!methods.TryGetValue (id, out obj)) {
 
8255
+                                       obj = new MethodMirror (this, id);
 
8256
+                                       methods [id] = obj;
 
8257
+                               }
 
8258
+                               return obj;
 
8259
+                       }
 
8260
+           }
 
8261
+
 
8262
+               Dictionary <long, AssemblyMirror> assemblies;
 
8263
+               object assemblies_lock = new object ();
 
8264
+
 
8265
+               internal AssemblyMirror GetAssembly (long id) {
 
8266
+                       lock (assemblies_lock) {
 
8267
+                               if (assemblies == null)
 
8268
+                                       assemblies = new Dictionary <long, AssemblyMirror> ();
 
8269
+                               AssemblyMirror obj;
 
8270
+                               if (id == 0)
 
8271
+                                       return null;
 
8272
+                               if (!assemblies.TryGetValue (id, out obj)) {
 
8273
+                                       obj = new AssemblyMirror (this, id);
 
8274
+                                       assemblies [id] = obj;
 
8275
+                               }
 
8276
+                               return obj;
 
8277
+                       }
 
8278
+           }
 
8279
+
 
8280
+               Dictionary <long, ModuleMirror> modules;
 
8281
+               object modules_lock = new object ();
 
8282
+
 
8283
+               internal ModuleMirror GetModule (long id) {
 
8284
+                       lock (modules_lock) {
 
8285
+                               if (modules == null)
 
8286
+                                       modules = new Dictionary <long, ModuleMirror> ();
 
8287
+                               ModuleMirror obj;
 
8288
+                               if (id == 0)
 
8289
+                                       return null;
 
8290
+                               if (!modules.TryGetValue (id, out obj)) {
 
8291
+                                       obj = new ModuleMirror (this, id);
 
8292
+                                       modules [id] = obj;
 
8293
+                               }
 
8294
+                               return obj;
 
8295
+                       }
 
8296
+           }
 
8297
+
 
8298
+               Dictionary <long, AppDomainMirror> domains;
 
8299
+               object domains_lock = new object ();
 
8300
+
 
8301
+               internal AppDomainMirror GetDomain (long id) {
 
8302
+                       lock (domains_lock) {
 
8303
+                               if (domains == null)
 
8304
+                                       domains = new Dictionary <long, AppDomainMirror> ();
 
8305
+                               AppDomainMirror obj;
 
8306
+                               if (id == 0)
 
8307
+                                       return null;
 
8308
+                               if (!domains.TryGetValue (id, out obj)) {
 
8309
+                                       obj = new AppDomainMirror (this, id);
 
8310
+                                       domains [id] = obj;
 
8311
+                               }
 
8312
+                               return obj;
 
8313
+                       }
 
8314
+           }
 
8315
+
 
8316
+               Dictionary <long, TypeMirror> types;
 
8317
+               object types_lock = new object ();
 
8318
+
 
8319
+               internal TypeMirror GetType (long id) {
 
8320
+                       lock (types_lock) {
 
8321
+                               if (types == null)
 
8322
+                                       types = new Dictionary <long, TypeMirror> ();
 
8323
+                               TypeMirror obj;
 
8324
+                               if (id == 0)
 
8325
+                                       return null;
 
8326
+                               if (!types.TryGetValue (id, out obj)) {
 
8327
+                                       obj = new TypeMirror (this, id);
 
8328
+                                       types [id] = obj;
 
8329
+                               }
 
8330
+                               return obj;
 
8331
+                       }
 
8332
+           }
 
8333
+
 
8334
+               Dictionary <long, ObjectMirror> objects;
 
8335
+               object objects_lock = new object ();
 
8336
+
 
8337
+               internal T GetObject<T> (long id, long domain_id, long type_id) where T : ObjectMirror {
 
8338
+                       lock (objects_lock) {
 
8339
+                               if (objects == null)
 
8340
+                                       objects = new Dictionary <long, ObjectMirror> ();
 
8341
+                               ObjectMirror obj;
 
8342
+                               if (!objects.TryGetValue (id, out obj)) {
 
8343
+                                       /*
 
8344
+                                        * Obtain the domain/type of the object to determine the type of
 
8345
+                                        * object we need to create.
 
8346
+                                        */
 
8347
+                                       if (domain_id == 0)
 
8348
+                                               domain_id = conn.Object_GetDomain (id);
 
8349
+                                       AppDomainMirror d = GetDomain (domain_id);
 
8350
+
 
8351
+                                       if (type_id == 0)
 
8352
+                                               type_id = conn.Object_GetType (id);
 
8353
+                                       TypeMirror t = GetType (type_id);
 
8354
+
 
8355
+                                       if (t.Assembly == d.Corlib && t.Namespace == "System.Threading" && t.Name == "Thread")
 
8356
+                                               obj = new ThreadMirror (this, id);
 
8357
+                                       else if (t.Assembly == d.Corlib && t.Namespace == "System" && t.Name == "String")
 
8358
+                                               obj = new StringMirror (this, id);
 
8359
+                                       else if (typeof (T) == typeof (ArrayMirror))
 
8360
+                                               obj = new ArrayMirror (this, id);
 
8361
+                                       else
 
8362
+                                               obj = new ObjectMirror (this, id);
 
8363
+                                       objects [id] = obj;
 
8364
+                               }
 
8365
+                               return (T)obj;
 
8366
+                       }
 
8367
+           }
 
8368
+
 
8369
+               internal T GetObject<T> (long id) where T : ObjectMirror {
 
8370
+                       return GetObject<T> (id, 0, 0);
 
8371
+               }
 
8372
+
 
8373
+               internal ObjectMirror GetObject (long objid) {
 
8374
+                       return GetObject<ObjectMirror> (objid);
 
8375
+               }
 
8376
+
 
8377
+               internal ThreadMirror GetThread (long id) {
 
8378
+                       return GetObject <ThreadMirror> (id);
 
8379
+               }
 
8380
+
 
8381
+               object requests_lock = new object ();
 
8382
+
 
8383
+               internal void AddRequest (EventRequest req, int id) {
 
8384
+                       lock (requests_lock) {
 
8385
+                               requests [id] = req;
 
8386
+                       }
 
8387
+               }
 
8388
+
 
8389
+               internal void RemoveRequest (EventRequest req, int id) {
 
8390
+                       lock (requests_lock) {
 
8391
+                               requests.Remove (id);
 
8392
+                       }
 
8393
+               }
 
8394
+
 
8395
+               internal EventRequest GetRequest (int id) {
 
8396
+                       lock (requests_lock) {
 
8397
+                               return requests [id];
 
8398
+                       }
 
8399
+               }
 
8400
+
 
8401
+               internal Value DecodeValue (ValueImpl v) {
 
8402
+                       if (v.Value != null)
 
8403
+                               return new PrimitiveValue (this, v.Value);
 
8404
+
 
8405
+                       switch (v.Type) {
 
8406
+                       case ElementType.Void:
 
8407
+                               return null;
 
8408
+                       case ElementType.SzArray:
 
8409
+                       case ElementType.Array:
 
8410
+                               return GetObject<ArrayMirror> (v.Objid);
 
8411
+                       case ElementType.String:
 
8412
+                               return GetObject<StringMirror> (v.Objid);
 
8413
+                       case ElementType.Class:
 
8414
+                       case ElementType.Object:
 
8415
+                               return GetObject (v.Objid);
 
8416
+                       case ElementType.ValueType:
 
8417
+                               if (v.IsEnum)
 
8418
+                                       return new EnumMirror (this, GetType (v.Klass), DecodeValues (v.Fields));
 
8419
+                               else
 
8420
+                                       return new StructMirror (this, GetType (v.Klass), DecodeValues (v.Fields));
 
8421
+                       case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
 
8422
+                               return new PrimitiveValue (this, null);
 
8423
+                       default:
 
8424
+                               throw new NotImplementedException ("" + v.Type);
 
8425
+                       }
 
8426
+               }
 
8427
+
 
8428
+               internal Value[] DecodeValues (ValueImpl[] values) {
 
8429
+                       Value[] res = new Value [values.Length];
 
8430
+                       for (int i = 0; i < values.Length; ++i)
 
8431
+                               res [i] = DecodeValue (values [i]);
 
8432
+                       return res;
 
8433
+               }
 
8434
+
 
8435
+               internal ValueImpl EncodeValue (Value v) {
 
8436
+                       if (v is PrimitiveValue) {
 
8437
+                               object val = (v as PrimitiveValue).Value;
 
8438
+                               if (val == null)
 
8439
+                                       return new ValueImpl { Type = (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL, Objid = 0 };
 
8440
+                               else
 
8441
+                                       return new ValueImpl { Value = val };
 
8442
+                       } else if (v is ObjectMirror) {
 
8443
+                               return new ValueImpl { Type = ElementType.Object, Objid = (v as ObjectMirror).Id };
 
8444
+                       } else if (v is StructMirror) {
 
8445
+                               return new ValueImpl { Type = ElementType.ValueType, Klass = (v as StructMirror).Type.Id, Fields = EncodeValues ((v as StructMirror).Fields) };
 
8446
+                       } else {
 
8447
+                               throw new NotSupportedException ();
 
8448
+                       }
 
8449
+               }
 
8450
+
 
8451
+               internal ValueImpl[] EncodeValues (IList<Value> values) {
 
8452
+                       ValueImpl[] res = new ValueImpl [values.Count];
 
8453
+                       for (int i = 0; i < values.Count; ++i)
 
8454
+                               res [i] = EncodeValue (values [i]);
 
8455
+                       return res;
 
8456
+               }
 
8457
+    }
 
8458
+
 
8459
+       class EventHandler : MarshalByRefObject, IEventHandler
 
8460
+       {               
 
8461
+               VirtualMachine vm;
 
8462
+
 
8463
+               public EventHandler (VirtualMachine vm) {
 
8464
+                       this.vm = vm;
 
8465
+               }
 
8466
+
 
8467
+               public void VMStart (int req_id, long thread_id, string vm_uri) {
 
8468
+                       vm.notify_vm_event (EventType.VMStart, req_id, thread_id, vm_uri);
 
8469
+        }
 
8470
+
 
8471
+               public void VMDeath (int req_id, long thread_id, string vm_uri) {
 
8472
+                       vm.notify_vm_event (EventType.VMDeath, req_id, thread_id, vm_uri);
 
8473
+        }
 
8474
+
 
8475
+               public void VMDisconnect (int req_id, long thread_id, string vm_uri) {
 
8476
+                       vm.notify_vm_event (EventType.VMDisconnect, req_id, thread_id, vm_uri);
 
8477
+        }
 
8478
+
 
8479
+               public void ThreadStart (int req_id, long thread_id, long id) {
 
8480
+                       vm.queue_event (new ThreadStartEvent (vm, req_id, id));
 
8481
+        }
 
8482
+
 
8483
+               public void ThreadDeath (int req_id, long thread_id, long id) {
 
8484
+                       vm.queue_event (new ThreadDeathEvent (vm, req_id, id));
 
8485
+        }
 
8486
+
 
8487
+               public void AssemblyLoad (int req_id, long thread_id, long id) {
 
8488
+                       vm.queue_event (new AssemblyLoadEvent (vm, req_id, thread_id, id));
 
8489
+        }
 
8490
+
 
8491
+               public void AssemblyUnload (int req_id, long thread_id, long id) {
 
8492
+                       vm.queue_event (new AssemblyUnloadEvent (vm, req_id, thread_id, id));
 
8493
+        }
 
8494
+
 
8495
+               public void TypeLoad (int req_id, long thread_id, long id) {
 
8496
+                       vm.queue_event (new TypeLoadEvent (vm, req_id, thread_id, id));
 
8497
+        }
 
8498
+
 
8499
+               public void MethodEntry (int req_id, long thread_id, long id) {
 
8500
+                       vm.queue_event (new MethodEntryEvent (vm, req_id, thread_id, id));
 
8501
+        }
 
8502
+
 
8503
+               public void MethodExit (int req_id, long thread_id, long id) {
 
8504
+                       vm.queue_event (new MethodExitEvent (vm, req_id, thread_id, id));
 
8505
+        }
 
8506
+
 
8507
+               public void Breakpoint (int req_id, long thread_id, long id, long loc) {
 
8508
+                       vm.queue_event (new BreakpointEvent (vm, req_id, thread_id, id, loc));
 
8509
+        }
 
8510
+
 
8511
+               public void Step (int req_id, long thread_id, long id, long loc) {
 
8512
+                       vm.queue_event (new StepEvent (vm, req_id, thread_id, id, loc));
 
8513
+        }
 
8514
+
 
8515
+               public void Exception (int req_id, long thread_id, long id, long loc) {
 
8516
+                       vm.queue_event (new ExceptionEvent (vm, req_id, thread_id, id, loc));
 
8517
+        }
 
8518
+
 
8519
+               public void AppDomainCreate (int req_id, long thread_id, long id) {
 
8520
+                       vm.queue_event (new AppDomainCreateEvent (vm, req_id, thread_id, id));
 
8521
+        }
 
8522
+
 
8523
+               public void AppDomainUnload (int req_id, long thread_id, long id) {
 
8524
+                       vm.queue_event (new AppDomainUnloadEvent (vm, req_id, thread_id, id));
 
8525
+        }
 
8526
+    }
 
8527
+
 
8528
+       internal class CommandException : Exception {
 
8529
+
 
8530
+               public CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
 
8531
+                       ErrorCode = error_code;
 
8532
+               }
 
8533
+
 
8534
+               public ErrorCode ErrorCode {
 
8535
+                       get; set;
 
8536
+               }
 
8537
+       }
 
8538
+}
 
8539
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs
 
8540
===================================================================
 
8541
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
8542
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs    2010-06-16 12:45:23.071079918 +0100
 
8543
@@ -0,0 +1,239 @@
 
8544
+using System;
 
8545
+using System.Collections.Generic;
 
8546
+using System.Diagnostics;
 
8547
+using System.IO;
 
8548
+using System.Net;
 
8549
+using System.Net.Sockets;
 
8550
+using System.Runtime.Remoting.Messaging;
 
8551
+
 
8552
+namespace Mono.Debugger.Soft
 
8553
+{
 
8554
+       public class LaunchOptions {
 
8555
+               public string AgentArgs {
 
8556
+                       get; set;
 
8557
+               }
 
8558
+
 
8559
+               public bool Valgrind {
 
8560
+                       get; set;
 
8561
+               }
 
8562
+               
 
8563
+               public ProcessLauncher CustomProcessLauncher {
 
8564
+                       get; set;
 
8565
+               }
 
8566
+
 
8567
+               public TargetProcessLauncher CustomTargetProcessLauncher {
 
8568
+                       get; set;
 
8569
+               }
 
8570
+
 
8571
+               public delegate Process ProcessLauncher (ProcessStartInfo info);
 
8572
+               public delegate ITargetProcess TargetProcessLauncher (ProcessStartInfo info);
 
8573
+       }
 
8574
+
 
8575
+       public class VirtualMachineManager
 
8576
+       {
 
8577
+               private delegate VirtualMachine LaunchCallback (ITargetProcess p, ProcessStartInfo info, Socket socket);
 
8578
+               private delegate VirtualMachine ListenCallback (Socket dbg_sock, Socket con_sock); 
 
8579
+
 
8580
+               internal VirtualMachineManager () {
 
8581
+               }
 
8582
+
 
8583
+               public static VirtualMachine LaunchInternal (Process p, ProcessStartInfo info, Socket socket)
 
8584
+               {
 
8585
+                       return LaunchInternal (new ProcessWrapper (p), info, socket);
 
8586
+               }
 
8587
+                       
 
8588
+               public static VirtualMachine LaunchInternal (ITargetProcess p, ProcessStartInfo info, Socket socket) {
 
8589
+                       Socket accepted = null;
 
8590
+                       try {
 
8591
+                               accepted = socket.Accept ();
 
8592
+                       } catch (Exception) {
 
8593
+                               throw;
 
8594
+                       }
 
8595
+
 
8596
+                       Connection conn = new Connection (accepted);
 
8597
+
 
8598
+                       VirtualMachine vm = new VirtualMachine (p, conn);
 
8599
+
 
8600
+                       if (info.RedirectStandardOutput)
 
8601
+                               vm.StandardOutput = p.StandardOutput;
 
8602
+                       
 
8603
+                       if (info.RedirectStandardError)
 
8604
+                               vm.StandardError = p.StandardError;
 
8605
+
 
8606
+                       conn.EventHandler = new EventHandler (vm);
 
8607
+
 
8608
+                       vm.connect ();
 
8609
+
 
8610
+                       return vm;
 
8611
+               }
 
8612
+
 
8613
+               public static IAsyncResult BeginLaunch (ProcessStartInfo info, AsyncCallback callback, LaunchOptions options = null) {
 
8614
+                       if (info == null)
 
8615
+                               throw new ArgumentNullException ("info");
 
8616
+
 
8617
+                       Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
8618
+                       socket.Bind (new IPEndPoint (IPAddress.Loopback, 0));
 
8619
+                       socket.Listen (1000);
 
8620
+                       IPEndPoint ep = (IPEndPoint) socket.LocalEndPoint;
 
8621
+
 
8622
+                       // We need to inject our arguments into the psi
 
8623
+                       info.Arguments = string.Format ("{0} --debug --debugger-agent=transport=dt_socket,address={1}:{2}{3} {4}", 
 
8624
+                                                               options == null || !options.Valgrind ? "" : info.FileName,
 
8625
+                                                               ep.Address,
 
8626
+                                                               ep.Port,
 
8627
+                                                               options == null || options.AgentArgs == null ? "" : "," + options.AgentArgs,
 
8628
+                                                               info.Arguments);
 
8629
+
 
8630
+                       if (options != null && options.Valgrind)
 
8631
+                               info.FileName = "valgrind";
 
8632
+                               
 
8633
+                       ITargetProcess p;
 
8634
+                       if (options != null && options.CustomProcessLauncher != null)
 
8635
+                               p = new ProcessWrapper (options.CustomProcessLauncher (info));
 
8636
+                       else if (options != null && options.CustomTargetProcessLauncher != null)
 
8637
+                               p = options.CustomTargetProcessLauncher (info);
 
8638
+                       else
 
8639
+                               p = new ProcessWrapper (Process.Start (info));
 
8640
+                       
 
8641
+                       p.Exited += delegate (object sender, EventArgs eargs) {
 
8642
+                               socket.Close ();
 
8643
+                       };
 
8644
+
 
8645
+                       LaunchCallback c = new LaunchCallback (LaunchInternal);
 
8646
+                       return c.BeginInvoke (p, info, socket, callback, socket);
 
8647
+               }
 
8648
+
 
8649
+               public static VirtualMachine EndLaunch (IAsyncResult asyncResult) {
 
8650
+                       if (asyncResult == null)
 
8651
+                               throw new ArgumentNullException ("asyncResult");
 
8652
+
 
8653
+                       if (!asyncResult.IsCompleted)
 
8654
+                               asyncResult.AsyncWaitHandle.WaitOne ();
 
8655
+
 
8656
+                       AsyncResult async = (AsyncResult) asyncResult;
 
8657
+                       LaunchCallback cb = (LaunchCallback) async.AsyncDelegate;
 
8658
+                       return cb.EndInvoke (asyncResult);
 
8659
+               }
 
8660
+
 
8661
+               public static VirtualMachine Launch (ProcessStartInfo info, LaunchOptions options = null) {
 
8662
+                       return EndLaunch (BeginLaunch (info, null, options));
 
8663
+               }
 
8664
+
 
8665
+               public static VirtualMachine Launch (string[] args, LaunchOptions options = null) {
 
8666
+                       ProcessStartInfo pi = new ProcessStartInfo ("mono");
 
8667
+                       pi.Arguments = String.Join (" ", args);
 
8668
+
 
8669
+                       return Launch (pi, options);
 
8670
+               }
 
8671
+                       
 
8672
+               public static VirtualMachine ListenInternal (Socket dbg_sock, Socket con_sock) {
 
8673
+                       Socket con_acc = null;
 
8674
+                       Socket dbg_acc = null;
 
8675
+
 
8676
+                       if (con_sock != null) {
 
8677
+                               try {
 
8678
+                                       con_acc = con_sock.Accept ();
 
8679
+                               } catch (Exception) {
 
8680
+                                       try {
 
8681
+                                               dbg_sock.Close ();
 
8682
+                                       } catch {}
 
8683
+                                       throw;
 
8684
+                               }
 
8685
+                       }
 
8686
+                                               
 
8687
+                       try {
 
8688
+                               dbg_acc = dbg_sock.Accept ();
 
8689
+                       } catch (Exception) {
 
8690
+                               if (con_sock != null) {
 
8691
+                                       try {
 
8692
+                                               con_sock.Close ();
 
8693
+                                               con_acc.Close ();
 
8694
+                                       } catch {}
 
8695
+                               }
 
8696
+                               throw;
 
8697
+                       }
 
8698
+
 
8699
+                       if (con_sock != null) {
 
8700
+                               con_sock.Disconnect (false);
 
8701
+                               con_sock.Close ();
 
8702
+                       }
 
8703
+
 
8704
+                       dbg_sock.Disconnect (false);
 
8705
+                       dbg_sock.Close ();
 
8706
+
 
8707
+                       Connection conn = new Connection (dbg_acc);
 
8708
+
 
8709
+                       VirtualMachine vm = new VirtualMachine (null, conn);
 
8710
+
 
8711
+                       if (con_acc != null) {
 
8712
+                               vm.StandardOutput = new StreamReader (new NetworkStream (con_acc));
 
8713
+                               vm.StandardError = null;
 
8714
+                       }
 
8715
+
 
8716
+                       conn.EventHandler = new EventHandler (vm);
 
8717
+
 
8718
+                       vm.connect ();
 
8719
+
 
8720
+                       return vm;
 
8721
+               }
 
8722
+
 
8723
+               public static IAsyncResult BeginListen (IPEndPoint dbg_ep, AsyncCallback callback) {
 
8724
+                       return BeginListen (dbg_ep, null, callback);
 
8725
+               }
 
8726
+
 
8727
+               public static IAsyncResult BeginListen (IPEndPoint dbg_ep, IPEndPoint con_ep, AsyncCallback callback) {
 
8728
+                       Socket dbg_sock = null;
 
8729
+                       Socket con_sock = null;
 
8730
+
 
8731
+                       dbg_sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
8732
+                       dbg_sock.Bind (dbg_ep);
 
8733
+                       dbg_sock.Listen (1000);
 
8734
+
 
8735
+                       if (con_ep != null) {
 
8736
+                               con_sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
8737
+                               con_sock.Bind (con_ep);
 
8738
+                               con_sock.Listen (1000);
 
8739
+                       }
 
8740
+                       
 
8741
+                       ListenCallback c = new ListenCallback (ListenInternal);
 
8742
+                       return c.BeginInvoke (dbg_sock, con_sock, callback, con_sock ?? dbg_sock);
 
8743
+               }
 
8744
+
 
8745
+               public static VirtualMachine EndListen (IAsyncResult asyncResult) {
 
8746
+                       if (asyncResult == null)
 
8747
+                               throw new ArgumentNullException ("asyncResult");
 
8748
+
 
8749
+                       if (!asyncResult.IsCompleted)
 
8750
+                               asyncResult.AsyncWaitHandle.WaitOne ();
 
8751
+
 
8752
+                       AsyncResult async = (AsyncResult) asyncResult;
 
8753
+                       ListenCallback cb = (ListenCallback) async.AsyncDelegate;
 
8754
+                       return cb.EndInvoke (asyncResult);
 
8755
+               }
 
8756
+
 
8757
+               public static VirtualMachine Listen (IPEndPoint dbg_ep, IPEndPoint con_ep = null) { 
 
8758
+                       return EndListen (BeginListen (dbg_ep, con_ep, null));
 
8759
+               }
 
8760
+
 
8761
+               /*
 
8762
+                * Connect to a virtual machine listening at the specified address.
 
8763
+                */
 
8764
+               public static VirtualMachine Connect (IPEndPoint endpoint) {
 
8765
+                       if (endpoint == null)
 
8766
+                               throw new ArgumentNullException ("endpoint");
 
8767
+
 
8768
+                       Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 
8769
+                       socket.Connect (endpoint);
 
8770
+
 
8771
+                       Connection conn = new Connection (socket);
 
8772
+
 
8773
+                       VirtualMachine vm = new VirtualMachine (null, conn);
 
8774
+
 
8775
+                       conn.EventHandler = new EventHandler (vm);
 
8776
+
 
8777
+                       vm.connect ();
 
8778
+
 
8779
+                       return vm;
 
8780
+               }
 
8781
+       }
 
8782
+}
 
8783
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Makefile.am
 
8784
===================================================================
 
8785
--- monodevelop.git.orig/src/addins/MonoDevelop.Debugger.Soft/Makefile.am       2010-06-16 12:45:20.441071007 +0100
 
8786
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Makefile.am    2010-06-16 12:45:23.071079918 +0100
 
8787
@@ -1,4 +1,5 @@
 
8788
 SUBDIRS = \
 
8789
+       Mono.Debugger.Soft \
 
8790
        Mono.Debugging.Soft \
 
8791
        MonoDevelop.Debugger.Soft \
 
8792
        MonoDevelop.Debugger.Soft.AspNet \
 
8793
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Makefile.am
 
8794
===================================================================
 
8795
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
 
8796
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Makefile.am 2010-06-16 12:46:05.430171228 +0100
 
8797
@@ -0,0 +1,106 @@
 
8798
+ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoDevelop.Debugger.Soft
 
8799
+ASSEMBLY = $(ADDIN_BUILD)/Mono.Debugger.Soft.dll
 
8800
+
 
8801
+SIGNING_KEY=$(top_srcdir)/src/core/Mono.Debugging/mono.debugging.snk
 
8802
+
 
8803
+CECIL_ASM_SRC = /usr/lib/mono-cecil/Mono.Cecil.dll
 
8804
+CECIL_ASM = $(ADDIN_BUILD)/Mono.Cecil.dll
 
8805
+
 
8806
+REFS =  \
 
8807
+       -r:System \
 
8808
+       -r:System.Core \
 
8809
+       -r:/usr/lib/mono-cecil/Mono.Cecil.dll
 
8810
+
 
8811
+FILES =  \
 
8812
+       AbsentInformationException.cs \
 
8813
+       AppDomainCreateEvent.cs \
 
8814
+       AppDomainMirror.cs \
 
8815
+       AppDomainUnloadEvent.cs \
 
8816
+       ArrayMirror.cs \
 
8817
+       AssemblyLoadEvent.cs \
 
8818
+       AssemblyMirror.cs \
 
8819
+       AssemblyUnloadEvent.cs \
 
8820
+       BreakpointEvent.cs \
 
8821
+       BreakpointEventRequest.cs \
 
8822
+       Connection.cs \
 
8823
+       CustomAttributeDataMirror.cs \
 
8824
+       CustomAttributeNamedArgumentMirror.cs \
 
8825
+       CustomAttributeTypedArgumentMirror.cs \
 
8826
+       DataConverter.cs \
 
8827
+       EnumMirror.cs \
 
8828
+       Event.cs \
 
8829
+       EventQueueImpl.cs \
 
8830
+       EventRequest.cs \
 
8831
+       EventType.cs \
 
8832
+       ExceptionEvent.cs \
 
8833
+       ExceptionEventRequest.cs \
 
8834
+       FieldInfoMirror.cs \
 
8835
+       IInvokeAsyncResult.cs \
 
8836
+       ILInstruction.cs \
 
8837
+       IMirror.cs \
 
8838
+       InvalidStackFrameException.cs \
 
8839
+       InvocationException.cs \
 
8840
+       InvokeOptions.cs \
 
8841
+       ITargetProcess.cs \
 
8842
+       LocalVariable.cs \
 
8843
+       Location.cs \
 
8844
+       MethodBodyMirror.cs \
 
8845
+       MethodEntryEvent.cs \
 
8846
+       MethodEntryEventRequest.cs \
 
8847
+       MethodExitEvent.cs \
 
8848
+       MethodExitEventRequest.cs \
 
8849
+       MethodMirror.cs \
 
8850
+       Mirror.cs \
 
8851
+       ModuleMirror.cs \
 
8852
+       ObjectCollectedException.cs \
 
8853
+       ObjectMirror.cs \
 
8854
+       ParameterInfoMirror.cs \
 
8855
+       PrimitiveValue.cs \
 
8856
+       PropertyInfoMirror.cs \
 
8857
+       StackFrame.cs \
 
8858
+       StepEvent.cs \
 
8859
+       StepEventRequest.cs \
 
8860
+       StringMirror.cs \
 
8861
+       StructMirror.cs \
 
8862
+       SuspendPolicy.cs \
 
8863
+       ThreadDeathEvent.cs \
 
8864
+       ThreadMirror.cs \
 
8865
+       ThreadStartEvent.cs \
 
8866
+       TypeLoadEvent.cs \
 
8867
+       TypeMirror.cs \
 
8868
+       Value.cs \
 
8869
+       VirtualMachine.cs \
 
8870
+       VirtualMachineManager.cs \
 
8871
+       VMDeathEvent.cs \
 
8872
+       VMDisconnectedException.cs \
 
8873
+       VMDisconnectEvent.cs \
 
8874
+       VMMismatchException.cs \
 
8875
+       VMStartEvent.cs
 
8876
+
 
8877
+RES =
 
8878
+
 
8879
+CSC_FLAGS = -unsafe -D:MONO_DATACONVERTER_STATIC_METHODS
 
8880
+
 
8881
+all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD) $(SIGNING_KEY)
 
8882
+
 
8883
+$(ASSEMBLY): $(build_sources) $(build_resources) $(DEPS) $(CECIL_ASM)
 
8884
+       mkdir -p $(ADDIN_BUILD)
 
8885
+       $(CSC) $(CSC_FLAGS) -debug -out:$@ -keyfile:$(SIGNING_KEY) -target:library $(REFS) $(build_deps) \
 
8886
+               $(build_resources:%=/resource:%) $(build_sources)
 
8887
+
 
8888
+$(ASSEMBLY).mdb: $(ASSEMBLY)
 
8889
+
 
8890
+$(CECIL_ASM): $(CECIL_ASM_SRC)
 
8891
+       mkdir -p $(ADDIN_BUILD)
 
8892
+       cp $^ $@
 
8893
+
 
8894
+check: all
 
8895
+
 
8896
+assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.Debugger.Soft
 
8897
+assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb $(CECIL_ASM)
 
8898
+
 
8899
+CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb
 
8900
+EXTRA_DIST = $(FILES) $(RES)
 
8901
+
 
8902
+include $(top_srcdir)/Makefile.include
 
8903
+
 
8904
Index: monodevelop.git/configure.in
 
8905
===================================================================
 
8906
--- monodevelop.git.orig/configure.in   2010-06-16 12:45:20.481069734 +0100
 
8907
+++ monodevelop.git/configure.in        2010-06-16 12:45:23.071079918 +0100
 
8908
@@ -372,6 +372,7 @@
 
8909
 src/addins/MonoDevelop.Refactoring/Makefile
 
8910
 src/addins/MonoDevelop.Debugger/Makefile
 
8911
 src/addins/MonoDevelop.Debugger.Soft/Makefile
 
8912
+src/addins/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft/Makefile
 
8913
 src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Makefile
 
8914
 src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/Makefile
 
8915
 src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.AspNet/Makefile
 
8916
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Makefile.am
 
8917
===================================================================
 
8918
--- monodevelop.git.orig/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Makefile.am   2010-06-16 12:45:20.451070531 +0100
 
8919
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Makefile.am        2010-06-16 12:45:23.071079918 +0100
 
8920
@@ -2,16 +2,13 @@
 
8921
 ASSEMBLY = $(ADDIN_BUILD)/Mono.Debugging.Soft.dll
 
8922
 
 
8923
 DBG_ASM = $(ADDIN_BUILD)/Mono.Debugger.Soft.dll
 
8924
-DBG_ASM_SRC = $(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll
 
8925
-DBG_MDB = $(DBG_ASM).mdb
 
8926
-DBG_MDB_SRC = $(DBG_ASM_SRC).mdb
 
8927
 
 
8928
 SIGNING_KEY=$(top_srcdir)/src/core/Mono.Debugging/mono.debugging.snk
 
8929
 
 
8930
 DEPS = $(top_builddir)/build/bin/Mono.Debugging.dll
 
8931
 
 
8932
 REFS =  \
 
8933
-       -r:$(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll \
 
8934
+       -r:$(DBG_ASM) \
 
8935
        -r:System \
 
8936
        -r:System.Core
 
8937
 
 
8938
@@ -32,28 +29,20 @@
 
8939
 
 
8940
 all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD) $(SIGNING_KEY)
 
8941
 
 
8942
-$(ASSEMBLY): $(build_sources) $(build_resources) $(DEPS) $(DBG_ASM) $(DBG_MDB)
 
8943
+$(ASSEMBLY): $(build_sources) $(build_resources) $(DEPS) $(DBG_ASM)
 
8944
        mkdir -p $(ADDIN_BUILD)
 
8945
        $(CSC) $(CSC_FLAGS) -debug -out:$@ -keycontainer:$(SIGNING_KEY) -target:library $(REFS) $(build_deps) \
 
8946
                $(build_resources:%=/resource:%) $(build_sources)
 
8947
 
 
8948
-$(DBG_ASM): $(DBG_ASM_SRC)
 
8949
-       mkdir -p $(ADDIN_BUILD)
 
8950
-       cp $^ $@ 
 
8951
-
 
8952
-$(DBG_MDB): $(DBG_MDB_SRC)
 
8953
-       mkdir -p $(ADDIN_BUILD)
 
8954
-       cp $^ $@
 
8955
-
 
8956
 $(ASSEMBLY).mdb: $(ASSEMBLY)
 
8957
 
 
8958
 check: all
 
8959
 
 
8960
 assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.Debugger.Soft
 
8961
-assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb $(DBG_ASM) $(DBG_MDB)
 
8962
+assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb
 
8963
 
 
8964
-CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb $(DBG_ASM) $(DBG_MDB)
 
8965
-EXTRA_DIST = $(FILES) $(RES) $(DBG_ASM_SRC) $(DBG_MDB_SRC)
 
8966
+CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb
 
8967
+EXTRA_DIST = $(FILES) $(RES)
 
8968
 
 
8969
 include $(top_srcdir)/Makefile.include
 
8970
 
 
8971
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/Makefile.am
 
8972
===================================================================
 
8973
--- monodevelop.git.orig/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/Makefile.am     2010-06-16 12:45:20.461070893 +0100
 
8974
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft/Makefile.am  2010-06-16 12:45:23.071079918 +0100
 
8975
@@ -13,7 +13,7 @@
 
8976
 REFS =  \
 
8977
        $(GLIB_SHARP_LIBS) \
 
8978
        $(GTK_SHARP_LIBS) \
 
8979
-       -r:$(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll \
 
8980
+       -r:$(top_builddir)/build/AddIns/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft.dll \
 
8981
        -r:System \
 
8982
        -r:System.Core
 
8983
 
 
8984
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.AspNet/Makefile.am
 
8985
===================================================================
 
8986
--- monodevelop.git.orig/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.AspNet/Makefile.am      2010-06-16 12:45:20.431080143 +0100
 
8987
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.AspNet/Makefile.am   2010-06-16 12:45:23.071079918 +0100
 
8988
@@ -14,7 +14,7 @@
 
8989
 REFS =  \
 
8990
        $(GLIB_SHARP_LIBS) \
 
8991
        $(GTK_SHARP_LIBS) \
 
8992
-       -r:$(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll \
 
8993
+       -r:$(top_builddir)/build/AddIns/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft.dll \
 
8994
        -r:System \
 
8995
        -r:System.Core
 
8996
 
 
8997
Index: monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.Moonlight/Makefile.am
 
8998
===================================================================
 
8999
--- monodevelop.git.orig/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.Moonlight/Makefile.am   2010-06-16 12:45:19.971079987 +0100
 
9000
+++ monodevelop.git/src/addins/MonoDevelop.Debugger.Soft/MonoDevelop.Debugger.Soft.Moonlight/Makefile.am        2010-06-16 12:45:23.071079918 +0100
 
9001
@@ -14,7 +14,7 @@
 
9002
 REFS =  \
 
9003
        $(GLIB_SHARP_LIBS) \
 
9004
        $(GTK_SHARP_LIBS) \
 
9005
-       -r:$(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll \
 
9006
+       -r:$(top_builddir)/build/AddIns/MonoDevelop.Debugger.Soft/Mono.Debugger.Soft.dll \
 
9007
        -r:System \
 
9008
        -r:System.Core
 
9009