Example #1
0
        static int GetDecompilerGeneratedVariablesCount(DbgMethodDebugScope rootScope, uint offset)
        {
            var scope = rootScope;
            int count = 0;

            for (;;)
            {
                foreach (var local in scope.Locals)
                {
                    if (local.IsDecompilerGenerated)
                    {
                        count++;
                    }
                }

                bool found = false;
                foreach (var childScope in scope.Scopes)
                {
                    if (childScope.Span.Start <= offset && offset < childScope.Span.End)
                    {
                        found = true;
                        scope = childScope;
                        break;
                    }
                }
                if (!found)
                {
                    return(count);
                }
            }
        }
 public Key(int debugInfoVersion, int methodToken, int methodVersion, DbgModuleReference[] moduleReferences, DbgMethodDebugScope scope, DbgValueNodeEvaluationOptions valueNodeEvaluationOptions, DbgLocalsValueNodeEvaluationOptions localsValueNodeEvaluationOptions)
 {
     this.debugInfoVersion                 = debugInfoVersion;
     this.methodToken                      = methodToken;
     this.methodVersion                    = methodVersion;
     this.moduleReferences                 = moduleReferences;
     this.scope                            = scope;
     this.valueNodeEvaluationOptions       = valueNodeEvaluationOptions;
     this.localsValueNodeEvaluationOptions = localsValueNodeEvaluationOptions;
 }
        public static void GetAllScopes(DbgMethodDebugScope rootScope, List <DbgMethodDebugScope> stack, List <DbgMethodDebugScope> allScopes, List <DbgMethodDebugScope> containingScopes, uint ilOffset)
        {
            stack.Add(rootScope);
            while (stack.Count > 0)
            {
                var scope = stack[stack.Count - 1];
                stack.RemoveAt(stack.Count - 1);
                allScopes.Add(scope);
                if (scope.Span.Start <= ilOffset && ilOffset < scope.Span.End)
                {
                    containingScopes.Add(scope);
                }

                foreach (var nested in scope.Scopes)
                {
                    stack.Add(nested);
                }
            }
        }
        public static DbgMethodDebugScope GetScope(DbgMethodDebugScope rootScope, uint offset)
        {
            var scope = rootScope;

            for (;;)
            {
                bool found = false;
                foreach (var childScope in scope.Scopes)
                {
                    if (childScope.Span.Start <= offset && offset < childScope.Span.End)
                    {
                        found = true;
                        scope = childScope;
                        break;
                    }
                }
                if (!found)
                {
                    return(scope);
                }
            }
        }
        protected override ImmutableArray <ImmutableArray <DSEEImportRecord> > GetImports(TypeDef declaringType, DbgMethodDebugScope scope, out string defaultNamespaceName)
        {
            var fileLevelBuilder    = ImmutableArray.CreateBuilder <DSEEImportRecord>(scope.Imports.Length);
            var projectLevelBuilder = ImmutableArray.CreateBuilder <DSEEImportRecord>(scope.Imports.Length);

            defaultNamespaceName = null;
            foreach (var info in scope.Imports)
            {
                var builder = info.VBImportScopeKind == DbgVBImportScopeKind.Project ? projectLevelBuilder : fileLevelBuilder;
                AddDSEEImportRecord(builder, info, ref defaultNamespaceName);
            }
            if (defaultNamespaceName == null)
            {
                defaultNamespaceName = string.Empty;
            }
            return(ImmutableArray.Create(fileLevelBuilder.ToImmutable(), projectLevelBuilder.ToImmutable()));
        }
        protected override ImmutableArray <ImmutableArray <DSEEImportRecord> > GetImports(TypeDef declaringType, DbgMethodDebugScope scope, out string?defaultNamespaceName)
        {
            var importRecordGroupBuilder = ImmutableArray.CreateBuilder <ImmutableArray <DSEEImportRecord> >();

            var type = declaringType;

            while (type.DeclaringType is not null)
            {
                type = type.DeclaringType;
            }
            var ns    = UTF8String.ToSystemStringOrEmpty(type.Namespace);
            int index = 0;

            for (;;)
            {
                index = ns.IndexOf('.', index);
                importRecordGroupBuilder.Add(ImmutableArray <DSEEImportRecord> .Empty);
                if (index < 0)
                {
                    break;
                }
                index++;
            }

            var globalLevelBuilder = ImmutableArray.CreateBuilder <DSEEImportRecord>(scope.Imports.Length);

            defaultNamespaceName = null;
            foreach (var info in scope.Imports)
            {
                AddDSEEImportRecord(globalLevelBuilder, info, ref defaultNamespaceName);
            }
            // C# doesn't use a default namespace, only VB does, so always initialize it to the empty string
            defaultNamespaceName = string.Empty;
            importRecordGroupBuilder.Add(globalLevelBuilder.ToImmutable());
            return(importRecordGroupBuilder.ToImmutable());
        }