private bool DoDefineScope(DefineScopeArgs args, StringBuilder output)
        {
            SampleThread thread = this.GetThread(args.ThreadId);

            if (thread == null)
            {
                output.AppendLine(Invariant($"Error: Invalid thread id '{args.ThreadId}'!"));
                return(false);
            }

            SampleStackFrame frame = thread.GetTopStackFrame();

            if (frame == null)
            {
                output.AppendLine(Invariant($"Error: Thread '{args.ThreadId}' has no stack frames!"));
                return(false);
            }

            if (frame.AllScopes.Any(s => String.Equals(s.Name, args.Name, StringComparison.OrdinalIgnoreCase)))
            {
                output.AppendLine(Invariant($"Error: Selected stack frame already has a scope called '{args.Name}'!"));
                return(false);
            }

            SampleScope scope = new SampleScope(this.adapter, args.Name, args.Expensive);

            frame.AddScope(scope);

            return(true);
        }
        internal SampleStackFrame(SampleDebugAdapter adapter, SampleModule module, string functionName, IEnumerable <SampleFunctionArgument> args, string fileName, int line, int column)
            : base(adapter)
        {
            this.childScopes = new List <SampleScope>();

            this.localsScope = new SampleScope(this.Adapter, "Locals", false);

            this.Module       = module;
            this.FunctionName = functionName;
            this.FileName     = fileName;
            this.Line         = line;
            this.Column       = column;

            if (args != null && args.Any())
            {
                this.Args      = args.ToList();
                this.argsScope = new SampleScope(this.Adapter, "Arguments", false);

                foreach (SampleFunctionArgument arg in args)
                {
                    SimpleVariable variable = new SimpleVariable(
                        adapter: this.Adapter,
                        name: arg.Name,
                        type: arg.Type,
                        value: arg.Value);

                    this.argsScope.AddVariable(variable);
                }
            }
            else
            {
                this.Args = Enumerable.Empty <SampleFunctionArgument>().ToList();;
            }
        }
示例#3
0
        private SampleScope CreateGlobalsScope()
        {
            SampleScope scope = new SampleScope(this, "Globals", false);

            scope.AddVariable(new WrapperVariable(this, "CurrentLine", "int", () => this.LineToClient(this.currentLineNum).ToString(CultureInfo.InvariantCulture)));
            scope.AddVariable(new WrapperVariable(this, "Line", "string", () => this.CurrentLine));
            scope.AddVariable(new WrapperVariable(this, "JustMyCodeStatus", "bool", () => (this.IsJustMyCodeOn ?? false) ? "on" : "off"));
            scope.AddVariable(new WrapperVariable(this, "StepFilteringStatus", "bool", () => (this.IsStepFilteringOn ?? false) ? "on" : "off"));

            SimpleVariable directiveInfo = new SimpleVariable(this, "DirectiveInfo", null, null);

            directiveInfo.AddChild(new WrapperVariable(this, "LineIsDirective", "bool", () => this.directiveProcessor.IsDirective(this.CurrentLine).ToString()));
            directiveInfo.AddChild(new WrapperVariable(this, "DirectiveArguments", null, () => null, () =>
            {
                string line = this.CurrentLine;
                if (this.directiveProcessor.IsDirective(line))
                {
                    object args = this.directiveProcessor.GetArguments(line);
                    if (args != null)
                    {
                        List <SampleVariable> argsVars = new List <SampleVariable>();

                        foreach (PropertyInfo pi in args.GetType().GetProperties())
                        {
                            object value = pi.GetValue(args);
                            if (value == null)
                            {
                                continue;
                            }

                            if (pi.PropertyType.IsArray)
                            {
                                SimpleVariable argsVar = new SimpleVariable(this, pi.Name, pi.PropertyType.Name, null);

                                int i = 0;
                                IEnumerable argsEnum = value as IEnumerable;
                                if (argsEnum != null)
                                {
                                    foreach (object val in (IEnumerable)value)
                                    {
                                        argsVar.AddChild(new SimpleVariable(this, i++.ToString(CultureInfo.InvariantCulture), null, val.ToString()));
                                    }
                                }

                                argsVars.Add(argsVar);
                            }
                            else
                            {
                                argsVars.Add(new SimpleVariable(this, pi.Name, pi.PropertyType.Name, value.ToString()));
                            }
                        }

                        return(argsVars);
                    }
                }

                return(null);
            }));

            scope.AddVariable(directiveInfo);

            return(scope);
        }
 internal void AddScope(SampleScope scope)
 {
     this.childScopes.Add(scope);
 }
        private IEnumerable <SampleScope> GetScopes()
        {
            SampleScope aggregateScope = null;

            if (this.argsScope != null && this.argsScope.ChildContainers.Any())
            {
                if (this.Adapter.UseArgsScope)
                {
                    // Returns the args directly
                    yield return(this.argsScope);
                }
                else
                {
                    // Merge the args into an aggregate scope
                    if (aggregateScope == null)
                    {
                        aggregateScope = new SampleScope(this.Adapter, "Locals", false);
                    }

                    foreach (SampleVariable variable in this.argsScope.ChildContainers)
                    {
                        aggregateScope.AddVariable(variable);
                    }
                }
            }

            if (this.Adapter.GlobalsScope != null && this.Adapter.GlobalsScope.ChildContainers.Any() && this.Adapter.ShowGlobals)
            {
                if (this.Adapter.UseGlobalsScope)
                {
                    // Return the globals directly
                    yield return(this.Adapter.GlobalsScope);
                }
                else
                {
                    // Merge the globals into an aggregate scope
                    if (aggregateScope == null)
                    {
                        aggregateScope = new SampleScope(this.Adapter, "Locals", false);
                    }

                    foreach (SampleVariable variable in this.Adapter.GlobalsScope.ChildContainers)
                    {
                        aggregateScope.AddVariable(variable);
                    }
                }
            }

            if (aggregateScope != null)
            {
                // We're already aggregating other scopes, so merge the Locals as well
                foreach (SampleVariable variable in this.localsScope.ChildContainers)
                {
                    aggregateScope.AddVariable(variable);
                }

                yield return(aggregateScope);
            }
            else
            {
                yield return(this.localsScope);
            }

            foreach (SampleScope scope in this.childScopes)
            {
                yield return(scope);
            }
        }