Пример #1
0
 public void WriteIteratorScopes(StateMachineScopeDebugInformation state_machine, MethodDebugInformation debug_info)
 {
     Write(CustomMetadataType.IteratorScopes, () => {
         var scopes = state_machine.Scopes;
         writer.WriteInt32(scopes.Count);
         foreach (var scope in scopes)
         {
             var start = scope.Start.Offset;
             var end   = scope.End.IsEndOfMethod ? debug_info.code_size : scope.End.Offset;
             writer.WriteInt32(start);
             writer.WriteInt32(end - 1);
         }
     });
 }
Пример #2
0
        public MethodDebugInformation Read(MethodDefinition method)
        {
            var method_token = method.MetadataToken;

            PdbFunction function;

            if (!functions.TryGetValue(method_token.ToUInt32(), out function))
            {
                return(null);
            }

            var symbol = new MethodDebugInformation(method);

            ReadSequencePoints(function, symbol);

            symbol.scope = !function.scopes.IsNullOrEmpty()
                                ? ReadScopeAndLocals(function.scopes [0], symbol)
                                : new ScopeDebugInformation {
                Start = new InstructionOffset(0), End = new InstructionOffset((int)function.length)
            };

            if (function.tokenOfMethodWhoseUsingInfoAppliesToThisMethod != method.MetadataToken.ToUInt32() && function.tokenOfMethodWhoseUsingInfoAppliesToThisMethod != 0)
            {
                symbol.scope.import = GetImport(function.tokenOfMethodWhoseUsingInfoAppliesToThisMethod, method.Module);
            }

            if (function.scopes.Length > 1)
            {
                for (int i = 1; i < function.scopes.Length; i++)
                {
                    var s = ReadScopeAndLocals(function.scopes [i], symbol);
                    if (!AddScope(symbol.scope.Scopes, s))
                    {
                        symbol.scope.Scopes.Add(s);
                    }
                }
            }

            if (function.iteratorScopes != null)
            {
                var state_machine = new StateMachineScopeDebugInformation();

                foreach (var iterator_scope in function.iteratorScopes)
                {
                    state_machine.Scopes.Add(new StateMachineScope((int)iterator_scope.Offset, (int)(iterator_scope.Offset + iterator_scope.Length + 1)));
                }

                symbol.CustomDebugInformations.Add(state_machine);
            }

            if (function.synchronizationInformation != null)
            {
                var async_debug_info = new AsyncMethodBodyDebugInformation((int)function.synchronizationInformation.GeneratedCatchHandlerOffset);

                foreach (var synchronization_point in function.synchronizationInformation.synchronizationPoints)
                {
                    async_debug_info.Yields.Add(new InstructionOffset((int)synchronization_point.SynchronizeOffset));
                    async_debug_info.Resumes.Add(new InstructionOffset((int)synchronization_point.ContinuationOffset));
                    async_debug_info.ResumeMethods.Add(method);
                }

                symbol.CustomDebugInformations.Add(async_debug_info);

                symbol.StateMachineKickOffMethod = (MethodDefinition)method.Module.LookupToken((int)function.synchronizationInformation.kickoffMethodToken);
            }

            return(symbol);
        }