Example #1
0
        private ObjectValue CreateObjectValue(string name, ResultData data)
        {
            string vname    = data.GetValue("name");
            string typeName = data.GetValue("type");
            string value    = data.GetValue("value");
            int    nchild   = data.GetInt("numchild");

            ObjectValue      val;
            ObjectValueFlags flags = ObjectValueFlags.Variable;

            // There can be 'public' et al children for C++ structures
            if (typeName == null)
            {
                typeName = "none";
            }

            if (typeName.EndsWith("]"))
            {
                val = ObjectValue.CreateArray(this, new ObjectPath(vname), typeName, nchild, flags, null);
            }
            else if (value == "{...}" || typeName.EndsWith("*") || nchild > 0)
            {
                val = ObjectValue.CreateObject(this, new ObjectPath(vname), typeName, value, flags, null);
            }
            else
            {
                val = ObjectValue.CreatePrimitive(this, new ObjectPath(vname), typeName, new EvaluationResult(value), flags);
            }
            val.Name = name;
            return(val);
        }
Example #2
0
        ObjectValue GetStackTrace(EvaluationOptions options)
        {
            ValueReference st = exception.GetChild("StackTrace", options);

            if (st == null)
            {
                return(ObjectValue.CreateUnknown("StackTrace"));
            }
            string trace = st.ObjectValue as string;

            if (trace == null)
            {
                return(ObjectValue.CreateUnknown("StackTrace"));
            }

            List <ObjectValue> frames = new List <ObjectValue> ();

            foreach (string sframe in trace.Split('\n'))
            {
                string        txt      = sframe.Trim(' ', '\r', '\n');
                string        file     = "";
                int           line     = 0;
                int           col      = 0;
                ObjectValue   fileVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None);
                ObjectValue   lineVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None);
                ObjectValue   colVal   = ObjectValue.CreatePrimitive(null, new ObjectPath("Col"), "", new EvaluationResult(col.ToString()), ObjectValueFlags.None);
                ObjectValue[] children = new ObjectValue[] { fileVal, lineVal, colVal };
                ObjectValue   frame    = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(txt), ObjectValueFlags.None, children);
                frames.Add(frame);
            }
            return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray()));
        }
