Пример #1
0
        static ScopeDebugInformation [] ReadScopes(MethodEntry entry, MethodDebugInformation info)
        {
            var blocks = entry.GetCodeBlocks();
            var scopes = new ScopeDebugInformation [blocks.Length + 1];

            info.scope = scopes [0] = new ScopeDebugInformation {
                Start = new InstructionOffset(0),
                End   = new InstructionOffset(info.code_size),
            };

            foreach (var block in blocks)
            {
                if (block.BlockType != CodeBlockEntry.Type.Lexical && block.BlockType != CodeBlockEntry.Type.CompilerGenerated)
                {
                    continue;
                }

                var scope = new ScopeDebugInformation();
                scope.Start = new InstructionOffset(block.StartOffset);
                scope.End   = new InstructionOffset(block.EndOffset);

                scopes [block.Index + 1] = scope;

                if (!AddScope(info.scope.Scopes, scope))
                {
                    info.scope.Scopes.Add(scope);
                }
            }

            return(scopes);
        }
Пример #2
0
        static Scope [] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper)
        {
            var blocks = entry.GetCodeBlocks();
            var scopes = new Scope [blocks.Length];

            foreach (var block in blocks)
            {
                if (block.BlockType != CodeBlockEntry.Type.Lexical)
                {
                    continue;
                }

                var scope = new Scope();
                scope.Start = mapper(block.StartOffset);
                scope.End   = mapper(block.EndOffset);

                scopes [block.Index] = scope;

                if (body.Scope == null)
                {
                    body.Scope = scope;
                }

                if (!AddScope(body.Scope, scope))
                {
                    body.Scope = scope;
                }
            }

            return(scopes);
        }
Пример #3
0
 private static Scope[] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper)
 {
     CodeBlockEntry[] blocks = entry.GetCodeBlocks();
     Scope[]          scopes = new Scope[blocks.Length];
     CodeBlockEntry[] array  = blocks;
     for (int i = 0; i < array.Length; i++)
     {
         CodeBlockEntry block = array[i];
         if (block.BlockType == CodeBlockEntry.Type.Lexical)
         {
             Scope scope = new Scope();
             scope.Start         = mapper(block.StartOffset);
             scope.End           = mapper(block.EndOffset);
             scopes[block.Index] = scope;
             if (body.Scope == null)
             {
                 body.Scope = scope;
             }
             if (!MdbReader.AddScope(body.Scope, scope))
             {
                 body.Scope = scope;
             }
         }
     }
     return(scopes);
 }
Пример #4
0
        public void PrintLocals(MethodEntry method)
        {
            CodeBlockEntry[] blocks = method.GetCodeBlocks() ?? new CodeBlockEntry [0];
            foreach (CodeBlockEntry block in blocks)
            {
                Message("  CodeBlock {0}", block);
            }

            LocalVariableEntry[] locals = method.GetLocals() ?? new LocalVariableEntry [0];
            foreach (LocalVariableEntry local in locals)
            {
                Message("  Local {0}", local);
            }
        }
Пример #5
0
        void ReadScopes(MethodEntry entry, MethodBody body, IDictionary instructions)
        {
            CodeBlockEntry[] blocks = entry.GetCodeBlocks();
            foreach (CodeBlockEntry cbe in blocks)
            {
                if (cbe.BlockType != CodeBlockEntry.Type.Lexical)
                {
                    continue;
                }

                Scope s = new Scope();
                s.Start = GetInstruction(body, instructions, cbe.StartOffset);
                s.End   = GetInstruction(body, instructions, cbe.EndOffset);
                m_scopes [entry.Index] = s;

                if (!AddScope(body, s))
                {
                    body.Scopes.Add(s);
                }
            }
        }
