Esempio n. 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);
        }
        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()));
        }
Esempio n. 3
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));
     }
 }
 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));
 }
Esempio n. 5
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));
 }
Esempio n. 6
0
        public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            List <ObjectValue> children = new List <ObjectValue>();

            session.SelectThread(threadId);

            if (Engine.Symbols.ScopeLocalSymbols == null)
            {
                return(children.ToArray());
            }

            DEW.DebugScopedSymbol parent = null;

            for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Symbols.Length; i++)
            {
                DEW.DebugScopedSymbol symbol = Engine.Symbols.ScopeLocalSymbols.Symbols[i];
                if (symbol.Name == path.LastName)
                {
                    parent = symbol;
                    break;
                }
            }

            if (parent == null || parent.ChildrenCount == 0)
            {
                return(children.ToArray());
            }

            for (uint i = 0; i < parent.ChildrenCount; i++)
            {
                DEW.DebugScopedSymbol child = parent.Children[i];

                string name     = child.Name;
                string typename = child.TypeName;
                string val      = child.TextValue;
                ulong  offset   = child.Offset;

                ObjectValue ov = symbolResolver.Resolve(offset, name, typename, val, child.Parent);
                if (ov == null)
                {
                    ObjectValueFlags flags = ObjectValueFlags.Variable;
                    ov = ObjectValue.CreatePrimitive(this, new ObjectPath(name), typename, new EvaluationResult(val), flags);
                }

                if (ov != null)
                {
                    children.Add(ov);
                }
            }

            return(children.ToArray());
        }
Esempio n. 7
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()));
        }
Esempio n. 8
0
        public ObjectValue [] GetLocalVariables(int frameIndex, EvaluationOptions options)
        {
            List <ObjectValue> results = new List <ObjectValue> ();
            var scopeBody = vsCodeDebuggerSession.protocolClient.SendRequestSync(new ScopesRequest(frames [frameIndex].Id));

            foreach (var variablesGroup in scopeBody.Scopes)
            {
                var varibles = vsCodeDebuggerSession.protocolClient.SendRequestSync(new VariablesRequest(variablesGroup.VariablesReference));
                foreach (var variable in varibles.Variables)
                {
                    results.Add(ObjectValue.CreatePrimitive(null, new ObjectPath(variable.Name), variable.Type ?? "<unknown>", new EvaluationResult(variable.Value), ObjectValueFlags.None));
                }
            }
            return(results.ToArray());
        }
Esempio n. 9
0
        internal void UpdateFromTrace(string trace)
        {
            EvaluationResult res   = new EvaluationResult(trace);
            ObjectValueFlags flags = ObjectValueFlags.Primitive | ObjectValueFlags.Field;
            string           type  = "";

            if (value != null)
            {
                flags = value.Flags;
                type  = value.TypeName;
            }
            value     = ObjectValue.CreatePrimitive(null, new ObjectPath(Expression), type, res, flags);
            evaluated = true;
            NotifyChanged();
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
        public ObjectValue[] GetAllLocals(int frameIndex, EvaluationOptions options)
        {
            session.RunCommand(true, "vars");
            List <ObjectValue> locals = new List <ObjectValue> ();

            lock (syncLock) {
                foreach (string varName in session.lastResult.vars)
                {
                    ObjectValue      val;
                    ObjectValueFlags flags = ObjectValueFlags.Variable;
                    val      = ObjectValue.CreatePrimitive(this, new ObjectPath(varName), "dummyInt", new EvaluationResult("test_val"), flags);
                    val.Name = varName;
                    locals.Add(val);
                }
            }

            return(locals.ToArray());
        }
Esempio n. 12
0
            public ObjectValue[] GetParameters(int frameIndex, EvaluationOptions options)
            {
                List <ObjectValue> results = new List <ObjectValue>();
                var scopeBody = vsCodeDebuggerSession.protocolClient.SendRequestAsync(new ScopesRequest(new ScopesArguments {
                    frameId = frames[frameIndex].id
                })).Result;

                foreach (var variablesGroup in scopeBody.scopes)
                {
                    var varibles = vsCodeDebuggerSession.protocolClient.SendRequestAsync(new VariablesRequest(new VariablesRequestArguments {
                        variablesReference = variablesGroup.variablesReference
                    })).Result;
                    foreach (var variable in varibles.variables)
                    {
                        results.Add(ObjectValue.CreatePrimitive(null, new ObjectPath(variable.name), "unknown", new EvaluationResult(variable.value), ObjectValueFlags.None));
                    }
                }
                return(results.ToArray());
            }
        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> ();

            var regex = new Regex("at (.*) in (.*):(.*)");

            foreach (string sframe in trace.Split('\n'))
            {
                string txt   = sframe.Trim(' ', '\r', '\n');
                string file  = "";
                int    line  = 0;
                int    col   = 0;
                var    match = regex.Match(sframe);
                if (match.Success)
                {
                    txt  = match.Groups [1].ToString();
                    file = match.Groups [2].ToString();
                    int.TryParse(match.Groups [3].ToString(), out line);
                }
                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("Column"), "", 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()));
        }
