Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RawValue.cs « Mono.Debugging.Client « Mono.Debugging - github.com/mono/debugger-libs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b99c11313b3cc27e8ae0100fac1d0685472e4a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// 
// RawValue.cs
//  
// Author:
//       Lluis Sanchez Gual <lluis@novell.com>
// 
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System;
using Mono.Debugging.Backend;

namespace Mono.Debugging.Client
{
	/// <summary>
	/// Represents an object in the process being debugged
	/// </summary>
	[Serializable]
	public class RawValue : IRawObject
	{
		IRawValue source;
		EvaluationOptions options;
		DebuggerSession session;

		/// <summary>
		/// Initializes a new instance of the <see cref="Mono.Debugging.Client.RawValue"/> class.
		/// </summary>
		/// <param name='source'>
		/// Value source
		/// </param>
		public RawValue (IRawValue source)
		{
			this.source = source;
		}

		void IRawObject.Connect (DebuggerSession session, EvaluationOptions options)
		{
			this.options = options;
			this.session = session;
			source = session.WrapDebuggerObject (source);
		}

		internal IRawValue Source {
			get { return this.source; }
		}

		/// <summary>
		/// Full name of the type of the object
		/// </summary>
		public string TypeName { get; set; }

		/// <summary>
		/// Invokes a method on the object
		/// </summary>
		/// <returns>
		/// The result of the invocation
		/// </returns>
		/// <param name='methodName'>
		/// The name of the method
		/// </param>
		/// <param name='parameters'>
		/// The parameters (primitive type values, RawValue instances or RawValueArray instances)
		/// </param>
		public object CallMethod (string methodName, params object [] parameters)
		{
			object res = source.CallMethod (methodName, parameters, options);
			RawValue val = res as RawValue;
			if (val != null)
				val.options = options;
			IRawObject raw = res as IRawObject;
			if (raw != null)
				raw.Connect (session, options);
			return res;
		}

		public object CallMethod (string methodName, out object [] outArgs, params object [] parameters)
		{
			object res = source.CallMethod (methodName, parameters, out outArgs, options);
			RawValue val = res as RawValue;
			if (val != null)
				val.options = options;
			IRawObject raw = res as IRawObject;
			if (raw != null)
				raw.Connect (session, options);
			return res;
		}

		/// <summary>
		/// Gets the value of a field or property
		/// </summary>
		/// <returns>
		/// The value (a primitive type value, a RawValue instance or a RawValueArray instance)
		/// </returns>
		/// <param name='name'>
		/// Name of the field or property
		/// </param>
		public object GetMemberValue (string name)
		{
			object res = source.GetMemberValue (name, options);
			RawValue val = res as RawValue;
			if (val != null)
				val.options = options;
			IRawObject raw = res as IRawObject;
			if (raw != null)
				raw.Connect (session, options);
			return res;
		}

		/// <summary>
		/// Sets the value of a field or property
		/// </summary>
		/// <param name='name'>
		/// Name of the field or property
		/// </param>
		/// <param name='value'>
		/// The value (a primitive type value, a RawValue instance or a RawValueArray instance)
		/// </param>
		public void SetMemberValue (string name, object value)
		{
			source.SetMemberValue (name, value, options);
		}
	}

	/// <summary>
	/// Represents an array of objects in the process being debugged
	/// </summary>
	[Serializable]
	public class RawValueArray : IRawObject
	{
		IRawValueArray source;
		EvaluationOptions options;
		DebuggerSession session;
		int [] dimensions;

		/// <summary>
		/// Initializes a new instance of the <see cref="Mono.Debugging.Client.RawValueArray"/> class.
		/// </summary>
		/// <param name='source'>
		/// Value source.
		/// </param>
		public RawValueArray (IRawValueArray source)
		{
			this.source = source;
		}

		void IRawObject.Connect (DebuggerSession session, EvaluationOptions options)
		{
			this.options = options;
			this.session = session;
			source = session.WrapDebuggerObject (source);
		}

		internal IRawValueArray Source {
			get { return this.source; }
		}

		/// <summary>
		/// Full type name of the array items
		/// </summary>
		public string ElementTypeName { get; set; }

		/// <summary>
		/// Gets or sets the item at the specified index.
		/// </summary>
		/// <param name='index'>
		/// The index
		/// </param>
		/// <remarks>
		/// The item value can be a primitive type value, a RawValue instance or a RawValueArray instance.
		/// </remarks>
		public object this [int index] {
			get {
				return source.GetValue (new int [] { index });
			}
			set {
				source.SetValue (new int [] { index }, value);
			}
		}

		/// <summary>
		/// Gets the values.
		/// </summary>
		/// <returns>The items.</returns>
		/// <param name="index">The index.</param>
		/// <param name="count">The number of items to get.</param>
		/// <remarks>
		/// This method is useful for incrementally fetching an array in order to avoid
		/// long waiting periods when the array is too large for ToArray().
		/// </remarks>
		public Array GetValues (int index, int count)
		{
			return source.GetValues (new int [] { index }, count);
		}

		/// <summary>
		/// Returns an array with all items of the RawValueArray
		/// </summary>
		/// <remarks>
		/// This method is useful to avoid unnecessary debugger-debuggee roundtrips
		/// when processing all items of an array. For example, if a RawValueArray
		/// represents an image encoded in a byte[], getting the values one by one
		/// using the indexer is very slow. The ToArray() will return the whole byte[]
		/// in a single call.
		/// </remarks>
		public Array ToArray ()
		{
			var array = source.ToArray ();
			for (int i = 0; i < array.Length; i++) {
				var val = array.GetValue (i) as IRawObject;
				if (val != null) {
					val.Connect (session, options);
				}
			}
			return array;
		}

		/// <summary>
		/// Gets the length of the array
		/// </summary>
		public int Length {
			get {
				if (dimensions == null)
					dimensions = source.Dimensions;
				return dimensions [0];
			}
		}
	}

	/// <summary>
	/// Represents a string object in the process being debugged
	/// </summary>
	[Serializable]
	public class RawValueString : IRawObject
	{
		IRawValueString source;

		/// <summary>
		/// Initializes a new instance of the <see cref="Mono.Debugging.Client.RawValueString"/> class.
		/// </summary>
		/// <param name='source'>
		/// Value source.
		/// </param>
		public RawValueString (IRawValueString source)
		{
			this.source = source;
		}

		void IRawObject.Connect (DebuggerSession session, EvaluationOptions options)
		{
			source = session.WrapDebuggerObject (source);
		}

		internal IRawValueString Source {
			get { return source; }
		}

		/// <summary>
		/// Gets the length of the string
		/// </summary>
		public int Length {
			get { return source.Length; }
		}

		/// <summary>
		/// Gets a substring of the string
		/// </summary>
		/// <param name='index'>
		/// The starting index of the requested substring.
		/// </param>
		/// <param name='length'>
		/// The length of the requested substring.
		/// </param>
		public string Substring (int index, int length)
		{
			return source.Substring (index, length);
		}

		/// <summary>
		/// Gets the value.
		/// </summary>
		/// <value>
		/// The value.
		/// </value>
		public string Value {
			get { return source.Value; }
		}
	}

	interface IRawObject
	{
		void Connect (DebuggerSession session, EvaluationOptions options);
	}
}