Пример #6
0
        protected void CheckMethod(MethodEntry method)
        {
            Cecil.MethodDefinition mdef = (Cecil.MethodDefinition)Assembly.MainModule.LookupToken(
                new Cecil.MetadataToken(Cecil.TokenType.Method, method.Token & 0xffffff));
            if ((mdef == null) || (mdef.Body == null))
            {
                throw new MonoSymbolFileException("Method {0} (token {1:x}) not found in assembly.",
                                                  method.Index, method.Token);
            }

            string name = String.Format("{0} ({1})", method.Index, GetMethodName(mdef));

            Debug("[Method {0} - {1} - {2}]", method.Index, method.CompileUnit.SourceFile.FileName,
                  GetMethodName(mdef));

            LineNumberTable lnt = method.GetLineNumberTable();

            if (lnt == null)
            {
                throw new MonoSymbolFileException("Cannot get LNT from method {0}.", name);
            }

            if (lnt.LineNumbers == null)
            {
                throw new MonoSymbolFileException("Cannot get LNT from method {0}.", name);
            }
            LineNumberEntry start, end;

            if (lnt.GetMethodBounds(out start, out end))
            {
                Debug("  Bounds: {0} {1}", start, end);
            }
            foreach (LineNumberEntry line in lnt.LineNumbers)
            {
                Debug("    Line: {0}", line);
            }

            CodeBlockEntry[] blocks = method.GetCodeBlocks() ?? new CodeBlockEntry [0];
            foreach (CodeBlockEntry block in blocks)
            {
                if ((block.Parent >= 0) && (block.Parent >= blocks.Length))
                {
                    throw new MonoSymbolFileException(
                              "Code block {0} in method {1} has invalid parent index {2} (valid is 0..{3}).",
                              block, name, block.Parent, blocks.Length);
                }
            }

            LocalVariableEntry[] locals = method.GetLocals() ?? new LocalVariableEntry [0];
            foreach (LocalVariableEntry local in locals)
            {
                if ((local.BlockIndex < 0) || ((local.BlockIndex > 0) && (local.BlockIndex > blocks.Length)))
                {
                    throw new MonoSymbolFileException(
                              "Local variable {0} in method {1} has invalid block index {2} (valid is 0..{3}).",
                              local, name, local.BlockIndex, blocks.Length);
                }

                Debug("  Local: {0}", local);
            }

            int num_locals = mdef.Body.Variables.Count;

            ScopeVariable[] scope_vars = method.GetScopeVariables() ?? new ScopeVariable [0];
            foreach (ScopeVariable var in scope_vars)
            {
                Debug("  Scope var: {0}", var);
                if ((mdef.IsStatic) && (var.Index < 0))
                {
                    throw new MonoSymbolFileException(
                              "Method {0} has invalid scope variable {1} (referencing `this' in static method).",
                              name, var);
                }
                if ((var.Index >= 0) && (var.Index >= num_locals))
                {
                    throw new MonoSymbolFileException(
                              "Method {0} has invalid scope variable {1} (index out of bounds: {2} / {3}).",
                              name, var, var.Index, num_locals);
                }
                if ((var.Scope > 0) && (File.GetAnonymousScope(var.Scope) == null))
                {
                    throw new MonoSymbolFileException(
                              "Method {0} has invalid scope variable {1} (can't find scope {2}).",
                              name, var, var.Scope);
                }
            }
        }
Пример #7
0
        static Scope[] ReadScopes(MethodEntry entry, MethodBody body, InstructionMapper mapper)
        {
            var blocks = entry.GetCodeBlocks ();
            var scopes = new Scope [blocks.Length];

            foreach (var block in blocks) {
                if (block.BlockType != CodeBlockEntry.Type.Lexical)
                    continue;

                var scope = new Scope ();
                scope.Start = mapper (block.StartOffset);
                scope.End = mapper (block.EndOffset);

                scopes [block.Index] = scope;

                if (body.Scope == null)
                    body.Scope = scope;

                if (!AddScope (body.Scope, scope))
                    body.Scope = scope;
            }

            return scopes;
        }