Example #1
0
        internal SequencePoint(int offset, Document document)
        {
            if (document == null)
                throw new ArgumentNullException ("document");

            this.offset = new InstructionOffset (offset);
            this.document = document;
        }
Example #2
0
        public SequencePoint(Instruction instruction, Document document)
        {
            if (document == null)
                throw new ArgumentNullException ("document");

            this.offset = new InstructionOffset (instruction);
            this.document = document;
        }
Example #3
0
        public static void HideLineFromDebugger(this Instruction i, Document doc)
        {
            if (doc == null)
                return;

            // This tells the debugger to ignore and step through
            // all the following instructions to the next instruction
            // with a valid SequencePoint. That way IL can be hidden from
            // the Debugger. See
            // http://blogs.msdn.com/b/abhinaba/archive/2005/10/10/479016.aspx
            i.SequencePoint = new SequencePoint(doc);
            i.SequencePoint.StartLine = 0xfeefee;
            i.SequencePoint.EndLine = 0xfeefee;
        }
		SourceFile GetSourceFile (Document document)
		{
			string url = document.Url;
			SourceFile file = m_documents [url] as SourceFile;
			if (file != null)
				return file;

			SourceFileEntry entry = m_writer.DefineDocument (url);
			CompileUnitEntry comp_unit = m_writer.DefineCompilationUnit (entry);

			file = new SourceFile (comp_unit, entry);
			m_documents [url] = file;
			return file;
		}
Example #5
0
		SourceFile GetSourceFile (Document document)
		{
			var url = document.Url;

			SourceFile source_file;
			if (source_files.TryGetValue (url, out source_file))
				return source_file;

			var entry = writer.DefineDocument (url);
			var compile_unit = writer.DefineCompilationUnit (entry);

			source_file = new SourceFile (compile_unit, entry);
			source_files.Add (url, source_file);
			return source_file;
		}
Example #6
0
		private Document GetDocument(SourceFileEntry file)
		{
			string file_name = file.FileName;
			Document document;
			Document result;
			if (this.documents.TryGetValue(file_name, out document))
			{
				result = document;
			}
			else
			{
				document = new Document(file_name);
				this.documents.Add(file_name, document);
				result = document;
			}
			return result;
		}
Example #7
0
		public File(Document document)
		{
			this.document_0 = document;
			this.string_3 = document.Url;
			if (document.Language == DocumentLanguage.CSharp)
			{
				this.string_2 = "C#";
			}
			else if (document.Language == DocumentLanguage.Basic)
			{
				this.string_2 = "VB";
			}
			else
			{
				this.string_0 = "Invalid Code Type. Only C# and VB will be parsed";
			}
			List<string> list = new List<string>();
			list.Add("");
			try
			{
				if (!System.IO.File.Exists(this.string_3))
				{
					this.string_0 = "File Doesn't Exist";
				}
				else
				{
					using (StreamReader streamReader = new StreamReader(this.string_3))
					{
						while (!streamReader.EndOfStream)
						{
							list.Add(streamReader.ReadLine());
						}
						this.string_1 = list.ToArray();
					}
				}
			}
			catch (Exception ex)
			{
				this.string_0 = ex.ToString();
			}
		}
Example #8
0
		Document GetDocument (SourceFileEntry file)
		{
			var file_name = file.FileName;

			Document document;
			if (documents.TryGetValue (file_name, out document))
				return document;

			document = new Document (file_name);
			documents.Add (file_name, document);

			return document;
		}
Example #9
0
		SymDocumentWriter GetDocument (Document document)
		{
			if (document == null)
				return null;

			SymDocumentWriter docWriter = m_documents[document.Url] as SymDocumentWriter;
			if (docWriter != null)
				return docWriter;

			docWriter = m_writer.DefineDocument (
				document.Url,
				document.Language,
				document.LanguageVendor,
				document.Type);

			m_documents [document.Url] = docWriter;
			return docWriter;
		}
