Index: ChangeLog =================================================================== --- ChangeLog (revision 100976) +++ ChangeLog (working copy) @@ -1,3 +1,12 @@ +2008-04-19 Sebastien Pouliot + + * Mono.Cecil.Cil/CodeReader.cs: + * Mono.Cecil.Cil/ISymbolReader.cs: + Move reading of debugging symbols where it's possible to + reuse the existing Hashtable (offset, Instruction) in + the debugging libraries. Change interface to allow + passing the Hashtable. + 2008-04-15 Sebastien Pouliot * Mono.Cecil.csproj Index: Mono.Cecil.Cil/CodeReader.cs =================================================================== --- Mono.Cecil.Cil/CodeReader.cs (revision 100976) +++ Mono.Cecil.Cil/CodeReader.cs (working copy) @@ -77,9 +77,6 @@ ReadSection (methBody, br); break; } - - if (m_reflectReader.SymbolReader != null) - m_reflectReader.SymbolReader.Read (methBody); } public static uint GetRid (int token) @@ -239,6 +236,9 @@ break; } } + + if (m_reflectReader.SymbolReader != null) + m_reflectReader.SymbolReader.Read (body, m_instructions); } Instruction GetInstruction (MethodBody body, int offset) Index: Mono.Cecil.Cil/ISymbolReader.cs =================================================================== --- Mono.Cecil.Cil/ISymbolReader.cs (revision 100976) +++ Mono.Cecil.Cil/ISymbolReader.cs (working copy) @@ -26,12 +26,13 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +using System; +using System.Collections; + namespace Mono.Cecil.Cil { - using System; - public interface ISymbolReader : IDisposable { - void Read (MethodBody body); + void Read (MethodBody body, IDictionary instructions); } } Index: Mono.Cecil.Mdb/MdbReader.cs =================================================================== --- Mono.Cecil.Mdb/MdbReader.cs (revision 100976) +++ Mono.Cecil.Mdb/MdbReader.cs (working copy) @@ -47,17 +47,8 @@ m_scopes = new Hashtable (); } - Hashtable GetInstructions (MethodBody body) + Instruction GetInstruction (MethodBody body, IDictionary instructions, int offset) { - Hashtable instructions = new Hashtable (body.Instructions.Count); - foreach (Instruction i in body.Instructions) - instructions.Add (i.Offset, i); - - return instructions; - } - - Instruction GetInstruction (MethodBody body, Hashtable instructions, int offset) - { Instruction instr = (Instruction) instructions [offset]; if (instr != null) return instr; @@ -65,13 +56,12 @@ return body.Instructions.Outside; } - public void Read (MethodBody body) + public void Read (MethodBody body, IDictionary instructions) { MethodEntry entry = m_symFile.GetMethodByToken ((int) body.Method.MetadataToken.ToUInt ()); if (entry == null) return; - Hashtable instructions = GetInstructions(body); ReadScopes (entry, body, instructions); ReadLineNumbers (entry, instructions); ReadLocalVariables (entry, body); @@ -90,7 +80,7 @@ } } - void ReadLineNumbers (MethodEntry entry, Hashtable instructions) + void ReadLineNumbers (MethodEntry entry, IDictionary instructions) { foreach (LineNumberEntry line in entry.LineNumbers) { Instruction instr = instructions [line.Offset] as Instruction; @@ -116,7 +106,7 @@ return doc; } - void ReadScopes (MethodEntry entry, MethodBody body, Hashtable instructions) + void ReadScopes (MethodEntry entry, MethodBody body, IDictionary instructions) { foreach (LexicalBlockEntry scope in entry.LexicalBlocks) { Scope s = new Scope (); Index: ChangeLog =================================================================== --- ChangeLog (revision 100976) +++ ChangeLog (working copy) @@ -1,3 +1,9 @@ +2008-04-18 Sebastien Pouliot + + * Mono.Cecil.Mdb/MdbReader.cs: Update wrt interface change (i.e. + Read now provide a Dictionary to reuse the existing Hashtable + between offsets and instructions). + 2008-04-08 Sebastien Pouliot * Mono.Cecil.Mdb/MdbReader.cs: +2008-04-18 Sebastien Pouliot + + * Mono.Cecil.Pdb/PdbFactory.cs: Use the same parameter names as the + ISymbolStoreFactory uses (this pleases Gendarme) + * Mono.Cecil.Pdb/PdbReader.cs: Update wrt interface change (i.e. + Read now provide a Dictionary to reuse the existing Hashtable + between offsets and instructions). + 2007-11-15 Rodrigo B. de Oliveira * Mono.Cecil.Pdb/default.build: fixed relative paths Index: Mono.Cecil.Pdb/PdbFactory.cs =================================================================== --- Mono.Cecil.Pdb/PdbFactory.cs (revision 100856) +++ Mono.Cecil.Pdb/PdbFactory.cs (working copy) @@ -32,15 +32,15 @@ public class PdbFactory : ISymbolStoreFactory { - public ISymbolReader CreateReader (ModuleDefinition module, string assembly) + public ISymbolReader CreateReader (ModuleDefinition module, string assemblyFileName) { - return new PdbReader (PdbHelper.CreateReader (assembly)); + return new PdbReader (PdbHelper.CreateReader (assemblyFileName)); } - public ISymbolWriter CreateWriter (ModuleDefinition module, string assembly) + public ISymbolWriter CreateWriter (ModuleDefinition module, string assemblyFileName) { - string pdb = string.Concat(assembly.Substring(0, assembly.LastIndexOf(".")), ".pdb"); - return new PdbWriter (PdbHelper.CreateWriter (assembly, pdb), module, pdb); + string pdb = string.Concat (assemblyFileName.Substring (0, assemblyFileName.LastIndexOf (".")), ".pdb"); + return new PdbWriter (PdbHelper.CreateWriter (assemblyFileName, pdb), module, pdb); } } } Index: Mono.Cecil.Pdb/PdbReader.cs =================================================================== --- Mono.Cecil.Pdb/PdbReader.cs (revision 100856) +++ Mono.Cecil.Pdb/PdbReader.cs (working copy) @@ -45,28 +45,18 @@ m_documents = new Hashtable (); } - public void Read (Cil.MethodBody body) + public void Read (Cil.MethodBody body, IDictionary instructions) { try { ISymbolMethod method = m_reader.GetMethod (new SymbolToken ((int) body.Method.MetadataToken.ToUInt ())); - Hashtable instructions = GetInstructions (body); ReadSequencePoints (method, instructions); ReadScopeAndLocals (method.RootScope, null, body, instructions); } catch (COMException) {} } - static Hashtable GetInstructions (Cil.MethodBody body) + static Cil.Instruction GetInstruction (Cil.MethodBody body, IDictionary instructions, int offset) { - Hashtable instructions = new Hashtable (body.Instructions.Count); - foreach (Cil.Instruction i in body.Instructions) - instructions.Add (i.Offset, i); - - return instructions; - } - - static Cil.Instruction GetInstruction (Cil.MethodBody body, Hashtable instructions, int offset) - { Cil.Instruction instr = (Cil.Instruction) instructions [offset]; if (instr != null) return instr; @@ -74,7 +64,7 @@ return body.Instructions.Outside; } - static void ReadScopeAndLocals (ISymbolScope scope, Cil.Scope parent, Cil.MethodBody body, Hashtable instructions) + static void ReadScopeAndLocals (ISymbolScope scope, Cil.Scope parent, Cil.MethodBody body, IDictionary instructions) { Cil.Scope s = new Cil.Scope (); s.Start = GetInstruction (body, instructions, scope.StartOffset); @@ -96,7 +86,9 @@ ReadScopeAndLocals (child, s, body, instructions); } - void ReadSequencePoints(ISymbolMethod method, Hashtable instructions) + // note: sadly it's not possible to cache all the [count] allocations and reuse them. + // a NRE is throw if the size of the arrays does not match SequencePointCount :( + void ReadSequencePoints (ISymbolMethod method, IDictionary instructions) { int count = method.SequencePointCount; int [] offsets = new int [count];