}
}
+ public class MonoDebuggerSupport
+ {
+ static GetTypeFunc get_type;
+ static GetMethodTokenFunc get_method_token;
+ static GetMethodFunc get_method;
+ static GetLocalTypeFromSignatureFunc local_type_from_sig;
+
+ 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);
+
+ static Delegate create_delegate (Type delegate_type, string name)
+ {
+ Type type = typeof (Assembly);
+
+ MethodInfo mi = type.GetMethod (name, BindingFlags.Static |
+ BindingFlags.NonPublic);
+ if (mi == null)
+ throw new Exception ("Can't find " + name);
+
+ return Delegate.CreateDelegate (delegate_type, mi);
+ }
+
+ static MonoDebuggerSupport ()
+ {
+ get_type = (GetTypeFunc) create_delegate (
+ typeof (GetTypeFunc), "MonoDebugger_GetType");
+
+ get_method_token = (GetMethodTokenFunc) create_delegate (
+ typeof (GetMethodTokenFunc), "MonoDebugger_GetMethodToken");
+
+ get_method = (GetMethodFunc) create_delegate (
+ typeof (GetMethodFunc), "MonoDebugger_GetMethod");
+
+ local_type_from_sig = (GetLocalTypeFromSignatureFunc) create_delegate (
+ typeof (GetLocalTypeFromSignatureFunc),
+ "MonoDebugger_GetLocalTypeFromSignature");
+ }
+
+ public static Type GetType (Assembly assembly, int token)
+ {
+ return get_type (assembly, token);
+ }
+
+ public static int GetMethodToken (MethodBase method)
+ {
+ return get_method_token (method.ReflectedType.Assembly, method);
+ }
+
+ public static MethodBase GetMethod (Assembly assembly, int token)
+ {
+ return get_method (assembly, token);
+ }
+
+ public static Type GetLocalTypeFromSignature (Assembly assembly, byte[] sig)
+ {
+ return local_type_from_sig (assembly, sig);
+ }
+ }
+
public class MonoSymbolFile : IDisposable
{
ArrayList methods = new ArrayList ();
return ++last_namespace_index;
}
- internal void WriteString (BinaryWriter bw, string text)
+ byte [] stringBuffer;
+ int maxCharsPerRound;
+ static Encoding enc = Encoding.UTF8;
+
+ internal void WriteString (BinaryWriter bw, string s)
{
- byte[] data = Encoding.UTF8.GetBytes (text);
- bw.Write ((int) data.Length);
- bw.Write (data);
- StringSize += data.Length;
+ int len = enc.GetByteCount (s);
+ bw.Write (len);
+ StringSize += len;
+
+ if (stringBuffer == null) {
+ stringBuffer = new byte [512];
+ maxCharsPerRound = 512 / enc.GetMaxByteCount (1);
+ }
+
+ int chpos = 0;
+ int chrem = s.Length;
+ while (chrem > 0) {
+ int cch = (chrem > maxCharsPerRound) ? maxCharsPerRound : chrem;
+ int blen = enc.GetBytes (s, chpos, cch, stringBuffer, 0);
+ bw.Write (stringBuffer, 0, blen);
+
+ chpos += cch;
+ chrem -= cch;
+ }
}
internal string ReadString (int offset)
using (MyMemoryStream stream = new MyMemoryStream ()) {
Write (new BinaryWriter (stream));
- Console.WriteLine ("WROTE SYMFILE: {0} sources, {1} methods, {2} types, " +
- "{3} line numbers, {4} locals, {5} namespaces, " +
- "{6} bytes of string data",
- SourceCount, MethodCount, TypeCount, LineNumberCount,
- LocalCount, NamespaceCount, StringSize);
- Console.WriteLine (ot);
return stream.GetContents ();
}
}
Hashtable source_file_hash;
Hashtable method_token_hash;
- Hashtable method_name_hash;
- Hashtable method_full_name_hash;
Hashtable source_name_hash;
protected MonoSymbolFile (Assembly assembly, Stream stream)
{
if (reader == null)
throw new InvalidOperationException ();
- int token = assembly.MonoDebugger_GetMethodToken (method);
+ int token = MonoDebuggerSupport.GetMethodToken (method);
return GetMethodByToken (token);
}
throw new MonoSymbolFileException ("Internal error.");
}
- public int FindMethod (string full_name)
- {
- if (reader == null)
- throw new InvalidOperationException ();
-
- if (method_full_name_hash == null) {
- method_full_name_hash = new Hashtable ();
-
- for (int i = 0; i < ot.MethodCount; i++) {
- MethodIndexEntry ie = GetMethodIndexEntry (i + 1);
- string name = ReadString (ie.FullNameOffset);
-
- method_full_name_hash.Add (name, i + 1);
- }
- }
-
- object value = method_full_name_hash [full_name];
- if (value == null)
- return -1;
- return (int) value;
- }
-
- public int[] MethodLookup (string query)
- {
- if (reader == null)
- throw new InvalidOperationException ();
-
- ArrayList list;
- if (method_name_hash == null) {
- method_name_hash = new Hashtable ();
-
- for (int i = 0; i < ot.MethodCount; i++) {
- MethodIndexEntry ie = GetMethodIndexEntry (i + 1);
- string full_name = ReadString (ie.FullNameOffset);
-
- int pos = full_name.IndexOf ('(');
- string name = full_name.Substring (0, pos);
-
- list = method_name_hash [name] as ArrayList;
- if (list == null) {
- list = new ArrayList ();
- method_name_hash.Add (name, list);
- }
-
- list.Add (i + 1);
- }
- }
-
- list = method_name_hash [query] as ArrayList;
- if (list == null)
- return new int [0];
-
- int[] retval = new int [list.Count];
- list.CopyTo (retval, 0);
- return retval;
- }
-
public int FindSource (string file_name)
{
if (reader == null)