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();;
            }
        }
示例#2
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);
        }
        protected override StackFrame CreateProtocolObject()
        {
            StringBuilder stackName = new StringBuilder();

            StackFrameFormat format = this.Format;

            bool showInHex      = format?.Hex ?? false;
            bool showModule     = format?.Module ?? false;
            bool showParameters = format?.Parameters ?? false;
            bool showNames      = format?.ParameterNames ?? false;
            bool showTypes      = format?.ParameterTypes ?? false;
            bool showValue      = format?.ParameterValues ?? false;
            bool showLine       = format?.Line ?? false;

            if (showModule && this.Module != null)
            {
                stackName.Append(this.Module.Name);
                stackName.Append("::");
            }

            stackName.Append(this.FunctionName);

            if (showParameters)
            {
                stackName.Append("(");

                if (this.Args.Any() && (showNames || showTypes || showValue))
                {
                    foreach (SampleFunctionArgument arg in this.Args)
                    {
                        if (showTypes)
                        {
                            stackName.Append(arg.Type);
                        }

                        if (showNames)
                        {
                            if (showTypes)
                            {
                                stackName.Append(" ");
                            }
                            stackName.Append(arg.Name);
                        }

                        if (showValue)
                        {
                            if (showNames)
                            {
                                stackName.Append(" = ");
                            }
                            else if (showTypes)
                            {
                                stackName.Append(" ");
                            }
                            stackName.Append(SimpleVariable.ShowAsHex(showInHex, arg.Value));
                        }

                        stackName.Append(", ");
                    }

                    stackName.Length -= 2;
                }

                stackName.Append(")");
            }

            if (showLine)
            {
                stackName.Append(" Line: ");
                stackName.Append(this.Line);
            }

            // If an existing protocol object exists reuse the id
            int id = this.ProtocolObject?.Id ?? this.Adapter.GetNextId();

            return(new StackFrame(
                       id: id,
                       name: stackName.ToString(),
                       line: this.Line,
                       column: this.Column,
                       source: new Source(
                           name: Path.GetFileName(this.FileName),
                           path: this.FileName),
                       moduleId: this.Module?.Id));
        }