Author: jbevain
Date: 2006-09-24 16:44:05 -0400 (Sun, 24 Sep 2006)
New Revision: 65872

Modified:
   trunk/cecil/pdb/Mono.Cecil.Pdb/PdbFactory.cs
   trunk/cecil/pdb/Mono.Cecil.Pdb/PdbHelper.cs
   trunk/cecil/pdb/Mono.Cecil.Pdb/PdbWriter.cs
Log:
ongoing work

Modified: trunk/cecil/pdb/Mono.Cecil.Pdb/PdbFactory.cs
===================================================================
--- trunk/cecil/pdb/Mono.Cecil.Pdb/PdbFactory.cs        2006-09-24 20:43:42 UTC 
(rev 65871)
+++ trunk/cecil/pdb/Mono.Cecil.Pdb/PdbFactory.cs        2006-09-24 20:44:05 UTC 
(rev 65872)
@@ -32,14 +32,15 @@
 
        public class PdbFactory : ISymbolStoreFactory {
 
-               public ISymbolReader CreateReader (ModuleDefinition module, 
string assemblyFilename)
+               public ISymbolReader CreateReader (ModuleDefinition module, 
string assembly)
                {
-                       return new PdbReader (PdbHelper.CreateReader 
(assemblyFilename));
+                       return new PdbReader (PdbHelper.CreateReader 
(assembly));
                }
 
-               public ISymbolWriter CreateWriter (ModuleDefinition module, 
string assemblyFilename)
+               public ISymbolWriter CreateWriter (ModuleDefinition module, 
string assembly)
                {
-                       return new PdbWriter (PdbHelper.CreateWriter 
(assemblyFilename));
+                       string pdb = string.Concat(assembly.Substring(0, 
assembly.LastIndexOf(".")), ".pdb");
+                       return new PdbWriter (PdbHelper.CreateWriter (assembly, 
pdb), module, pdb);
                }
        }
 }

Modified: trunk/cecil/pdb/Mono.Cecil.Pdb/PdbHelper.cs
===================================================================
--- trunk/cecil/pdb/Mono.Cecil.Pdb/PdbHelper.cs 2006-09-24 20:43:42 UTC (rev 
65871)
+++ trunk/cecil/pdb/Mono.Cecil.Pdb/PdbHelper.cs 2006-09-24 20:44:05 UTC (rev 
65872)
@@ -32,6 +32,7 @@
 
        using System;
        using System.Diagnostics.SymbolStore;
+       using System.IO;
        using System.Runtime.InteropServices;
 
        internal class PdbHelper {
@@ -71,7 +72,7 @@
                        return reader;
                }
 
-               public static ISymbolWriter CreateWriter (string filename)
+               public static ISymbolWriter CreateWriter (string assembly, 
string pdb)
                {
                        SymWriter writer = new SymWriter (false);
 
@@ -79,12 +80,14 @@
                        CoCreateInstance (ref s_dispenserClassID, null, 1, ref 
s_dispenserIID, out objDispenser);
 
                        IMetaDataDispenser dispenser = (IMetaDataDispenser) 
objDispenser;
-                       dispenser.OpenScope (filename, 1, ref s_importerIID, 
out objImporter);
+                       dispenser.OpenScope (assembly, 1, ref s_importerIID, 
out objImporter);
 
                        IntPtr importerPtr = Marshal.GetComInterfaceForObject 
(objImporter, typeof (IMetadataImport));
-                       string pdb = string.Concat (filename.Substring (0, 
filename.LastIndexOf (".")), ".pdb");
 
                        try {
+                               if (File.Exists (pdb))
+                                       File.Delete (pdb);
+
                                writer.Initialize (importerPtr, pdb, false);
                        } finally {
                                if (importerPtr != IntPtr.Zero) {

Modified: trunk/cecil/pdb/Mono.Cecil.Pdb/PdbWriter.cs
===================================================================
--- trunk/cecil/pdb/Mono.Cecil.Pdb/PdbWriter.cs 2006-09-24 20:43:42 UTC (rev 
65871)
+++ trunk/cecil/pdb/Mono.Cecil.Pdb/PdbWriter.cs 2006-09-24 20:44:05 UTC (rev 
65872)
@@ -33,21 +33,26 @@
        using System;
        using System.Collections;
        using System.Diagnostics.SymbolStore;
+       using System.IO;
 
        public class PdbWriter : Cil.ISymbolWriter {
 
                static readonly Guid Zero = new Guid ();
 
+               ModuleDefinition m_module;
                ISymbolWriter m_writer;
                Hashtable m_documents;
+               string m_pdb;
 
-               internal PdbWriter (ISymbolWriter writer)
+               internal PdbWriter (ISymbolWriter writer, ModuleDefinition 
module, string pdb)
                {
                        m_writer = writer;
+                       m_module = module;
                        m_documents = new Hashtable ();
+                       m_pdb = pdb;
                }
 
-               public void Write (Cil.MethodBody body)
+               public void Write (MethodBody body)
                {
                        CreateDocuments (body);
                        m_writer.OpenMethod (new SymbolToken ((int) 
body.Method.MetadataToken.ToUInt ()));
@@ -59,6 +64,8 @@
                {
                        foreach (Scope s in scopes) {
                                m_writer.OpenScope (s.Start.Offset);
+                               m_writer.UsingNamespace 
(body.Method.DeclaringType.Namespace);
+                               m_writer.OpenNamespace 
(body.Method.DeclaringType.Namespace);
 
                                int start = body.Instructions.IndexOf (s.Start);
                                int end = s.End == body.Instructions.Outside ?
@@ -98,7 +105,13 @@
                                // TODO: local variables
 
                                CreateScopes (body, s.Scopes);
-                               m_writer.CloseScope (s.End.Offset);
+                               m_writer.CloseNamespace ();
+
+                               Instruction last = body.Instructions 
[body.Instructions.Count - 1];
+                               if (s.End == body.Instructions.Outside)
+                                       m_writer.CloseScope (last.Offset + 1);
+                               else
+                                       m_writer.CloseScope (s.End.Offset);
                        }
                }
 
@@ -126,6 +139,41 @@
                public void Dispose ()
                {
                        m_writer.Close ();
+                       Patch ();
                }
+
+               void Patch ()
+               {
+                       FileStream fs = new FileStream (m_pdb, FileMode.Open, 
FileAccess.ReadWrite);
+                       uint age = m_module.Image.DebugHeader.Age;
+                       Guid g = m_module.Image.DebugHeader.Signature;
+
+                       BinaryReader reader = new BinaryReader (fs);
+                       reader.BaseStream.Position = 32;
+
+                       uint pageSize = reader.ReadUInt32 ();
+                       reader.BaseStream.Position += 4;
+
+                       uint pageCount = reader.ReadUInt32 ();
+                       reader.BaseStream.Position += pageSize - 44;
+
+                       uint magic = 0x1312e94;
+                       int page = 0;
+                       for (int i = 1; i < pageCount; i++) {
+                               if (magic == reader.ReadUInt32 ()) {
+                                       page = i;
+                                       break;
+                               }
+                               reader.BaseStream.Position += pageSize - 4;
+                       }
+
+                       BinaryWriter writer = new BinaryWriter (fs);
+                       writer.BaseStream.Position = page * pageSize + 8;
+
+                       writer.Write (age);
+                       writer.Write (g.ToByteArray ());
+
+                       fs.Close ();
+               }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to