Esempio n. 14
0
        ObjectValue CreateObjectValue(ISymbolValue v, IExpression originalExpression, ObjectPath pathOpt, EvaluationOptions evalOptions, IDBacktraceSymbol symbolOpt = null)
        {
            if (v != null)
            {
                try
                {
                    return(v.Accept(new ObjectValueSynthVisitor(this)
                    {
                        evalOptions = evalOptions, OriginalExpression = originalExpression, Path = pathOpt
                    }));
                }
                catch (NotImplementedException) { }
            }

            if (symbolOpt != null)
            {
                return(ObjectValue.CreatePrimitive(this, pathOpt, symbolOpt.TypeName, new Mono.Debugging.Backend.EvaluationResult(symbolOpt.Value), ObjectValueFlags.Variable));
            }

            return(ObjectValue.CreateError(this, pathOpt, "", "Couldn't evaluate expression " + (originalExpression != null ? originalExpression.ToString() : ""), ObjectValueFlags.Error));
        }
Esempio n. 15
0
        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));
        }
Esempio n. 16
0
        public ObjectValue[] GetLocalVariables(int frameIndex, EvaluationOptions options)
        {
            List <ObjectValue> values = new List <ObjectValue>();

            if (Engine.Symbols.ScopeLocalSymbols == null)
            {
                return(values.ToArray());
            }

            for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Count; i++)
            {
                if (Engine.Symbols.ScopeLocalSymbols.Symbols[i].Parent != null)
                {
                    continue;
                }

                string name     = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Name;
                string typename = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TypeName;
                string val      = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TextValue;
                ulong  offset   = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Offset;
                DEW.DebugScopedSymbol parentSymbol = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Parent;

                ObjectValue ov = symbolResolver.Resolve(offset, name, typename, val, parentSymbol);
                if (ov == null)
                {
                    ObjectValueFlags flags = ObjectValueFlags.Variable;
                    ov = ObjectValue.CreatePrimitive(this, new ObjectPath(name), typename, new EvaluationResult(val), flags);
                }

                if (ov != null)
                {
                    values.Add(ov);
                }
            }
            return(values.ToArray());
        }
