Example #1
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.Write(file_name);

            if (guid == null)
            {
                guid = new byte[16];
            }

            if (hash == null)
            {
                try {
                    using (FileStream fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read)) {
                        MD5 md5 = MD5.Create();
                        hash = md5.ComputeHash(fs);
                    }
                } catch {
                    hash = new byte [16];
                }
            }

            bw.Write(guid);
            bw.Write(hash);
            bw.Write((byte)(auto_generated ? 1 : 0));
        }
Example #2
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128((int)BlockType);
     bw.WriteLeb128(Parent);
     bw.WriteLeb128(StartOffset);
     bw.WriteLeb128(EndOffset);
 }
Example #3
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.Write(Name);
     bw.WriteLeb128(Index);
     bw.WriteLeb128(Parent);
     bw.WriteLeb128(UsingClauses.Length);
     foreach (string uc in UsingClauses)
     {
         bw.Write(uc);
     }
 }
Example #4
0
        internal void Write(MyBinaryWriter bw)
        {
            if ((index <= 0) || (DataOffset == 0))
            {
                throw new InvalidOperationException();
            }

            bw.Write(Token);
            bw.Write(DataOffset);
            bw.Write(LineNumberTableOffset);
        }
Example #5
0
        internal void Write(MyBinaryWriter bw)
        {
            bw.WriteLeb128(ID);

            bw.WriteLeb128(captured_vars.Count);
            foreach (CapturedVariable cv in captured_vars)
            {
                cv.Write(bw);
            }

            bw.WriteLeb128(captured_scopes.Count);
            foreach (CapturedScope cs in captured_scopes)
            {
                cs.Write(bw);
            }
        }
Example #6
0
        internal void WriteData(MyBinaryWriter bw)
        {
            DataOffset = (int)bw.BaseStream.Position;
            bw.WriteLeb128(source.Index);

            int count_includes = include_files != null ? include_files.Count : 0;

            bw.WriteLeb128(count_includes);
            if (include_files != null)
            {
                foreach (SourceFileEntry entry in include_files)
                {
                    bw.WriteLeb128(entry.Index);
                }
            }

            bw.WriteLeb128(namespaces.Count);
            foreach (NamespaceEntry ns in namespaces)
            {
                ns.Write(file, bw);
            }
        }
Example #7
0
        internal void Write(MonoSymbolFile file, MyBinaryWriter bw, bool hasColumnsInfo, bool hasEndInfo)
        {
            int start = (int)bw.BaseStream.Position;

            bool last_is_hidden = false;
            int  last_line = 1, last_offset = 0, last_file = 1;

            for (int i = 0; i < LineNumbers.Length; i++)
            {
                int line_inc   = LineNumbers [i].Row - last_line;
                int offset_inc = LineNumbers [i].Offset - last_offset;

                if (LineNumbers [i].File != last_file)
                {
                    bw.Write(DW_LNS_set_file);
                    bw.WriteLeb128(LineNumbers [i].File);
                    last_file = LineNumbers [i].File;
                }

                if (LineNumbers [i].IsHidden != last_is_hidden)
                {
                    bw.Write((byte)0);
                    bw.Write((byte)1);
                    bw.Write(DW_LNE_MONO_negate_is_hidden);
                    last_is_hidden = LineNumbers [i].IsHidden;
                }

                if (offset_inc >= MaxAddressIncrement)
                {
                    if (offset_inc < 2 * MaxAddressIncrement)
                    {
                        bw.Write(DW_LNS_const_add_pc);
                        offset_inc -= MaxAddressIncrement;
                    }
                    else
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                        offset_inc = 0;
                    }
                }

                if ((line_inc < LineBase) || (line_inc >= LineBase + LineRange))
                {
                    bw.Write(DW_LNS_advance_line);
                    bw.WriteLeb128(line_inc);
                    if (offset_inc != 0)
                    {
                        bw.Write(DW_LNS_advance_pc);
                        bw.WriteLeb128(offset_inc);
                    }
                    bw.Write(DW_LNS_copy);
                }
                else
                {
                    byte opcode;
                    opcode = (byte)(line_inc - LineBase + (LineRange * offset_inc) +
                                    OpcodeBase);
                    bw.Write(opcode);
                }

                last_line   = LineNumbers [i].Row;
                last_offset = LineNumbers [i].Offset;
            }

            bw.Write((byte)0);
            bw.Write((byte)1);
            bw.Write(DW_LNE_end_sequence);

            if (hasColumnsInfo)
            {
                for (int i = 0; i < LineNumbers.Length; i++)
                {
                    var ln = LineNumbers [i];
                    if (ln.Row >= 0)
                    {
                        bw.WriteLeb128(ln.Column);
                    }
                }
            }

            if (hasEndInfo)
            {
                for (int i = 0; i < LineNumbers.Length; i++)
                {
                    var ln = LineNumbers [i];
                    if (ln.EndRow == -1 || ln.EndColumn == -1 || ln.Row > ln.EndRow)
                    {
                        bw.WriteLeb128(0xffffff);
                    }
                    else
                    {
                        bw.WriteLeb128(ln.EndRow - ln.Row);
                        bw.WriteLeb128(ln.EndColumn);
                    }
                }
            }

            file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - start;
        }
Example #8
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128(Scope);
     bw.WriteLeb128(Index);
 }
Example #9
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.WriteLeb128(Scope);
     bw.Write(CapturedName);
 }
Example #10
0
 internal void Write(MyBinaryWriter bw)
 {
     bw.Write(Name);
     bw.Write(CapturedName);
     bw.Write((byte)Kind);
 }
Example #11
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.WriteLeb128(Index);
     bw.Write(Name);
     bw.WriteLeb128(BlockIndex);
 }
