Inheritance: IDisposable
Beispiel #1
0
 public SourceFileEntry(MonoSymbolFile file, string file_name)
 {
     this.file = file;
     this.file_name = file_name;
     this.Index = file.AddSource(this);
     this.creating = true;
 }
Beispiel #2
0
		protected LineNumberTable(MonoSymbolFile file)
		{
			this.LineBase = file.OffsetTable.LineNumberTable_LineBase;
			this.LineRange = file.OffsetTable.LineNumberTable_LineRange;
			this.OpcodeBase = (byte)file.OffsetTable.LineNumberTable_OpcodeBase;
			this.MaxAddressIncrement = (int)(255 - this.OpcodeBase) / this.LineRange;
		}
		public MonoSymbolWriter (Stream stream)
		{
			this.stream = stream;
			this.methods = new List<SourceMethodBuilder> ();
			this.sources = new List<SourceFileEntry> ();
			this.comp_units = new List<CompileUnitEntry> ();
			this.file = new MonoSymbolFile ();
		}
		public CompileUnitEntry(MonoSymbolFile file, SourceFileEntry source)
		{
			this.file = file;
			this.source = source;
			this.Index = file.AddCompileUnit(this);
			this.creating = true;
			this.namespaces = new List<NamespaceEntry>();
		}
		public MonoSymbolWriter (string filename)
		{
			this.methods = new List<SourceMethodBuilder> ();
			this.sources = new List<SourceFileEntry> ();
			this.comp_units = new List<CompileUnitEntry> ();
			this.file = new MonoSymbolFile ();

			this.filename = filename + ".mdb";
		}
		public MonoSymbolWriter (string filename)
		{
			this.methods = new ArrayList ();
			this.sources = new ArrayList ();
			this.comp_units = new ArrayList ();
			this.current_method_stack = new Stack ();
			this.file = new MonoSymbolFile ();

			this.filename = filename + ".mdb";
		}
Beispiel #7
0
		internal NamespaceEntry(MonoSymbolFile file, MyBinaryReader reader)
		{
			this.Name = reader.ReadString();
			this.Index = reader.ReadLeb128();
			this.Parent = reader.ReadLeb128();
			int count = reader.ReadLeb128();
			this.UsingClauses = new string[count];
			for (int i = 0; i < count; i++)
			{
				this.UsingClauses[i] = reader.ReadString();
			}
		}
Beispiel #8
0
 //internal void WriteData(MyBinaryWriter bw)
 //{
 //    this.DataOffset = (int)bw.BaseStream.Position;
 //    bw.Write(this.file_name);
 //    if (this.guid == null)
 //    {
 //        this.guid = Guid.NewGuid().ToByteArray();
 //        try
 //        {
 //            using (FileStream fs = new FileStream(this.file_name, FileMode.Open, FileAccess.Read))
 //            {
 //                MD5 md5 = MD5.Create();
 //                this.hash = md5.ComputeHash(fs);
 //            }
 //        }
 //        catch
 //        {
 //            this.hash = new byte[16];
 //        }
 //    }
 //    bw.Write(this.guid);
 //    bw.Write(this.hash);
 //    bw.Write(this.auto_generated ? 1 : 0);
 //}
 //internal void Write(BinaryWriter bw)
 //{
 //    bw.Write(this.Index);
 //    bw.Write(this.DataOffset);
 //}
 internal SourceFileEntry(MonoSymbolFile file, MyBinaryReader reader)
 {
     this.file = file;
     this.Index = reader.ReadInt32();
     this.DataOffset = reader.ReadInt32();
     int old_pos = (int)reader.BaseStream.Position;
     reader.BaseStream.Position = (long)this.DataOffset;
     this.file_name = reader.ReadString();
     //??this.guid = reader.ReadBytes(16);
     this.hash = reader.ReadBytes(16);
     this.auto_generated = (reader.ReadByte() == 1);
     reader.BaseStream.Position = (long)old_pos;
 }
