public class MonoDebuggerSupport
{
- static MethodInfo get_token;
- static MethodInfo get_method_token;
- static MethodInfo get_method;
- static MethodInfo local_type_from_sig;
+ static GetTypeFunc get_type;
+ static GetMethodTokenFunc get_method_token;
+ static GetMethodFunc get_method;
+ static GetLocalTypeFromSignatureFunc local_type_from_sig;
- static MonoDebuggerSupport ()
+ 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);
- get_method_token = type.GetMethod ("MonoDebugger_GetMethodToken",
- BindingFlags.Instance |
- BindingFlags.NonPublic);
- if (get_method_token == null)
- throw new Exception (
- "Can't find Assembly.MonoDebugger_GetMethodToken");
-
- get_method = type.GetMethod ("MonoDebugger_GetMethod",
- BindingFlags.Instance |
- BindingFlags.NonPublic);
- if (get_method == null)
- throw new Exception (
- "Can't find Assembly.MonoDebugger_GetMethod");
-
- local_type_from_sig = type.GetMethod (
- "MonoDebugger_GetLocalTypeFromSignature",
- BindingFlags.Instance | BindingFlags.NonPublic);
- if (local_type_from_sig == null)
- throw new Exception (
- "Can't find Assembly.MonoDebugger_GetLocalTypeFromSignature");
+
+ 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)
{
- object[] args = new object[] { method };
- return (int) get_method_token.Invoke (method.ReflectedType.Assembly, args);
+ return get_method_token (method.ReflectedType.Assembly, method);
}
public static MethodBase GetMethod (Assembly assembly, int token)
{
- object[] args = new object[] { token };
- return (MethodBase) get_method.Invoke (assembly, args);
+ return get_method (assembly, token);
}
public static Type GetLocalTypeFromSignature (Assembly assembly, byte[] sig)
{
- object[] args = new object[] { sig };
- return (Type) local_type_from_sig.Invoke (assembly, args);
+ return local_type_from_sig (assembly, sig);
}
}
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)
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)