Example #12
0
        internal void WriteData(MonoSymbolFile file, MyBinaryWriter bw)
        {
            if (index <= 0)
            {
                throw new InvalidOperationException();
            }

            LocalVariableTableOffset = (int)bw.BaseStream.Position;
            int num_locals = locals != null ? locals.Length : 0;

            bw.WriteLeb128(num_locals);
            for (int i = 0; i < num_locals; i++)
            {
                locals [i].Write(file, bw);
            }
            file.LocalCount += num_locals;

            CodeBlockTableOffset = (int)bw.BaseStream.Position;
            int num_code_blocks = code_blocks != null ? code_blocks.Length : 0;

            bw.WriteLeb128(num_code_blocks);
            for (int i = 0; i < num_code_blocks; i++)
            {
                code_blocks [i].Write(bw);
            }

            ScopeVariableTableOffset = (int)bw.BaseStream.Position;
            int num_scope_vars = scope_vars != null ? scope_vars.Length : 0;

            bw.WriteLeb128(num_scope_vars);
            for (int i = 0; i < num_scope_vars; i++)
            {
                scope_vars [i].Write(bw);
            }

            if (real_name != null)
            {
                RealNameOffset = (int)bw.BaseStream.Position;
                bw.Write(real_name);
            }

            foreach (var lne in lnt.LineNumbers)
            {
                if (lne.EndRow != -1 || lne.EndColumn != -1)
                {
                    flags |= Flags.EndInfoIncluded;
                }
            }

            LineNumberTableOffset = (int)bw.BaseStream.Position;
            lnt.Write(file, bw, (flags & Flags.ColumnsInfoIncluded) != 0, (flags & Flags.EndInfoIncluded) != 0);

            DataOffset = (int)bw.BaseStream.Position;

            bw.WriteLeb128(CompileUnitIndex);
            bw.WriteLeb128(LocalVariableTableOffset);
            bw.WriteLeb128(NamespaceID);

            bw.WriteLeb128(CodeBlockTableOffset);
            bw.WriteLeb128(ScopeVariableTableOffset);

            bw.WriteLeb128(RealNameOffset);
            bw.WriteLeb128((int)flags);
        }
Example #13
0
        void Write(MyBinaryWriter bw, Guid guid)
        {
            // Magic number and file version.
            bw.Write(OffsetTable.Magic);
            bw.Write(MajorVersion);
            bw.Write(MinorVersion);

            bw.Write(guid.ToByteArray());

            //
            // Offsets of file sections; we must write this after we're done
            // writing the whole file, so we just reserve the space for it here.
            //
            long offset_table_offset = bw.BaseStream.Position;

            ot.Write(bw, MajorVersion, MinorVersion);

            //
            // Sort the methods according to their tokens and update their index.
            //
            methods.Sort();
            for (int i = 0; i < methods.Count; i++)
            {
                methods [i].Index = i + 1;
            }

            //
            // Write data sections.
            //
            ot.DataSectionOffset = (int)bw.BaseStream.Position;
            foreach (SourceFileEntry source in sources)
            {
                source.WriteData(bw);
            }
            foreach (CompileUnitEntry comp_unit in comp_units)
            {
                comp_unit.WriteData(bw);
            }
            foreach (MethodEntry method in methods)
            {
                method.WriteData(this, bw);
            }
            ot.DataSectionSize = (int)bw.BaseStream.Position - ot.DataSectionOffset;

            //
            // Write the method index table.
            //
            ot.MethodTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < methods.Count; i++)
            {
                MethodEntry entry = methods [i];
                entry.Write(bw);
            }
            ot.MethodTableSize = (int)bw.BaseStream.Position - ot.MethodTableOffset;

            //
            // Write source table.
            //
            ot.SourceTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < sources.Count; i++)
            {
                SourceFileEntry source = sources [i];
                source.Write(bw);
            }
            ot.SourceTableSize = (int)bw.BaseStream.Position - ot.SourceTableOffset;

            //
            // Write compilation unit table.
            //
            ot.CompileUnitTableOffset = (int)bw.BaseStream.Position;
            for (int i = 0; i < comp_units.Count; i++)
            {
                CompileUnitEntry unit = comp_units [i];
                unit.Write(bw);
            }
            ot.CompileUnitTableSize = (int)bw.BaseStream.Position - ot.CompileUnitTableOffset;

            //
            // Write anonymous scope table.
            //
            ot.AnonymousScopeCount       = anonymous_scopes != null ? anonymous_scopes.Count : 0;
            ot.AnonymousScopeTableOffset = (int)bw.BaseStream.Position;
            if (anonymous_scopes != null)
            {
                foreach (AnonymousScopeEntry scope in anonymous_scopes.Values)
                {
                    scope.Write(bw);
                }
            }
            ot.AnonymousScopeTableSize = (int)bw.BaseStream.Position - ot.AnonymousScopeTableOffset;

            //
            // Fixup offset table.
            //
            ot.TypeCount        = last_type_index;
            ot.MethodCount      = methods.Count;
            ot.SourceCount      = sources.Count;
            ot.CompileUnitCount = comp_units.Count;

            //
            // Write offset table.
            //
            ot.TotalFileSize = (int)bw.BaseStream.Position;
            bw.Seek((int)offset_table_offset, SeekOrigin.Begin);
            ot.Write(bw, MajorVersion, MinorVersion);
            bw.Seek(0, SeekOrigin.End);

#if false
            Console.WriteLine("TOTAL: {0} line numbes, {1} bytes, extended {2} bytes, " +
                              "{3} methods.", NumLineNumbers, LineNumberSize,
                              ExtendedLineNumberSize, methods.Count);
#endif
        }