Beispiel #9
0
		internal MethodEntry(MonoSymbolFile file, CompileUnitEntry comp_unit, int token, ScopeVariable[] scope_vars, LocalVariableEntry[] locals, LineNumberEntry[] lines, CodeBlockEntry[] code_blocks, string real_name, MethodEntry.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;
			this.index = -1;
			this.Token = token;
			this.CompileUnitIndex = comp_unit.Index;
			this.CompileUnit = comp_unit;
			this.NamespaceID = namespace_id;
			this.CheckLineNumberTable(lines);
			this.lnt = new LineNumberTable(file, lines);
			file.NumLineNumbers += lines.Length;
			int num_locals = (locals != null) ? locals.Length : 0;
			if (num_locals <= 32)
			{
				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 |= MethodEntry.Flags.LocalNamesAmbiguous;
							goto IL_108;
						}
					}
				}
				IL_108:;
			}
			else
			{
				Dictionary<string, LocalVariableEntry> local_names = new Dictionary<string, LocalVariableEntry>();
				for (int k = 0; k < locals.Length; k++)
				{
					LocalVariableEntry local = locals[k];
					if (local_names.ContainsKey(local.Name))
					{
						flags |= MethodEntry.Flags.LocalNamesAmbiguous;
						break;
					}
					local_names.Add(local.Name, local);
				}
			}
		}
Beispiel #10
0
		public void RewriteMdbFile (string inputFile)
		{
			if (!settings.Quiet)
				Console.WriteLine ("Processing {0}", inputFile);
			var input = MonoSymbolFile.ReadSymbolFile (inputFile);

			var output = new MonoSymbolFile ();

			foreach (var s in input.Sources) {
				var newFileName = settings.FileNamesOnly
					? Path.Combine (Path.GetDirectoryName (s.FileName), settings.Replace (Path.GetFileName (s.FileName)))
					: settings.Replace (s.FileName);

				if (settings.Verbose)
					Console.WriteLine ("{0} -> {1}", s.FileName, newFileName);

				s.FileName = newFileName;
				output.AddSource (s);
			}

			foreach (var cu in input.CompileUnits) {
				cu.ReadAll ();
				output.AddCompileUnit (cu);
			}
		
			foreach (var m in input.Methods) {
				m.ReadAll ();
				output.AddMethod (m);
			}


			var mdbName = new FileInfo (inputFile).Name;
			var tmpMdb = Path.GetTempFileName ();
			var finalMdb = inputFile;
			if (settings.OutputDirectory != null)
				finalMdb = Path.Combine (settings.OutputDirectory, mdbName);

			using (var stream = new FileStream (tmpMdb, FileMode.Create)) {
				output.CreateSymbolFile (input.Guid, stream);
			}
			input.Dispose ();

			File.Delete (finalMdb);
			File.Move (tmpMdb, finalMdb);
		}
Beispiel #11
0
		internal MethodEntry(MonoSymbolFile file, MyBinaryReader reader, int index)
		{
			this.SymbolFile = file;
			this.index = index;
			this.Token = reader.ReadInt32();
			this.DataOffset = reader.ReadInt32();
			this.LineNumberTableOffset = reader.ReadInt32();
			long old_pos = reader.BaseStream.Position;
			reader.BaseStream.Position = (long)this.DataOffset;
			this.CompileUnitIndex = reader.ReadLeb128();
			this.LocalVariableTableOffset = reader.ReadLeb128();
			this.NamespaceID = reader.ReadLeb128();
			this.CodeBlockTableOffset = reader.ReadLeb128();
			this.ScopeVariableTableOffset = reader.ReadLeb128();
			this.RealNameOffset = reader.ReadLeb128();
			this.flags = (MethodEntry.Flags)reader.ReadLeb128();
			reader.BaseStream.Position = old_pos;
			this.CompileUnit = file.GetCompileUnit(this.CompileUnitIndex);
		}
