Exemple #1
0
        public void Read(MethodSymbols symbols)
        {
            var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ());
            if (entry == null)
                return;

            ReadLineNumbers (entry, symbols);
            ReadLocalVariables (entry, symbols);
        }
Exemple #2
0
        public ByteBuffer PatchRawMethodBody(MethodDefinition method, CodeWriter writer, out MethodSymbols symbols)
        {
            var buffer = new ByteBuffer ();
            symbols = new MethodSymbols (method.Name);

            this.method = method;
            reader.context = method;

            MoveTo (method.RVA);

            var flags = ReadByte ();

            MetadataToken local_var_token;

            switch (flags & 0x3) {
            case 0x2: // tiny
                buffer.WriteByte (flags);
                local_var_token = MetadataToken.Zero;
                symbols.code_size = flags >> 2;
                PatchRawCode (buffer, symbols.code_size, writer);
                break;
            case 0x3: // fat
                base.position--;

                PatchRawFatMethod (buffer, symbols, writer, out local_var_token);
                break;
            default:
                throw new NotSupportedException ();
            }

            var symbol_reader = reader.module.symbol_reader;
            if (symbol_reader != null && writer.metadata.write_symbols) {
                symbols.method_token = GetOriginalToken (writer.metadata, method);
                symbols.local_var_token = local_var_token;
                symbol_reader.Read (symbols);
            }

            return buffer;
        }
Exemple #3
0
        void PatchRawFatMethod(ByteBuffer buffer, MethodSymbols symbols, CodeWriter writer, out MetadataToken local_var_token)
        {
            var flags = ReadUInt16 ();
            buffer.WriteUInt16 (flags);
            buffer.WriteUInt16 (ReadUInt16 ());
            symbols.code_size = ReadInt32 ();
            buffer.WriteInt32 (symbols.code_size);
            local_var_token = ReadToken ();

            if (local_var_token.RID > 0) {
                var variables = symbols.variables = ReadVariables (local_var_token);
                buffer.WriteUInt32 (variables != null
                    ? writer.GetStandAloneSignature (symbols.variables).ToUInt32 ()
                    : 0);
            } else
                buffer.WriteUInt32 (0);

            PatchRawCode (buffer, symbols.code_size, writer);

            if ((flags & 0x8) != 0)
                PatchRawSection (buffer, writer.metadata);
        }
Exemple #4
0
 public SourceMethodSymbol(MethodSymbols symbols)
 {
     name = symbols.MethodName;
     token = symbols.MethodToken.ToInt32 ();
 }
Exemple #5
0
        public void Write(MethodSymbols symbols)
        {
            var method = new SourceMethodSymbol (symbols);

            var file = GetSourceFile (symbols.Instructions [0].SequencePoint.Document);
            var builder = writer.OpenMethod (file.CompilationUnit, 0, method);
            var count = symbols.Instructions.Count;

            for (int i = 0; i < count; i++) {
                var instruction = symbols.Instructions [i];
                var sequence_point = instruction.SequencePoint;

                builder.MarkSequencePoint (
                    instruction.Offset,
                    GetSourceFile (sequence_point.Document).CompilationUnit.SourceFile,
                    sequence_point.StartLine,
                    sequence_point.StartColumn,
                    sequence_point.EndLine,
                    sequence_point.EndColumn,
                    false);
            }

            if (symbols.HasVariables)
                AddVariables (symbols.Variables);

            writer.CloseMethod ();
        }
Exemple #6
0
        static MetadataToken GetLocalVarToken(ByteBuffer buffer, MethodSymbols symbols)
        {
            if (symbols.variables.IsNullOrEmpty ())
                return MetadataToken.Zero;

            buffer.position = 8;
            return new MetadataToken (buffer.ReadUInt32 ());
        }