Esempio n. 17
0
        public ObjectValue[] GetLocalVariables(int frameIndex, EvaluationOptions options)
        {
            List <ObjectValue> values = new List <ObjectValue> ();

            if (Engine.Symbols.ScopeLocalSymbols == null)
            {
                return(values.ToArray());
            }

            for (uint i = 0; i < Engine.Symbols.ScopeLocalSymbols.Count; i++)
            {
                string name     = Engine.Symbols.ScopeLocalSymbols.Symbols[i].Name;
                string typename = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TypeName;
                string val      = Engine.Symbols.ScopeLocalSymbols.Symbols[i].TextValue;

                ObjectValueFlags flags = ObjectValueFlags.Variable;
                ObjectValue      ov    = ObjectValue.CreatePrimitive(this, new ObjectPath(name), typename, new EvaluationResult(val), flags);

                values.Add(ov);
            }
            return(values.ToArray());

            //Engine.CallStack[0]
            //Engine
            //ScopeLocalSymbols

            /*
             * List<ObjectValue> values = new List<ObjectValue> ();
             * SelectFrame (frameIndex);
             * DDebugCommandResult res = session.RunCommand("-stack-list-locals", "0");
             * foreach (ResultData data in res.GetObject ("locals"))
             *  values.Add (CreateVarObject (data.GetValue ("name")));
             *
             * 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));
        }
Esempio n. 19
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 Resolve(ulong offset, string symbolname, string typename, string val, DEW.DebugScopedSymbol parentsymbol)
        {
            DModule module;
            int     codeLine;
            INode   variableNode = null;

            // Search currently scoped module
            string file = "";
            uint   line = 0;

            Engine.Symbols.GetLineByOffset(Engine.CurrentInstructionOffset, out file, out line);
            codeLine = (int)line;

            if (string.IsNullOrWhiteSpace(file))
            {
                return(null);
            }

            AbstractDProject dproj = null;

            module = GetFileSyntaxTree(file, out dproj);

            // If syntax tree built, search the variable location
            if (module != null)
            {
                var ed   = Resolver.DResolverWrapper.CreateEditorData(IdeApp.Workbench.ActiveDocument);
                var ctxt = ResolutionContext.Create(ed, false);

                CodeCompletion.DoTimeoutableCompletionTask(null, ctxt, () =>
                {
                    var loc = new CodeLocation(0, codeLine);
                    ctxt.Push(DResolver.SearchBlockAt(module, loc), loc);

                    AbstractType[] res;
                    if (parentsymbol != null)
                    {
                        var parentres = ResolveParentSymbol(parentsymbol, ctxt);
                        res           = TypeDeclarationResolver.ResolveFurtherTypeIdentifier(symbolname, parentres, ctxt, null);
                    }
                    else
                    {
                        res = TypeDeclarationResolver.ResolveIdentifier(symbolname, ctxt, null);
                    }

                    if (res != null && res.Length > 0 && res[0] is DSymbol)
                    {
                        variableNode = (res[0] as DSymbol).Definition;
                    }
                });
            }

            // Set type string
            string _typeString = typename;

            if (variableNode != null)
            {
                var t = variableNode.Type;
                if (t != null)
                {
                    _typeString = t.ToString();
                }
            }

            // Set value string
            string _valueString = val;

            ObjectValueFlags flags = ObjectValueFlags.Variable;

            if (variableNode != null)
            {
                ITypeDeclaration curValueType = variableNode.Type;
                if (curValueType != null)
                {
                    if (!IsBasicType(curValueType))
                    {
                        if (_typeString == "string")                         //TODO: Replace this by searching the alias definition in the cache
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Char)
                            }
                        }
                        ;
                        else if (_typeString == "wstring")
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Wchar)
                            }
                        }
                        ;
                        else if (_typeString == "dstring")
                        {
                            curValueType = new ArrayDecl()
                            {
                                InnerDeclaration = new DTokenDeclaration(DTokens.Dchar)
                            }
                        }
                        ;

                        if (IsArray(curValueType))
                        {
                            flags = ObjectValueFlags.Array;

                            var clampDecl = curValueType as ArrayDecl;
                            var valueType = clampDecl.InnerDeclaration;

                            if (valueType is DTokenDeclaration)
                            {
                                bool IsString = false;
                                uint elsz     = 0;
                                var  realType = DetermineArrayType((valueType as DTokenDeclaration).Token, out elsz, out IsString);

                                var arr = Engine.Symbols.ReadArray(offset, realType, elsz);

                                if (arr != null)
                                {
                                    _valueString = BuildArrayContentString(arr, IsString);
                                }
                            }
                        }
                        else
                        {
                            flags = ObjectValueFlags.Object;
                        }
                    }
                }
            }

            return(ObjectValue.CreatePrimitive(ObjectValueSource, new ObjectPath(symbolname), _typeString, new EvaluationResult(_valueString), flags));
        }
        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));
        }