// // RawValue.cs // // Author: // Lluis Sanchez Gual // // 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 { /// /// Represents an object in the process being debugged /// [Serializable] public class RawValue : IRawObject { IRawValue source; EvaluationOptions options; DebuggerSession session; /// /// Initializes a new instance of the class. /// /// /// Value source /// 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; } } /// /// Full name of the type of the object /// public string TypeName { get; set; } /// /// Invokes a method on the object /// /// /// The result of the invocation /// /// /// The name of the method /// /// /// The parameters (primitive type values, RawValue instances or RawValueArray instances) /// 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; } /// /// Gets the value of a field or property /// /// /// The value (a primitive type value, a RawValue instance or a RawValueArray instance) /// /// /// Name of the field or property /// 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; } /// /// Sets the value of a field or property /// /// /// Name of the field or property /// /// /// The value (a primitive type value, a RawValue instance or a RawValueArray instance) /// public void SetMemberValue (string name, object value) { source.SetMemberValue (name, value, options); } } /// /// Represents an array of objects in the process being debugged /// [Serializable] public class RawValueArray : IRawObject { IRawValueArray source; EvaluationOptions options; DebuggerSession session; int [] dimensions; /// /// Initializes a new instance of the class. /// /// /// Value source. /// 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; } } /// /// Full type name of the array items /// public string ElementTypeName { get; set; } /// /// Gets or sets the item at the specified index. /// /// /// The index /// /// /// The item value can be a primitive type value, a RawValue instance or a RawValueArray instance. /// public object this [int index] { get { return source.GetValue (new int [] { index }); } set { source.SetValue (new int [] { index }, value); } } /// /// Gets the values. /// /// The items. /// The index. /// The number of items to get. /// /// This method is useful for incrementally fetching an array in order to avoid /// long waiting periods when the array is too large for ToArray(). /// public Array GetValues (int index, int count) { return source.GetValues (new int [] { index }, count); } /// /// Returns an array with all items of the RawValueArray /// /// /// 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. /// 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; } /// /// Gets the length of the array /// public int Length { get { if (dimensions == null) dimensions = source.Dimensions; return dimensions [0]; } } } /// /// Represents a string object in the process being debugged /// [Serializable] public class RawValueString : IRawObject { IRawValueString source; /// /// Initializes a new instance of the class. /// /// /// Value source. /// public RawValueString (IRawValueString source) { this.source = source; } void IRawObject.Connect (DebuggerSession session, EvaluationOptions options) { source = session.WrapDebuggerObject (source); } internal IRawValueString Source { get { return source; } } /// /// Gets the length of the string /// public int Length { get { return source.Length; } } /// /// Gets a substring of the string /// /// /// The starting index of the requested substring. /// /// /// The length of the requested substring. /// public string Substring (int index, int length) { return source.Substring (index, length); } /// /// Gets the value. /// /// /// The value. /// public string Value { get { return source.Value; } } } interface IRawObject { void Connect (DebuggerSession session, EvaluationOptions options); } }