Example #3
0
        public ObjectValue CreateObjectValue()
        {
            Connect();
            StringBuilder sb = new StringBuilder("[");

            for (int n = 0; n < baseIndices.Length; n++)
            {
                if (n > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(baseIndices [n].ToString());
            }
            if (IsRange)
            {
                if (baseIndices.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(firstIndex.ToString()).Append("..").Append(lastIndex.ToString());
            }
            if (bounds.Length > 1 && baseIndices.Length < bounds.Length)
            {
                sb.Append(", ...");
            }

            sb.Append("]");

            ObjectValue res = ObjectValue.CreateObject(this, new ObjectPath(sb.ToString()), "", "", ObjectValueFlags.ArrayElement | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            res.ChildSelector = "";
            return(res);
        }
        public static ObjectValue GetStackTrace(string trace)
        {
            if (trace == null)
            {
                return(ObjectValue.CreateUnknown("StackTrace"));
            }

            var regex     = new Regex("at (?<MethodName>.*) in (?<FileName>.*):(?<LineNumber>\\d+)(,(?<Column>\\d+))?");
            var regexLine = new Regex("at (?<MethodName>.*) in (?<FileName>.*):line (?<LineNumber>\\d+)(,(?<Column>\\d+))?");
            var frames    = new List <ObjectValue> ();

            foreach (var sframe in trace.Split('\n'))
            {
                string text   = sframe.Trim(' ', '\r', '\t', '"');
                string file   = "";
                int    column = 0;
                int    line   = 0;

                if (text.Length == 0)
                {
                    continue;
                }
                //Ignore entries like "--- End of stack trace from previous location where exception was thrown ---"
                if (text.StartsWith("---", StringComparison.Ordinal))
                {
                    continue;
                }

                var match = regex.Match(text);
                if (match.Success)
                {
                    text = match.Groups ["MethodName"].ToString();
                    file = match.Groups ["FileName"].ToString();
                    int.TryParse(match.Groups ["LineNumber"].ToString(), out line);
                    int.TryParse(match.Groups ["Column"].ToString(), out column);
                }
                else
                {
                    match = regexLine.Match(text);
                    if (match.Success)
                    {
                        text = match.Groups ["MethodName"].ToString();
                        file = match.Groups ["FileName"].ToString();
                        int.TryParse(match.Groups ["LineNumber"].ToString(), out line);
                        int.TryParse(match.Groups ["Column"].ToString(), out column);
                    }
                }

                var fileVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None);
                var lineVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None);
                var colVal   = ObjectValue.CreatePrimitive(null, new ObjectPath("Column"), "", new EvaluationResult(column.ToString()), ObjectValueFlags.None);
                var children = new ObjectValue [] { fileVal, lineVal, colVal };

                var frame = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(text), ObjectValueFlags.None, children);
                frames.Add(frame);
            }

            return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray()));
        }
        static ObjectValue CreateNode(EvaluationContext ctx, IObjectSource objectSource, object type, object obj, BindingFlags bindingFlags, string label)
        {
            FilteredMembersSource src = new FilteredMembersSource(ctx, objectSource, type, obj, bindingFlags);

            src.Connect();
            ObjectValue val = ObjectValue.CreateObject(src, new ObjectPath(label), "", "", ObjectValueFlags.Group | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            val.ChildSelector = "";
            return(val);
        }
        public static ObjectValue CreateRawView(EvaluationContext ctx, IObjectSource objectSource, object obj)
        {
            RawViewSource src = new RawViewSource(ctx, objectSource, obj);

            src.Connect();
            ObjectValue val = ObjectValue.CreateObject(src, new ObjectPath("Raw View"), "", "", ObjectValueFlags.Group | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            val.ChildSelector = "";
            return(val);
        }
Example #7
0
 static ObjectValue VsCodeVariableToObjectValue(VSCodeDebuggerSession vsCodeDebuggerSession, string name, string value, int variablesReference)
 {
     if (variablesReference == 0)                //This is some kind of primitive...
     {
         return(ObjectValue.CreatePrimitive(null, new ObjectPath(name), "unknown", new EvaluationResult(value), ObjectValueFlags.ReadOnly));
     }
     else
     {
         return(ObjectValue.CreateObject(new VSCodeObjectSource(vsCodeDebuggerSession, variablesReference), new ObjectPath(name), "unknown", new EvaluationResult(value), ObjectValueFlags.ReadOnly, null));
     }
 }
Example #8
0
        private static ObjectValue InitialiseObjectValues(IObjectValueSource objectValueSource)
        {
            // ReSharper disable ArgumentsStyleNamedExpression
            // Displayed in the debugger as "objectValueSource.Name = {typeName} value"
            var objectValue = ObjectValue.CreateObject(objectValueSource, new ObjectPath(objectValueSource.Name),
                                                       typeDisplayName: string.Empty, string.Empty, string.Empty,
                                                       ObjectValueFlags.Group | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            objectValue.ChildSelector = string.Empty;
            return(objectValue);
        }
Example #9
0
        public static ObjectValue CreateBaseTypeView(EvaluationContext ctx, IObjectSource objectSource, object type, object obj)
        {
            BaseTypeViewSource src = new BaseTypeViewSource(ctx, objectSource, type, obj);

            src.Connect();
            string      tname = ctx.Adapter.GetDisplayTypeName(ctx, type);
            ObjectValue val   = ObjectValue.CreateObject(src, new ObjectPath("base"), tname, "{" + tname + "}", ObjectValueFlags.Type | ObjectValueFlags.ReadOnly | ObjectValueFlags.NoRefresh, null);

            val.ChildSelector = "";
            return(val);
        }
 public ObjectValue GetValue(ObjectPath path, EvaluationOptions options)
 {
     if (val == "null")
     {
         return(ObjectValue.CreateNullObject(this, name, type, flags));
     }
     if (variablesReference == 0)            //This is some kind of primitive...
     {
         return(ObjectValue.CreatePrimitive(this, new ObjectPath(name), type, new EvaluationResult(val, display), flags));
     }
     return(ObjectValue.CreateObject(this, new ObjectPath(name), type, new EvaluationResult(val, display), flags, null));
 }
Example #11
0
 public ObjectValue GetValue(ObjectPath path, EvaluationOptions options)
 {
     if (val == "null")
     {
         return(ObjectValue.CreateNullObject(this, name, type, parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly));
     }
     if (variablesReference == 0)            //This is some kind of primitive...
     {
         return(ObjectValue.CreatePrimitive(this, new ObjectPath(name), type, new EvaluationResult(val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly));
     }
     return(ObjectValue.CreateObject(this, new ObjectPath(name), type, new EvaluationResult(val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly, null));
 }
Example #12
0
        ObjectValue GetStackTrace(EvaluationOptions options)
        {
            var stackTrace = Exception.GetChild("StackTrace", options);

            if (stackTrace == null)
            {
                return(ObjectValue.CreateUnknown("StackTrace"));
            }

            string trace = stackTrace.ObjectValue as string;

            if (trace == null)
            {
                return(ObjectValue.CreateUnknown("StackTrace"));
            }

            var regex  = new Regex("at (?<MethodName>.*) in (?<FileName>.*):(?<LineNumber>\\d+)(,(?<Column>\\d+))?");
            var frames = new List <ObjectValue> ();

            foreach (var sframe in trace.Split('\n'))
            {
                string text   = sframe.Trim(' ', '\r', '\t');
                string file   = "";
                int    column = 0;
                int    line   = 0;

                if (text.Length == 0)
                {
                    continue;
                }

                var match = regex.Match(text);
                if (match.Success)
                {
                    text = match.Groups["MethodName"].ToString();
                    file = match.Groups["FileName"].ToString();
                    int.TryParse(match.Groups["LineNumber"].ToString(), out line);
                    int.TryParse(match.Groups["Column"].ToString(), out column);
                }

                var fileVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("File"), "", new EvaluationResult(file), ObjectValueFlags.None);
                var lineVal  = ObjectValue.CreatePrimitive(null, new ObjectPath("Line"), "", new EvaluationResult(line.ToString()), ObjectValueFlags.None);
                var colVal   = ObjectValue.CreatePrimitive(null, new ObjectPath("Column"), "", new EvaluationResult(column.ToString()), ObjectValueFlags.None);
                var children = new ObjectValue[] { fileVal, lineVal, colVal };

                var frame = ObjectValue.CreateObject(null, new ObjectPath(), "", new EvaluationResult(text), ObjectValueFlags.None, children);
                frames.Add(frame);
            }

            return(ObjectValue.CreateArray(null, new ObjectPath("StackTrace"), "", frames.Count, ObjectValueFlags.None, frames.ToArray()));
        }
Example #13
0
        protected virtual ObjectValue CreateObjectValueImpl(EvaluationContext ctx, Mono.Debugging.Backend.IObjectValueSource source, ObjectPath path, object obj, ObjectValueFlags flags)
        {
            string typeName = obj != null?GetValueTypeName(ctx, obj) : "";

            if (obj == null || IsNull(ctx, obj))
            {
                return(ObjectValue.CreateNullObject(source, path, GetDisplayTypeName(typeName), flags));
            }
            else if (IsPrimitive(ctx, obj) || IsEnum(ctx, obj))
            {
                return(ObjectValue.CreatePrimitive(source, path, GetDisplayTypeName(typeName), ctx.Evaluator.TargetObjectToExpression(ctx, obj), flags));
            }
            else if (IsArray(ctx, obj))
            {
                return(ObjectValue.CreateObject(source, path, GetDisplayTypeName(typeName), ctx.Evaluator.TargetObjectToExpression(ctx, obj), flags, null));
            }
            else
            {
                TypeDisplayData tdata = GetTypeDisplayData(ctx, GetValueType(ctx, obj));

                EvaluationResult tvalue;
                if (!string.IsNullOrEmpty(tdata.ValueDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
                {
                    tvalue = new EvaluationResult(EvaluateDisplayString(ctx, obj, tdata.ValueDisplayString));
                }
                else
                {
                    tvalue = ctx.Evaluator.TargetObjectToExpression(ctx, obj);
                }

                string tname;
                if (!string.IsNullOrEmpty(tdata.TypeDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
                {
                    tname = EvaluateDisplayString(ctx, obj, tdata.TypeDisplayString);
                }
                else
                {
                    tname = GetDisplayTypeName(typeName);
                }

                ObjectValue oval = ObjectValue.CreateObject(source, path, tname, tvalue, flags, null);
                if (!string.IsNullOrEmpty(tdata.NameDisplayString) && ctx.Options.AllowDisplayStringEvaluation)
                {
                    oval.Name = EvaluateDisplayString(ctx, obj, tdata.NameDisplayString);
                }
                return(oval);
            }
        }
        public ObjectValue GetValue(ObjectPath path, EvaluationOptions options)
        {
            string shortName    = name;
            var    indexOfSpace = name.IndexOf(' ');

            if (indexOfSpace != -1)            //Remove " [TypeName]" from variable name
            {
                shortName = name.Remove(indexOfSpace);
            }
            if (type == null)
            {
                return(ObjectValue.CreateError(null, new ObjectPath(shortName), "", val, ObjectValueFlags.None));
            }
            if (val == "null")
            {
                return(ObjectValue.CreateNullObject(this, shortName, type, parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly));
            }
            if (variablesReference == 0)            //This is some kind of primitive...
            {
                return(ObjectValue.CreatePrimitive(this, new ObjectPath(shortName), type, new EvaluationResult(val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly));
            }
            return(ObjectValue.CreateObject(this, new ObjectPath(shortName), type, new EvaluationResult(val), parentVariablesReference > 0 ? ObjectValueFlags.None : ObjectValueFlags.ReadOnly, null));
        }
        private ObjectValue CreateExceptionObject(ExceptionRecord expRec)
        {
            List <ObjectValue> children = new List <ObjectValue>();

            //message
            ObjectValue message = ObjectValue.CreateObject(
                this,
                new ObjectPath(new string[] { expRec.ExceptionName }),
                "string",
                expRec.ExceptionInfo,
                ObjectValueFlags.Object,
                new ObjectValue[0]);

            message.Name = "Message";
            children.Add(message);

            //inner exception
            if (expRec.InnerExceptionRecord != null)
            {
                ObjectValue innerExp = CreateExceptionObject(expRec.InnerExceptionRecord);
                innerExp.Name = "InnerException";
                children.Add(innerExp);
            }

            //do these for first level only?
            if (expRec == exceptionRecord)
            {
                //stack trace
                List <ObjectValue> stackList = new List <ObjectValue>();
                for (int i = 0; i < magoCallStackFrames.Count; i++)
                {
                    List <ObjectValue> stkValChildren = new List <ObjectValue>();

                    // line
                    ObjectValue stkValLine = ObjectValue.CreateObject(
                        this,
                        new ObjectPath(new string[] { expRec.ExceptionName, "StackTrace", i.ToString(CultureInfo.InvariantCulture) }),
                        "Int",
                        i.ToString(CultureInfo.InvariantCulture),
                        ObjectValueFlags.Object,
                        new ObjectValue[0]);
                    stkValLine.Name = "Line";
                    stkValChildren.Add(stkValLine);

                    ObjectValue stkVal = ObjectValue.CreateObject(
                        this,
                        new ObjectPath(new string[] { expRec.ExceptionName, "StackTrace" }),
                        "Object",
                        magoCallStackFrames[i].FunctionName,
                        ObjectValueFlags.Object,
                        stkValChildren.ToArray());
                    stackList.Add(stkVal);
                }

                ObjectValue stacktrace = ObjectValue.CreateArray(
                    this,
                    new ObjectPath(new string[] { expRec.ExceptionName }),
                    "StackTrace",
                    magoCallStackFrames.Count,
                    ObjectValueFlags.Array,
                    stackList.ToArray());
                stacktrace.Name = "StackTrace";
                children.Add(stacktrace);

                //instance message
                List <ObjectValue> instanceChildren = new List <ObjectValue>();
                ObjectValue        instanceMessage  = ObjectValue.CreateObject(
                    this,
                    new ObjectPath(new string[] { expRec.ExceptionName, "Instance" }),
                    "string",
                    expRec.ExceptionInfo,
                    ObjectValueFlags.Object | ObjectValueFlags.Public,
                    new ObjectValue[0]);
                instanceMessage.Name = "Message";
                instanceChildren.Add(instanceMessage);

                //instance
                ObjectValue instance = ObjectValue.CreateObject(
                    this,
                    new ObjectPath(new string[] { expRec.ExceptionName }),
                    expRec.ExceptionName,
                    expRec.ExceptionName,
                    ObjectValueFlags.Object,
                    instanceChildren.ToArray());
                instance.Name = "Instance";
                children.Add(instance);
            }

            //parent
            ObjectValue val = ObjectValue.CreateObject(
                this,
                new ObjectPath(new string[] {}),
                expRec.ExceptionName,
                String.Empty,
                ObjectValueFlags.Error, children.ToArray());

            return(val);
        }
Example #16
0
        public virtual ObjectValue[] GetObjectValueChildren(EvaluationContext ctx, IObjectSource objectSource, object type, object obj, int firstItemIndex, int count, bool dereferenceProxy)
        {
            if (IsArray(ctx, obj))
            {
                ArrayElementGroup agroup = new ArrayElementGroup(ctx, CreateArrayAdaptor(ctx, obj));
                return(agroup.GetChildren(ctx.Options));
            }

            if (IsPrimitive(ctx, obj))
            {
                return(new ObjectValue[0]);
            }

            bool showRawView = false;

            // If there is a proxy, it has to show the members of the proxy
            object proxy = obj;

            if (dereferenceProxy)
            {
                proxy = GetProxyObject(ctx, obj);
                if (proxy != obj)
                {
                    type        = GetValueType(ctx, proxy);
                    showRawView = true;
                }
            }

            TypeDisplayData tdata = GetTypeDisplayData(ctx, type);
            bool            groupPrivateMembers = ctx.Options.GroupPrivateMembers && (ctx.Options.GroupUserPrivateMembers || IsExternalType(ctx, type));

            List <ObjectValue> values           = new List <ObjectValue> ();
            BindingFlags       flattenFlag      = ctx.Options.FlattenHierarchy ? (BindingFlags)0 : BindingFlags.DeclaredOnly;
            BindingFlags       nonNonPublicFlag = groupPrivateMembers || showRawView ? (BindingFlags)0 : BindingFlags.NonPublic;
            BindingFlags       staticFlag       = ctx.Options.GroupStaticMembers ? (BindingFlags)0 : BindingFlags.Static;
            BindingFlags       access           = BindingFlags.Public | BindingFlags.Instance | flattenFlag | nonNonPublicFlag | staticFlag;

            // Load all members to a list before creating the object values,
            // to avoid problems with objects being invalidated due to evaluations in the target,
            List <ValueReference> list = new List <ValueReference> ();

            list.AddRange(GetMembersSorted(ctx, objectSource, type, proxy, access));

            object tdataType = type;

            foreach (ValueReference val in list)
            {
                try {
                    object decType = val.DeclaringType;
                    if (decType != null && decType != tdataType)
                    {
                        tdataType = decType;
                        tdata     = GetTypeDisplayData(ctx, decType);
                    }
                    DebuggerBrowsableState state = tdata.GetMemberBrowsableState(val.Name);
                    if (state == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }

                    if (state == DebuggerBrowsableState.RootHidden && dereferenceProxy)
                    {
                        object ob = val.Value;
                        if (ob != null)
                        {
                            values.Clear();
                            values.AddRange(GetObjectValueChildren(ctx, val, ob, -1, -1));
                            showRawView = true;
                            break;
                        }
                    }
                    else
                    {
                        ObjectValue oval = val.CreateObjectValue(true);
                        values.Add(oval);
                    }
                }
                catch (Exception ex) {
                    ctx.WriteDebuggerError(ex);
                    values.Add(ObjectValue.CreateError(null, new ObjectPath(val.Name), GetDisplayTypeName(GetTypeName(ctx, val.Type)), ex.Message, val.Flags));
                }
            }

            if (showRawView)
            {
                values.Add(RawViewSource.CreateRawView(ctx, objectSource, obj));
            }
            else
            {
                if (IsArray(ctx, proxy))
                {
                    ICollectionAdaptor col    = CreateArrayAdaptor(ctx, proxy);
                    ArrayElementGroup  agroup = new ArrayElementGroup(ctx, col);
                    ObjectValue        val    = ObjectValue.CreateObject(null, new ObjectPath("Raw View"), "", "", ObjectValueFlags.ReadOnly, values.ToArray());
                    values = new List <ObjectValue> ();
                    values.Add(val);
                    values.AddRange(agroup.GetChildren(ctx.Options));
                }
                else
                {
                    if (ctx.Options.GroupStaticMembers && HasMembers(ctx, type, proxy, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | flattenFlag))
                    {
                        access = BindingFlags.Static | BindingFlags.Public | flattenFlag | nonNonPublicFlag;
                        values.Add(FilteredMembersSource.CreateStaticsNode(ctx, objectSource, type, proxy, access));
                    }
                    if (groupPrivateMembers && HasMembers(ctx, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag))
                    {
                        values.Add(FilteredMembersSource.CreateNonPublicsNode(ctx, objectSource, type, proxy, BindingFlags.Instance | BindingFlags.NonPublic | flattenFlag | staticFlag));
                    }

                    if (!ctx.Options.FlattenHierarchy)
                    {
                        object baseType = GetBaseType(ctx, type, false);
                        if (baseType != null)
                        {
                            values.Insert(0, BaseTypeViewSource.CreateBaseTypeView(ctx, objectSource, baseType, proxy));
                        }
                    }
                }
            }
            return(values.ToArray());
        }
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            options = options.Clone();
            options.EllipsizeStrings  = false;
            options.AllowTargetInvoke = true;
            ctx = ctx.WithOptions(options);
            string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue);

            var excInstance = Exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue  = null;
            ObjectValue helpLinkValue = null;
            var         exceptionType = ctx.Adapter.GetValueType(ctx, Exception.Value);

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message");
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("Message"));
                });
            }
            else
            {
                var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "Message");
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Get the help link

            if (withTimeout)
            {
                helpLinkValue = ctx.Adapter.CreateObjectValueAsync("HelpLink", ObjectValueFlags.None, delegate {
                    var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink");
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("HelpLink"));
                });
            }
            else
            {
                var mref = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "HelpLink");
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    helpLinkValue = ObjectValue.CreatePrimitive(null, new ObjectPath("HelpLink"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (helpLinkValue == null)
            {
                helpLinkValue = ObjectValue.CreateUnknown("HelpLink");
            }

            helpLinkValue.Name = "HelpLink";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate {
                    var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException");
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        //Console.WriteLine ("pp got child:" + type);
                        var innerSource = new ExceptionInfoSource(ctx, inner);
                        var res         = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }

                    return(ObjectValue.CreateUnknown("InnerException"));
                });
            }
            else
            {
                var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerException");
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    //Console.WriteLine ("pp got child:" + type);
                    var innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }

            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Inner exceptions in case of AgregatedException

            ObjectValue             childExceptionsValue       = null;
            ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate {
                var inner = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "InnerExceptions");
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    var obj          = inner.GetValue(ctx);
                    var objType      = ctx.Adapter.GetValueType(ctx, obj);
                    var count        = (int)ctx.Adapter.GetMember(ctx, null, obj, "Count").ObjectValue;
                    var childrenList = new List <ObjectValue>();
                    for (int i = 0; i < count; i++)
                    {
                        childrenList.Add(new ExceptionInfoSource(ctx, ctx.Adapter.GetIndexerReference(ctx, obj, objType, new object[] { ctx.Adapter.CreateValue(ctx, i) })).CreateObjectValue(withTimeout, ctx.Options));
                    }
                    return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray()));
                }

                return(ObjectValue.CreateUnknown("InnerExceptions"));
            };

            if (withTimeout)
            {
                childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate);
            }
            else
            {
                childExceptionsValue = getInnerExceptionsDelegate();
            }

            if (childExceptionsValue == null)
            {
                childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate {
                    var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace");
                    if (stackTrace == null)
                    {
                        return(ObjectValue.CreateUnknown("StackTrace"));
                    }
                    return(GetStackTrace(stackTrace.ObjectValue as string));
                });
            }
            else
            {
                var stackTrace = ctx.Adapter.GetMember(ctx, Exception, exceptionType, Exception.Value, "StackTrace");
                if (stackTrace == null)
                {
                    return(ObjectValue.CreateUnknown("StackTrace"));
                }
                stackTraceValue = GetStackTrace(stackTrace.ObjectValue as string);
            }

            var children = new ObjectValue [] { excInstance, messageValue, helpLinkValue, stackTraceValue, childExceptionValue, childExceptionsValue };

            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }
