diff options
author | Marek Safar <marek.safar@gmail.com> | 2012-04-27 22:43:16 +0400 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2012-04-27 22:43:16 +0400 |
commit | 12a948c37fd3687a51ee299598d8be642cd94672 (patch) | |
tree | d29ef516483fc7a8ed43a315bdc03acb0144efee /mcs/class/Mono.Cecil.Mdb | |
parent | 97cc622799f6e26deda0da0babc3d854cc3d562c (diff) |
Switch Cecil to common git://github.com/mono/cecil.git
Diffstat (limited to 'mcs/class/Mono.Cecil.Mdb')
-rw-r--r-- | mcs/class/Mono.Cecil.Mdb/Makefile | 4 | ||||
-rw-r--r-- | mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources | 14 | ||||
-rw-r--r-- | mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs | 41 | ||||
-rw-r--r-- | mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs | 213 | ||||
-rw-r--r-- | mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs | 251 |
5 files changed, 8 insertions, 515 deletions
diff --git a/mcs/class/Mono.Cecil.Mdb/Makefile b/mcs/class/Mono.Cecil.Mdb/Makefile index ecb9bb41d83..58d527dfed4 100644 --- a/mcs/class/Mono.Cecil.Mdb/Makefile +++ b/mcs/class/Mono.Cecil.Mdb/Makefile @@ -5,9 +5,7 @@ LIBRARY = Mono.Cecil.Mdb.dll LIBRARY_SNK = ../mono.snk LIBRARY_PACKAGE = none -CECIL = $(topdir)/class/lib/$(PROFILE)/Mono.Cecil.dll - -LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:$(CECIL) /d:CECIL -keyfile:$(LIBRARY_SNK) +LIB_MCS_FLAGS = /r:$(corlib) /r:System.dll /r:Mono.Cecil.dll /d:CECIL -keyfile:$(LIBRARY_SNK) NO_TEST = yes diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources index 0cd3f087cca..eedadff94e7 100644 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources +++ b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb.dll.sources @@ -1,7 +1,7 @@ -./Mono.Cecil.Mdb/AssemblyInfo.cs -./Mono.Cecil.Mdb/MdbReader.cs -./Mono.Cecil.Mdb/MdbWriter.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs -../Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs -../Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/AssemblyInfo.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbReader.cs +../../../external/cecil/symbols/mdb/Mono.Cecil.Mdb/MdbWriter.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/MonoSymbolWriter.cs +../../../external/cecil/symbols/mdb/Mono.CompilerServices.SymbolWriter/SymbolWriterImpl.cs diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs deleted file mode 100644 index 8186b506bc6..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/AssemblyInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -// -// AssemblyInfo.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle ("Mono.Cecil.Mdb")] -[assembly: AssemblyProduct ("Mono.Cecil")] -[assembly: AssemblyCopyright ("Copyright © 2008 - 2011 Jb Evain")] - -[assembly: CLSCompliant (false)] -[assembly: ComVisible (false)] - -[assembly: AssemblyVersion ("0.9.5.0")] -[assembly: AssemblyFileVersion ("0.9.5.0")] diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs deleted file mode 100644 index 7f5d640c8ee..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbReader.cs +++ /dev/null @@ -1,213 +0,0 @@ -// -// MdbReader.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Cecil.Cil; -using Mono.Collections.Generic; -using Mono.CompilerServices.SymbolWriter; - -namespace Mono.Cecil.Mdb { - - public class MdbReaderProvider : ISymbolReaderProvider { - - public ISymbolReader GetSymbolReader (ModuleDefinition module, string fileName) - { - return new MdbReader (MonoSymbolFile.ReadSymbolFile (fileName + ".mdb", module.Mvid)); - } - - public ISymbolReader GetSymbolReader (ModuleDefinition module, Stream symbolStream) - { - throw new NotImplementedException (); - } - } - - public class MdbReader : ISymbolReader { - - readonly MonoSymbolFile symbol_file; - readonly Dictionary<string, Document> documents; - - public MdbReader (MonoSymbolFile symFile) - { - symbol_file = symFile; - documents = new Dictionary<string, Document> (); - } - - public bool ProcessDebugHeader (ImageDebugDirectory directory, byte [] header) - { - return true; - } - - public void Read (MethodBody body, InstructionMapper mapper) - { - var method_token = body.Method.MetadataToken; - var entry = symbol_file.GetMethodByToken (method_token.ToInt32 ()); - if (entry == null) - return; - - var scopes = ReadScopes (entry, body, mapper); - ReadLineNumbers (entry, mapper); - ReadLocalVariables (entry, body, scopes); - } - - static void ReadLocalVariables (MethodEntry entry, MethodBody body, Scope [] scopes) - { - var locals = entry.GetLocals (); - foreach (var local in locals) { - var variable = body.Variables [local.Index]; - variable.Name = local.Name; - - var index = local.BlockIndex; - if (index < 0 || index >= scopes.Length) - continue; - - var scope = scopes [index]; - if (scope == null) - continue; - - scope.Variables.Add (variable); - } - } - - void ReadLineNumbers (MethodEntry entry, InstructionMapper mapper) - { - Document document = null; - var table = entry.GetLineNumberTable (); - - foreach (var line in table.LineNumbers) { - var instruction = mapper (line.Offset); - if (instruction == null) - continue; - - if (document == null) - document = GetDocument (entry.CompileUnit.SourceFile); - - instruction.SequencePoint = new SequencePoint (document) { - StartLine = line.Row, - EndLine = line.Row, - }; - } - } - - 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; - } - - static Scope [] ReadScopes (MethodEntry entry, MethodBody body, InstructionMapper mapper) - { - var blocks = entry.GetCodeBlocks (); - var scopes = new Scope [blocks.Length]; - - foreach (var block in blocks) { - if (block.BlockType != CodeBlockEntry.Type.Lexical) - continue; - - var scope = new Scope (); - scope.Start = mapper (block.StartOffset); - scope.End = mapper (block.EndOffset); - - scopes [block.Index] = scope; - - if (body.Scope == null) - body.Scope = scope; - - if (!AddScope (body.Scope, scope)) - body.Scope = scope; - } - - return scopes; - } - - static bool AddScope (Scope provider, Scope scope) - { - foreach (var sub_scope in provider.Scopes) { - if (AddScope (sub_scope, scope)) - return true; - - if (scope.Start.Offset >= sub_scope.Start.Offset && scope.End.Offset <= sub_scope.End.Offset) { - sub_scope.Scopes.Add (scope); - return true; - } - } - - return false; - } - - public void Read (MethodSymbols symbols) - { - var entry = symbol_file.GetMethodByToken (symbols.MethodToken.ToInt32 ()); - if (entry == null) - return; - - ReadLineNumbers (entry, symbols); - ReadLocalVariables (entry, symbols); - } - - 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, new SequencePoint (GetDocument (entry.CompileUnit.SourceFile)) { - StartLine = line.Row, - EndLine = line.Row, - })); - } - } - - static void ReadLocalVariables (MethodEntry entry, MethodSymbols symbols) - { - foreach (var local in entry.GetLocals ()) { - var variable = symbols.Variables [local.Index]; - variable.Name = local.Name; - } - } - - public void Dispose () - { - symbol_file.Dispose (); - } - } -} diff --git a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs b/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs deleted file mode 100644 index 6f4aa20e390..00000000000 --- a/mcs/class/Mono.Cecil.Mdb/Mono.Cecil.Mdb/MdbWriter.cs +++ /dev/null @@ -1,251 +0,0 @@ -// -// MdbWriter.cs -// -// Author: -// Jb Evain (jbevain@gmail.com) -// -// Copyright (c) 2008 - 2011 Jb Evain -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// - -using System; -using System.Collections.Generic; -using System.IO; - -using Mono.Cecil.Cil; -using Mono.Collections.Generic; -using Mono.CompilerServices.SymbolWriter; - -namespace Mono.Cecil.Mdb { - -#if !READ_ONLY - public class MdbWriterProvider : ISymbolWriterProvider { - - public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName) - { - return new MdbWriter (module.Mvid, fileName); - } - - public ISymbolWriter GetSymbolWriter (ModuleDefinition module, Stream symbolStream) - { - throw new NotImplementedException (); - } - } - - public class MdbWriter : ISymbolWriter { - - readonly Guid mvid; - readonly MonoSymbolWriter writer; - readonly Dictionary<string, SourceFile> source_files; - - public MdbWriter (Guid mvid, string assembly) - { - this.mvid = mvid; - this.writer = new MonoSymbolWriter (assembly); - this.source_files = new Dictionary<string, SourceFile> (); - } - - static Collection<Instruction> GetInstructions (MethodBody body) - { - var instructions = new Collection<Instruction> (); - foreach (var instruction in body.Instructions) - if (instruction.SequencePoint != null) - instructions.Add (instruction); - - return instructions; - } - - 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; - } - - void Populate (Collection<Instruction> instructions, int [] offsets, - int [] startRows, int [] startCols, out SourceFile file) - { - SourceFile source_file = null; - - for (int i = 0; i < instructions.Count; i++) { - var instruction = instructions [i]; - offsets [i] = instruction.Offset; - - var sequence_point = instruction.SequencePoint; - if (source_file == null) - source_file = GetSourceFile (sequence_point.Document); - - startRows [i] = sequence_point.StartLine; - startCols [i] = sequence_point.StartColumn; - } - - file = source_file; - } - - public void Write (MethodBody body) - { - var method = new SourceMethod (body.Method); - - var instructions = GetInstructions (body); - int count = instructions.Count; - if (count == 0) - return; - - var offsets = new int [count]; - var start_rows = new int [count]; - var start_cols = new int [count]; - - SourceFile file; - Populate (instructions, offsets, start_rows, start_cols, out file); - - var builder = writer.OpenMethod (file.CompilationUnit, 0, method); - - for (int i = 0; i < count; i++) - builder.MarkSequencePoint ( - offsets [i], - file.CompilationUnit.SourceFile, - start_rows [i], - start_cols [i], - false); - - if (body.HasVariables) - AddVariables (body.Variables); - - writer.CloseMethod (); - } - - readonly static byte [] empty_header = new byte [0]; - - public bool GetDebugHeader (out ImageDebugDirectory directory, out byte [] header) - { - directory = new ImageDebugDirectory (); - header = empty_header; - return false; - } - - void AddVariables (IList<VariableDefinition> variables) - { - for (int i = 0; i < variables.Count; i++) { - var variable = variables [i]; - writer.DefineLocalVariable (i, variable.Name); - } - } - - 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.EndLine, - false); - } - - if (symbols.HasVariables) - AddVariables (symbols.Variables); - - writer.CloseMethod (); - } - - public void Dispose () - { - writer.WriteSymbolFile (mvid); - } - - class SourceFile : ISourceFile { - - readonly CompileUnitEntry compilation_unit; - readonly SourceFileEntry entry; - - public SourceFileEntry Entry { - get { return entry; } - } - - public CompileUnitEntry CompilationUnit { - get { return compilation_unit; } - } - - public SourceFile (CompileUnitEntry comp_unit, SourceFileEntry entry) - { - this.compilation_unit = comp_unit; - this.entry = entry; - } - } - - class SourceMethodSymbol : IMethodDef { - - readonly string name; - readonly int token; - - public string Name { - get { return name;} - } - - public int Token { - get { return token; } - } - - public SourceMethodSymbol (MethodSymbols symbols) - { - name = symbols.MethodName; - token = symbols.MethodToken.ToInt32 (); - } - } - - class SourceMethod : IMethodDef { - - readonly MethodDefinition method; - - public string Name { - get { return method.Name; } - } - - public int Token { - get { return method.MetadataToken.ToInt32 (); } - } - - public SourceMethod (MethodDefinition method) - { - this.method = method; - } - } - } -#endif -} |