Exemple #7
0
        public void Write(MethodSymbols symbols)
        {
            var sym_token = new SymbolToken (symbols.MethodToken.ToInt32 ());

            var start_offset = 0;
            var end_offset = symbols.CodeSize;

            writer.OpenMethod (sym_token);
            writer.OpenScope (start_offset);

            DefineSequencePoints (symbols);
            DefineVariables (symbols, start_offset, end_offset);

            writer.CloseScope (end_offset);
            writer.CloseMethod ();
        }
Exemple #8
0
        void DefineVariables(MethodSymbols symbols, int start_offset, int end_offset)
        {
            if (!symbols.HasVariables)
                return;

            var sym_token = new SymbolToken (symbols.LocalVarToken.ToInt32 ());

            var variables = symbols.Variables;
            for (int i = 0; i < variables.Count; i++) {
                var variable = variables [i];
                CreateLocalVariable (variable, sym_token, start_offset, end_offset);
            }
        }
Exemple #9
0
        void DefineSequencePoints(MethodSymbols symbols)
        {
            var instructions = symbols.instructions;

            for (int i = 0; i < instructions.Count; i++) {
                var instruction = instructions [i];
                var sequence_point = instruction.SequencePoint;

                writer.DefineSequencePoints (
                    GetDocument (sequence_point.Document),
                    new [] { instruction.Offset },
                    new [] { sequence_point.StartLine },
                    new [] { sequence_point.StartColumn },
                    new [] { sequence_point.EndLine },
                    new [] { sequence_point.EndColumn });
            }
        }
Exemple #10
0
        public void Read(MethodSymbols symbols)
        {
            PdbFunction function;
            if (!functions.TryGetValue (symbols.MethodToken.ToUInt32 (), out function))
                return;

            ReadSequencePoints (function, symbols);
            ReadLocals (function.scopes, symbols);
        }
Exemple #11
0
        void ReadSequencePoints(PdbFunction function, MethodSymbols symbols)
        {
            if (function.lines == null)
                return;

            foreach (PdbLines lines in function.lines)
                ReadLines (lines, symbols);
        }
Exemple #12
0
        void ReadLocals(PdbScope scope, MethodSymbols symbols)
        {
            if (scope == null)
                return;

            foreach (var slot in scope.slots) {
                int index = (int) slot.slot;
                if (index < 0 || index >= symbols.Variables.Count)
                    continue;

                var variable = symbols.Variables [index];
                variable.Name = slot.name;
            }

            ReadLocals (scope.scopes, symbols);
        }
Exemple #13
0
 void ReadLocals(PdbScope [] scopes, MethodSymbols symbols)
 {
     foreach (var scope in scopes)
         ReadLocals (scope, symbols);
 }
Exemple #14
0
        void ReadLines(PdbLines lines, MethodSymbols symbols)
        {
            for (int i = 0; i < lines.lines.Length; i++) {
                var line = lines.lines [i];

                symbols.Instructions.Add (new InstructionSymbol ((int) line.offset, new SequencePoint (GetDocument (lines.file)) {
                    StartLine = (int) line.lineBegin,
                    StartColumn = (int) line.colBegin,
                    EndLine = (int) line.lineEnd,
                    EndColumn = (int) line.colEnd,
                }));
            }
        }
Exemple #15
0
        void ReadLineNumbers(MethodEntry entry, MethodSymbols symbols)
        {
            var table = entry.GetLineNumberTable ();
            var lines = table.LineNumbers;

            var instructions = symbols.instructions = new Collection<InstructionSymbol> (lines.Length);

            for (int i = 0; i < lines.Length; i++) {
                var line = lines [i];

                instructions.Add (new InstructionSymbol (
                    line.Offset,
                    LineToSequencePoint (line, entry, GetDocument (entry.CompileUnit.SourceFile))));
            }
        }
Exemple #16
0
        static void ReadLocalVariables(MethodEntry entry, MethodSymbols symbols)
        {
            foreach (var local in entry.GetLocals ()) {
                if (local.Index < 0 || local.Index >= symbols.Variables.Count) // Mono 2.6 emits wrong local infos for iterators
                    continue;

                var variable = symbols.Variables [local.Index];
                variable.Name = local.Name;
            }
        }