Example #18
0
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            string type = ctx.Adapter.GetTypeName(ctx, exception.Type);

            ObjectValue excInstance = exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue = null;

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    ValueReference mref = exception.GetChild("Message", options);
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("Message"));
                    }
                });
            }
            else
            {
                ValueReference mref = exception.GetChild("Message", options);
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "System.String", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }
            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate {
                    ValueReference inner = exception.GetChild("InnerException", options);
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        Console.WriteLine("pp got child:" + type);
                        ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                        ObjectValue res = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }
                    else
                    {
                        return(ObjectValue.CreateUnknown("InnerException"));
                    }
                });
            }
            else
            {
                ValueReference inner = exception.GetChild("InnerException", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    Console.WriteLine("pp got child:" + type);
                    ExceptionInfoSource innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }
            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate {
                    return(GetStackTrace(options));
                });
            }
            else
            {
                stackTraceValue = GetStackTrace(options);
            }

            ObjectValue[] children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue };
            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }
        public ObjectValue CreateObjectValue(bool withTimeout, EvaluationOptions options)
        {
            options = options.Clone();
            options.EllipsizeStrings = false;
            string type = ctx.Adapter.GetValueTypeName(ctx, Exception.ObjectValue);

            var excInstance = Exception.CreateObjectValue(withTimeout, options);

            excInstance.Name = "Instance";

            ObjectValue messageValue = null;

            // Get the message

            if (withTimeout)
            {
                messageValue = ctx.Adapter.CreateObjectValueAsync("Message", ObjectValueFlags.None, delegate {
                    var mref = Exception.GetChild("Message", options);
                    if (mref != null)
                    {
                        string val = (string)mref.ObjectValue;
                        return(ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal));
                    }

                    return(ObjectValue.CreateUnknown("Message"));
                });
            }
            else
            {
                var mref = Exception.GetChild("Message", options);
                if (mref != null)
                {
                    string val = (string)mref.ObjectValue;
                    messageValue = ObjectValue.CreatePrimitive(null, new ObjectPath("Message"), "string", new EvaluationResult(val), ObjectValueFlags.Literal);
                }
            }

            if (messageValue == null)
            {
                messageValue = ObjectValue.CreateUnknown("Message");
            }

            messageValue.Name = "Message";

            // Inner exception

            ObjectValue childExceptionValue = null;

            if (withTimeout)
            {
                childExceptionValue = ctx.Adapter.CreateObjectValueAsync("InnerException", ObjectValueFlags.None, delegate {
                    var inner = Exception.GetChild("InnerException", options);
                    if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                    {
                        //Console.WriteLine ("pp got child:" + type);
                        var innerSource = new ExceptionInfoSource(ctx, inner);
                        var res         = innerSource.CreateObjectValue(false, options);
                        return(res);
                    }

                    return(ObjectValue.CreateUnknown("InnerException"));
                });
            }
            else
            {
                var inner = Exception.GetChild("InnerException", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    //Console.WriteLine ("pp got child:" + type);
                    var innerSource = new ExceptionInfoSource(ctx, inner);
                    childExceptionValue      = innerSource.CreateObjectValue(false, options);
                    childExceptionValue.Name = "InnerException";
                }
            }

            if (childExceptionValue == null)
            {
                childExceptionValue = ObjectValue.CreateUnknown("InnerException");
            }

            // Inner exceptions in case of AgregatedException

            ObjectValue             childExceptionsValue       = null;
            ObjectEvaluatorDelegate getInnerExceptionsDelegate = delegate {
                var inner = Exception.GetChild("InnerExceptions", options);
                if (inner != null && !ctx.Adapter.IsNull(ctx, inner.Value))
                {
                    var obj            = inner.GetValue(ctx);
                    var objType        = ctx.Adapter.GetValueType(ctx, obj);
                    var enumerator     = ctx.Adapter.RuntimeInvoke(ctx, objType, obj, "GetEnumerator", new object[0], new object[0]);
                    var enumeratorType = ctx.Adapter.GetImplementedInterfaces(ctx, ctx.Adapter.GetValueType(ctx, enumerator)).First(f => ctx.Adapter.GetTypeName(ctx, f) == "System.Collections.IEnumerator");
                    var childrenList   = new List <ObjectValue> ();
                    while ((bool)ctx.Adapter.TargetObjectToObject(ctx, ctx.Adapter.RuntimeInvoke(ctx, enumeratorType, enumerator, "MoveNext", new object[0], new object[0])))
                    {
                        var valCurrent = ctx.Adapter.GetMember(ctx, null, enumeratorType, enumerator, "Current");
                        childrenList.Add(new ExceptionInfoSource(ctx, valCurrent).CreateObjectValue(withTimeout, ctx.Options));
                    }
                    return(ObjectValue.CreateObject(null, new ObjectPath("InnerExceptions"), "", "", ObjectValueFlags.None, childrenList.ToArray()));
                }

                return(ObjectValue.CreateUnknown("InnerExceptions"));
            };

            if (withTimeout)
            {
                childExceptionsValue = ctx.Adapter.CreateObjectValueAsync("InnerExceptions", ObjectValueFlags.None, getInnerExceptionsDelegate);
            }
            else
            {
                childExceptionsValue = getInnerExceptionsDelegate();
            }

            if (childExceptionsValue == null)
            {
                childExceptionsValue = ObjectValue.CreateUnknown("InnerExceptions");
            }

            // Stack trace

            ObjectValue stackTraceValue;

            if (withTimeout)
            {
                stackTraceValue = ctx.Adapter.CreateObjectValueAsync("StackTrace", ObjectValueFlags.None, delegate {
                    return(GetStackTrace(options));
                });
            }
            else
            {
                stackTraceValue = GetStackTrace(options);
            }

            var children = new ObjectValue [] { excInstance, messageValue, stackTraceValue, childExceptionValue, childExceptionsValue };

            return(ObjectValue.CreateObject(null, new ObjectPath("InnerException"), type, "", ObjectValueFlags.None, children));
        }