2004-10-20 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / Mono.CSharp.Debugger / MonoSymbolFile.cs
index 0dfd709674b6e2a9da1fac548c30a07677466ef0..2a130bc92fb99a114134ee8e3f7e0ca066543c1d 100644 (file)
@@ -32,6 +32,7 @@ using System;
 using System.Reflection;
 using System.Collections;
 using System.Text;
+using System.Threading;
 using System.IO;
        
 namespace Mono.CompilerServices.SymbolWriter
@@ -221,12 +222,14 @@ namespace Mono.CompilerServices.SymbolWriter
                static GetMethodFunc get_method;
                static GetLocalTypeFromSignatureFunc local_type_from_sig;
                static GetGuidFunc get_guid;
+               static CheckRuntimeVersionFunc check_runtime_version;
 
                delegate Type GetTypeFunc (Assembly assembly, int token);
                delegate int GetMethodTokenFunc (Assembly assembly, MethodBase method);
                delegate MethodBase GetMethodFunc (Assembly assembly, int token);
                delegate Type GetLocalTypeFromSignatureFunc (Assembly assembly, byte[] sig);
                delegate Guid GetGuidFunc (Module module);
+               delegate string CheckRuntimeVersionFunc (string filename);
 
                static Delegate create_delegate (Type type, Type delegate_type, string name)
                {
@@ -258,6 +261,10 @@ namespace Mono.CompilerServices.SymbolWriter
 
                        get_guid = (GetGuidFunc) create_delegate (
                                typeof (Module), typeof (GetGuidFunc), "Mono_GetGuid");
+
+                       check_runtime_version = (CheckRuntimeVersionFunc) create_delegate (
+                               typeof (Assembly), typeof (CheckRuntimeVersionFunc),
+                               "MonoDebugger_CheckRuntimeVersion");
                }
 
                public static Type GetType (Assembly assembly, int token)
@@ -280,6 +287,11 @@ namespace Mono.CompilerServices.SymbolWriter
                        return local_type_from_sig (assembly, sig);
                }
 
+               public static string CheckRuntimeVersion (string filename)
+               {
+                       return check_runtime_version (filename);
+               }
+
                public static Guid GetGuid (Module module)
                {
                        return get_guid (module);
@@ -370,6 +382,13 @@ namespace Mono.CompilerServices.SymbolWriter
                        long offset_table_offset = bw.BaseStream.Position;
                        ot.Write (bw);
 
+                       //
+                       // Sort the methods according to their tokens and update their index.
+                       //
+                       methods.Sort ();
+                       for (int i = 0; i < methods.Count; i++)
+                               ((MethodEntry) methods [i]).Index = i + 1;
+
                        //
                        // Write data sections.
                        //
@@ -379,10 +398,8 @@ namespace Mono.CompilerServices.SymbolWriter
                        ot.DataSectionSize = (int) bw.BaseStream.Position - ot.DataSectionOffset;
 
                        //
-                       // Sort the methods according to their tokens and write
-                       // the method table.
+                       // Write the method index table.
                        //
-                       methods.Sort ();
                        ot.MethodTableOffset = (int) bw.BaseStream.Position;
                        for (int i = 0; i < methods.Count; i++) {
                                MethodEntry entry = (MethodEntry) methods [i];
@@ -442,6 +459,8 @@ namespace Mono.CompilerServices.SymbolWriter
                        FileStream stream = new FileStream (filename, FileMode.Open, FileAccess.Read);
                        reader = new MyBinaryReader (stream);
 
+                       Guid guid;
+
                        try {
                                long magic = reader.ReadInt64 ();
                                long version = reader.ReadInt32 ();
@@ -454,13 +473,15 @@ namespace Mono.CompilerServices.SymbolWriter
                                                "Symbol file `{0}' has version {1}, " +
                                                "but expected {2}", filename, version,
                                                OffsetTable.Version);
+
+                               guid = new Guid (reader.ReadBytes (16));
+
                                ot = new OffsetTable (reader);
                        } catch {
                                throw new MonoSymbolFileException (
                                        "Cannot read symbol file `{0}'", filename);
                        }
 
-                       Guid guid = new Guid (reader.ReadBytes (16));
                        Module[] modules = assembly.GetModules ();
                        Guid assembly_guid = MonoDebuggerSupport.GetGuid (modules [0]);