Example #10
0
        static void Main(string[] args)
        {
            if (args == null || args.Length != 1)
            {
                Console.WriteLine("One argument expected: Input file (DLL or EXE).");
                Console.WriteLine("A .pdb is expected to exist in the same directory.");
                Console.WriteLine("A .il file will be created (and overwritten if it exists).");
                return;
            }

            var assemblyFile = args[0];
            var ilPath = Path.Combine(Path.GetDirectoryName(assemblyFile), Path.GetFileNameWithoutExtension(assemblyFile) + ".il");
            var pdbPath = Path.Combine(Path.GetDirectoryName(assemblyFile), Path.GetFileNameWithoutExtension(assemblyFile) + ".pdb");

            var assembly = AssemblyDefinition.ReadAssembly(assemblyFile);
            assembly.MainModule.ReadSymbols();
            var doc = new Document(ilPath) { Language = DocumentLanguage.Cil };

            using (var ilFile = File.Open(ilPath, FileMode.Create, FileAccess.Write, FileShare.Read))
            using (var il = new StreamWriter(ilFile))
            {
                var curLine = 1;
                Action<string> writeLine = line =>
                {
                    curLine += line.Count(ch => ch == '\n') + 1;
                    il.WriteLine(line);
                };

                foreach (var type in assembly.Modules.SelectMany(m => m.Types))
                {
                    writeLine("Type: " + type.FullName);
                    foreach (var method in type.Methods)
                    {
                        writeLine("    Method: " + method.FullName);
                        if (method.Body != null)
                        {
                            foreach (var local in method.Body.Variables)
                                writeLine("        Local: " + local.VariableType + " " + local.Name);
                            writeLine("");
                            var newInstructions = new Collection<Instruction>();
                            foreach (var instruction in method.Body.Instructions)
                            {
                                if (newInstructions.Count > 0)
                                    newInstructions.Add(Instruction.Create(OpCodes.Nop));
                                newInstructions.Add(instruction);
                                var prevLine = curLine + 1;
                                var instrStr = instruction.ToString();
                                writeLine("        " + instrStr);
                                instruction.SequencePoint = new SequencePoint(doc)
                                {
                                    StartLine = prevLine,
                                    StartColumn = 9,
                                    EndLine = curLine,
                                    EndColumn = (instrStr.Contains('\n') ? instrStr.Length - instrStr.LastIndexOf('\n') : instrStr.Length) + 9
                                };
                            }
                            method.Body.Instructions.Clear();
                            foreach (var instr in newInstructions)
                                method.Body.Instructions.Add(instr);
                            writeLine("");
                        }
                        writeLine("");
                    }
                }
            }

            assembly.Write(assemblyFile, new WriterParameters { WriteSymbols = true });
        }
Example #11
0
        Document GetDocument(PdbSource source)
        {
            string name = source.name;
            Document document;
            if (documents.TryGetValue (name, out document))
                return document;

            document = new Document (name) {
                Language = source.language.ToLanguage (),
                LanguageVendor = source.vendor.ToVendor (),
                Type = source.doctype.ToType (),
            };
            documents.Add (name, document);
            return document;
        }
Example #12
0
        SymDocumentWriter GetDocument(Document document)
        {
            if (document == null)
                return null;

            SymDocumentWriter doc_writer;
            if (documents.TryGetValue (document.Url, out doc_writer))
                return doc_writer;

            doc_writer = writer.DefineDocument (
                document.Url,
                document.Language.ToGuid (),
                document.LanguageVendor.ToGuid (),
                document.Type.ToGuid ());

            documents [document.Url] = doc_writer;
            return doc_writer;
        }
		void ReadLines (PdbLine line, Document document, IDictionary instructions)
		{
			Instruction instruction = (Instruction) instructions [(int) line.offset];
			if (instruction == null)
				return;

			SequencePoint point = new SequencePoint (document);
			point.StartLine = (int) line.lineBegin;
			point.StartColumn = (int) line.colBegin;
			point.EndLine = (int) line.lineEnd;
			point.EndColumn = (int) line.colEnd;

			instruction.SequencePoint = point;
		}
Example #14
0
        static void ReadLine(PdbLine line, Document document, MethodDebugInformation info)
        {
            var sequence_point = new SequencePoint ((int) line.offset, document);
            sequence_point.StartLine = (int) line.lineBegin;
            sequence_point.StartColumn = (int) line.colBegin;
            sequence_point.EndLine = (int) line.lineEnd;
            sequence_point.EndColumn = (int) line.colEnd;

            info.sequence_points.Add (sequence_point);
        }
Example #15
0
		internal File method_4(Document document_0)
		{
			File result;
			if (!this.dictionary_2.ContainsKey(document_0.Url))
			{
				File file = new File(document_0);
				this.dictionary_2.Add(document_0.Url, file);
				result = file;
			}
			else
			{
				result = this.dictionary_2[document_0.Url];
			}
			return result;
		}
Example #16
0
        static void ReadLine(PdbLine line, Document document, InstructionMapper mapper)
        {
            var instruction = mapper ((int) line.offset);
            if (instruction == null)
                return;

            var sequence_point = new SequencePoint (document);
            sequence_point.StartLine = (int) line.lineBegin;
            sequence_point.StartColumn = (int) line.colBegin;
            sequence_point.EndLine = (int) line.lineEnd;
            sequence_point.EndColumn = (int) line.colEnd;

            instruction.SequencePoint = sequence_point;
        }
		Document GetDocument (SourceFileEntry file)
		{
			Document doc = m_documents [file.FileName] as Document;
			if (doc != null)
				return doc;

			doc = new Document (file.FileName);

			m_documents [file.FileName] = doc;
			return doc;
		}
Example #18
0
 static SequencePoint LineToSequencePoint(LineNumberEntry line, MethodEntry entry, Document document)
 {
     return new SequencePoint (document) {
         StartLine = line.Row,
         EndLine = line.EndRow,
         StartColumn = line.Column,
         EndColumn = line.EndColumn,
     };
 }
		Document GetDocument (PdbSource source)
		{
			string name = source.name;
			Document document;
			if (documents.TryGetValue (name, out document))
				return document;

			document = new Document (name);
			document.Language = source.language;
			document.LanguageVendor = source.vendor;
			document.Type = source.doctype;
			documents.Add (name, document);
			return document;
		}