Beispiel #12
0
        static void MdbRebase(string mdbFile, string toRemove)
        {
            #if WINDOWS_BUILD
            Console.Error.WriteLine ("Warning: skipping MDB rebasing of {0} (not supported on Windows)", mdbFile);
            #else
            using (var input = MonoSymbolFile.ReadSymbolFile (mdbFile)) {
                var output = new MonoSymbolFile ();

                foreach (var source in input.Sources) {
                    source.FileName = Path.Combine (
                        Path.GetDirectoryName (source.FileName),
                        Path.GetFileName (source.FileName).Replace (toRemove, String.Empty)
                    );

                    output.AddSource (source);
                }

                foreach (var compileUnit in input.CompileUnits) {
                    compileUnit.ReadAll ();
                    output.AddCompileUnit (compileUnit);
                }

                foreach (var method in input.Methods) {
                    method.ReadAll ();
                    output.AddMethod (method);
                }

                var tmpMdb = Path.GetTempFileName ();

                using (var stream = new FileStream (tmpMdb, FileMode.Create))
                    output.CreateSymbolFile (input.Guid, stream);

                File.Delete (mdbFile);
                File.Move (tmpMdb, mdbFile);
            }
            #endif
        }
Beispiel #13
0
		public void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (debug_builder == null)
				return;

			var token = builder.GetToken ();
			int t = token.Token;
#if STATIC
			if (ModuleBuilder.IsPseudoToken (t))
				t = member.Module.Builder.ResolvePseudoToken (t);
#endif

			debug_builder.DefineMethod (file, t);
		}
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (get != null)
				get.WriteDebugSymbol (file);

			if (set != null)
				set.WriteDebugSymbol (file);
		}
Beispiel #15
0
		static void ConvertSymbolFileToXml (MonoSymbolFile symbolFile, string xmlFile)
		{
			using (XmlTextWriter writer = new XmlTextWriter (xmlFile, Encoding.UTF8)) {
				writer.Formatting = Formatting.Indented;

				writer.WriteStartDocument ();

				writer.WriteStartElement ("symbols");

				writer.WriteStartElement ("files");
				foreach (var file in symbolFile.Sources) {
					writer.WriteStartElement ("file");
					writer.WriteAttributeString ("id", file.Index.ToString ());
					writer.WriteAttributeString ("name", Path.GetFileName (file.FileName));
					var checksum = file.Checksum;
					if (checksum != null)
						writer.WriteAttributeString ("checksum", ChecksumToString (checksum));

					writer.WriteEndElement ();
				}
				writer.WriteEndElement ();

				writer.WriteStartElement ("methods");
				foreach (var method in symbolFile.Methods) {
					writer.WriteStartElement ("method");
					writer.WriteAttributeString ("token", IntToHex (method.Token));

					var il_entries = method.GetLineNumberTable ();
					writer.WriteStartElement ("sequencepoints");
					foreach (var entry in il_entries.LineNumbers) {
						writer.WriteStartElement ("entry");
						writer.WriteAttributeString ("il", IntToHex (entry.Offset));
						writer.WriteAttributeString ("row", entry.Row.ToString ());
						writer.WriteAttributeString ("col", entry.Column.ToString ());
						writer.WriteAttributeString ("file_ref", entry.File.ToString ());
						writer.WriteAttributeString ("hidden", BoolToString (entry.IsHidden));
						writer.WriteEndElement ();
					}
					writer.WriteEndElement ();

					writer.WriteStartElement ("locals");
					foreach (var local in method.GetLocals ()) {
						writer.WriteStartElement ("entry");
						writer.WriteAttributeString ("name", local.Name);
						writer.WriteAttributeString ("il_index", local.Index.ToString ());
						writer.WriteAttributeString ("scope_ref", local.BlockIndex.ToString ());
						writer.WriteEndElement ();
					}
					writer.WriteEndElement ();

					writer.WriteStartElement ("scopes");
					foreach (var scope in method.GetCodeBlocks ()) {
						writer.WriteStartElement ("entry");
						writer.WriteAttributeString ("index", scope.Index.ToString ());
						writer.WriteAttributeString ("start", IntToHex (scope.StartOffset));
						writer.WriteAttributeString ("end", IntToHex (scope.EndOffset));
						writer.WriteEndElement ();
					}
					writer.WriteEndElement ();

					writer.WriteEndElement ();
				}
				writer.WriteEndElement ();

				writer.WriteEndElement ();
				writer.WriteEndDocument ();
			}
		}
