Ejemplo n.º 1
0
 internal LineNumberTable(MonoSymbolFile file, LineNumberEntry[] lines)
     : this(file)
 {
     this._line_numbers = lines;
 }
Ejemplo n.º 2
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.WriteLeb128(Index);
     bw.Write(Name);
     bw.WriteLeb128(BlockIndex);
 }
Ejemplo n.º 3
0
 public SourceFileEntry(MonoSymbolFile file, string sourceFile, byte [] guid, byte [] checksum)
     : this(file, sourceFile, sourceFile, guid, checksum)
 {
 }
Ejemplo n.º 4
0
 internal LocalVariableEntry(MonoSymbolFile file, MyBinaryReader reader)
 {
     Index      = reader.ReadLeb128();
     Name       = reader.ReadString();
     BlockIndex = reader.ReadLeb128();
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        internal MethodEntry(MonoSymbolFile file, CompileUnitEntry comp_unit,
                             int token, ScopeVariable[] scope_vars,
                             LocalVariableEntry[] locals, LineNumberEntry[] lines,
                             CodeBlockEntry[] code_blocks, string real_name,
                             Flags flags, int namespace_id)
        {
            this.SymbolFile  = file;
            this.real_name   = real_name;
            this.locals      = locals;
            this.code_blocks = code_blocks;
            this.scope_vars  = scope_vars;
            this.flags       = flags;

            index = -1;

            Token            = token;
            CompileUnitIndex = comp_unit.Index;
            CompileUnit      = comp_unit;
            NamespaceID      = namespace_id;

            CheckLineNumberTable(lines);
            lnt = new LineNumberTable(file, lines);
            file.NumLineNumbers += lines.Length;

            int num_locals = locals != null ? locals.Length : 0;

            if (num_locals <= 32)
            {
                // Most of the time, the O(n^2) factor is actually
                // less than the cost of allocating the hash table,
                // 32 is a rough number obtained through some testing.

                for (int i = 0; i < num_locals; i++)
                {
                    string nm = locals [i].Name;

                    for (int j = i + 1; j < num_locals; j++)
                    {
                        if (locals [j].Name == nm)
                        {
                            flags |= Flags.LocalNamesAmbiguous;
                            goto locals_check_done;
                        }
                    }
                }
locals_check_done:
                ;
            }
            else
            {
                var local_names = new Dictionary <string, LocalVariableEntry> ();
                foreach (LocalVariableEntry local in locals)
                {
                    if (local_names.ContainsKey(local.Name))
                    {
                        flags |= Flags.LocalNamesAmbiguous;
                        break;
                    }
                    local_names.Add(local.Name, local);
                }
            }
        }
Ejemplo n.º 7
0
        void DoRead(MonoSymbolFile file, MyBinaryReader br, bool includesColumns, bool includesEnds)
        {
            var lines = new List <LineNumberEntry> ();

            bool is_hidden = false, modified = false;
            int  stm_line = 1, stm_offset = 0, stm_file = 1;

            while (true)
            {
                byte opcode = br.ReadByte();

                if (opcode == 0)
                {
                    byte size    = br.ReadByte();
                    long end_pos = br.BaseStream.Position + size;
                    opcode = br.ReadByte();

                    if (opcode == DW_LNE_end_sequence)
                    {
                        if (modified)
                        {
                            lines.Add(new LineNumberEntry(
                                          stm_file, stm_line, -1, stm_offset, is_hidden));
                        }
                        break;
                    }
                    else if (opcode == DW_LNE_MONO_negate_is_hidden)
                    {
                        is_hidden = !is_hidden;
                        modified  = true;
                    }
                    else if ((opcode >= DW_LNE_MONO__extensions_start) &&
                             (opcode <= DW_LNE_MONO__extensions_end))
                    {
                        ;                         // reserved for future extensions
                    }
                    else
                    {
                        throw new MonoSymbolFileException("Unknown extended opcode {0:x}", opcode);
                    }

                    br.BaseStream.Position = end_pos;
                    continue;
                }
                else if (opcode < OpcodeBase)
                {
                    switch (opcode)
                    {
                    case DW_LNS_copy:
                        lines.Add(new LineNumberEntry(
                                      stm_file, stm_line, -1, stm_offset, is_hidden));
                        modified = false;
                        break;

                    case DW_LNS_advance_pc:
                        stm_offset += br.ReadLeb128();
                        modified    = true;
                        break;

                    case DW_LNS_advance_line:
                        stm_line += br.ReadLeb128();
                        modified  = true;
                        break;

                    case DW_LNS_set_file:
                        stm_file = br.ReadLeb128();
                        modified = true;
                        break;

                    case DW_LNS_const_add_pc:
                        stm_offset += MaxAddressIncrement;
                        modified    = true;
                        break;

                    default:
                        throw new MonoSymbolFileException(
                                  "Unknown standard opcode {0:x} in LNT",
                                  opcode);
                    }
                }
                else
                {
                    opcode -= OpcodeBase;

                    stm_offset += opcode / LineRange;
                    stm_line   += LineBase + (opcode % LineRange);
                    lines.Add(new LineNumberEntry(
                                  stm_file, stm_line, -1, stm_offset, is_hidden));
                    modified = false;
                }
            }

            _line_numbers = lines.ToArray();

            if (includesColumns)
            {
                for (int i = 0; i < _line_numbers.Length; ++i)
                {
                    var ln = _line_numbers[i];
                    if (ln.Row >= 0)
                    {
                        ln.Column = br.ReadLeb128();
                    }
                }
            }
            if (includesEnds)
            {
                for (int i = 0; i < _line_numbers.Length; ++i)
                {
                    var ln = _line_numbers[i];

                    int row = br.ReadLeb128();
                    if (row == 0xffffff)
                    {
                        ln.EndRow    = -1;
                        ln.EndColumn = -1;
                    }
                    else
                    {
                        ln.EndRow    = ln.Row + row;
                        ln.EndColumn = br.ReadLeb128();
                    }
                }
            }
        }
Ejemplo n.º 8
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;
        }