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
8
+namespace Mono.Debugger.Soft
10
+ public class AbsentInformationException : Exception {
12
+ public AbsentInformationException () : base ("Debug information is not available for this frame.") {
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
22
+namespace Mono.Debugger.Soft
24
+ public class AppDomainCreateEvent : Event {
25
+ AppDomainMirror domain;
28
+ internal AppDomainCreateEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AppDomainCreate, vm, req_id, thread_id) {
32
+ public AppDomainMirror Domain {
35
+ domain = vm.GetDomain (id);
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
48
+namespace Mono.Debugger.Soft
50
+ public class AppDomainMirror : Mirror
52
+ string friendly_name;
53
+ AssemblyMirror entry_assembly, corlib;
55
+ internal AppDomainMirror (VirtualMachine vm, long id) : base (vm, id) {
58
+ public string FriendlyName {
60
+ if (friendly_name == null)
61
+ friendly_name = vm.conn.Domain_GetName (id);
62
+ return friendly_name;
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]);
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);
81
+ entry_assembly = vm.GetAssembly (ass_id);
83
+ return entry_assembly;
86
+ public AssemblyMirror Corlib {
88
+ if (corlib == null) {
89
+ long ass_id = vm.conn.Domain_GetCorlib (id);
91
+ corlib = vm.GetAssembly (ass_id);
97
+ public StringMirror CreateString (string s) {
99
+ throw new ArgumentNullException ("s");
101
+ return vm.GetObject<StringMirror> (vm.conn.Domain_CreateString (id, s));
104
+ public ObjectMirror CreateBoxedValue (Value value) {
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)
112
+ TypeMirror t = null;
113
+ if (value is PrimitiveValue)
114
+ t = GetCorrespondingType ((value as PrimitiveValue).Value.GetType ());
116
+ t = (value as StructMirror).Type;
118
+ return vm.GetObject<ObjectMirror> (vm.conn.Domain_CreateBoxedValue (id, t.Id, vm.EncodeValue (value)));
121
+ TypeMirror[] primitiveTypes = new TypeMirror [32];
123
+ public TypeMirror GetCorrespondingType (Type t) {
125
+ throw new ArgumentNullException ("t");
126
+ TypeCode tc = Type.GetTypeCode (t);
128
+ if (tc == TypeCode.Empty || tc == TypeCode.Object)
129
+ throw new ArgumentException ("t must be a primitive type", "t");
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 ();
137
+ return primitiveTypes [tc_index];
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
147
+namespace Mono.Debugger.Soft
149
+ public class AppDomainUnloadEvent : Event {
150
+ AppDomainMirror domain;
153
+ internal AppDomainUnloadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AppDomainUnload, vm, req_id, thread_id) {
157
+ public AppDomainMirror Domain {
159
+ if (domain == null)
160
+ domain = vm.GetDomain (id);
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
172
+using System.Collections;
173
+using System.Collections.Generic;
175
+namespace Mono.Debugger.Soft
177
+ public class ArrayMirror : ObjectMirror, IEnumerable {
179
+ public int[] lengths;
180
+ public int[] lower_bounds;
183
+ internal ArrayMirror (VirtualMachine vm, long id) : base (vm, id) {
186
+ public int Length {
190
+ int length = lengths [0];
192
+ for (int i = 1; i < Rank; i++) {
193
+ length *= lengths [i];
208
+ public int GetLength (int dimension) {
211
+ if (dimension < 0 || dimension >= Rank)
212
+ throw new ArgumentOutOfRangeException ("dimension");
214
+ return lengths [dimension];
217
+ public int GetLowerBound (int dimension) {
220
+ if (dimension < 0 || dimension >= Rank)
221
+ throw new ArgumentOutOfRangeException ("dimension");
223
+ return lower_bounds [dimension];
226
+ void GetLengths () {
227
+ if (lengths == null)
228
+ lengths = vm.conn.Array_GetLength (id, out this.rank, out this.lower_bounds);
231
+ public Value this [int index] {
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]);
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) });
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));
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));
262
+ IEnumerator IEnumerable.GetEnumerator ()
264
+ return new SimpleEnumerator (this);
267
+ internal class SimpleEnumerator : IEnumerator, ICloneable
272
+ public SimpleEnumerator (ArrayMirror arr)
276
+ this.length = arr.Length;
279
+ public object Current {
282
+ throw new InvalidOperationException ("Enumeration has not started.");
284
+ throw new InvalidOperationException ("Enumeration has already ended");
289
+ public bool MoveNext()
299
+ public void Reset()
304
+ public object Clone ()
306
+ return MemberwiseClone ();
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
317
+namespace Mono.Debugger.Soft
319
+ public class AssemblyLoadEvent : Event {
320
+ AssemblyMirror assembly;
323
+ internal AssemblyLoadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AssemblyLoad, vm, req_id, thread_id) {
327
+ public AssemblyMirror Assembly {
329
+ if (assembly == null)
330
+ assembly = vm.GetAssembly (id);
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
342
+using System.Reflection;
343
+using Mono.Debugger;
346
+namespace Mono.Debugger.Soft
348
+ public class AssemblyMirror : Mirror
351
+ MethodMirror entry_point;
352
+ bool entry_point_set;
353
+ ModuleMirror main_module;
354
+ AssemblyName aname;
355
+ AssemblyDefinition meta;
357
+ internal AssemblyMirror (VirtualMachine vm, long id) : base (vm, id) {
360
+ public string Location {
362
+ if (location == null)
363
+ location = vm.conn.Assembly_GetLocation (id);
368
+ public MethodMirror EntryPoint {
370
+ if (!entry_point_set) {
371
+ long mid = vm.conn.Assembly_GetEntryPoint (id);
374
+ entry_point = vm.GetMethod (mid);
375
+ entry_point_set = true;
377
+ return entry_point;
381
+ public ModuleMirror ManifestModule {
383
+ if (main_module == null) {
384
+ main_module = vm.GetModule (vm.conn.Assembly_GetManifestModule (id));
386
+ return main_module;
390
+ public virtual AssemblyName GetName () {
391
+ if (aname == null) {
392
+ string name = vm.conn.Assembly_GetName (id);
393
+ aname = new AssemblyName (name);
398
+ public ObjectMirror GetAssemblyObject () {
399
+ return vm.GetObject (vm.conn.Assembly_GetObject (id));
402
+ public TypeMirror GetType (string name, bool throwOnError, bool ignoreCase)
405
+ throw new ArgumentNullException (name);
406
+ if (name.Length == 0)
407
+ throw new ArgumentException ("name", "Name cannot be empty");
410
+ throw new NotImplementedException ();
411
+ return vm.GetType (vm.conn.Assembly_GetType (id, name, ignoreCase));
414
+ public TypeMirror GetType (String name, Boolean throwOnError)
416
+ return GetType (name, throwOnError, false);
419
+ public TypeMirror GetType (String name) {
420
+ return GetType (name, false, false);
424
+ * An optional Cecil assembly which could be used to access metadata instead
425
+ * of reading it from the debuggee.
427
+ public AssemblyDefinition Metadata {
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");
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
447
+namespace Mono.Debugger.Soft
449
+ public class AssemblyUnloadEvent : Event {
450
+ AssemblyMirror assembly;
453
+ internal AssemblyUnloadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.AssemblyUnload, vm, req_id, thread_id) {
457
+ public AssemblyMirror Assembly {
459
+ if (assembly == null)
460
+ assembly = vm.GetAssembly (id);
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
472
+namespace Mono.Debugger.Soft
474
+ public class BreakpointEvent : Event {
475
+ MethodMirror method;
478
+ internal BreakpointEvent (VirtualMachine vm, int req_id, long thread_id, long id, long loc) : base (EventType.Breakpoint, vm, req_id, thread_id) {
482
+ public MethodMirror Method {
484
+ if (method == null)
485
+ method = vm.GetMethod (id);
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
497
+using System.Collections.Generic;
500
+namespace Mono.Debugger.Soft
502
+ public sealed class BreakpointEventRequest : EventRequest {
504
+ MethodMirror method;
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;
517
+ public override void Enable () {
518
+ var mods = new List <Modifier> ();
519
+ mods.Add (new LocationModifier () { Method = method.Id, Location = location });
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
533
+using System.Net.Sockets;
534
+using System.Threading;
535
+using System.Collections.Generic;
537
+using Mono.Cecil.Metadata;
539
+namespace Mono.Debugger.Soft
541
+ public class VersionInfo {
542
+ public string VMVersion {
546
+ public int MajorVersion {
550
+ public int MinorVersion {
556
+ public int max_il_offset;
557
+ public string filename;
558
+ public int[] il_offsets;
559
+ public int[] line_numbers;
564
+ public long method;
565
+ public int il_offset;
566
+ public StackFrameFlags flags;
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;
578
+ public int attributes, iattributes, token;
581
+ class MethodBodyInfo {
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;
594
+ struct LocalsInfo {
595
+ public long[] types;
596
+ public string[] names;
597
+ public int[] live_range_start;
598
+ public int[] live_range_end;
603
+ public string name;
604
+ public long get_method, set_method;
608
+ class CattrNamedArgInfo {
609
+ public bool is_property;
611
+ public ValueImpl value;
615
+ public long ctor_id;
616
+ public ValueImpl[] ctor_args;
617
+ public CattrNamedArgInfo[] named_args;
621
+ public bool is_thread_pool;
625
+ VALUE_TYPE_ID_NULL = 0xf0,
626
+ VALUE_TYPE_ID_TYPE = 0xf1
631
+ DISABLE_BREAKPOINTS = 0x1,
632
+ SINGLE_THREADED = 0x2
636
+ public ElementType Type; /* or one of the VALUE_TYPE_ID constants */
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 */
646
+ public string Name, ScopeName, FQName, Guid;
647
+ public long Assembly;
658
+ enum StackFrameFlags {
659
+ DEBUGGER_INVOKE = 1
662
+ class ResolvedToken {
663
+ public TokenType Type;
671
+ class CountModifier : Modifier {
677
+ class LocationModifier : Modifier {
678
+ public long Method {
682
+ public long Location {
687
+ class StepModifier : Modifier {
688
+ public long Thread {
701
+ class ThreadModifier : Modifier {
702
+ public long Thread {
707
+ class ExceptionModifier : Modifier {
711
+ public bool Caught {
714
+ public bool Uncaught {
719
+ class AssemblyModifier : Modifier {
720
+ public long[] Assemblies {
725
+ public enum ErrorCode {
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
738
+ public class ErrorHandlerEventArgs : EventArgs {
740
+ public ErrorCode ErrorCode {
746
+ * Represents the connection to the debuggee
751
+ * The protocol and the packet format is based on JDWP, the differences
752
+ * are in the set of supported events, and the commands.
754
+ public const string HANDSHAKE_STRING = "DWP-Handshake";
756
+ public const int HEADER_LENGTH = 11;
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.
765
+ public const int MAJOR_VERSION = 2;
766
+ public const int MINOR_VERSION = 1;
768
+ enum WPSuspendPolicy {
780
+ EVENT_REQUEST = 15,
795
+ APPDOMAIN_CREATE = 4, // Not in JDI
796
+ APPDOMAIN_UNLOAD = 5, // Not in JDI
800
+ ASSEMBLY_UNLOAD = 9,
807
+ enum ModifierKind {
811
+ EXCEPTION_ONLY = 8,
824
+ SET_PROTOCOL_VERSION = 8,
833
+ GET_FRAME_INFO = 1,
837
+ /* FIXME: Merge into GET_INFO when the major protocol version is increased */
841
+ enum CmdEventRequest {
844
+ CLEAR_ALL_BREAKPOINTS = 3
847
+ enum CmdAppDomain {
848
+ GET_ROOT_DOMAIN = 1,
849
+ GET_FRIENDLY_NAME = 2,
850
+ GET_ASSEMBLIES = 3,
851
+ GET_ENTRY_ASSEMBLY = 4,
854
+ CREATE_BOXED_VALUE = 7
859
+ GET_ENTRY_POINT = 2,
860
+ GET_MANIFEST_MODULE = 3,
872
+ GET_DECLARING_TYPE = 2,
873
+ GET_DEBUG_INFO = 3,
874
+ GET_PARAM_INFO = 4,
875
+ GET_LOCALS_INFO = 5,
887
+ GET_SOURCE_FILES = 6,
889
+ IS_ASSIGNABLE_FROM = 8,
890
+ GET_PROPERTIES = 9,
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
898
+ enum CmdStackFrame {
910
+ enum CmdStringRef {
914
+ enum CmdObjectRef {
925
+ public int command_set;
926
+ public int command;
930
+ public static int GetPacketLength (byte[] header) {
932
+ return decode_int (header, ref offset);
935
+ public static bool IsReplyPacket (byte[] packet) {
937
+ return decode_byte (packet, ref offset) == 0x80;
940
+ public static int GetPacketId (byte[] packet) {
942
+ return decode_int (packet, ref offset);
945
+ static int decode_byte (byte[] packet, ref int offset) {
946
+ return packet [offset++];
949
+ static int decode_short (byte[] packet, ref int offset) {
950
+ int res = ((int)packet [offset] << 8) | (int)packet [offset + 1];
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];
961
+ static long decode_id (byte[] packet, ref int offset) {
962
+ return decode_int (packet, ref offset);
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);
969
+ return (long)(((ulong)high << 32) | (ulong)low);
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;
981
+ throw new NotImplementedException ();
985
+ static Header decode_command_header (byte[] packet) {
987
+ Header res = new Header ();
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);
998
+ static void encode_byte (byte[] buf, int b, ref int offset) {
999
+ buf [offset] = (byte)b;
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);
1011
+ static void encode_id (byte[] buf, long id, ref int offset) {
1012
+ encode_int (buf, (int)id, ref offset);
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);
1020
+ public static byte[] EncodePacket (int id, int commandSet, int command, byte[] data, int dataLen) {
1021
+ byte[] buf = new byte [dataLen + 11];
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);
1030
+ for (int i = 0; i < dataLen; ++i)
1031
+ buf [offset + i] = data [i];
1036
+ class PacketReader {
1040
+ public PacketReader (byte[] packet) {
1041
+ this.packet = packet;
1043
+ // For event packets
1044
+ Header header = decode_command_header (packet);
1045
+ CommandSet = (CommandSet)header.command_set;
1046
+ Command = header.command;
1048
+ // For reply packets
1050
+ ReadInt (); // length
1052
+ ReadByte (); // flags
1053
+ ErrorCode = ReadShort ();
1056
+ public CommandSet CommandSet {
1060
+ public int Command {
1064
+ public int ErrorCode {
1068
+ public int Offset {
1074
+ public int ReadByte () {
1075
+ return decode_byte (packet, ref offset);
1078
+ public int ReadShort () {
1079
+ return decode_short (packet, ref offset);
1082
+ public int ReadInt () {
1083
+ return decode_int (packet, ref offset);
1086
+ public long ReadId () {
1087
+ return decode_id (packet, ref offset);
1090
+ public long ReadLong () {
1091
+ return decode_long (packet, ref offset);
1094
+ public float ReadFloat () {
1095
+ float f = DataConverter.FloatFromBE (packet, offset);
1100
+ public double ReadDouble () {
1101
+ double d = DataConverter.DoubleFromBE (packet, offset);
1106
+ public string ReadString () {
1107
+ int len = decode_int (packet, ref offset);
1108
+ string res = new String (Encoding.UTF8.GetChars (packet, offset, len));
1113
+ public ValueImpl ReadValue () {
1114
+ ElementType etype = (ElementType)ReadByte ();
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 () };
1168
+ throw new NotImplementedException ("Unable to handle type " + etype);
1173
+ class PacketWriter {
1178
+ public PacketWriter () {
1180
+ data = new byte [1024];
1184
+ public PacketWriter WriteByte (byte val) {
1185
+ encode_byte (data, val, ref offset);
1189
+ public PacketWriter WriteInt (int val) {
1190
+ encode_int (data, val, ref offset);
1194
+ public PacketWriter WriteId (long id) {
1195
+ encode_id (data, id, ref offset);
1199
+ public PacketWriter WriteLong (long val) {
1200
+ encode_long (data, val, ref offset);
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];
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];
1220
+ public PacketWriter WriteInts (int[] ids) {
1221
+ for (int i = 0; i < ids.Length; ++i)
1222
+ WriteInt (ids [i]);
1226
+ public PacketWriter WriteIds (long[] ids) {
1227
+ for (int i = 0; i < ids.Length; ++i)
1228
+ WriteId (ids [i]);
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;
1240
+ public PacketWriter WriteBool (bool val) {
1241
+ WriteByte (val ? (byte)1 : (byte)0);
1245
+ public PacketWriter WriteValue (ValueImpl v) {
1248
+ if (v.Value != null)
1249
+ t = TypeCodeToElementType (Type.GetTypeCode (v.Value.GetType ()));
1252
+ WriteByte ((byte)t);
1254
+ case ElementType.Boolean:
1255
+ WriteInt ((bool)v.Value ? 1 : 0);
1257
+ case ElementType.Char:
1258
+ WriteInt ((int)(char)v.Value);
1260
+ case ElementType.I1:
1261
+ WriteInt ((int)(sbyte)v.Value);
1263
+ case ElementType.U1:
1264
+ WriteInt ((int)(byte)v.Value);
1266
+ case ElementType.I2:
1267
+ WriteInt ((int)(short)v.Value);
1269
+ case ElementType.U2:
1270
+ WriteInt ((int)(ushort)v.Value);
1272
+ case ElementType.I4:
1273
+ WriteInt ((int)(int)v.Value);
1275
+ case ElementType.U4:
1276
+ WriteInt ((int)(uint)v.Value);
1278
+ case ElementType.I8:
1279
+ WriteLong ((long)(long)v.Value);
1281
+ case ElementType.U8:
1282
+ WriteLong ((long)(ulong)v.Value);
1284
+ case ElementType.R4:
1285
+ WriteFloat ((float)v.Value);
1287
+ case ElementType.R8:
1288
+ WriteDouble ((double)v.Value);
1290
+ case ElementType.String:
1291
+ case ElementType.SzArray:
1292
+ case ElementType.Class:
1293
+ case ElementType.Array:
1294
+ case ElementType.Object:
1295
+ WriteId (v.Objid);
1297
+ case ElementType.ValueType:
1300
+ throw new NotImplementedException ();
1302
+ WriteId (v.Klass);
1303
+ WriteInt (v.Fields.Length);
1304
+ for (int i = 0; i < v.Fields.Length; ++i)
1305
+ WriteValue (v.Fields [i]);
1307
+ case (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL:
1310
+ throw new NotImplementedException ();
1316
+ public PacketWriter WriteValues (ValueImpl[] values) {
1317
+ for (int i = 0; i < values.Length; ++i)
1318
+ WriteValue (values [i]);
1322
+ public byte[] Data {
1328
+ public int Offset {
1335
+ delegate void ReplyCallback (int packet_id, byte[] packet);
1339
+ Thread receiver_thread;
1340
+ Dictionary<int, byte[]> reply_packets;
1341
+ Dictionary<int, ReplyCallback> reply_cbs;
1342
+ object reply_packets_monitor;
1344
+ public event EventHandler<ErrorHandlerEventArgs> ErrorHandler;
1346
+ public Connection (Socket socket) {
1347
+ this.socket = socket;
1348
+ //socket.SetSocketOption (SocketOptionLevel.IP, SocketOptionName.NoDelay, 1);
1350
+ reply_packets = new Dictionary<int, byte[]> ();
1351
+ reply_cbs = new Dictionary<int, ReplyCallback> ();
1352
+ reply_packets_monitor = new Object ();
1355
+ int Receive (byte[] buf, int buf_offset, int len) {
1358
+ while (offset < len) {
1359
+ int n = socket.Receive (buf, buf_offset + offset, len - offset, SocketFlags.None);
1369
+ public VersionInfo Version;
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];
1376
+ // FIXME: Add a timeout
1377
+ int n = Receive (buf, 0, buf.Length);
1379
+ throw new IOException ("DWP Handshake failed.");
1380
+ for (int i = 0; i < buf.Length; ++i)
1381
+ cbuf [i] = (char)buf [i];
1383
+ if (new String (cbuf) != HANDSHAKE_STRING)
1384
+ throw new IOException ("DWP Handshake failed.");
1386
+ socket.Send (buf);
1388
+ receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
1389
+ receiver_thread.Start ();
1391
+ Version = VM_GetVersion ();
1394
+ // Tell the debuggee our protocol version, so newer debuggees can work
1395
+ // with older clients
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 ();
1406
+ VM_SetProtocolVersion (MAJOR_VERSION, MINOR_VERSION);
1407
+ } catch (NotSupportedException) {
1409
+ ErrorHandler = OrigErrorHandler;
1412
+ public EndPoint EndPoint {
1414
+ return socket.RemoteEndPoint;
1418
+ public byte[] ReadPacket () {
1419
+ // FIXME: Throw ClosedConnectionException () if the connection is closed
1420
+ // FIXME: Throw ClosedConnectionException () if another thread closes the connection
1422
+ byte[] header = new byte [HEADER_LENGTH];
1424
+ int len = Receive (header, 0, header.Length);
1426
+ return new byte [0];
1427
+ if (len != HEADER_LENGTH) {
1429
+ throw new IOException ("Packet of length " + len + " is read.");
1432
+ int packetLength = GetPacketLength (header);
1433
+ if (packetLength < 11)
1434
+ throw new IOException ("Invalid packet length.");
1436
+ if (packetLength == 11) {
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 ();
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
1453
+ socket.Send (packet);
1456
+ public void Close () {
1460
+ public bool IsClosed {
1466
+ bool disconnected;
1468
+ void receiver_thread_main () {
1471
+ bool res = ReceivePacket ();
1474
+ } catch (Exception ex) {
1475
+ Console.WriteLine (ex);
1480
+ lock (reply_packets_monitor) {
1481
+ disconnected = true;
1482
+ Monitor.PulseAll (reply_packets_monitor);
1484
+ EventHandler.VMDisconnect (0, 0, null);
1487
+ bool ReceivePacket () {
1488
+ byte[] packet = ReadPacket ();
1490
+ if (packet.Length == 0) {
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);
1500
+ reply_packets [id] = packet;
1501
+ Monitor.PulseAll (reply_packets_monitor);
1506
+ cb.Invoke (id, packet);
1508
+ PacketReader r = new PacketReader (packet);
1510
+ if (r.CommandSet == CommandSet.EVENT && r.Command == (int)CmdEvent.COMPOSITE) {
1511
+ r.ReadByte (); // suspend_policy
1512
+ int nevents = r.ReadInt ();
1514
+ for (int i = 0; i < nevents; ++i) {
1515
+ EventKind kind = (EventKind)r.ReadByte ();
1516
+ int req_id = r.ReadInt ();
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);
1573
+ throw new NotImplementedException ("Unknown event kind: " + kind);
1582
+ public IEventHandler EventHandler {
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;
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);
1598
+ if (packet == null)
1599
+ WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
1601
+ WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
1606
+ PacketReader SendReceive (CommandSet command_set, int command, PacketWriter packet) {
1607
+ int id = IdGenerator;
1609
+ if (packet == null)
1610
+ WritePacket (EncodePacket (id, (int)command_set, command, null, 0));
1612
+ WritePacket (EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset));
1614
+ int packetId = id;
1616
+ /* Wait for the reply packet */
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.");
1632
+ throw new VMDisconnectedException ();
1633
+ Monitor.Wait (reply_packets_monitor);
1639
+ PacketReader SendReceive (CommandSet command_set, int command) {
1640
+ return SendReceive (command_set, command, null);
1643
+ int packet_id_generator;
1647
+ return Interlocked.Increment (ref packet_id_generator);
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 ();
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;
1674
+ static ElementType TypeCodeToElementType (TypeCode 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;
1701
+ throw new NotImplementedException ();
1706
+ * Implementation of debugger commands
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 ();
1718
+ public void VM_SetProtocolVersion (int major, int minor) {
1719
+ SendReceive (CommandSet.VM, (int)CmdVM.SET_PROTOCOL_VERSION, new PacketWriter ().WriteInt (major).WriteInt (minor));
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 ();
1731
+ public void VM_Suspend () {
1732
+ SendReceive (CommandSet.VM, (int)CmdVM.SUSPEND);
1735
+ public void VM_Resume () {
1736
+ SendReceive (CommandSet.VM, (int)CmdVM.RESUME);
1739
+ public void VM_Exit (int exitCode) {
1740
+ SendReceive (CommandSet.VM, (int)CmdVM.EXIT, new PacketWriter ().WriteInt (exitCode));
1743
+ public void VM_Dispose () {
1744
+ SendReceive (CommandSet.VM, (int)CmdVM.DISPOSE);
1747
+ public ValueImpl VM_InvokeMethod (long thread, long method, ValueImpl this_arg, ValueImpl[] arguments, InvokeFlags flags, out ValueImpl exc) {
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 ();
1754
+ return r.ReadValue ();
1758
+ public delegate void InvokeMethodCallback (ValueImpl v, ValueImpl exc, ErrorCode error, object state);
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) {
1764
+ if (r.ErrorCode != 0) {
1765
+ callback (null, null, (ErrorCode)r.ErrorCode, state);
1767
+ if (r.ReadByte () == 0) {
1768
+ exc = r.ReadValue ();
1771
+ v = r.ReadValue ();
1775
+ callback (v, exc, 0, state);
1780
+ public void VM_AbortInvoke (long thread, int id)
1782
+ SendReceive (CommandSet.VM, (int)CmdVM.ABORT_INVOKE, new PacketWriter ().WriteId (thread).WriteInt (id));
1789
+ public long RootDomain {
1791
+ return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ROOT_DOMAIN, null).ReadId ();
1795
+ public string Domain_GetName (long id) {
1796
+ return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_FRIENDLY_NAME, new PacketWriter ().WriteId (id)).ReadString ();
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;
1808
+ public long Domain_GetEntryAssembly (long id) {
1809
+ return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_ENTRY_ASSEMBLY, new PacketWriter ().WriteId (id)).ReadId ();
1812
+ public long Domain_GetCorlib (long id) {
1813
+ return SendReceive (CommandSet.APPDOMAIN, (int)CmdAppDomain.GET_CORLIB, new PacketWriter ().WriteId (id)).ReadId ();
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 ();
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 ();
1828
+ public string Method_GetName (long id) {
1829
+ return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
1832
+ public long Method_GetDeclaringType (long id) {
1833
+ return SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DECLARING_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
1836
+ public DebugInfo Method_GetDebugInfo (long id) {
1837
+ var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_DEBUG_INFO, new PacketWriter ().WriteId (id));
1839
+ DebugInfo info = new DebugInfo ();
1840
+ info.max_il_offset = res.ReadInt ();
1841
+ info.filename = res.ReadString ();
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 ();
1854
+ public ParamInfo Method_GetParamInfo (long id) {
1855
+ var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_PARAM_INFO, new PacketWriter ().WriteId (id));
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 ();
1872
+ public LocalsInfo Method_GetLocalsInfo (long id) {
1873
+ var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_LOCALS_INFO, new PacketWriter ().WriteId (id));
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 ();
1893
+ public MethodInfo Method_GetInfo (long id) {
1894
+ var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_INFO, new PacketWriter ().WriteId (id));
1896
+ MethodInfo info = new MethodInfo ();
1897
+ info.attributes = res.ReadInt ();
1898
+ info.iattributes = res.ReadInt ();
1899
+ info.token = res.ReadInt ();
1904
+ public MethodBodyInfo Method_GetBody (long id) {
1905
+ var res = SendReceive (CommandSet.METHOD, (int)CmdMethod.GET_BODY, new PacketWriter ().WriteId (id));
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 ();
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));
1918
+ TokenType type = (TokenType)res.ReadByte ();
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 };
1929
+ throw new NotImplementedException ();
1937
+ public string Thread_GetName (long id) {
1938
+ return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
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 ();
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 ();
1955
+ public int Thread_GetState (long id) {
1956
+ return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_STATE, new PacketWriter ().WriteId (id)).ReadInt ();
1959
+ public ThreadInfo Thread_GetInfo (long id) {
1960
+ PacketReader r = SendReceive (CommandSet.THREAD, (int)CmdThread.GET_INFO, new PacketWriter ().WriteId (id));
1962
+ ThreadInfo res = new ThreadInfo () { is_thread_pool = r.ReadByte () > 0 ? true : false };
1967
+ public long Thread_GetId (long id) {
1968
+ return SendReceive (CommandSet.THREAD, (int)CmdThread.GET_ID, new PacketWriter ().WriteId (id)).ReadLong ();
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 () };
1985
+ public string Assembly_GetLocation (long id) {
1986
+ return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_LOCATION, new PacketWriter ().WriteId (id)).ReadString ();
1989
+ public long Assembly_GetEntryPoint (long id) {
1990
+ return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_ENTRY_POINT, new PacketWriter ().WriteId (id)).ReadId ();
1993
+ public long Assembly_GetManifestModule (long id) {
1994
+ return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_MANIFEST_MODULE, new PacketWriter ().WriteId (id)).ReadId ();
1997
+ public long Assembly_GetObject (long id) {
1998
+ return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
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 ();
2005
+ public string Assembly_GetName (long id) {
2006
+ return SendReceive (CommandSet.ASSEMBLY, (int)CmdAssembly.GET_NAME, new PacketWriter ().WriteId (id)).ReadString ();
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 ();
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;
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 ();
2042
+ public long[] Type_GetMethods (long id) {
2043
+ PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_METHODS, new PacketWriter ().WriteId (id));
2045
+ int n = r.ReadInt ();
2046
+ long[] res = new long [n];
2047
+ for (int i = 0; i < n; ++i)
2048
+ res [i] = r.ReadId ();
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));
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 ();
2069
+ public PropInfo[] Type_GetProperties (long id) {
2070
+ PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_PROPERTIES, new PacketWriter ().WriteId (id));
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 ();
2086
+ public long Type_GetObject (long id) {
2087
+ return SendReceive (CommandSet.TYPE, (int)CmdType.GET_OBJECT, new PacketWriter ().WriteId (id)).ReadId ();
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));
2094
+ ValueImpl[] res = new ValueImpl [len];
2095
+ for (int i = 0; i < len; ++i)
2096
+ res [i] = r.ReadValue ();
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));
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 ();
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;
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);
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);
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);
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.");
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)
2176
+ throw new NotImplementedException ();
2182
+ return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
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));
2189
+ public void ClearAllBreakpoints () {
2190
+ SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.CLEAR_ALL_BREAKPOINTS, new PacketWriter ());
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 ();
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));
2207
+ ValueImpl[] res = new ValueImpl [len];
2208
+ for (int i = 0; i < len; ++i)
2209
+ res [i] = r.ReadValue ();
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));
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 ();
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 ();
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));
2250
+ public string String_GetValue (long id) {
2251
+ return SendReceive (CommandSet.STRING_REF, (int)CmdStringRef.GET_VALUE, new PacketWriter ().WriteId (id)).ReadString ();
2257
+ public long Object_GetType (long id) {
2258
+ return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_TYPE, new PacketWriter ().WriteId (id)).ReadId ();
2261
+ public long Object_GetDomain (long id) {
2262
+ return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_DOMAIN, new PacketWriter ().WriteId (id)).ReadId ();
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));
2269
+ ValueImpl[] res = new ValueImpl [len];
2270
+ for (int i = 0; i < len; ++i)
2271
+ res [i] = r.ReadValue ();
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));
2279
+ public bool Object_IsCollected (long id) {
2280
+ return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.IS_COLLECTED, new PacketWriter ().WriteId (id)).ReadInt () == 1;
2283
+ public long Object_GetAddress (long id) {
2284
+ return SendReceive (CommandSet.OBJECT_REF, (int)CmdObjectRef.GET_ADDRESS, new PacketWriter ().WriteId (id)).ReadLong ();
2289
+ /* This is the interface exposed by the debugger towards the debugger agent */
2290
+ interface IEventHandler
2292
+ void VMStart (int req_id, long thread_id, string vm_uri);
2294
+ void VMDeath (int req_id, long thread_id, string vm_uri);
2296
+ void VMDisconnect (int req_id, long thread_id, string vm_uri);
2298
+ void ThreadStart (int req_id, long thread_id, long id);
2300
+ void ThreadDeath (int req_id, long thread_id, long id);
2302
+ void AssemblyLoad (int req_id, long thread_id, long id);
2304
+ void AssemblyUnload (int req_id, long thread_id, long id);
2306
+ void TypeLoad (int req_id, long thread_id, long id);
2308
+ void MethodEntry (int req_id, long thread_id, long id);
2310
+ void MethodExit (int req_id, long thread_id, long id);
2312
+ void Breakpoint (int req_id, long thread_id, long method_id, long loc);
2314
+ void Step (int req_id, long thread_id, long method_id, long loc);
2316
+ void Exception (int req_id, long thread_id, long exc_id, long loc);
2318
+ void AppDomainCreate (int req_id, long thread_id, long id);
2320
+ void AppDomainUnload (int req_id, long thread_id, long id);
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
2329
+using System.Collections.Generic;
2330
+using System.Runtime.CompilerServices;
2331
+using System.Runtime.InteropServices;
2332
+using System.Reflection;
2334
+using Mono.Cecil.Metadata;
2336
+namespace Mono.Debugger.Soft {
2338
+ public sealed class CustomAttributeDataMirror {
2339
+ MethodMirror ctorInfo;
2340
+ IList<CustomAttributeTypedArgumentMirror> ctorArgs;
2341
+ IList<CustomAttributeNamedArgumentMirror> namedArgs;
2343
+ internal CustomAttributeDataMirror (MethodMirror ctorInfo, object [] ctorArgs, object [] namedArgs)
2345
+ this.ctorInfo = ctorInfo;
2347
+ this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgumentMirror>
2348
+ (ctorArgs != null ? UnboxValues<CustomAttributeTypedArgumentMirror> (ctorArgs) : new CustomAttributeTypedArgumentMirror [0]);
2350
+ this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgumentMirror>
2351
+ (namedArgs != null ? UnboxValues<CustomAttributeNamedArgumentMirror> (namedArgs) : new CustomAttributeNamedArgumentMirror [0]);
2354
+ [ComVisible (true)]
2355
+ public MethodMirror Constructor {
2361
+ [ComVisible (true)]
2362
+ public IList<CustomAttributeTypedArgumentMirror> ConstructorArguments {
2368
+ public IList<CustomAttributeNamedArgumentMirror> NamedArguments {
2374
+ public override string ToString ()
2376
+ StringBuilder sb = new StringBuilder ();
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)
2387
+ if (namedArgs != null) {
2388
+ if (namedArgs.Count > 0)
2391
+ for (int j = 0; j < namedArgs.Count; j++) {
2392
+ sb.Append (namedArgs [j].ToString ());
2393
+ if (j + 1 < namedArgs.Count)
2397
+ sb.AppendFormat (")]");
2399
+ return sb.ToString ();
2402
+ static T [] UnboxValues<T> (object [] values)
2404
+ T [] retval = new T [values.Length];
2405
+ for (int i = 0; i < values.Length; i++)
2406
+ retval [i] = (T) values [i];
2412
+ * Construct a normal object from the value, so accessing the cattr doesn't
2413
+ * require remoting calls.
2415
+ static CustomAttributeTypedArgumentMirror CreateArg (VirtualMachine vm, ValueImpl vi) {
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);
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;
2431
+ return new CustomAttributeTypedArgumentMirror (null, val);
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;
2447
+ val = CreateArg (vm, arg.value);
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);
2455
+ foreach (var field in ctor.DeclaringType.GetFields ()) {
2456
+ if (field.Id == arg.id)
2457
+ named_args [j] = new CustomAttributeNamedArgumentMirror (null, field, val);
2460
+ if (named_args [j] == null)
2461
+ throw new NotImplementedException ();
2463
+ res [i] = new CustomAttributeDataMirror (vm.GetMethod (attr.ctor_id), ctor_args, named_args);
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
2477
+using System.Runtime.InteropServices;
2478
+using System.Reflection;
2480
+namespace Mono.Debugger.Soft {
2482
+ public struct CustomAttributeNamedArgumentMirror {
2483
+ CustomAttributeTypedArgumentMirror arg;
2484
+ PropertyInfoMirror prop;
2485
+ FieldInfoMirror field;
2487
+ internal CustomAttributeNamedArgumentMirror (PropertyInfoMirror prop, FieldInfoMirror field, CustomAttributeTypedArgumentMirror arg)
2491
+ this.field = field;
2494
+ public PropertyInfoMirror Property {
2500
+ public FieldInfoMirror Field {
2506
+ public CustomAttributeTypedArgumentMirror TypedValue {
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
2519
+using System.Runtime.InteropServices;
2520
+using System.Collections.ObjectModel;
2521
+using System.Reflection;
2523
+namespace Mono.Debugger.Soft {
2525
+ public struct CustomAttributeTypedArgumentMirror {
2529
+ internal CustomAttributeTypedArgumentMirror (Type type, object value)
2532
+ this.value = value;
2534
+ if (value != null)
2535
+ this.type = value.GetType ();
2537
+ this.type = typeof (void);
2539
+ // MS seems to convert arrays into a ReadOnlyCollection
2540
+ if (value is Array) {
2541
+ Array a = (Array)value;
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);
2551
+ public Type ArgumentType {
2557
+ public object Value {
2563
+ public override string ToString ()
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;
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
2584
+// Miguel de Icaza (miguel@novell.com)
2586
+// See the following url for documentation:
2587
+// http://www.mono-project.com/Mono_DataConvert
2589
+// Compilation Options:
2590
+// MONO_DATACONVERTER_PUBLIC:
2591
+// Makes the class public instead of the default internal.
2593
+// MONO_DATACONVERTER_STATIC_METHODS:
2594
+// Exposes the public static methods.
2597
+// Support for "DoubleWordsAreSwapped" for ARM devices
2599
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
2609
+// The above copyright notice and this permission notice shall be
2610
+// included in all copies or substantial portions of the Software.
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.
2621
+using System.Collections;
2624
+#pragma warning disable 3021
2628
+#if MONO_DATACONVERTER_PUBLIC
2629
+ unsafe public abstract class DataConverter {
2631
+ unsafe internal abstract class DataConverter {
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
2637
+ static DataConverter SwapConv = new SwapConverter ();
2638
+ static DataConverter CopyConv = new CopyConverter ();
2640
+ public static readonly bool IsLittleEndian = BitConverter.IsLittleEndian;
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);
2647
+ public abstract short GetInt16 (byte [] data, int index);
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);
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);
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);
2669
+ public byte[] GetBytes (double value)
2671
+ byte [] ret = new byte [8];
2672
+ PutBytes (ret, 0, value);
2676
+ public byte[] GetBytes (float value)
2678
+ byte [] ret = new byte [4];
2679
+ PutBytes (ret, 0, value);
2683
+ public byte[] GetBytes (int value)
2685
+ byte [] ret = new byte [4];
2686
+ PutBytes (ret, 0, value);
2690
+ public byte[] GetBytes (long value)
2692
+ byte [] ret = new byte [8];
2693
+ PutBytes (ret, 0, value);
2697
+ public byte[] GetBytes (short value)
2699
+ byte [] ret = new byte [2];
2700
+ PutBytes (ret, 0, value);
2704
+ [CLSCompliant (false)]
2705
+ public byte[] GetBytes (ushort value)
2707
+ byte [] ret = new byte [2];
2708
+ PutBytes (ret, 0, value);
2712
+ [CLSCompliant (false)]
2713
+ public byte[] GetBytes (uint value)
2715
+ byte [] ret = new byte [4];
2716
+ PutBytes (ret, 0, value);
2720
+ [CLSCompliant (false)]
2721
+ public byte[] GetBytes (ulong value)
2723
+ byte [] ret = new byte [8];
2724
+ PutBytes (ret, 0, value);
2728
+ static public DataConverter LittleEndian {
2730
+ return BitConverter.IsLittleEndian ? CopyConv : SwapConv;
2734
+ static public DataConverter BigEndian {
2736
+ return BitConverter.IsLittleEndian ? SwapConv : CopyConv;
2740
+ static public DataConverter Native {
2746
+ static int Align (int current, int align)
2748
+ return ((current + align - 1) / align) * align;
2751
+ class PackContext {
2753
+ public byte [] buffer;
2756
+ public string description;
2757
+ public int i; // position in the description
2758
+ public DataConverter conv;
2759
+ public int repeat;
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
2768
+ public void Add (byte [] group)
2770
+ //Console.WriteLine ("Adding {0} bytes to {1} (next={2}", group.Length,
2771
+ // buffer == null ? "null" : buffer.Length.ToString (), next);
2773
+ if (buffer == null){
2775
+ next = group.Length;
2780
+ next = Align (next, group.Length);
2782
+ next = Align (next, align);
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;
2793
+ Array.Copy (group, 0, buffer, next, group.Length);
2794
+ next += group.Length;
2798
+ public byte [] Get ()
2800
+ if (buffer == null)
2801
+ return new byte [0];
2803
+ if (buffer.Length != next){
2804
+ byte [] b = new byte [next];
2805
+ Array.Copy (buffer, b, next);
2813
+ // Format includes:
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).
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
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
2852
+ static public byte [] Pack (string description, params object [] args)
2855
+ PackContext b = new PackContext ();
2856
+ b.conv = CopyConv;
2857
+ b.description = description;
2859
+ for (b.i = 0; b.i < description.Length; ){
2862
+ if (argn < args.Length)
2863
+ oarg = args [argn];
2865
+ if (b.repeat != 0)
2873
+ if (PackOne (b, oarg)){
2875
+ if (b.repeat > 0){
2876
+ if (--b.repeat > 0)
2888
+ static public byte [] PackEnumerable (string description, IEnumerable args)
2890
+ PackContext b = new PackContext ();
2891
+ b.conv = CopyConv;
2892
+ b.description = description;
2894
+ IEnumerator enumerator = args.GetEnumerator ();
2895
+ bool ok = enumerator.MoveNext ();
2897
+ for (b.i = 0; b.i < description.Length; ){
2901
+ oarg = enumerator.Current;
2903
+ if (b.repeat != 0)
2910
+ if (PackOne (b, oarg)){
2911
+ ok = enumerator.MoveNext ();
2912
+ if (b.repeat > 0){
2913
+ if (--b.repeat > 0)
2926
+ // Packs one datum `oarg' into the buffer `b', using the string format
2927
+ // in `description' at position `i'
2929
+ // Returns: true if we must pick the next object from the list
2931
+ static bool PackOne (PackContext b, object oarg)
2935
+ switch (b.description [b.i]){
2937
+ b.conv = BigEndian;
2940
+ b.conv = LittleEndian;
2951
+ b.Add (new byte [] { 0 });
2954
+ // Type Conversions
2956
+ b.Add (b.conv.GetBytes (Convert.ToInt32 (oarg)));
2960
+ b.Add (b.conv.GetBytes (Convert.ToUInt32 (oarg)));
2964
+ b.Add (b.conv.GetBytes (Convert.ToInt16 (oarg)));
2968
+ b.Add (b.conv.GetBytes (Convert.ToUInt16 (oarg)));
2972
+ b.Add (b.conv.GetBytes (Convert.ToInt64 (oarg)));
2976
+ b.Add (b.conv.GetBytes (Convert.ToUInt64 (oarg)));
2980
+ b.Add (b.conv.GetBytes (Convert.ToSingle (oarg)));
2984
+ b.Add (b.conv.GetBytes (Convert.ToDouble (oarg)));
2988
+ b.Add (new byte [] { Convert.ToByte (oarg) });
2992
+ b.Add (new byte [] { (byte) (Convert.ToSByte (oarg)) });
2996
+ b.Add (new byte [] { Convert.ToByte (oarg) });
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');
3006
+ b.repeat = Int32.MaxValue;
3010
+ int count = -1, j;
3012
+ for (j = b.i+1; j < b.description.Length; j++){
3013
+ if (b.description [j] == ']')
3015
+ n = ((short) b.description [j]) - ((short) '0');
3016
+ if (n >= 0 && n <= 9){
3020
+ count = count * 10 + n;
3024
+ throw new ArgumentException ("invalid size specification");
3029
+ case '$': case 'z':
3030
+ bool add_null = b.description [b.i] == 'z';
3032
+ if (b.i >= b.description.Length)
3033
+ throw new ArgumentException ("$ description needs a type specified", "description");
3034
+ char d = b.description [b.i];
3039
+ e = Encoding.UTF8;
3043
+ e = Encoding.Unicode;
3047
+ e = Encoding.UTF7;
3051
+ e = Encoding.BigEndianUnicode;
3055
+ e = Encoding.GetEncoding (12000);
3059
+ e = Encoding.GetEncoding (12001);
3064
+ throw new ArgumentException ("Invalid format for $ specifier", "description");
3066
+ if (b.align == -1)
3068
+ b.Add (e.GetBytes (Convert.ToString (oarg)));
3070
+ b.Add (new byte [n]);
3073
+ throw new ArgumentException (String.Format ("invalid format specified `{0}'",
3074
+ b.description [b.i]));
3079
+ static bool Prepare (byte [] buffer, ref int idx, int size, ref bool align)
3082
+ idx = Align (idx, size);
3085
+ if (idx + size > buffer.Length){
3086
+ idx = buffer.Length;
3092
+ static public IList Unpack (string description, byte [] buffer, int startIndex)
3094
+ DataConverter conv = CopyConv;
3095
+ ArrayList result = new ArrayList ();
3096
+ int idx = startIndex;
3097
+ bool align = false;
3098
+ int repeat = 0, n;
3100
+ for (int i = 0; i < description.Length && idx < buffer.Length; ){
3103
+ switch (description [i]){
3108
+ conv = LittleEndian;
3121
+ // Type Conversions
3123
+ if (Prepare (buffer, ref idx, 4, ref align)){
3124
+ result.Add (conv.GetInt32 (buffer, idx));
3130
+ if (Prepare (buffer, ref idx, 4, ref align)){
3131
+ result.Add (conv.GetUInt32 (buffer, idx));
3137
+ if (Prepare (buffer, ref idx, 2, ref align)){
3138
+ result.Add (conv.GetInt16 (buffer, idx));
3144
+ if (Prepare (buffer, ref idx, 2, ref align)){
3145
+ result.Add (conv.GetUInt16 (buffer, idx));
3151
+ if (Prepare (buffer, ref idx, 8, ref align)){
3152
+ result.Add (conv.GetInt64 (buffer, idx));
3158
+ if (Prepare (buffer, ref idx, 8, ref align)){
3159
+ result.Add (conv.GetUInt64 (buffer, idx));
3165
+ if (Prepare (buffer, ref idx, 4, ref align)){
3166
+ result.Add (conv.GetDouble (buffer, idx));
3172
+ if (Prepare (buffer, ref idx, 8, ref align)){
3173
+ result.Add (conv.GetDouble (buffer, idx));
3179
+ if (Prepare (buffer, ref idx, 1, ref align)){
3180
+ result.Add (buffer [idx]);
3185
+ case 'c': case 'C':
3186
+ if (Prepare (buffer, ref idx, 1, ref align)){
3189
+ if (description [i] == 'c')
3190
+ c = ((char) ((sbyte)buffer [idx]));
3192
+ c = ((char) ((byte)buffer [idx]));
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');
3207
+ repeat = Int32.MaxValue;
3211
+ int count = -1, j;
3213
+ for (j = i+1; j < description.Length; j++){
3214
+ if (description [j] == ']')
3216
+ n = ((short) description [j]) - ((short) '0');
3217
+ if (n >= 0 && n <= 9){
3221
+ count = count * 10 + n;
3225
+ throw new ArgumentException ("invalid size specification");
3230
+ case '$': case 'z':
3231
+ // bool with_null = description [i] == 'z';
3233
+ if (i >= description.Length)
3234
+ throw new ArgumentException ("$ description needs a type specified", "description");
3235
+ char d = description [i];
3238
+ idx = Align (idx, 4);
3241
+ if (idx >= buffer.Length)
3246
+ e = Encoding.UTF8;
3250
+ e = Encoding.Unicode;
3254
+ e = Encoding.UTF7;
3258
+ e = Encoding.BigEndianUnicode;
3262
+ e = Encoding.GetEncoding (12000);
3266
+ e = Encoding.GetEncoding (12001);
3271
+ throw new ArgumentException ("Invalid format for $ specifier", "description");
3276
+ for (; k < buffer.Length && buffer [k] != 0; k++)
3278
+ result.Add (e.GetChars (buffer, idx, k-idx));
3279
+ if (k == buffer.Length)
3286
+ for (; k < buffer.Length; k++){
3287
+ if (k+1 == buffer.Length){
3291
+ if (buffer [k] == 0 && buffer [k+1] == 0)
3294
+ result.Add (e.GetChars (buffer, idx, k-idx));
3295
+ if (k == buffer.Length)
3302
+ for (; k < buffer.Length; k++){
3303
+ if (k+3 >= buffer.Length){
3304
+ k = buffer.Length;
3307
+ if (buffer[k]==0 && buffer[k+1] == 0 && buffer[k+2] == 0 && buffer[k+3]== 0)
3310
+ result.Add (e.GetChars (buffer, idx, k-idx));
3311
+ if (k == buffer.Length)
3319
+ throw new ArgumentException (String.Format ("invalid format specified `{0}'",
3320
+ description [i]));
3332
+ internal void Check (byte [] dest, int destIdx, int size)
3335
+ throw new ArgumentNullException ("dest");
3336
+ if (destIdx < 0 || destIdx > dest.Length - size)
3337
+ throw new ArgumentException ("destIdx");
3340
+ class CopyConverter : DataConverter {
3341
+ public override double GetDouble (byte [] data, int index)
3344
+ throw new ArgumentNullException ("data");
3345
+ if (data.Length - index < 8)
3346
+ throw new ArgumentException ("index");
3348
+ throw new ArgumentException ("index");
3350
+ byte *b = (byte *)&ret;
3352
+ for (int i = 0; i < 8; i++)
3353
+ b [i] = data [index+i];
3358
+ public override ulong GetUInt64 (byte [] data, int index)
3361
+ throw new ArgumentNullException ("data");
3362
+ if (data.Length - index < 8)
3363
+ throw new ArgumentException ("index");
3365
+ throw new ArgumentException ("index");
3368
+ byte *b = (byte *)&ret;
3370
+ for (int i = 0; i < 8; i++)
3371
+ b [i] = data [index+i];
3376
+ public override long GetInt64 (byte [] data, int index)
3379
+ throw new ArgumentNullException ("data");
3380
+ if (data.Length - index < 8)
3381
+ throw new ArgumentException ("index");
3383
+ throw new ArgumentException ("index");
3386
+ byte *b = (byte *)&ret;
3388
+ for (int i = 0; i < 8; i++)
3389
+ b [i] = data [index+i];
3394
+ public override float GetFloat (byte [] data, int index)
3397
+ throw new ArgumentNullException ("data");
3398
+ if (data.Length - index < 4)
3399
+ throw new ArgumentException ("index");
3401
+ throw new ArgumentException ("index");
3404
+ byte *b = (byte *)&ret;
3406
+ for (int i = 0; i < 4; i++)
3407
+ b [i] = data [index+i];
3412
+ public override int GetInt32 (byte [] data, int index)
3415
+ throw new ArgumentNullException ("data");
3416
+ if (data.Length - index < 4)
3417
+ throw new ArgumentException ("index");
3419
+ throw new ArgumentException ("index");
3422
+ byte *b = (byte *)&ret;
3424
+ for (int i = 0; i < 4; i++)
3425
+ b [i] = data [index+i];
3430
+ public override uint GetUInt32 (byte [] data, int index)
3433
+ throw new ArgumentNullException ("data");
3434
+ if (data.Length - index < 4)
3435
+ throw new ArgumentException ("index");
3437
+ throw new ArgumentException ("index");
3440
+ byte *b = (byte *)&ret;
3442
+ for (int i = 0; i < 4; i++)
3443
+ b [i] = data [index+i];
3448
+ public override short GetInt16 (byte [] data, int index)
3451
+ throw new ArgumentNullException ("data");
3452
+ if (data.Length - index < 2)
3453
+ throw new ArgumentException ("index");
3455
+ throw new ArgumentException ("index");
3458
+ byte *b = (byte *)&ret;
3460
+ for (int i = 0; i < 2; i++)
3461
+ b [i] = data [index+i];
3466
+ public override ushort GetUInt16 (byte [] data, int index)
3469
+ throw new ArgumentNullException ("data");
3470
+ if (data.Length - index < 2)
3471
+ throw new ArgumentException ("index");
3473
+ throw new ArgumentException ("index");
3476
+ byte *b = (byte *)&ret;
3478
+ for (int i = 0; i < 2; i++)
3479
+ b [i] = data [index+i];
3484
+ public override void PutBytes (byte [] dest, int destIdx, double value)
3486
+ Check (dest, destIdx, 8);
3487
+ fixed (byte *target = &dest [destIdx]){
3488
+ long *source = (long *) &value;
3490
+ *((long *)target) = *source;
3494
+ public override void PutBytes (byte [] dest, int destIdx, float value)
3496
+ Check (dest, destIdx, 4);
3497
+ fixed (byte *target = &dest [destIdx]){
3498
+ uint *source = (uint *) &value;
3500
+ *((uint *)target) = *source;
3504
+ public override void PutBytes (byte [] dest, int destIdx, int value)
3506
+ Check (dest, destIdx, 4);
3507
+ fixed (byte *target = &dest [destIdx]){
3508
+ uint *source = (uint *) &value;
3510
+ *((uint *)target) = *source;
3514
+ public override void PutBytes (byte [] dest, int destIdx, uint value)
3516
+ Check (dest, destIdx, 4);
3517
+ fixed (byte *target = &dest [destIdx]){
3518
+ uint *source = (uint *) &value;
3520
+ *((uint *)target) = *source;
3524
+ public override void PutBytes (byte [] dest, int destIdx, long value)
3526
+ Check (dest, destIdx, 8);
3527
+ fixed (byte *target = &dest [destIdx]){
3528
+ long *source = (long *) &value;
3530
+ *((long*)target) = *source;
3534
+ public override void PutBytes (byte [] dest, int destIdx, ulong value)
3536
+ Check (dest, destIdx, 8);
3537
+ fixed (byte *target = &dest [destIdx]){
3538
+ ulong *source = (ulong *) &value;
3540
+ *((ulong *) target) = *source;
3544
+ public override void PutBytes (byte [] dest, int destIdx, short value)
3546
+ Check (dest, destIdx, 2);
3547
+ fixed (byte *target = &dest [destIdx]){
3548
+ ushort *source = (ushort *) &value;
3550
+ *((ushort *)target) = *source;
3554
+ public override void PutBytes (byte [] dest, int destIdx, ushort value)
3556
+ Check (dest, destIdx, 2);
3557
+ fixed (byte *target = &dest [destIdx]){
3558
+ ushort *source = (ushort *) &value;
3560
+ *((ushort *)target) = *source;
3565
+ class SwapConverter : DataConverter {
3566
+ public override double GetDouble (byte [] data, int index)
3569
+ throw new ArgumentNullException ("data");
3570
+ if (data.Length - index < 8)
3571
+ throw new ArgumentException ("index");
3573
+ throw new ArgumentException ("index");
3576
+ byte *b = (byte *)&ret;
3578
+ for (int i = 0; i < 8; i++)
3579
+ b [7-i] = data [index+i];
3584
+ public override ulong GetUInt64 (byte [] data, int index)
3587
+ throw new ArgumentNullException ("data");
3588
+ if (data.Length - index < 8)
3589
+ throw new ArgumentException ("index");
3591
+ throw new ArgumentException ("index");
3594
+ byte *b = (byte *)&ret;
3596
+ for (int i = 0; i < 8; i++)
3597
+ b [7-i] = data [index+i];
3602
+ public override long GetInt64 (byte [] data, int index)
3605
+ throw new ArgumentNullException ("data");
3606
+ if (data.Length - index < 8)
3607
+ throw new ArgumentException ("index");
3609
+ throw new ArgumentException ("index");
3612
+ byte *b = (byte *)&ret;
3614
+ for (int i = 0; i < 8; i++)
3615
+ b [7-i] = data [index+i];
3620
+ public override float GetFloat (byte [] data, int index)
3623
+ throw new ArgumentNullException ("data");
3624
+ if (data.Length - index < 4)
3625
+ throw new ArgumentException ("index");
3627
+ throw new ArgumentException ("index");
3630
+ byte *b = (byte *)&ret;
3632
+ for (int i = 0; i < 4; i++)
3633
+ b [3-i] = data [index+i];
3638
+ public override int GetInt32 (byte [] data, int index)
3641
+ throw new ArgumentNullException ("data");
3642
+ if (data.Length - index < 4)
3643
+ throw new ArgumentException ("index");
3645
+ throw new ArgumentException ("index");
3648
+ byte *b = (byte *)&ret;
3650
+ for (int i = 0; i < 4; i++)
3651
+ b [3-i] = data [index+i];
3656
+ public override uint GetUInt32 (byte [] data, int index)
3659
+ throw new ArgumentNullException ("data");
3660
+ if (data.Length - index < 4)
3661
+ throw new ArgumentException ("index");
3663
+ throw new ArgumentException ("index");
3666
+ byte *b = (byte *)&ret;
3668
+ for (int i = 0; i < 4; i++)
3669
+ b [3-i] = data [index+i];
3674
+ public override short GetInt16 (byte [] data, int index)
3677
+ throw new ArgumentNullException ("data");
3678
+ if (data.Length - index < 2)
3679
+ throw new ArgumentException ("index");
3681
+ throw new ArgumentException ("index");
3684
+ byte *b = (byte *)&ret;
3686
+ for (int i = 0; i < 2; i++)
3687
+ b [1-i] = data [index+i];
3692
+ public override ushort GetUInt16 (byte [] data, int index)
3695
+ throw new ArgumentNullException ("data");
3696
+ if (data.Length - index < 2)
3697
+ throw new ArgumentException ("index");
3699
+ throw new ArgumentException ("index");
3702
+ byte *b = (byte *)&ret;
3704
+ for (int i = 0; i < 2; i++)
3705
+ b [1-i] = data [index+i];
3710
+ public override void PutBytes (byte [] dest, int destIdx, double value)
3712
+ Check (dest, destIdx, 8);
3714
+ fixed (byte *target = &dest [destIdx]){
3715
+ byte *source = (byte *) &value;
3717
+ for (int i = 0; i < 8; i++)
3718
+ target [i] = source [7-i];
3722
+ public override void PutBytes (byte [] dest, int destIdx, float value)
3724
+ Check (dest, destIdx, 4);
3726
+ fixed (byte *target = &dest [destIdx]){
3727
+ byte *source = (byte *) &value;
3729
+ for (int i = 0; i < 4; i++)
3730
+ target [i] = source [3-i];
3734
+ public override void PutBytes (byte [] dest, int destIdx, int value)
3736
+ Check (dest, destIdx, 4);
3738
+ fixed (byte *target = &dest [destIdx]){
3739
+ byte *source = (byte *) &value;
3741
+ for (int i = 0; i < 4; i++)
3742
+ target [i] = source [3-i];
3746
+ public override void PutBytes (byte [] dest, int destIdx, uint value)
3748
+ Check (dest, destIdx, 4);
3750
+ fixed (byte *target = &dest [destIdx]){
3751
+ byte *source = (byte *) &value;
3753
+ for (int i = 0; i < 4; i++)
3754
+ target [i] = source [3-i];
3758
+ public override void PutBytes (byte [] dest, int destIdx, long value)
3760
+ Check (dest, destIdx, 8);
3762
+ fixed (byte *target = &dest [destIdx]){
3763
+ byte *source = (byte *) &value;
3765
+ for (int i = 0; i < 8; i++)
3766
+ target [i] = source [7-i];
3770
+ public override void PutBytes (byte [] dest, int destIdx, ulong value)
3772
+ Check (dest, destIdx, 8);
3774
+ fixed (byte *target = &dest [destIdx]){
3775
+ byte *source = (byte *) &value;
3777
+ for (int i = 0; i < 4; i++)
3778
+ target [i] = source [7-i];
3782
+ public override void PutBytes (byte [] dest, int destIdx, short value)
3784
+ Check (dest, destIdx, 2);
3786
+ fixed (byte *target = &dest [destIdx]){
3787
+ byte *source = (byte *) &value;
3789
+ for (int i = 0; i < 2; i++)
3790
+ target [i] = source [1-i];
3794
+ public override void PutBytes (byte [] dest, int destIdx, ushort value)
3796
+ Check (dest, destIdx, 2);
3798
+ fixed (byte *target = &dest [destIdx]){
3799
+ byte *source = (byte *) &value;
3801
+ for (int i = 0; i < 2; i++)
3802
+ target [i] = source [1-i];
3807
+#if MONO_DATACONVERTER_STATIC_METHODS
3808
+ static unsafe void PutBytesLE (byte *dest, byte *src, int count)
3812
+ if (BitConverter.IsLittleEndian){
3813
+ for (; i < count; i++)
3817
+ for (; i < count; i++)
3818
+ *(--dest) = *src++;
3822
+ static unsafe void PutBytesBE (byte *dest, byte *src, int count)
3826
+ if (BitConverter.IsLittleEndian){
3828
+ for (; i < count; i++)
3829
+ *(--dest) = *src++;
3831
+ for (; i < count; i++)
3836
+ static unsafe void PutBytesNative (byte *dest, byte *src, int count)
3840
+ for (; i < count; i++)
3841
+ dest [i-count] = *src++;
3844
+ static public unsafe double DoubleFromLE (byte[] data, int index)
3847
+ throw new ArgumentNullException ("data");
3848
+ if (data.Length - index < 8)
3849
+ throw new ArgumentException ("index");
3851
+ throw new ArgumentException ("index");
3854
+ fixed (byte *src = &data[index]){
3855
+ PutBytesLE ((byte *) &ret, src, 8);
3860
+ static public unsafe float FloatFromLE (byte [] data, int index)
3863
+ throw new ArgumentNullException ("data");
3864
+ if (data.Length - index < 4)
3865
+ throw new ArgumentException ("index");
3867
+ throw new ArgumentException ("index");
3870
+ fixed (byte *src = &data[index]){
3871
+ PutBytesLE ((byte *) &ret, src, 4);
3876
+ static public unsafe long Int64FromLE (byte [] data, int index)
3879
+ throw new ArgumentNullException ("data");
3880
+ if (data.Length - index < 8)
3881
+ throw new ArgumentException ("index");
3883
+ throw new ArgumentException ("index");
3886
+ fixed (byte *src = &data[index]){
3887
+ PutBytesLE ((byte *) &ret, src, 8);
3892
+ static public unsafe ulong UInt64FromLE (byte [] data, int index)
3895
+ throw new ArgumentNullException ("data");
3896
+ if (data.Length - index < 8)
3897
+ throw new ArgumentException ("index");
3899
+ throw new ArgumentException ("index");
3902
+ fixed (byte *src = &data[index]){
3903
+ PutBytesLE ((byte *) &ret, src, 8);
3908
+ static public unsafe int Int32FromLE (byte [] data, int index)
3911
+ throw new ArgumentNullException ("data");
3912
+ if (data.Length - index < 4)
3913
+ throw new ArgumentException ("index");
3915
+ throw new ArgumentException ("index");
3918
+ fixed (byte *src = &data[index]){
3919
+ PutBytesLE ((byte *) &ret, src, 4);
3924
+ static public unsafe uint UInt32FromLE (byte [] data, int index)
3927
+ throw new ArgumentNullException ("data");
3928
+ if (data.Length - index < 4)
3929
+ throw new ArgumentException ("index");
3931
+ throw new ArgumentException ("index");
3934
+ fixed (byte *src = &data[index]){
3935
+ PutBytesLE ((byte *) &ret, src, 4);
3940
+ static public unsafe short Int16FromLE (byte [] data, int index)
3943
+ throw new ArgumentNullException ("data");
3944
+ if (data.Length - index < 2)
3945
+ throw new ArgumentException ("index");
3947
+ throw new ArgumentException ("index");
3950
+ fixed (byte *src = &data[index]){
3951
+ PutBytesLE ((byte *) &ret, src, 2);
3956
+ static public unsafe ushort UInt16FromLE (byte [] data, int index)
3959
+ throw new ArgumentNullException ("data");
3960
+ if (data.Length - index < 2)
3961
+ throw new ArgumentException ("index");
3963
+ throw new ArgumentException ("index");
3966
+ fixed (byte *src = &data[index]){
3967
+ PutBytesLE ((byte *) &ret, src, 2);
3972
+ static public unsafe double DoubleFromBE (byte[] data, int index)
3975
+ throw new ArgumentNullException ("data");
3976
+ if (data.Length - index < 8)
3977
+ throw new ArgumentException ("index");
3979
+ throw new ArgumentException ("index");
3982
+ fixed (byte *src = &data[index]){
3983
+ PutBytesBE ((byte *) &ret, src, 8);
3988
+ static public unsafe float FloatFromBE (byte [] data, int index)
3991
+ throw new ArgumentNullException ("data");
3992
+ if (data.Length - index < 4)
3993
+ throw new ArgumentException ("index");
3995
+ throw new ArgumentException ("index");
3998
+ fixed (byte *src = &data[index]){
3999
+ PutBytesBE ((byte *) &ret, src, 4);
4004
+ static public unsafe long Int64FromBE (byte [] data, int index)
4007
+ throw new ArgumentNullException ("data");
4008
+ if (data.Length - index < 8)
4009
+ throw new ArgumentException ("index");
4011
+ throw new ArgumentException ("index");
4014
+ fixed (byte *src = &data[index]){
4015
+ PutBytesBE ((byte *) &ret, src, 8);
4020
+ static public unsafe ulong UInt64FromBE (byte [] data, int index)
4023
+ throw new ArgumentNullException ("data");
4024
+ if (data.Length - index < 8)
4025
+ throw new ArgumentException ("index");
4027
+ throw new ArgumentException ("index");
4030
+ fixed (byte *src = &data[index]){
4031
+ PutBytesBE ((byte *) &ret, src, 8);
4036
+ static public unsafe int Int32FromBE (byte [] data, int index)
4039
+ throw new ArgumentNullException ("data");
4040
+ if (data.Length - index < 4)
4041
+ throw new ArgumentException ("index");
4043
+ throw new ArgumentException ("index");
4046
+ fixed (byte *src = &data[index]){
4047
+ PutBytesBE ((byte *) &ret, src, 4);
4052
+ static public unsafe uint UInt32FromBE (byte [] data, int index)
4055
+ throw new ArgumentNullException ("data");
4056
+ if (data.Length - index < 4)
4057
+ throw new ArgumentException ("index");
4059
+ throw new ArgumentException ("index");
4062
+ fixed (byte *src = &data[index]){
4063
+ PutBytesBE ((byte *) &ret, src, 4);
4068
+ static public unsafe short Int16FromBE (byte [] data, int index)
4071
+ throw new ArgumentNullException ("data");
4072
+ if (data.Length - index < 2)
4073
+ throw new ArgumentException ("index");
4075
+ throw new ArgumentException ("index");
4078
+ fixed (byte *src = &data[index]){
4079
+ PutBytesBE ((byte *) &ret, src, 2);
4084
+ static public unsafe ushort UInt16FromBE (byte [] data, int index)
4087
+ throw new ArgumentNullException ("data");
4088
+ if (data.Length - index < 2)
4089
+ throw new ArgumentException ("index");
4091
+ throw new ArgumentException ("index");
4094
+ fixed (byte *src = &data[index]){
4095
+ PutBytesBE ((byte *) &ret, src, 2);
4100
+ static public unsafe double DoubleFromNative (byte[] data, int index)
4103
+ throw new ArgumentNullException ("data");
4104
+ if (data.Length - index < 8)
4105
+ throw new ArgumentException ("index");
4107
+ throw new ArgumentException ("index");
4110
+ fixed (byte *src = &data[index]){
4111
+ PutBytesNative ((byte *) &ret, src, 8);
4116
+ static public unsafe float FloatFromNative (byte [] data, int index)
4119
+ throw new ArgumentNullException ("data");
4120
+ if (data.Length - index < 4)
4121
+ throw new ArgumentException ("index");
4123
+ throw new ArgumentException ("index");
4126
+ fixed (byte *src = &data[index]){
4127
+ PutBytesNative ((byte *) &ret, src, 4);
4132
+ static public unsafe long Int64FromNative (byte [] data, int index)
4135
+ throw new ArgumentNullException ("data");
4136
+ if (data.Length - index < 8)
4137
+ throw new ArgumentException ("index");
4139
+ throw new ArgumentException ("index");
4142
+ fixed (byte *src = &data[index]){
4143
+ PutBytesNative ((byte *) &ret, src, 8);
4148
+ static public unsafe ulong UInt64FromNative (byte [] data, int index)
4151
+ throw new ArgumentNullException ("data");
4152
+ if (data.Length - index < 8)
4153
+ throw new ArgumentException ("index");
4155
+ throw new ArgumentException ("index");
4158
+ fixed (byte *src = &data[index]){
4159
+ PutBytesNative ((byte *) &ret, src, 8);
4164
+ static public unsafe int Int32FromNative (byte [] data, int index)
4167
+ throw new ArgumentNullException ("data");
4168
+ if (data.Length - index < 4)
4169
+ throw new ArgumentException ("index");
4171
+ throw new ArgumentException ("index");
4174
+ fixed (byte *src = &data[index]){
4175
+ PutBytesNative ((byte *) &ret, src, 4);
4180
+ static public unsafe uint UInt32FromNative (byte [] data, int index)
4183
+ throw new ArgumentNullException ("data");
4184
+ if (data.Length - index < 4)
4185
+ throw new ArgumentException ("index");
4187
+ throw new ArgumentException ("index");
4190
+ fixed (byte *src = &data[index]){
4191
+ PutBytesNative ((byte *) &ret, src, 4);
4196
+ static public unsafe short Int16FromNative (byte [] data, int index)
4199
+ throw new ArgumentNullException ("data");
4200
+ if (data.Length - index < 2)
4201
+ throw new ArgumentException ("index");
4203
+ throw new ArgumentException ("index");
4206
+ fixed (byte *src = &data[index]){
4207
+ PutBytesNative ((byte *) &ret, src, 2);
4212
+ static public unsafe ushort UInt16FromNative (byte [] data, int index)
4215
+ throw new ArgumentNullException ("data");
4216
+ if (data.Length - index < 2)
4217
+ throw new ArgumentException ("index");
4219
+ throw new ArgumentException ("index");
4222
+ fixed (byte *src = &data[index]){
4223
+ PutBytesNative ((byte *) &ret, src, 2);
4228
+ unsafe static byte[] GetBytesPtr (byte *ptr, int count)
4230
+ byte [] ret = new byte [count];
4232
+ for (int i = 0; i < count; i++) {
4233
+ ret [i] = ptr [i];
4239
+ unsafe static byte[] GetBytesSwap (bool swap, byte *ptr, int count)
4241
+ byte [] ret = new byte [count];
4245
+ for (int i = 0; i < count; i++) {
4246
+ ret [t-i] = ptr [i];
4249
+ for (int i = 0; i < count; i++) {
4250
+ ret [i] = ptr [i];
4256
+ unsafe public static byte[] GetBytesNative (bool value)
4258
+ return GetBytesPtr ((byte *) &value, 1);
4261
+ unsafe public static byte[] GetBytesNative (char value)
4263
+ return GetBytesPtr ((byte *) &value, 2);
4266
+ unsafe public static byte[] GetBytesNative (short value)
4268
+ return GetBytesPtr ((byte *) &value, 2);
4271
+ unsafe public static byte[] GetBytesNative (int value)
4273
+ return GetBytesPtr ((byte *) &value, 4);
4276
+ unsafe public static byte[] GetBytesNative (long value)
4278
+ return GetBytesPtr ((byte *) &value, 8);
4281
+ [CLSCompliant (false)]
4282
+ unsafe public static byte[] GetBytesNative (ushort value)
4284
+ return GetBytesPtr ((byte *) &value, 2);
4287
+ [CLSCompliant (false)]
4288
+ unsafe public static byte[] GetBytesNative (uint value)
4290
+ return GetBytesPtr ((byte *) &value, 4);
4293
+ [CLSCompliant (false)]
4294
+ unsafe public static byte[] GetBytesNative (ulong value)
4296
+ return GetBytesPtr ((byte *) &value, 8);
4299
+ unsafe public static byte[] GetBytesNative (float value)
4301
+ return GetBytesPtr ((byte *) &value, 4);
4304
+ unsafe public static byte[] GetBytesNative (double value)
4306
+ return GetBytesPtr ((byte *) &value, 8);
4309
+ unsafe public static byte[] GetBytesLE (bool value)
4311
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 1);
4314
+ unsafe public static byte[] GetBytesLE (char value)
4316
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
4319
+ unsafe public static byte[] GetBytesLE (short value)
4321
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
4324
+ unsafe public static byte[] GetBytesLE (int value)
4326
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
4329
+ unsafe public static byte[] GetBytesLE (long value)
4331
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
4334
+ [CLSCompliant (false)]
4335
+ unsafe public static byte[] GetBytesLE (ushort value)
4337
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 2);
4340
+ [CLSCompliant (false)]
4341
+ unsafe public static byte[] GetBytesLE (uint value)
4343
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
4346
+ [CLSCompliant (false)]
4347
+ unsafe public static byte[] GetBytesLE (ulong value)
4349
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
4352
+ unsafe public static byte[] GetBytesLE (float value)
4354
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 4);
4357
+ unsafe public static byte[] GetBytesLE (double value)
4359
+ return GetBytesSwap (!BitConverter.IsLittleEndian, (byte *) &value, 8);
4362
+ unsafe public static byte[] GetBytesBE (bool value)
4364
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 1);
4367
+ unsafe public static byte[] GetBytesBE (char value)
4369
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
4372
+ unsafe public static byte[] GetBytesBE (short value)
4374
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
4377
+ unsafe public static byte[] GetBytesBE (int value)
4379
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
4382
+ unsafe public static byte[] GetBytesBE (long value)
4384
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
4387
+ [CLSCompliant (false)]
4388
+ unsafe public static byte[] GetBytesBE (ushort value)
4390
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 2);
4393
+ [CLSCompliant (false)]
4394
+ unsafe public static byte[] GetBytesBE (uint value)
4396
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
4399
+ [CLSCompliant (false)]
4400
+ unsafe public static byte[] GetBytesBE (ulong value)
4402
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
4405
+ unsafe public static byte[] GetBytesBE (float value)
4407
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 4);
4410
+ unsafe public static byte[] GetBytesBE (double value)
4412
+ return GetBytesSwap (BitConverter.IsLittleEndian, (byte *) &value, 8);
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
4424
+using System.Collections.Generic;
4426
+namespace Mono.Debugger.Soft
4429
+ * Represents an enum value in the debuggee
4431
+ public class EnumMirror : StructMirror {
4433
+ internal EnumMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, type, fields) {
4436
+ internal EnumMirror (VirtualMachine vm, TypeMirror type, PrimitiveValue value) : base (vm, type, new Value[] { value }) {
4438
+ throw new ArgumentNullException ("type");
4439
+ if (value == null)
4440
+ throw new ArgumentNullException ("value");
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.");
4448
+ public object Value {
4450
+ return ((PrimitiveValue)Fields [0]).Value;
4453
+ SetField (0, vm.CreateValue (value));
4457
+ public string StringValue {
4459
+ foreach (FieldInfoMirror f in Type.GetFields ()) {
4461
+ object v = (Type.GetValue (f) as EnumMirror).Value;
4462
+ if (f.IsStatic && v.Equals (Value))
4466
+ return Value.ToString ();
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
4478
+namespace Mono.Debugger.Soft
4480
+ public abstract class Event {
4481
+ protected VirtualMachine vm;
4483
+ ThreadMirror thread;
4487
+ internal Event (EventType evtype, VirtualMachine vm, int req_id, long thread_id) {
4488
+ this.evtype = evtype;
4490
+ this.req_id = req_id;
4491
+ this.thread_id = thread_id;
4494
+ internal Event (EventType evtype, VirtualMachine vm) {
4495
+ this.evtype = evtype;
4497
+ this.thread_id = -1;
4500
+ public EventType EventType {
4506
+ public override string ToString () {
4507
+ return evtype.ToString ();
4510
+ public ThreadMirror Thread {
4512
+ if (thread_id == -1)
4514
+ if (thread == null)
4515
+ thread = vm.GetThread (thread_id);
4520
+ public EventRequest Request {
4522
+ return vm.GetRequest (req_id);
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
4534
+using System.Collections;
4535
+using System.Collections.Generic;
4537
+using System.Threading;
4538
+using Mono.Debugger;
4539
+using Mono.Debugger.Requests;
4540
+using Mono.Debugger.Events;
4542
+namespace Mono.Debugger.Soft
4544
+ class EventQueueImpl : MirrorImpl, EventQueue
4546
+ bool disconnected;
4547
+ Dictionary<int, byte[]> reply_packets;
4548
+ Thread receiver_thread;
4550
+ object queue_monitor;
4551
+ object reply_packets_monitor;
4553
+ public EventQueueImpl (VirtualMachineImpl vm) : base (vm) {
4554
+ reply_packets = new Dictionary<int, byte[]> ();
4555
+ reply_packets_monitor = new Object ();
4557
+ queue = new Queue ();
4558
+ queue_monitor = new Object ();
4559
+ receiver_thread = new Thread (new ThreadStart (receiver_thread_main));
4560
+ receiver_thread.Start ();
4563
+ public EventSet Remove () {
4565
+ // FIXME: VMDisconnectedException
4566
+ throw new IOException ();
4568
+ lock (queue_monitor) {
4569
+ if (queue.Count == 0)
4570
+ Monitor.Wait (queue_monitor);
4571
+ return (EventSet)queue.Dequeue ();
4575
+ public EventSet Remove (int timeout) {
4576
+ throw new NotImplementedException ();
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));
4593
+ throw new NotImplementedException ();
4597
+ EventRequest FindRequest (int requestId) {
4598
+ if (requestId == 0)
4601
+ return ((EventRequestManagerImpl)vm.EventRequestManager).FindRequest (requestId);
4604
+ // Wait for the reply for a command packet
4605
+ public byte[] WaitForReply (int packetId) {
4607
+ lock (reply_packets_monitor) {
4608
+ if (reply_packets.ContainsKey (packetId)) {
4609
+ byte[] reply = reply_packets [packetId];
4610
+ reply_packets.Remove (packetId);
4613
+ Monitor.Wait (reply_packets_monitor);
4619
+ void add_event_set (EventSet set) {
4620
+ lock (queue_monitor) {
4621
+ queue.Enqueue (set);
4622
+ Monitor.Pulse (queue_monitor);
4626
+ void receiver_thread_main () {
4628
+ Connection conn = vm.Connection;
4631
+ byte[] packet = conn.ReadPacket ();
4633
+ if (packet.Length == 0) {
4634
+ disconnected = true;
4636
+ VMDisconnectEventImpl ev = new VMDisconnectEventImpl (vm, null);
4637
+ add_event_set (new EventSetImpl (vm, new Event [] { ev }, SuspendPolicy.SuspendNone));
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);
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]);
4657
+ add_event_set (new EventSetImpl (vm, events, p.suspendPolicy));
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
4672
+using System.Collections.Generic;
4675
+namespace Mono.Debugger.Soft
4677
+ public abstract class EventRequest {
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;
4687
+ internal EventRequest (VirtualMachine vm, EventType etype) {
4689
+ this.etype = etype;
4690
+ this.suspend = SuspendPolicy.All;
4693
+ internal EventRequest (EventType etype, int id) {
4695
+ this.etype = etype;
4707
+ public EventType EventType {
4713
+ public bool Enabled {
4718
+ if (value != enabled) {
4727
+ public int Count {
4737
+ public ThreadMirror Thread {
4743
+ if (value != null && value.VirtualMachine != vm)
4744
+ throw new VMMismatchException ();
4749
+ public IList<AssemblyMirror> AssemblyFilter {
4751
+ return assembly_filter;
4755
+ if (value != null) {
4756
+ foreach (var ass in value)
4758
+ throw new ArgumentException ("one of the elements of the array is null.");
4760
+ assembly_filter = value;
4765
+ * Every time an EventRequest object is enabled, a new JDWP event request
4766
+ * is created, and the event request's id changes.
4768
+ internal void SendReq (List<Modifier> mods) {
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);
4781
+ public virtual void Enable () {
4782
+ SendReq (new List<Modifier> ());
4785
+ public void Disable () {
4787
+ vm.conn.ClearEventRequest (etype, id);
4789
+ // FIXME: This causes problems because Events can still reference
4791
+ //vm.RemoveRequest (this, id);
4796
+ protected void SetEnabled (int id) {
4799
+ vm.AddRequest (this, id);
4802
+ protected void CheckDisabled () {
4804
+ throw new InvalidOperationException ("Request objects can only be modified while they are disabled.");
4807
+ protected void CheckMirror (VirtualMachine vm, Mirror m) {
4808
+ if (vm != m.VirtualMachine)
4809
+ throw new VMMismatchException ();
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
4820
+namespace Mono.Debugger.Soft
4822
+ // Keep it in sync with debugger-agent.h
4823
+ public enum EventType {
4828
+ AppDomainCreate = 4,
4829
+ AppDomainUnload = 5,
4833
+ AssemblyUnload = 9,
4838
+ // Not part of the wire protocol
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
4849
+namespace Mono.Debugger.Soft
4851
+ public class ExceptionEvent : Event {
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;
4859
+ public ObjectMirror Exception {
4862
+ exc = vm.GetObject (exc_id);
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
4874
+using System.Collections.Generic;
4876
+namespace Mono.Debugger.Soft
4878
+ public sealed class ExceptionEventRequest : EventRequest {
4880
+ TypeMirror exc_type;
4881
+ bool caught, uncaught;
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");
4890
+ this.exc_type = exc_type;
4891
+ this.caught = caught;
4892
+ this.uncaught = uncaught;
4895
+ public TypeMirror ExceptionType {
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 });
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
4915
+using System.Collections.Generic;
4917
+using System.Reflection;
4918
+using C = Mono.Cecil;
4919
+using Mono.Cecil.Metadata;
4921
+namespace Mono.Debugger.Soft
4923
+ public class FieldInfoMirror : Mirror {
4925
+ TypeMirror parent;
4928
+ FieldAttributes attrs;
4929
+ CustomAttributeDataMirror[] cattrs;
4931
+ public FieldInfoMirror (TypeMirror parent, long id, string name, TypeMirror type, FieldAttributes attrs) : base (parent.VirtualMachine, id) {
4932
+ this.parent = parent;
4935
+ this.attrs = attrs;
4938
+ public TypeMirror DeclaringType {
4944
+ public string Name {
4950
+ public TypeMirror FieldType {
4956
+ public FieldAttributes Attributes {
4962
+ public bool IsLiteral
4964
+ get {return (Attributes & FieldAttributes.Literal) != 0;}
4967
+ public bool IsStatic
4969
+ get {return (Attributes & FieldAttributes.Static) != 0;}
4972
+ public bool IsInitOnly
4974
+ get {return (Attributes & FieldAttributes.InitOnly) != 0;}
4977
+ public Boolean IsPublic
4981
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
4985
+ public Boolean IsPrivate
4989
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
4993
+ public Boolean IsFamily
4997
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family;
5001
+ public Boolean IsAssembly
5005
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly;
5009
+ public Boolean IsFamilyAndAssembly
5012
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem;
5016
+ public Boolean IsFamilyOrAssembly
5020
+ return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem;
5024
+ public Boolean IsPinvokeImpl
5028
+ return (Attributes & FieldAttributes.PinvokeImpl) == FieldAttributes.PinvokeImpl;
5032
+ public Boolean IsSpecialName
5036
+ return (Attributes & FieldAttributes.SpecialName) == FieldAttributes.SpecialName;
5040
+ public Boolean IsNotSerialized
5044
+ return (Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized;
5048
+ public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
5049
+ return GetCAttrs (null, inherit);
5052
+ public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
5053
+ if (attributeType == null)
5054
+ throw new ArgumentNullException ("attributeType");
5055
+ return GetCAttrs (attributeType, inherit);
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);
5064
+ var res = new List<CustomAttributeDataMirror> ();
5065
+ foreach (var attr in cattrs)
5066
+ if (type == null || attr.Constructor.DeclaringType == type)
5068
+ return res.ToArray ();
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
5079
+using System.Collections.Generic;
5081
+namespace Mono.Debugger.Soft
5083
+ public interface IInvokeAsyncResult : IAsyncResult
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
5094
+using System.Collections.Generic;
5096
+using Mono.Cecil.Cil;
5097
+using Mono.Cecil.Metadata;
5099
+using System.Reflection;
5101
+namespace Mono.Debugger.Soft
5104
+ * This is similar to the Instruction class in Cecil, we can't use that
5105
+ * as its constructor is internal.
5107
+ public class ILInstruction
5112
+ ILInstruction prev, next;
5114
+ internal ILInstruction (int offset, OpCode opcode, object operand) {
5115
+ this.offset = offset;
5116
+ this.opcode = opcode;
5117
+ this.operand = operand;
5120
+ public int Offset {
5126
+ public OpCode OpCode {
5132
+ public Object Operand {
5141
+ public ILInstruction Next {
5150
+ public ILInstruction Previous {
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
5167
+namespace Mono.Debugger.Soft
5170
+ * A Mirror represents a runtime object in the remote virtual machine. Calling
5171
+ * methods/properties of mirror objects potentially involves a remoting call,
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
5176
+ * FIXME: Thread safety in the api ?
5178
+ public interface IMirror
5180
+ VirtualMachine VirtualMachine {
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
5191
+using System.Diagnostics;
5194
+namespace Mono.Debugger.Soft
5196
+ public interface ITargetProcess
5198
+ event System.EventHandler Exited;
5199
+ StreamReader StandardOutput { get; }
5200
+ StreamReader StandardError { get; }
5201
+ bool HasExited { get; }
5204
+ string ProcessName { get; }
5207
+ internal class ProcessWrapper: ITargetProcess
5211
+ public ProcessWrapper (Process process)
5213
+ this.process = process;
5216
+ public Process Process {
5217
+ get { return process; }
5220
+ public event System.EventHandler Exited {
5221
+ add { process.Exited += value; }
5222
+ remove { process.Exited -= value; }
5225
+ public StreamReader StandardOutput {
5227
+ return process.StandardOutput;
5231
+ public StreamReader StandardError {
5233
+ return process.StandardError;
5237
+ public bool HasExited {
5239
+ return process.HasExited;
5243
+ public void Kill ()
5250
+ return process.Id;
5254
+ public string ProcessName {
5256
+ return process.ProcessName;
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
5271
+namespace Mono.Debugger.Soft
5273
+ public class InvalidStackFrameException : Exception {
5275
+ public InvalidStackFrameException () : base ("The requested operation cannot be completed because the specified stack frame is no longer valid.") {
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
5285
+using System.Collections.Generic;
5287
+namespace Mono.Debugger.Soft
5289
+ public class InvocationException : Exception {
5291
+ ObjectMirror exception;
5293
+ public InvocationException (ObjectMirror exception) {
5294
+ this.exception = exception;
5297
+ public ObjectMirror Exception {
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
5311
+using System.Collections.Generic;
5313
+namespace Mono.Debugger.Soft
5316
+ public enum InvokeOptions {
5319
+ * Disable breakpoints on the thread doing the invoke
5321
+ DisableBreakpoints = 1,
5323
+ * Only resume the target thread during the invoke
5325
+ SingleThreaded = 2
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
5335
+namespace Mono.Debugger.Soft
5337
+ public class LocalVariable : Mirror {
5339
+ MethodMirror method;
5345
+ int live_range_start, live_range_end;
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;
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;
5357
+ public string Name {
5363
+ public int Index {
5369
+ public TypeMirror Type {
5372
+ t = vm.GetType (type_id);
5377
+ public bool IsArg {
5383
+ public MethodMirror Method {
5389
+ internal int LiveRangeStart {
5391
+ return live_range_start;
5395
+ internal int LiveRangeEnd {
5397
+ return live_range_end;
5401
+ internal int GetValueIndex {
5404
+ return (-Index) - 1;
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
5419
+namespace Mono.Debugger.Soft
5421
+ public class Location : Mirror
5423
+ MethodMirror method;
5424
+ //long native_addr;
5426
+ string source_file;
5428
+ //int column_number;
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;
5439
+ public MethodMirror Method {
5445
+ public int ILOffset {
5451
+ public string SourceFile {
5453
+ return source_file;
5457
+ public int LineNumber {
5459
+ return line_number;
5463
+ public override string ToString () {
5464
+ return String.Format ("{0}+0x{1:x} at {2}:{3}", Method.FullName, ILOffset, SourceFile, LineNumber);
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
5474
+using System.Collections.Generic;
5476
+using Mono.Cecil.Cil;
5477
+using Mono.Cecil.Metadata;
5479
+using System.Reflection;
5481
+namespace Mono.Debugger.Soft
5483
+ public class MethodBodyMirror : Mirror
5485
+ MethodMirror method;
5488
+ internal MethodBodyMirror (VirtualMachine vm, MethodMirror method, byte[] il) : base (vm, 0) {
5489
+ this.method = method;
5493
+ public MethodMirror Method {
5499
+ public byte[] GetILAsByteArray () {
5503
+ public List<ILInstruction> Instructions {
5505
+ return ReadCilBody (new BinaryReader (new MemoryStream (il)), il.Length);
5509
+ static bool opcodes_inited;
5511
+ static OpCode [] OneByteOpCode = new OpCode [0xe0 + 1];
5512
+ static OpCode [] TwoBytesOpCode = new OpCode [0x1e + 1];
5514
+ // Adapted from Cecil
5515
+ List<ILInstruction> ReadCilBody (BinaryReader br, int code_size)
5517
+ long start = br.BaseStream.Position;
5518
+ ILInstruction last = null;
5519
+ //GenericContext context = new GenericContext (body.Method);
5520
+ List<ILInstruction> code = new List<ILInstruction> ();
5522
+ var by_offset = new Dictionary<int, ILInstruction> ();
5524
+ if (!opcodes_inited) {
5525
+ foreach (FieldInfo fi in typeof (OpCodes).GetFields (BindingFlags.Static|BindingFlags.Public)) {
5526
+ var val = (OpCode)fi.GetValue (null);
5528
+ if (val.Op1 == 0xff)
5529
+ OneByteOpCode [val.Op2] = val;
5531
+ TwoBytesOpCode [val.Op2] = val;
5533
+ opcodes_inited = true;
5536
+ while (br.BaseStream.Position < start + code_size) {
5538
+ long offset = br.BaseStream.Position - start;
5539
+ int cursor = br.ReadByte ();
5543
+ if (cursor == 0xfe)
5544
+ op = TwoBytesOpCode [br.ReadByte ()];
5546
+ op = OneByteOpCode [cursor];
5548
+ ILInstruction instr = new ILInstruction ((int)offset, op, null);
5550
+ by_offset [instr.Offset] = instr;
5552
+ switch (op.OperandType) {
5553
+ case OperandType.InlineNone :
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;
5565
+ case OperandType.ShortInlineBrTarget :
5566
+ sbyte sbrtgt = br.ReadSByte ();
5567
+ instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + sbrtgt);
5569
+ case OperandType.InlineBrTarget :
5570
+ int brtgt = br.ReadInt32 ();
5571
+ instr.Operand = Convert.ToInt32 (br.BaseStream.Position - start + brtgt);
5573
+ case OperandType.ShortInlineI :
5574
+ if (op == OpCodes.Ldc_I4_S)
5575
+ instr.Operand = br.ReadSByte ();
5577
+ instr.Operand = br.ReadByte ();
5579
+ case OperandType.ShortInlineVar :
5581
+ //instr.Operand = GetVariable (body, br.ReadByte ());
5583
+ case OperandType.ShortInlineParam :
5585
+ //instr.Operand = GetParameter (body, br.ReadByte ());
5587
+ case OperandType.InlineSig :
5589
+ //instr.Operand = GetCallSiteAt (br.ReadInt32 (), context);
5591
+ case OperandType.InlineI :
5593
+ //instr.Operand = br.ReadInt32 ();
5595
+ case OperandType.InlineVar :
5597
+ //instr.Operand = GetVariable (body, br.ReadInt16 ());
5599
+ case OperandType.InlineParam :
5601
+ //instr.Operand = GetParameter (body, br.ReadInt16 ());
5603
+ case OperandType.InlineI8 :
5604
+ instr.Operand = br.ReadInt64 ();
5606
+ case OperandType.ShortInlineR :
5607
+ instr.Operand = br.ReadSingle ();
5609
+ case OperandType.InlineR :
5610
+ instr.Operand = br.ReadDouble ();
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;
5618
+ case OperandType.InlineField :
5619
+ case OperandType.InlineMethod :
5620
+ case OperandType.InlineType :
5621
+ case OperandType.InlineTok :
5622
+ token = br.ReadInt32 ();
5624
+ t = vm.conn.Method_ResolveToken (Method.Id, token);
5627
+ case TokenType.TYPE:
5628
+ instr.Operand = vm.GetType (t.Id);
5630
+ case TokenType.FIELD:
5631
+ // FIXME: No vm.GetField ()
5632
+ //instr.Operand = vm.GetField (t.Id);
5634
+ case TokenType.METHOD:
5635
+ instr.Operand = vm.GetMethod (t.Id);
5637
+ case TokenType.UNKNOWN:
5640
+ throw new NotImplementedException ("Unknown token type: " + t.Type);
5645
+ if (last != null) {
5646
+ last.Next = instr;
5647
+ instr.Previous = last;
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];
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;
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
5682
+namespace Mono.Debugger.Soft
5684
+ public class MethodEntryEvent : Event {
5685
+ MethodMirror method;
5688
+ internal MethodEntryEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.MethodEntry, vm, req_id, thread_id) {
5692
+ public MethodMirror Method {
5694
+ if (method == null)
5695
+ method = vm.GetMethod (id);
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
5708
+namespace Mono.Debugger.Soft
5710
+ public sealed class MethodEntryEventRequest : EventRequest {
5712
+ internal MethodEntryEventRequest (VirtualMachine vm) : base (vm, EventType.MethodEntry) {
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
5723
+namespace Mono.Debugger.Soft
5725
+ public class MethodExitEvent : Event {
5726
+ MethodMirror method;
5729
+ internal MethodExitEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.MethodExit, vm, req_id, thread_id) {
5733
+ public MethodMirror Method {
5735
+ if (method == null)
5736
+ method = vm.GetMethod (id);
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
5749
+namespace Mono.Debugger.Soft
5751
+ public sealed class MethodExitEventRequest : EventRequest {
5753
+ internal MethodExitEventRequest (VirtualMachine vm) : base (vm, EventType.MethodExit) {
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
5764
+using System.Collections.Generic;
5766
+using System.Reflection;
5767
+using C = Mono.Cecil;
5768
+using Mono.Cecil.Metadata;
5770
+namespace Mono.Debugger.Soft
5772
+ public class MethodMirror : Mirror
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;
5785
+ internal MethodMirror (VirtualMachine vm, long id) : base (vm, id) {
5788
+ public string Name {
5791
+ name = vm.conn.Method_GetName (id);
5796
+ public TypeMirror DeclaringType {
5798
+ if (declaring_type == null)
5799
+ declaring_type = vm.GetType (vm.conn.Method_GetDeclaringType (id));
5800
+ return declaring_type;
5804
+ public TypeMirror ReturnType {
5806
+ return ReturnParameter.ParameterType;
5811
+ public string FullName {
5813
+ string type_namespace = DeclaringType.Namespace;
5814
+ string type_name = DeclaringType.Name;
5815
+ StringBuilder sb = new StringBuilder ();
5816
+ sb.Append (ReturnType.Name);
5818
+ if (type_namespace == String.Empty)
5819
+ sb.Append (type_name + ":" + Name + " ()");
5821
+ sb.Append (type_namespace + "." + type_name + ":" + Name + " ()");
5822
+ return sb.ToString ();
5828
+ info = vm.conn.Method_GetInfo (id);
5831
+ public int MetadataToken {
5834
+ return info.token;
5838
+ public MethodAttributes Attributes {
5841
+ return (MethodAttributes)info.attributes;
5845
+ public bool IsPublic {
5847
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
5850
+ public bool IsPrivate {
5852
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
5855
+ public bool IsFamily {
5857
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
5860
+ public bool IsAssembly {
5862
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
5865
+ public bool IsFamilyAndAssembly {
5867
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
5870
+ public bool IsFamilyOrAssembly {
5872
+ return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
5875
+ public bool IsStatic {
5877
+ return (Attributes & MethodAttributes.Static) != 0;
5880
+ public bool IsFinal {
5882
+ return (Attributes & MethodAttributes.Final) != 0;
5885
+ public bool IsVirtual {
5887
+ return (Attributes & MethodAttributes.Virtual) != 0;
5890
+ public bool IsHideBySig {
5892
+ return (Attributes & MethodAttributes.HideBySig) != 0;
5895
+ public bool IsAbstract {
5897
+ return (Attributes & MethodAttributes.Abstract) != 0;
5900
+ public bool IsSpecialName {
5902
+ return (Attributes & MethodAttributes.SpecialName) != 0;
5906
+ public bool IsConstructor {
5908
+ int attr = (int)Attributes;
5909
+ return ((attr & (int)MethodAttributes.RTSpecialName) != 0
5910
+ && (Name == ".ctor"));
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];
5919
+ ret_param = new ParameterInfoMirror (this, -1, vm.GetType (pi.ret_type), null, ParameterAttributes.Retval);
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);
5927
+ return param_info;
5930
+ public ParameterInfoMirror ReturnParameter {
5932
+ if (ret_param == null)
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);
5944
+ locals = new LocalVariable [pi.param_count + li.names.Length];
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);
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);
5955
+ public LocalVariable GetLocal (string name) {
5957
+ throw new ArgumentNullException ("name");
5961
+ LocalVariable res = null;
5962
+ for (int i = 0; i < locals.Length; ++i) {
5963
+ if (locals [i].Name == name) {
5965
+ throw new AmbiguousMatchException ("More that one local has the name '" + name + "'.");
5973
+ public MethodBodyMirror GetMethodBody () {
5974
+ if (body == null) {
5975
+ MethodBodyInfo info = vm.conn.Method_GetBody (id);
5977
+ body = new MethodBodyMirror (vm, this, info.il);
5982
+ public IList<int> ILOffsets {
5984
+ if (debug_info == null)
5985
+ debug_info = vm.conn.Method_GetDebugInfo (id);
5986
+ return Array.AsReadOnly (debug_info.il_offsets);
5990
+ public IList<int> LineNumbers {
5992
+ if (debug_info == null)
5993
+ debug_info = vm.conn.Method_GetDebugInfo (id);
5994
+ return Array.AsReadOnly (debug_info.line_numbers);
5998
+ public string SourceFile {
6000
+ if (debug_info == null)
6001
+ debug_info = vm.conn.Method_GetDebugInfo (id);
6002
+ return debug_info.filename;
6006
+ public IList<Location> Locations {
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);
6020
+ internal int il_offset_to_line_number (int il_offset) {
6021
+ if (debug_info == null)
6022
+ debug_info = vm.conn.Method_GetDebugInfo (id);
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];
6032
+ public Location LocationAtILOffset (int il_offset) {
6033
+ IList<Location> locs = Locations;
6035
+ // FIXME: Optimize this
6036
+ for (int i = locs.Count - 1; i >= 0; --i) {
6037
+ if (locs [i].ILOffset <= il_offset)
6044
+ public C.MethodDefinition Metadata {
6047
+ meta = (C.MethodDefinition)DeclaringType.Assembly.Metadata.MainModule.LookupByToken (new MetadataToken (MetadataToken));
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
6060
+namespace Mono.Debugger.Soft
6062
+ public abstract class Mirror : IMirror
6064
+ protected VirtualMachine vm;
6065
+ protected long id; // The id used in the protocol
6067
+ internal Mirror (VirtualMachine vm, long id) {
6072
+ internal Mirror () {
6075
+ public VirtualMachine VirtualMachine {
6081
+ internal long Id {
6087
+ protected void SetVirtualMachine (VirtualMachine vm) {
6091
+ protected void CheckMirror (Mirror m) {
6092
+ if (vm != m.VirtualMachine)
6093
+ throw new VMMismatchException ();
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
6103
+using Mono.Debugger;
6106
+namespace Mono.Debugger.Soft
6108
+ public class ModuleMirror : Mirror
6112
+ AssemblyMirror assembly;
6114
+ internal ModuleMirror (VirtualMachine vm, long id) : base (vm, id) {
6117
+ void ReadInfo () {
6119
+ info = vm.conn.Module_GetInfo (id);
6122
+ public string Name {
6129
+ public string ScopeName {
6132
+ return info.ScopeName;
6136
+ public string FullyQualifiedName {
6139
+ return info.FQName;
6143
+ public Guid ModuleVersionId {
6145
+ if (guid == Guid.Empty) {
6147
+ guid = new Guid (info.Guid);
6153
+ public AssemblyMirror Assembly {
6155
+ if (assembly == null) {
6157
+ if (info.Assembly == 0)
6159
+ assembly = vm.GetAssembly (info.Assembly);
6165
+ // FIXME: Add function to query the guid, check in Metadata
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
6175
+namespace Mono.Debugger.Soft
6177
+ public class ObjectCollectedException : Exception {
6179
+ public ObjectCollectedException () : base ("The requested operation cannot be completed because the object has been garbage collected.") {
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
6189
+using System.Collections.Generic;
6190
+using System.Runtime.Remoting.Messaging;
6191
+using System.Threading;
6193
+namespace Mono.Debugger.Soft
6195
+ public class ObjectMirror : Value {
6197
+ internal ObjectMirror (VirtualMachine vm, long id) : base (vm, id) {
6200
+ public TypeMirror Type {
6202
+ return vm.GetType (vm.conn.Object_GetType (id));
6206
+ public AppDomainMirror Domain {
6208
+ return vm.GetDomain (vm.conn.Object_GetDomain (id));
6212
+ public bool IsCollected {
6214
+ return vm.conn.Object_IsCollected (id);
6218
+ public Value GetValue (FieldInfoMirror field) {
6219
+ return GetValues (new FieldInfoMirror [] { field }) [0];
6222
+ public Value[] GetValues (IList<FieldInfoMirror> fields) {
6223
+ if (fields == null)
6224
+ throw new ArgumentNullException ("fields");
6225
+ foreach (FieldInfoMirror f in fields) {
6227
+ throw new ArgumentNullException ("field");
6230
+ long[] ids = new long [fields.Count];
6231
+ for (int i = 0; i < fields.Count; ++i)
6232
+ ids [i] = fields [i].Id;
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");
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) {
6250
+ throw new ArgumentNullException ("field");
6253
+ foreach (Value v in values) {
6255
+ throw new ArgumentNullException ("values");
6258
+ long[] ids = new long [fields.Count];
6259
+ for (int i = 0; i < fields.Count; ++i)
6260
+ ids [i] = fields [i].Id;
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");
6273
+ public void SetValue (FieldInfoMirror field, Value value) {
6274
+ SetValues (new FieldInfoMirror [] { field }, new Value [] { value });
6278
+ * The current address of the object. It can change during garbage
6279
+ * collections. Use a long since the debuggee might have a different
6282
+ public long Address {
6284
+ return vm.conn.Object_GetAddress (id);
6288
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
6289
+ return InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
6292
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
6293
+ return InvokeMethod (vm, thread, method, this, arguments, options);
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);
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);
6305
+ public Value EndInvokeMethod (IAsyncResult asyncResult) {
6306
+ return EndInvokeMethodInternal (asyncResult);
6310
+ * Common implementation for invokes
6313
+ class InvokeAsyncResult : IInvokeAsyncResult {
6315
+ public object AsyncState {
6319
+ public WaitHandle AsyncWaitHandle {
6323
+ public bool CompletedSynchronously {
6329
+ public bool IsCompleted {
6333
+ public AsyncCallback Callback {
6337
+ public ErrorCode ErrorCode {
6341
+ public VirtualMachine VM {
6345
+ public ThreadMirror Thread {
6349
+ public ValueImpl Value {
6353
+ public ValueImpl Exception {
6361
+ public void Abort ()
6363
+ if (ID == 0) // Ooops
6366
+ ObjectMirror.AbortInvoke (VM, Thread, ID);
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];
6378
+ InvokeFlags f = InvokeFlags.NONE;
6380
+ if ((options & InvokeOptions.DisableBreakpoints) != 0)
6381
+ f |= InvokeFlags.DISABLE_BREAKPOINTS;
6382
+ if ((options & InvokeOptions.SingleThreaded) != 0)
6383
+ f |= InvokeFlags.SINGLE_THREADED;
6385
+ InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback };
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);
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;
6397
+ r.ErrorCode = error;
6400
+ r.Exception = exc;
6403
+ r.IsCompleted = true;
6404
+ ((ManualResetEvent)r.AsyncWaitHandle).Set ();
6406
+ if (r.Callback != null)
6407
+ r.Callback.BeginInvoke (r, null, null);
6410
+ internal static Value EndInvokeMethodInternal (IAsyncResult asyncResult) {
6411
+ if (asyncResult == null)
6412
+ throw new ArgumentNullException ("asyncResult");
6414
+ InvokeAsyncResult r = (InvokeAsyncResult)asyncResult;
6416
+ if (!r.IsCompleted)
6417
+ r.AsyncWaitHandle.WaitOne ();
6419
+ if (r.ErrorCode != 0) {
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");
6428
+ throw new NotImplementedException ();
6430
+ if (r.Exception != null)
6431
+ throw new InvocationException ((ObjectMirror)r.VM.DecodeValue (r.Exception));
6433
+ return r.VM.DecodeValue (r.Value);
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));
6441
+ internal static void AbortInvoke (VirtualMachine vm, ThreadMirror thread, int id)
6443
+ vm.conn.VM_AbortInvoke (thread.Id, id);
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
6453
+using System.Collections.Generic;
6455
+using System.Reflection;
6457
+namespace Mono.Debugger.Soft
6459
+ public class ParameterInfoMirror : Mirror {
6461
+ MethodMirror method;
6465
+ ParameterAttributes attrs;
6467
+ internal ParameterInfoMirror (MethodMirror method, int pos, TypeMirror type, string name, ParameterAttributes attrs) : base (method.VirtualMachine, 0) {
6468
+ this.method = method;
6472
+ this.attrs = attrs;
6475
+ public TypeMirror ParameterType {
6481
+ public MethodMirror Method {
6487
+ public string Name {
6493
+ public int Position {
6499
+ public ParameterAttributes Attributes {
6505
+ public bool IsRetval {
6507
+ return (Attributes & ParameterAttributes.Retval) != 0;
6511
+ public override string ToString () {
6512
+ return String.Format ("ParameterInfo ({0})", Name);
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
6523
+using System.Collections.Generic;
6525
+namespace Mono.Debugger.Soft
6528
+ * Represents a value of a primitive type in the debuggee
6530
+ public class PrimitiveValue : Value {
6534
+ public PrimitiveValue (VirtualMachine vm, object value) : base (vm, 0) {
6535
+ this.value = value;
6538
+ public object Value {
6544
+ public override bool Equals (object obj) {
6547
+ if (obj != null && obj is PrimitiveValue)
6548
+ return value == (obj as PrimitiveValue).Value;
6549
+ return base.Equals (obj);
6552
+ public override int GetHashCode () {
6553
+ return base.GetHashCode ();
6556
+ public override string ToString () {
6557
+ return "PrimitiveValue<" + Value + ">";
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
6568
+using System.Collections.Generic;
6570
+using System.Reflection;
6571
+using C = Mono.Cecil;
6572
+using Mono.Cecil.Metadata;
6574
+namespace Mono.Debugger.Soft
6576
+ public class PropertyInfoMirror : Mirror {
6578
+ TypeMirror parent;
6580
+ PropertyAttributes attrs;
6581
+ MethodMirror get_method, set_method;
6582
+ CustomAttributeDataMirror[] cattrs;
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;
6587
+ this.attrs = attrs;
6588
+ this.get_method = get_method;
6589
+ this.set_method = set_method;
6592
+ public TypeMirror DeclaringType {
6598
+ public string Name {
6604
+ public TypeMirror PropertyType {
6606
+ if (get_method != null)
6607
+ return get_method.ReturnType;
6609
+ ParameterInfoMirror[] parameters = set_method.GetParameters ();
6611
+ return parameters [parameters.Length - 1].ParameterType;
6616
+ public PropertyAttributes Attributes {
6622
+ public bool IsSpecialName {
6623
+ get {return (Attributes & PropertyAttributes.SpecialName) != 0;}
6626
+ public MethodMirror GetGetMethod ()
6628
+ return GetGetMethod (false);
6631
+ public MethodMirror GetGetMethod (bool nonPublic)
6633
+ if (get_method != null && (nonPublic || get_method.IsPublic))
6634
+ return get_method;
6639
+ public MethodMirror GetSetMethod ()
6641
+ return GetSetMethod (false);
6644
+ public MethodMirror GetSetMethod (bool nonPublic)
6646
+ if (set_method != null && (nonPublic || set_method.IsPublic))
6647
+ return set_method;
6652
+ public ParameterInfoMirror[] GetIndexParameters()
6654
+ if (get_method != null)
6655
+ return get_method.GetParameters ();
6656
+ return new ParameterInfoMirror [0];
6659
+ public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
6660
+ return GetCAttrs (null, inherit);
6663
+ public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
6664
+ if (attributeType == null)
6665
+ throw new ArgumentNullException ("attributeType");
6666
+ return GetCAttrs (attributeType, inherit);
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);
6675
+ var res = new List<CustomAttributeDataMirror> ();
6676
+ foreach (var attr in cattrs)
6677
+ if (type == null || attr.Constructor.DeclaringType == type)
6679
+ return res.ToArray ();
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
6690
+using System.Collections.Generic;
6693
+namespace Mono.Debugger.Soft
6695
+ public class StackFrame : Mirror
6697
+ ThreadMirror thread;
6698
+ MethodMirror method;
6700
+ Location location;
6701
+ StackFrameFlags flags;
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.
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;
6717
+ public ThreadMirror Thread {
6723
+ public MethodMirror Method {
6729
+ public Location Location {
6731
+ if (location == null) {
6734
+ if (il_offset == -1)
6737
+ line_number = method.il_offset_to_line_number (il_offset);
6739
+ location = new Location (vm, Method, 0, il_offset, method.SourceFile, line_number, 0);
6745
+ public string FileName {
6747
+ return Location.SourceFile;
6751
+ public int ILOffset {
6753
+ return Location.ILOffset;
6757
+ public int LineNumber {
6759
+ return Location.LineNumber;
6763
+ public bool IsDebuggerInvoke {
6765
+ return (flags & StackFrameFlags.DEBUGGER_INVOKE) != 0;
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.");
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]);
6782
+ public Value GetValue (LocalVariable var) {
6784
+ throw new ArgumentNullException ("var");
6785
+ if (var.Method != Method)
6786
+ throw new ArgumentException ("Local variable doesn't belong to this frame's method.");
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]);
6794
+ public Value[] GetValues (LocalVariable[] vars) {
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.");
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));
6809
+ public Value GetArgument (int pos) {
6810
+ return GetValue (Method.GetParameters () [pos]);
6813
+ public Value GetThis () {
6814
+ return vm.DecodeValue (vm.conn.StackFrame_GetThis (thread.Id, Id));
6817
+ public void SetValue (LocalVariable var, Value value) {
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
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.");
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);
6848
+ // FIXME: Liveness
6849
+ // FIXME: Allow setting the frame return value if possible
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.");
6860
+ public IList<LocalVariable> GetVisibleVariables () {
6861
+ if (Location.ILOffset == -1)
6862
+ throw new AbsentInformationException ();
6864
+ return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset).ToList ();
6867
+ public LocalVariable GetVisibleVariableByName (string name) {
6869
+ throw new ArgumentNullException ("name");
6871
+ if (Location.ILOffset == -1)
6872
+ throw new AbsentInformationException ();
6874
+ return Method.GetLocals ().Where (l => l.LiveRangeStart <= location.ILOffset && l.LiveRangeEnd >= location.ILOffset && l.Name == name).FirstOrDefault ();
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
6884
+namespace Mono.Debugger.Soft
6886
+ public class StepEvent : Event {
6887
+ MethodMirror method;
6890
+ internal StepEvent (VirtualMachine vm, int req_id, long thread_id, long id, long loc) : base (EventType.Step, vm, req_id, thread_id) {
6895
+ public MethodMirror Method {
6897
+ if (method == null)
6898
+ method = vm.GetMethod (id);
6903
+ public long Location {
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
6916
+using System.Collections.Generic;
6918
+namespace Mono.Debugger.Soft
6920
+ public enum StepDepth {
6926
+ public enum StepSize {
6931
+ public sealed class StepEventRequest : EventRequest {
6933
+ ThreadMirror step_thread;
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;
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 });
6952
+ public new ThreadMirror Thread {
6954
+ return step_thread;
6958
+ public StepDepth Depth {
6968
+ public StepSize Size {
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
6986
+using System.Collections;
6988
+namespace Mono.Debugger.Soft
6990
+ public class StringMirror : ObjectMirror {
6992
+ internal StringMirror (VirtualMachine vm, long id) : base (vm, id) {
6995
+ public string Value {
6997
+ return vm.conn.String_GetValue (id);
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
7008
+using System.Collections.Generic;
7010
+namespace Mono.Debugger.Soft
7013
+ * Represents a valuetype value in the debuggee
7015
+ public class StructMirror : Value {
7020
+ internal StructMirror (VirtualMachine vm, TypeMirror type, Value[] fields) : base (vm, 0) {
7022
+ this.fields = fields;
7025
+ public TypeMirror Type {
7031
+ public Value[] Fields {
7037
+ public Value this [String field] {
7039
+ FieldInfoMirror[] field_info = Type.GetFields ();
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];
7048
+ throw new ArgumentException ("Unknown struct field '" + field + "'.", "field");
7052
+ internal void SetField (int index, Value value) {
7053
+ fields [index] = value;
7056
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
7057
+ return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, InvokeOptions.None);
7060
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
7061
+ return ObjectMirror.InvokeMethod (vm, thread, method, this, arguments, options);
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);
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);
7073
+ public Value EndInvokeMethod (IAsyncResult asyncResult) {
7074
+ return ObjectMirror.EndInvokeMethodInternal (asyncResult);
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
7084
+namespace Mono.Debugger.Soft
7086
+ // Keep it in sync with debugger-agent.h
7087
+ public enum SuspendPolicy {
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
7099
+namespace Mono.Debugger.Soft
7101
+ public class ThreadDeathEvent : Event {
7102
+ internal ThreadDeathEvent (VirtualMachine vm, int req_id, long id) : base (EventType.ThreadDeath, vm, req_id, id) {
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
7112
+using System.Threading;
7114
+namespace Mono.Debugger.Soft
7116
+ public class ThreadMirror : ObjectMirror
7120
+ internal ThreadMirror (VirtualMachine vm, long id) : base (vm, id) {
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);
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);
7137
+ public string Name {
7140
+ name = vm.conn.Thread_GetName (id);
7145
+ public new long Id {
7151
+ public ThreadState ThreadState {
7153
+ return (ThreadState)vm.conn.Thread_GetState (id);
7157
+ public bool IsThreadPoolThread {
7159
+ ThreadInfo info = vm.conn.Thread_GetInfo (id);
7161
+ return info.is_thread_pool;
7166
+ * Return a unique identifier for this thread, multiple ThreadMirror objects
7167
+ * may have the same ThreadId because of appdomains.
7169
+ public long ThreadId {
7171
+ return vm.conn.Thread_GetId (id);
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
7182
+namespace Mono.Debugger.Soft
7184
+ public class ThreadStartEvent : Event {
7185
+ internal ThreadStartEvent (VirtualMachine vm, int req_id, long id) : base (EventType.ThreadStart, vm, req_id, id) {
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
7195
+namespace Mono.Debugger.Soft
7197
+ public class TypeLoadEvent : Event {
7201
+ internal TypeLoadEvent (VirtualMachine vm, int req_id, long thread_id, long id) : base (EventType.TypeLoad, vm, req_id, thread_id) {
7205
+ public TypeMirror Type {
7208
+ type = vm.GetType (id);
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
7220
+using System.Collections.Generic;
7221
+using System.Reflection;
7222
+using C = Mono.Cecil;
7223
+using Mono.Cecil.Metadata;
7225
+namespace Mono.Debugger.Soft
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.
7232
+ public class TypeMirror : Mirror
7234
+ MethodMirror[] methods;
7235
+ AssemblyMirror ass;
7236
+ ModuleMirror module;
7237
+ C.TypeDefinition meta;
7238
+ FieldInfoMirror[] fields;
7239
+ PropertyInfoMirror[] properties;
7241
+ TypeMirror base_type, element_type;
7242
+ TypeMirror[] nested;
7243
+ CustomAttributeDataMirror[] cattrs;
7245
+ internal const BindingFlags DefaultBindingFlags =
7246
+ BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
7248
+ internal TypeMirror (VirtualMachine vm, long id) : base (vm, id) {
7251
+ public string Name {
7253
+ return GetInfo ().name;
7257
+ public string Namespace {
7259
+ return GetInfo ().ns;
7263
+ public AssemblyMirror Assembly {
7265
+ if (ass == null) {
7266
+ ass = vm.GetAssembly (GetInfo ().assembly);
7272
+ public ModuleMirror Module {
7274
+ if (module == null) {
7275
+ module = vm.GetModule (GetInfo ().module);
7281
+ public int MetadataToken {
7283
+ return GetInfo ().token;
7287
+ public TypeAttributes Attributes {
7289
+ return (TypeAttributes)GetInfo ().attributes;
7293
+ public TypeMirror BaseType {
7295
+ // FIXME: base_type could be null for object/interfaces
7296
+ if (base_type == null) {
7297
+ base_type = vm.GetType (GetInfo ().base_type);
7303
+ public int GetArrayRank () {
7305
+ if (info.rank == 0)
7306
+ throw new ArgumentException ("Type must be an array type.");
7311
+ public bool IsAbstract {
7313
+ return (Attributes & TypeAttributes.Abstract) != 0;
7317
+ public bool IsAnsiClass {
7319
+ return (Attributes & TypeAttributes.StringFormatMask)
7320
+ == TypeAttributes.AnsiClass;
7324
+ public bool IsArray {
7326
+ return IsArrayImpl ();
7330
+ public bool IsAutoClass {
7332
+ return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass;
7336
+ public bool IsAutoLayout {
7338
+ return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout;
7342
+ public bool IsByRef {
7344
+ return IsByRefImpl ();
7348
+ public bool IsClass {
7353
+ return !IsValueType;
7357
+ public bool IsCOMObject {
7359
+ return IsCOMObjectImpl ();
7363
+ public bool IsContextful {
7365
+ return IsContextfulImpl ();
7369
+ public bool IsEnum {
7371
+ return GetInfo ().is_enum;
7375
+ public bool IsExplicitLayout {
7377
+ return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout;
7381
+ public bool IsImport {
7383
+ return (Attributes & TypeAttributes.Import) != 0;
7387
+ public bool IsInterface {
7389
+ return (Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface;
7393
+ public bool IsLayoutSequential {
7395
+ return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout;
7399
+ public bool IsMarshalByRef {
7401
+ return IsMarshalByRefImpl ();
7405
+ public bool IsNestedAssembly {
7407
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedAssembly;
7411
+ public bool IsNestedFamANDAssem {
7413
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamANDAssem;
7417
+ public bool IsNestedFamily {
7419
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamily;
7423
+ public bool IsNestedFamORAssem {
7425
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedFamORAssem;
7429
+ public bool IsNestedPrivate {
7431
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPrivate;
7435
+ public bool IsNestedPublic {
7437
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
7441
+ public bool IsNotPublic {
7443
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NotPublic;
7447
+ public bool IsPointer {
7449
+ return IsPointerImpl ();
7453
+ public bool IsPrimitive {
7455
+ return IsPrimitiveImpl ();
7459
+ public bool IsPublic {
7461
+ return (Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.Public;
7465
+ public bool IsSealed {
7467
+ return (Attributes & TypeAttributes.Sealed) != 0;
7471
+ public bool IsSerializable {
7473
+ if ((Attributes & TypeAttributes.Serializable) != 0)
7481
+ public bool IsSpecialName {
7483
+ return (Attributes & TypeAttributes.SpecialName) != 0;
7487
+ public bool IsUnicodeClass {
7489
+ return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass;
7493
+ public bool IsValueType {
7495
+ return IsValueTypeImpl ();
7499
+ public bool HasElementType {
7501
+ return HasElementTypeImpl ();
7505
+ public TypeMirror GetElementType () {
7507
+ if (element_type == null && info.element_type != 0)
7508
+ element_type = vm.GetType (info.element_type);
7509
+ return element_type;
7512
+ public string FullName {
7514
+ return GetInfo ().full_name;
7518
+ public string CSharpName {
7521
+ if (GetArrayRank () == 1)
7522
+ return GetElementType ().CSharpName + "[]";
7524
+ string ranks = "";
7525
+ for (int i = 0; i < GetArrayRank (); ++i)
7527
+ return GetElementType ().CSharpName + "[" + ranks + "]";
7530
+ if (IsPrimitive) {
7542
+ // FIXME: Only do this for real corlib types
7543
+ if (Namespace == "System") {
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]);
7569
+ // FIXME: Sync this with Type
7570
+ public MethodMirror GetMethod (string name) {
7571
+ foreach (var m in GetMethods ())
7572
+ if (m.Name == name)
7577
+ public FieldInfoMirror[] GetFields () {
7578
+ if (fields != null)
7584
+ long[] ids = vm.conn.Type_GetFields (id, out names, out types, out attrs);
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]);
7594
+ public FieldInfoMirror GetField (string name) {
7596
+ throw new ArgumentNullException ("name");
7597
+ foreach (var f in GetFields ())
7598
+ if (f.Name == name)
7603
+ public TypeMirror[] GetNestedTypes ()
7605
+ return GetNestedTypes (DefaultBindingFlags);
7608
+ public TypeMirror[] GetNestedTypes (BindingFlags bindingAttr) {
7609
+ if (nested != null)
7612
+ // FIXME: bindingAttr
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]);
7622
+ public PropertyInfoMirror[] GetProperties () {
7623
+ return GetProperties (DefaultBindingFlags);
7626
+ public PropertyInfoMirror[] GetProperties (BindingFlags bindingAttr) {
7627
+ if (properties != null)
7628
+ return properties;
7630
+ PropInfo[] info = vm.conn.Type_GetProperties (id);
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);
7637
+ return properties;
7640
+ public PropertyInfoMirror GetProperty (string name) {
7642
+ throw new ArgumentNullException ("name");
7643
+ foreach (var p in GetProperties ())
7644
+ if (p.Name == name)
7649
+ public virtual bool IsAssignableFrom (TypeMirror c) {
7651
+ throw new ArgumentNullException ("c");
7655
+ // This is complex so do it in the debuggee
7656
+ return vm.conn.Type_IsAssignableFrom (id, c.Id);
7659
+ public Value GetValue (FieldInfoMirror field) {
7660
+ return GetValues (new FieldInfoMirror [] { field }) [0];
7663
+ public Value[] GetValues (IList<FieldInfoMirror> fields) {
7664
+ if (fields == null)
7665
+ throw new ArgumentNullException ("fields");
7666
+ foreach (FieldInfoMirror f in fields) {
7668
+ throw new ArgumentNullException ("field");
7671
+ long[] ids = new long [fields.Count];
7672
+ for (int i = 0; i < fields.Count; ++i)
7673
+ ids [i] = fields [i].Id;
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");
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) {
7691
+ throw new ArgumentNullException ("field");
7694
+ foreach (Value v in values) {
7696
+ throw new ArgumentNullException ("values");
7699
+ long[] ids = new long [fields.Count];
7700
+ for (int i = 0; i < fields.Count; ++i)
7701
+ ids [i] = fields [i].Id;
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");
7712
+ public void SetValue (FieldInfoMirror field, Value value) {
7713
+ SetValues (new FieldInfoMirror [] { field }, new Value [] { value });
7716
+ public ObjectMirror GetTypeObject () {
7717
+ return vm.GetObject (vm.conn.Type_GetObject (id));
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
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.
7728
+ public string[] GetSourceFiles () {
7729
+ return GetSourceFiles (false);
7732
+ public string[] GetSourceFiles (bool return_full_paths) {
7733
+ return vm.conn.Type_GetSourceFiles (id, return_full_paths);
7736
+ public C.TypeDefinition Metadata {
7738
+ if (meta == null) {
7739
+ if (Assembly.Metadata == null || MetadataToken == 0)
7741
+ meta = (C.TypeDefinition)Assembly.Metadata.MainModule.LookupByToken (new MetadataToken (MetadataToken));
7747
+ TypeInfo GetInfo () {
7749
+ info = vm.conn.Type_GetInfo (id);
7753
+ protected virtual TypeAttributes GetAttributeFlagsImpl () {
7754
+ return (TypeAttributes)GetInfo ().attributes;
7757
+ protected virtual bool HasElementTypeImpl () {
7758
+ return IsArray || IsByRef || IsPointer;
7761
+ protected virtual bool IsArrayImpl () {
7762
+ return GetInfo ().rank > 0;
7765
+ protected virtual bool IsByRefImpl () {
7766
+ return GetInfo ().is_byref;
7769
+ protected virtual bool IsCOMObjectImpl () {
7773
+ protected virtual bool IsPointerImpl () {
7774
+ return GetInfo ().is_pointer;
7777
+ protected virtual bool IsPrimitiveImpl () {
7778
+ return GetInfo ().is_primitive;
7781
+ protected virtual bool IsValueTypeImpl ()
7783
+ return GetInfo ().is_valuetype;
7786
+ protected virtual bool IsContextfulImpl ()
7792
+ protected virtual bool IsMarshalByRefImpl ()
7798
+ // Same as Enum.GetUnderlyingType ()
7799
+ public TypeMirror EnumUnderlyingType {
7802
+ throw new ArgumentException ("Type is not an enum type.");
7803
+ foreach (FieldInfoMirror f in GetFields ()) {
7805
+ return f.FieldType;
7807
+ throw new NotImplementedException ();
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.
7816
+ public CustomAttributeDataMirror[] GetCustomAttributes (bool inherit) {
7817
+ return GetCAttrs (null, inherit);
7820
+ public CustomAttributeDataMirror[] GetCustomAttributes (TypeMirror attributeType, bool inherit) {
7821
+ if (attributeType == null)
7822
+ throw new ArgumentNullException ("attributeType");
7823
+ return GetCAttrs (attributeType, inherit);
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);
7832
+ var res = new List<CustomAttributeDataMirror> ();
7833
+ foreach (var attr in cattrs)
7834
+ if (type == null || attr.Constructor.DeclaringType == type)
7836
+ return res.ToArray ();
7839
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
7840
+ return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, InvokeOptions.None);
7843
+ public Value InvokeMethod (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
7844
+ return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
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);
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);
7856
+ public Value EndInvokeMethod (IAsyncResult asyncResult) {
7857
+ return ObjectMirror.EndInvokeMethodInternal (asyncResult);
7860
+ public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments) {
7861
+ return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, InvokeOptions.None);
7864
+ public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
7865
+ return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
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
7876
+namespace Mono.Debugger.Soft
7878
+ public class VMDeathEvent : Event
7880
+ public VMDeathEvent (VirtualMachine vm, int req_id) : base (EventType.VMDeath, vm, req_id, -1) {
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
7891
+namespace Mono.Debugger.Soft
7893
+ public class VMDisconnectEvent : Event
7895
+ public VMDisconnectEvent (VirtualMachine vm, int req_id) : base (EventType.VMDisconnect, vm, req_id, -1) {
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
7906
+namespace Mono.Debugger.Soft
7908
+ public class VMDisconnectedException : Exception {
7910
+ public VMDisconnectedException () : base () {
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
7921
+namespace Mono.Debugger.Soft
7923
+ public class VMMismatchException : Exception
7925
+ public VMMismatchException () : base () {
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
7936
+namespace Mono.Debugger.Soft
7938
+ public class VMStartEvent : Event
7940
+ public VMStartEvent (VirtualMachine vm, int req_id, long thread_id) : base (EventType.VMStart, vm, req_id, thread_id) {
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
7950
+using System.Collections.Generic;
7952
+namespace Mono.Debugger.Soft
7954
+ public abstract class Value : Mirror {
7956
+ // FIXME: Add a 'Value' field
7958
+ internal Value (VirtualMachine vm, long id) : base (vm, id) {
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
7970
+using System.Threading;
7972
+using System.Diagnostics;
7973
+using System.Collections;
7974
+using System.Collections.Generic;
7975
+using Mono.Cecil.Metadata;
7977
+namespace Mono.Debugger.Soft
7979
+ public class VirtualMachine : Mirror
7982
+ object queue_monitor;
7983
+ object startup_monitor;
7984
+ AppDomainMirror root_domain;
7985
+ Dictionary<int, EventRequest> requests;
7986
+ ITargetProcess process;
7988
+ internal Connection conn;
7990
+ VersionInfo version;
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> ();
7999
+ this.process = process;
8000
+ conn.ErrorHandler += ErrorHandler;
8003
+ // The standard output of the process is available normally through Process
8004
+ public StreamReader StandardOutput { get; set; }
8005
+ public StreamReader StandardError { get; set; }
8008
+ public Process Process {
8010
+ ProcessWrapper pw = process as ProcessWrapper;
8012
+ throw new InvalidOperationException ("Process instance not available");
8013
+ return pw.Process;
8017
+ public ITargetProcess TargetProcess {
8023
+ public AppDomainMirror RootDomain {
8025
+ return root_domain;
8029
+ public EndPoint EndPoint {
8031
+ return conn.EndPoint;
8035
+ public VersionInfo Version {
8041
+ public Event GetNextEvent () {
8042
+ lock (queue_monitor) {
8043
+ if (queue.Count == 0)
8044
+ Monitor.Wait (queue_monitor);
8045
+ return (Event)queue.Dequeue ();
8049
+ public Event GetNextEvent (int timeout) {
8050
+ throw new NotImplementedException ();
8053
+ public T GetNextEvent<T> () where T : Event {
8054
+ return GetNextEvent () as T;
8057
+ public void Suspend () {
8058
+ conn.VM_Suspend ();
8061
+ public void Resume () {
8063
+ conn.VM_Resume ();
8064
+ } catch (CommandException ex) {
8065
+ if (ex.ErrorCode == ErrorCode.NOT_SUSPENDED)
8066
+ throw new InvalidOperationException ("The vm is not suspended.");
8072
+ public void Exit (int exitCode) {
8073
+ conn.VM_Exit (exitCode);
8076
+ public void Dispose () {
8077
+ conn.VM_Dispose ();
8079
+ notify_vm_event (EventType.VMDisconnect, 0, 0, null);
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]);
8090
+ // Same as the mirrorOf methods in JDI
8091
+ public PrimitiveValue CreateValue (object value) {
8092
+ if (value == null)
8093
+ return new PrimitiveValue (vm, null);
8095
+ if (!value.GetType ().IsPrimitive)
8096
+ throw new ArgumentException ("value must be of a primitive type instead of '" + value.GetType () + "'", "value");
8098
+ return new PrimitiveValue (vm, value);
8101
+ public EnumMirror CreateEnumMirror (TypeMirror type, PrimitiveValue value) {
8102
+ return new EnumMirror (this, type, value);
8106
+ // Methods to create event request objects
8108
+ public BreakpointEventRequest CreateBreakpointRequest (MethodMirror method, long il_offset) {
8109
+ return new BreakpointEventRequest (this, method, il_offset);
8112
+ public BreakpointEventRequest CreateBreakpointRequest (Location loc) {
8114
+ throw new ArgumentNullException ("loc");
8115
+ CheckMirror (loc);
8116
+ return new BreakpointEventRequest (this, loc.Method, loc.ILOffset);
8119
+ public StepEventRequest CreateStepRequest (ThreadMirror thread) {
8120
+ return new StepEventRequest (this, thread);
8123
+ public MethodEntryEventRequest CreateMethodEntryRequest () {
8124
+ return new MethodEntryEventRequest (this);
8127
+ public MethodExitEventRequest CreateMethodExitRequest () {
8128
+ return new MethodExitEventRequest (this);
8131
+ public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type) {
8132
+ return new ExceptionEventRequest (this, exc_type, true, true);
8135
+ public ExceptionEventRequest CreateExceptionRequest (TypeMirror exc_type, bool caught, bool uncaught) {
8136
+ return new ExceptionEventRequest (this, exc_type, caught, uncaught);
8139
+ public void EnableEvents (params EventType[] events) {
8140
+ foreach (EventType etype in events)
8141
+ conn.EnableEvent (etype, SuspendPolicy.All, null);
8144
+ public BreakpointEventRequest SetBreakpoint (MethodMirror method, long il_offset) {
8145
+ BreakpointEventRequest req = CreateBreakpointRequest (method, il_offset);
8152
+ public void ClearAllBreakpoints () {
8153
+ conn.ClearAllBreakpoints ();
8156
+ internal void queue_event (Event e) {
8157
+ lock (queue_monitor) {
8158
+ queue.Enqueue (e);
8159
+ Monitor.Pulse (queue_monitor);
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 ();
8176
+ throw new CommandException (args.ErrorCode);
8180
+ /* Wait for the debuggee to start up and connect to it */
8181
+ internal void connect () {
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));
8189
+ long root_domain_id = conn.RootDomain;
8190
+ root_domain = GetDomain (root_domain_id);
8193
+ internal void notify_vm_event (EventType evtype, int req_id, long thread_id, string vm_uri) {
8194
+ //Console.WriteLine ("Event: " + evtype + "(" + vm_uri + ")");
8197
+ case EventType.VMStart:
8198
+ /* Notify the main thread that the debuggee started up */
8199
+ lock (startup_monitor) {
8200
+ Monitor.Pulse (startup_monitor);
8202
+ queue_event (new VMStartEvent (vm, req_id, thread_id));
8204
+ case EventType.VMDeath:
8205
+ queue_event (new VMDeathEvent (vm, req_id));
8207
+ case EventType.VMDisconnect:
8208
+ queue_event (new VMDisconnectEvent (vm, req_id));
8211
+ throw new Exception ();
8216
+ // Methods to create instances of mirror objects
8220
+ class MirrorCache<T> {
8221
+ static Dictionary <long, T> mirrors;
8222
+ static object mirror_lock = new object ();
8224
+ internal static T GetMirror (VirtualMachine vm, long id) {
8225
+ lock (mirror_lock) {
8226
+ if (mirrors == null)
8227
+ mirrors = new Dictionary <long, T> ();
8229
+ if (!mirrors.TryGetValue (id, out obj)) {
8230
+ obj = CreateMirror (vm, id);
8231
+ mirrors [id] = obj;
8237
+ internal static T CreateMirror (VirtualMachine vm, long id) {
8242
+ // FIXME: When to remove items from the cache ?
8244
+ Dictionary <long, MethodMirror> methods;
8245
+ object methods_lock = new object ();
8247
+ internal MethodMirror GetMethod (long id) {
8248
+ lock (methods_lock) {
8249
+ if (methods == null)
8250
+ methods = new Dictionary <long, MethodMirror> ();
8254
+ if (!methods.TryGetValue (id, out obj)) {
8255
+ obj = new MethodMirror (this, id);
8256
+ methods [id] = obj;
8262
+ Dictionary <long, AssemblyMirror> assemblies;
8263
+ object assemblies_lock = new object ();
8265
+ internal AssemblyMirror GetAssembly (long id) {
8266
+ lock (assemblies_lock) {
8267
+ if (assemblies == null)
8268
+ assemblies = new Dictionary <long, AssemblyMirror> ();
8269
+ AssemblyMirror obj;
8272
+ if (!assemblies.TryGetValue (id, out obj)) {
8273
+ obj = new AssemblyMirror (this, id);
8274
+ assemblies [id] = obj;
8280
+ Dictionary <long, ModuleMirror> modules;
8281
+ object modules_lock = new object ();
8283
+ internal ModuleMirror GetModule (long id) {
8284
+ lock (modules_lock) {
8285
+ if (modules == null)
8286
+ modules = new Dictionary <long, ModuleMirror> ();
8290
+ if (!modules.TryGetValue (id, out obj)) {
8291
+ obj = new ModuleMirror (this, id);
8292
+ modules [id] = obj;
8298
+ Dictionary <long, AppDomainMirror> domains;
8299
+ object domains_lock = new object ();
8301
+ internal AppDomainMirror GetDomain (long id) {
8302
+ lock (domains_lock) {
8303
+ if (domains == null)
8304
+ domains = new Dictionary <long, AppDomainMirror> ();
8305
+ AppDomainMirror obj;
8308
+ if (!domains.TryGetValue (id, out obj)) {
8309
+ obj = new AppDomainMirror (this, id);
8310
+ domains [id] = obj;
8316
+ Dictionary <long, TypeMirror> types;
8317
+ object types_lock = new object ();
8319
+ internal TypeMirror GetType (long id) {
8320
+ lock (types_lock) {
8321
+ if (types == null)
8322
+ types = new Dictionary <long, TypeMirror> ();
8326
+ if (!types.TryGetValue (id, out obj)) {
8327
+ obj = new TypeMirror (this, id);
8334
+ Dictionary <long, ObjectMirror> objects;
8335
+ object objects_lock = new object ();
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> ();
8342
+ if (!objects.TryGetValue (id, out obj)) {
8344
+ * Obtain the domain/type of the object to determine the type of
8345
+ * object we need to create.
8347
+ if (domain_id == 0)
8348
+ domain_id = conn.Object_GetDomain (id);
8349
+ AppDomainMirror d = GetDomain (domain_id);
8352
+ type_id = conn.Object_GetType (id);
8353
+ TypeMirror t = GetType (type_id);
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);
8362
+ obj = new ObjectMirror (this, id);
8363
+ objects [id] = obj;
8369
+ internal T GetObject<T> (long id) where T : ObjectMirror {
8370
+ return GetObject<T> (id, 0, 0);
8373
+ internal ObjectMirror GetObject (long objid) {
8374
+ return GetObject<ObjectMirror> (objid);
8377
+ internal ThreadMirror GetThread (long id) {
8378
+ return GetObject <ThreadMirror> (id);
8381
+ object requests_lock = new object ();
8383
+ internal void AddRequest (EventRequest req, int id) {
8384
+ lock (requests_lock) {
8385
+ requests [id] = req;
8389
+ internal void RemoveRequest (EventRequest req, int id) {
8390
+ lock (requests_lock) {
8391
+ requests.Remove (id);
8395
+ internal EventRequest GetRequest (int id) {
8396
+ lock (requests_lock) {
8397
+ return requests [id];
8401
+ internal Value DecodeValue (ValueImpl v) {
8402
+ if (v.Value != null)
8403
+ return new PrimitiveValue (this, v.Value);
8406
+ case ElementType.Void:
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:
8418
+ return new EnumMirror (this, GetType (v.Klass), DecodeValues (v.Fields));
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);
8424
+ throw new NotImplementedException ("" + v.Type);
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]);
8435
+ internal ValueImpl EncodeValue (Value v) {
8436
+ if (v is PrimitiveValue) {
8437
+ object val = (v as PrimitiveValue).Value;
8439
+ return new ValueImpl { Type = (ElementType)ValueTypeId.VALUE_TYPE_ID_NULL, Objid = 0 };
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) };
8447
+ throw new NotSupportedException ();
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]);
8459
+ class EventHandler : MarshalByRefObject, IEventHandler
8461
+ VirtualMachine vm;
8463
+ public EventHandler (VirtualMachine vm) {
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);
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);
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);
8479
+ public void ThreadStart (int req_id, long thread_id, long id) {
8480
+ vm.queue_event (new ThreadStartEvent (vm, req_id, id));
8483
+ public void ThreadDeath (int req_id, long thread_id, long id) {
8484
+ vm.queue_event (new ThreadDeathEvent (vm, req_id, id));
8487
+ public void AssemblyLoad (int req_id, long thread_id, long id) {
8488
+ vm.queue_event (new AssemblyLoadEvent (vm, req_id, thread_id, id));
8491
+ public void AssemblyUnload (int req_id, long thread_id, long id) {
8492
+ vm.queue_event (new AssemblyUnloadEvent (vm, req_id, thread_id, id));
8495
+ public void TypeLoad (int req_id, long thread_id, long id) {
8496
+ vm.queue_event (new TypeLoadEvent (vm, req_id, thread_id, id));
8499
+ public void MethodEntry (int req_id, long thread_id, long id) {
8500
+ vm.queue_event (new MethodEntryEvent (vm, req_id, thread_id, id));
8503
+ public void MethodExit (int req_id, long thread_id, long id) {
8504
+ vm.queue_event (new MethodExitEvent (vm, req_id, thread_id, id));
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));
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));
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));
8519
+ public void AppDomainCreate (int req_id, long thread_id, long id) {
8520
+ vm.queue_event (new AppDomainCreateEvent (vm, req_id, thread_id, id));
8523
+ public void AppDomainUnload (int req_id, long thread_id, long id) {
8524
+ vm.queue_event (new AppDomainUnloadEvent (vm, req_id, thread_id, id));
8528
+ internal class CommandException : Exception {
8530
+ public CommandException (ErrorCode error_code) : base ("Debuggee returned error code " + error_code + ".") {
8531
+ ErrorCode = error_code;
8534
+ public ErrorCode ErrorCode {
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
8545
+using System.Collections.Generic;
8546
+using System.Diagnostics;
8549
+using System.Net.Sockets;
8550
+using System.Runtime.Remoting.Messaging;
8552
+namespace Mono.Debugger.Soft
8554
+ public class LaunchOptions {
8555
+ public string AgentArgs {
8559
+ public bool Valgrind {
8563
+ public ProcessLauncher CustomProcessLauncher {
8567
+ public TargetProcessLauncher CustomTargetProcessLauncher {
8571
+ public delegate Process ProcessLauncher (ProcessStartInfo info);
8572
+ public delegate ITargetProcess TargetProcessLauncher (ProcessStartInfo info);
8575
+ public class VirtualMachineManager
8577
+ private delegate VirtualMachine LaunchCallback (ITargetProcess p, ProcessStartInfo info, Socket socket);
8578
+ private delegate VirtualMachine ListenCallback (Socket dbg_sock, Socket con_sock);
8580
+ internal VirtualMachineManager () {
8583
+ public static VirtualMachine LaunchInternal (Process p, ProcessStartInfo info, Socket socket)
8585
+ return LaunchInternal (new ProcessWrapper (p), info, socket);
8588
+ public static VirtualMachine LaunchInternal (ITargetProcess p, ProcessStartInfo info, Socket socket) {
8589
+ Socket accepted = null;
8591
+ accepted = socket.Accept ();
8592
+ } catch (Exception) {
8596
+ Connection conn = new Connection (accepted);
8598
+ VirtualMachine vm = new VirtualMachine (p, conn);
8600
+ if (info.RedirectStandardOutput)
8601
+ vm.StandardOutput = p.StandardOutput;
8603
+ if (info.RedirectStandardError)
8604
+ vm.StandardError = p.StandardError;
8606
+ conn.EventHandler = new EventHandler (vm);
8613
+ public static IAsyncResult BeginLaunch (ProcessStartInfo info, AsyncCallback callback, LaunchOptions options = null) {
8615
+ throw new ArgumentNullException ("info");
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;
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,
8627
+ options == null || options.AgentArgs == null ? "" : "," + options.AgentArgs,
8630
+ if (options != null && options.Valgrind)
8631
+ info.FileName = "valgrind";
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);
8639
+ p = new ProcessWrapper (Process.Start (info));
8641
+ p.Exited += delegate (object sender, EventArgs eargs) {
8645
+ LaunchCallback c = new LaunchCallback (LaunchInternal);
8646
+ return c.BeginInvoke (p, info, socket, callback, socket);
8649
+ public static VirtualMachine EndLaunch (IAsyncResult asyncResult) {
8650
+ if (asyncResult == null)
8651
+ throw new ArgumentNullException ("asyncResult");
8653
+ if (!asyncResult.IsCompleted)
8654
+ asyncResult.AsyncWaitHandle.WaitOne ();
8656
+ AsyncResult async = (AsyncResult) asyncResult;
8657
+ LaunchCallback cb = (LaunchCallback) async.AsyncDelegate;
8658
+ return cb.EndInvoke (asyncResult);
8661
+ public static VirtualMachine Launch (ProcessStartInfo info, LaunchOptions options = null) {
8662
+ return EndLaunch (BeginLaunch (info, null, options));
8665
+ public static VirtualMachine Launch (string[] args, LaunchOptions options = null) {
8666
+ ProcessStartInfo pi = new ProcessStartInfo ("mono");
8667
+ pi.Arguments = String.Join (" ", args);
8669
+ return Launch (pi, options);
8672
+ public static VirtualMachine ListenInternal (Socket dbg_sock, Socket con_sock) {
8673
+ Socket con_acc = null;
8674
+ Socket dbg_acc = null;
8676
+ if (con_sock != null) {
8678
+ con_acc = con_sock.Accept ();
8679
+ } catch (Exception) {
8681
+ dbg_sock.Close ();
8688
+ dbg_acc = dbg_sock.Accept ();
8689
+ } catch (Exception) {
8690
+ if (con_sock != null) {
8692
+ con_sock.Close ();
8699
+ if (con_sock != null) {
8700
+ con_sock.Disconnect (false);
8701
+ con_sock.Close ();
8704
+ dbg_sock.Disconnect (false);
8705
+ dbg_sock.Close ();
8707
+ Connection conn = new Connection (dbg_acc);
8709
+ VirtualMachine vm = new VirtualMachine (null, conn);
8711
+ if (con_acc != null) {
8712
+ vm.StandardOutput = new StreamReader (new NetworkStream (con_acc));
8713
+ vm.StandardError = null;
8716
+ conn.EventHandler = new EventHandler (vm);
8723
+ public static IAsyncResult BeginListen (IPEndPoint dbg_ep, AsyncCallback callback) {
8724
+ return BeginListen (dbg_ep, null, callback);
8727
+ public static IAsyncResult BeginListen (IPEndPoint dbg_ep, IPEndPoint con_ep, AsyncCallback callback) {
8728
+ Socket dbg_sock = null;
8729
+ Socket con_sock = null;
8731
+ dbg_sock = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
8732
+ dbg_sock.Bind (dbg_ep);
8733
+ dbg_sock.Listen (1000);
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);
8741
+ ListenCallback c = new ListenCallback (ListenInternal);
8742
+ return c.BeginInvoke (dbg_sock, con_sock, callback, con_sock ?? dbg_sock);
8745
+ public static VirtualMachine EndListen (IAsyncResult asyncResult) {
8746
+ if (asyncResult == null)
8747
+ throw new ArgumentNullException ("asyncResult");
8749
+ if (!asyncResult.IsCompleted)
8750
+ asyncResult.AsyncWaitHandle.WaitOne ();
8752
+ AsyncResult async = (AsyncResult) asyncResult;
8753
+ ListenCallback cb = (ListenCallback) async.AsyncDelegate;
8754
+ return cb.EndInvoke (asyncResult);
8757
+ public static VirtualMachine Listen (IPEndPoint dbg_ep, IPEndPoint con_ep = null) {
8758
+ return EndListen (BeginListen (dbg_ep, con_ep, null));
8762
+ * Connect to a virtual machine listening at the specified address.
8764
+ public static VirtualMachine Connect (IPEndPoint endpoint) {
8765
+ if (endpoint == null)
8766
+ throw new ArgumentNullException ("endpoint");
8768
+ Socket socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
8769
+ socket.Connect (endpoint);
8771
+ Connection conn = new Connection (socket);
8773
+ VirtualMachine vm = new VirtualMachine (null, conn);
8775
+ conn.EventHandler = new EventHandler (vm);
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
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
8798
+ADDIN_BUILD = $(top_builddir)/build/AddIns/MonoDevelop.Debugger.Soft
8799
+ASSEMBLY = $(ADDIN_BUILD)/Mono.Debugger.Soft.dll
8801
+SIGNING_KEY=$(top_srcdir)/src/core/Mono.Debugging/mono.debugging.snk
8803
+CECIL_ASM_SRC = /usr/lib/mono-cecil/Mono.Cecil.dll
8804
+CECIL_ASM = $(ADDIN_BUILD)/Mono.Cecil.dll
8809
+ -r:/usr/lib/mono-cecil/Mono.Cecil.dll
8812
+ AbsentInformationException.cs \
8813
+ AppDomainCreateEvent.cs \
8814
+ AppDomainMirror.cs \
8815
+ AppDomainUnloadEvent.cs \
8817
+ AssemblyLoadEvent.cs \
8818
+ AssemblyMirror.cs \
8819
+ AssemblyUnloadEvent.cs \
8820
+ BreakpointEvent.cs \
8821
+ BreakpointEventRequest.cs \
8823
+ CustomAttributeDataMirror.cs \
8824
+ CustomAttributeNamedArgumentMirror.cs \
8825
+ CustomAttributeTypedArgumentMirror.cs \
8826
+ DataConverter.cs \
8829
+ EventQueueImpl.cs \
8832
+ ExceptionEvent.cs \
8833
+ ExceptionEventRequest.cs \
8834
+ FieldInfoMirror.cs \
8835
+ IInvokeAsyncResult.cs \
8836
+ ILInstruction.cs \
8838
+ InvalidStackFrameException.cs \
8839
+ InvocationException.cs \
8840
+ InvokeOptions.cs \
8841
+ ITargetProcess.cs \
8842
+ LocalVariable.cs \
8844
+ MethodBodyMirror.cs \
8845
+ MethodEntryEvent.cs \
8846
+ MethodEntryEventRequest.cs \
8847
+ MethodExitEvent.cs \
8848
+ MethodExitEventRequest.cs \
8852
+ ObjectCollectedException.cs \
8854
+ ParameterInfoMirror.cs \
8855
+ PrimitiveValue.cs \
8856
+ PropertyInfoMirror.cs \
8859
+ StepEventRequest.cs \
8862
+ SuspendPolicy.cs \
8863
+ ThreadDeathEvent.cs \
8865
+ ThreadStartEvent.cs \
8866
+ TypeLoadEvent.cs \
8869
+ VirtualMachine.cs \
8870
+ VirtualMachineManager.cs \
8872
+ VMDisconnectedException.cs \
8873
+ VMDisconnectEvent.cs \
8874
+ VMMismatchException.cs \
8879
+CSC_FLAGS = -unsafe -D:MONO_DATACONVERTER_STATIC_METHODS
8881
+all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD) $(SIGNING_KEY)
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)
8888
+$(ASSEMBLY).mdb: $(ASSEMBLY)
8890
+$(CECIL_ASM): $(CECIL_ASM_SRC)
8891
+ mkdir -p $(ADDIN_BUILD)
8896
+assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.Debugger.Soft
8897
+assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb $(CECIL_ASM)
8899
+CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb
8900
+EXTRA_DIST = $(FILES) $(RES)
8902
+include $(top_srcdir)/Makefile.include
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
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
8921
ASSEMBLY = $(ADDIN_BUILD)/Mono.Debugging.Soft.dll
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
8928
SIGNING_KEY=$(top_srcdir)/src/core/Mono.Debugging/mono.debugging.snk
8930
DEPS = $(top_builddir)/build/bin/Mono.Debugging.dll
8933
- -r:$(top_srcdir)/src/addins/MonoDevelop.Debugger.Soft/Mono.Debugging.Soft/Mono.Debugger.Soft.dll \
8940
all: $(ASSEMBLY) $(ASSEMBLY).mdb $(DATA_FILE_BUILD) $(SIGNING_KEY)
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)
8948
-$(DBG_ASM): $(DBG_ASM_SRC)
8949
- mkdir -p $(ADDIN_BUILD)
8952
-$(DBG_MDB): $(DBG_MDB_SRC)
8953
- mkdir -p $(ADDIN_BUILD)
8956
$(ASSEMBLY).mdb: $(ASSEMBLY)
8960
assemblydir = $(MD_ADDIN_DIR)/MonoDevelop.Debugger.Soft
8961
-assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb $(DBG_ASM) $(DBG_MDB)
8962
+assembly_DATA = $(ASSEMBLY) $(ASSEMBLY).mdb
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)
8969
include $(top_srcdir)/Makefile.include
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
8977
$(GLIB_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 \
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
8990
$(GLIB_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 \
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
9003
$(GLIB_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 \