Beispiel #16
0
		public MdbReader (MonoSymbolFile symFile)
		{
			symbol_file = symFile;
			documents = new Dictionary<string, Document> ();
		}
Beispiel #17
0
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (debug_builder == null)
				return;

			var token = ConstructorBuilder.GetToken ();
			int t = token.Token;
#if STATIC
			if (token.IsPseudoToken)
				t = Module.Builder.ResolvePseudoToken (t);
#endif

			debug_builder.DefineMethod (file, t);
		}
Beispiel #18
0
		public void DefineMethod (MonoSymbolFile file)
		{
			DefineMethod (file, method.Token);
		}
		void DoRead (MonoSymbolFile file, MyBinaryReader br)
		{
			ArrayList lines = new ArrayList ();

			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, stm_offset, is_hidden));
						break;
					} else if (opcode == DW_LNE_MONO_negate_is_hidden) {
						is_hidden = !is_hidden;
						modified = true;
					} else
						throw new MonoSymbolFileException (
							"Unknown extended opcode {0:x} in LNT ({1})",
							opcode, file.FileName);

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

			_line_numbers = new LineNumberEntry [lines.Count];
			lines.CopyTo (_line_numbers, 0);
		}
Beispiel #20
0
 public SourceFileEntry(MonoSymbolFile file, string sourceFile, byte [] guid, byte [] checksum)
     : this(file, sourceFile, sourceFile, guid, checksum)
 {
 }
Beispiel #21
0
 internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
 {
     bw.WriteLeb128(Index);
     bw.Write(Name);
     bw.WriteLeb128(BlockIndex);
 }
Beispiel #22
0
 internal LocalVariableEntry(MonoSymbolFile file, MyBinaryReader reader)
 {
     Index      = reader.ReadLeb128();
     Name       = reader.ReadString();
     BlockIndex = reader.ReadLeb128();
 }
Beispiel #23
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);
        }
Beispiel #24
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);
                }
            }
        }
Beispiel #25
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();
                    }
                }
            }
        }
Beispiel #26
0
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (IsPartialPart)
				return;

			foreach (var m in members) {
				m.WriteDebugSymbol (file);
			}
		}
 public void DefineMethod(MonoSymbolFile file)
 {
     DefineMethod(file, method.Token);
 }
Beispiel #28
0
 internal LineNumberTable(MonoSymbolFile file, LineNumberEntry[] lines)
     : this(file)
 {
     this._line_numbers = lines;
 }
Beispiel #29
0
		public MdbReader (ModuleDefinition module, MonoSymbolFile symFile)
		{
			this.module = module;
			this.symbol_file = symFile;
			this.documents = new Dictionary<string, Document> ();
		}
Beispiel #30
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;
        }
Beispiel #31
0
		public void DefineMethod (MonoSymbolFile file, int token)
		{
			MethodEntry entry = new MethodEntry (
				file, _comp_unit.Entry, token, ScopeVariables,
				Locals, method_lines.ToArray (), Blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);

			file.AddMethod (entry);
		}
 public SourceFileEntry(MonoSymbolFile file, string file_name, byte[] guid, byte[] checksum)
     : this(file, file_name)
 {
     this.guid = guid;
     this.hash = checksum;
 }
Beispiel #33
0
		public virtual void WriteDebugSymbol (MonoSymbolFile file)
		{
		}
Beispiel #34
0
 public static MonoSymbolFile ReadSymbolFile(ModuleDefinition module)
 {
     return(MonoSymbolFile.ReadSymbolFile(module, module.FullyQualifiedName));
 }
        //
        // Creates symbol file index in debug symbol file
        //
        void CreateUnitSymbolInfo(MonoSymbolFile symwriter)
        {
            var si = file.CreateSymbolInfo (symwriter);
            comp_unit = new CompileUnitEntry (symwriter, si);

            if (include_files != null) {
                foreach (SourceFile include in include_files.Values) {
                    si = include.CreateSymbolInfo (symwriter);
                    comp_unit.AddFile (si);
                }
            }
        }
Beispiel #36
0
        public void DefineMethod(MonoSymbolFile file, int token)
        {
            var blocks = Blocks;

            if (blocks.Length > 0)
            {
                //
                // When index is provided by user it can be inserted in
                // any order but mdb format does not store its value. It
                // uses stored order as the index instead.
                //
                var sorted    = new List <CodeBlockEntry> (blocks.Length);
                int max_index = 0;
                for (int i = 0; i < blocks.Length; ++i)
                {
                    max_index = System.Math.Max(max_index, blocks [i].Index);
                }

                for (int i = 0; i < max_index; ++i)
                {
                    var scope_index = i + 1;

                    //
                    // Common fast path
                    //
                    if (i < blocks.Length && blocks [i].Index == scope_index)
                    {
                        sorted.Add(blocks [i]);
                        continue;
                    }

                    bool found = false;
                    for (int ii = 0; ii < blocks.Length; ++ii)
                    {
                        if (blocks [ii].Index == scope_index)
                        {
                            sorted.Add(blocks [ii]);
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        continue;
                    }

                    //
                    // Ideally this should never happen but with current design we can
                    // generate scope index for unreachable code before reachable code
                    //
                    sorted.Add(new CodeBlockEntry(scope_index, -1, CodeBlockEntry.Type.CompilerGenerated, 0));
                }

                blocks = sorted.ToArray();
                //for (int i = 0; i < blocks.Length; ++i) {
                //	if (blocks [i].Index - 1 != i)
                //			throw new ArgumentException ("CodeBlocks cannot be converted to mdb format");
                //}
            }

            var entry = new MethodEntry(
                file, _comp_unit.Entry, token, ScopeVariables,
                Locals, method_lines.ToArray(), blocks, null, MethodEntry.Flags.ColumnsInfoIncluded, ns_id);

            file.AddMethod(entry);
        }
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			add.WriteDebugSymbol (file);
			remove.WriteDebugSymbol (file);
		}
        void DoRead(MonoSymbolFile file, MyBinaryReader br)
        {
            ArrayList lines = new ArrayList();

            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, 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} in LNT ({1})",
                                  opcode, file.FileName);
                    }

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

            _line_numbers = new LineNumberEntry [lines.Count];
            lines.CopyTo(_line_numbers, 0);
        }
Beispiel #39
0
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (MethodData != null && !IsPartialDefinition)
				MethodData.WriteDebugSymbol (file);
		}
        internal void Write(MonoSymbolFile file, MyBinaryWriter bw)
        {
            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 (SuppressDuplicates && (i + 1 < LineNumbers.Length))
                {
                    if (LineNumbers [i + 1].Equals(LineNumbers [i]))
                    {
                        continue;
                    }
                }

                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);

            file.ExtendedLineNumberSize += (int)bw.BaseStream.Position - start;
        }
Beispiel #41
0
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (MethodData != null)
				MethodData.WriteDebugSymbol (file);
		}
		internal void Write (MonoSymbolFile file, MyBinaryWriter bw)
		{
			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 (SuppressDuplicates && (i+1 < LineNumbers.Length)) {
					if (LineNumbers [i+1].Equals (LineNumbers [i]))
						continue;
				}

				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);

			file.ExtendedLineNumberSize += (int) bw.BaseStream.Position - start;
		}
Beispiel #43
0
		public override void WriteDebugSymbol (MonoSymbolFile file)
		{
			if (containers != null) {
				foreach (TypeContainer tc in containers) {
					tc.WriteDebugSymbol (file);
				}
			}
		}
		internal static LineNumberTable Read (MonoSymbolFile file, MyBinaryReader br)
		{
			LineNumberTable lnt = new LineNumberTable (file);
			lnt.DoRead (file, br);
			return lnt;
		}