Merge pull request #199 from slide/master
authorAnkit Jain <radical@gmail.com>
Wed, 7 Dec 2011 14:05:41 +0000 (06:05 -0800)
committerAnkit Jain <radical@gmail.com>
Wed, 7 Dec 2011 14:05:41 +0000 (06:05 -0800)
[xbuild] Add 'OverrideReadOnlyFiles' property to Copy task. bug#2239

Also, fixed bug #2239 where the copy task does not
behave the same as msbuild when a file being copied is
ReadOnly. msbuild resets the attributes of the file to
Normal.

14 files changed:
man/mono.1
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft.dll.sources
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/InterfaceMappingMirror.cs [new file with mode: 0644]
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/TypeMirror.cs
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs
mcs/class/Mono.Debugger.Soft/Test/dtest-app.cs
mcs/class/Mono.Debugger.Soft/Test/dtest.cs
mcs/class/System/System.Net.Sockets/Socket_2_1.cs
mcs/class/System/System.Net/WebClient.cs
mcs/class/System/System.Net/WebRequest.cs
mcs/class/corlib/System/Type.cs
mono/mini/debugger-agent.c
mono/utils/mono-time.c

index 14cbb43e3f13f4217cedd08b7f12962ed8e4d0c1..9220f1cfa5d5aa0bfd6ba2f639dc0fb62693b6ee 100644 (file)
@@ -956,6 +956,10 @@ a Mono process through the environment.   This is useful for example
 to force all of your Mono processes to use LLVM or SGEN without having
 to modify any launch scripts.
 .TP
+\fBMONO_ENV_OPTIONS\fR
+Used to pass extra options to the debugger agent in the runtime, as they were passed
+using --debugger-agent=.
+.TP
 \fBMONO_EVENTLOG_TYPE\fR
 Sets the type of event log provider to use (for System.Diagnostics.EventLog).
 .Sp
index 6feba0316f14485a2e93bfe2787c67817b6a454e..a7cc5d555f48a93399d7e27d06254455260748d9 100644 (file)
@@ -12,6 +12,7 @@ Mono.Debugger.Soft/StackFrame.cs
 Mono.Debugger.Soft/CustomAttributeDataMirror.cs
 Mono.Debugger.Soft/ThreadStartEvent.cs
 Mono.Debugger.Soft/ILInstruction.cs
+Mono.Debugger.Soft/InterfaceMappingMirror.cs
 Mono.Debugger.Soft/PrimitiveValue.cs
 Mono.Debugger.Soft/VMDisconnectedException.cs
 Mono.Debugger.Soft/Mirror.cs
index c4ee6a5be758b843166e16b7921758aedea5c055..e68651f9543a01e63b2c47641b31dab51e483112 100644 (file)
@@ -56,6 +56,12 @@ namespace Mono.Debugger.Soft
                public long[] nested;
        }
 
+       struct IfaceMapInfo {
+               public long iface_id;
+               public long[] iface_methods;
+               public long[] target_methods;
+       }
+
        class MethodInfo {
                public int attributes, iattributes, token;
        }
@@ -353,7 +359,7 @@ namespace Mono.Debugger.Soft
                 * with newer runtimes, and vice versa.
                 */
                internal const int MAJOR_VERSION = 2;
-               internal const int MINOR_VERSION = 10;
+               internal const int MINOR_VERSION = 11;
 
                enum WPSuspendPolicy {
                        NONE = 0,
@@ -496,6 +502,8 @@ namespace Mono.Debugger.Soft
                        /* FIXME: Merge into GET_VALUES when the major protocol version is increased */
                        GET_VALUES_2 = 14,
                        CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
+                       GET_INTERFACES = 16,
+                       GET_INTERFACE_MAP = 17
                }
 
                enum BindingFlagsExtensions {
@@ -778,6 +786,13 @@ namespace Mono.Debugger.Soft
                                        throw new NotImplementedException ("Unable to handle type " + etype);
                                }
                        }
+
+                       public long[] ReadIds (int n) {
+                               long[] res = new long [n];
+                               for (int i = 0; i < n; ++i)
+                                       res [i] = ReadId ();
+                               return res;
+                       }
                }
 
                class PacketWriter {
@@ -1923,6 +1938,27 @@ namespace Mono.Debugger.Soft
                                res [i] = r.ReadId ();
                        return res;
                }
+
+               internal long[] Type_GetInterfaces (long id) {
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACES, new PacketWriter ().WriteId (id));
+                       int len = r.ReadInt ();
+                       return r.ReadIds (len);
+               }
+
+               internal IfaceMapInfo[] Type_GetInterfaceMap (long id, long[] ids) {
+                       PacketReader r = SendReceive (CommandSet.TYPE, (int)CmdType.GET_INTERFACE_MAP, new PacketWriter ().WriteId (id).WriteInt (ids.Length).WriteIds (ids));
+                       var res = new IfaceMapInfo [ids.Length];
+                       for (int i = 0; i < ids.Length; ++i) {
+                               int n = r.ReadInt ();
+
+                               res [i].iface_id = ids [i];
+                               res [i].iface_methods = r.ReadIds (n);
+                               res [i].target_methods = r.ReadIds (n);
+                       }
+
+                       return res;
+               }
+
                /*
                 * EVENTS
                 */
diff --git a/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/InterfaceMappingMirror.cs b/mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/InterfaceMappingMirror.cs
new file mode 100644 (file)
index 0000000..a4ccfbb
--- /dev/null
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using C = Mono.Cecil;
+using Mono.Cecil.Metadata;
+
+namespace Mono.Debugger.Soft
+{
+       public class InterfaceMappingMirror : Mirror {
+
+               internal InterfaceMappingMirror (VirtualMachine vm, TypeMirror target, TypeMirror iface, MethodMirror[] iface_methods, MethodMirror[] target_methods) : base (vm, 0) {
+                       TargetType = target;
+                       InterfaceType = iface;
+                       InterfaceMethods = iface_methods;
+                       TargetMethods = target_methods;
+               }
+
+               public MethodMirror[] InterfaceMethods;
+
+               public TypeMirror InterfaceType;
+
+               public MethodMirror[] TargetMethods;
+
+               public TypeMirror TargetType;
+       }
+}
index 803783cbc60b2442c26d0f1e2033377ae7465ada..402e09d1f200c6adba6dd5658e543983eebfd24a 100644 (file)
@@ -23,6 +23,8 @@ namespace Mono.Debugger.Soft
                TypeMirror base_type, element_type;
                TypeMirror[] nested;
                CustomAttributeDataMirror[] cattrs;
+               TypeMirror[] ifaces;
+               Dictionary<TypeMirror, InterfaceMappingMirror> iface_map;
 
                internal const BindingFlags DefaultBindingFlags =
                BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
@@ -691,6 +693,58 @@ namespace Mono.Debugger.Soft
 
                public Value NewInstance (ThreadMirror thread, MethodMirror method, IList<Value> arguments, InvokeOptions options) {
                        return ObjectMirror.InvokeMethod (vm, thread, method, null, arguments, options);
-               }                       
+               }
+
+               // Since protocol version 2.11
+               public TypeMirror[] GetInterfaces () {
+                       if (ifaces == null)
+                               ifaces = vm.GetTypes (vm.conn.Type_GetInterfaces (id));
+                       return ifaces;
+               }
+
+               // Since protocol version 2.11
+               public InterfaceMappingMirror GetInterfaceMap (TypeMirror interfaceType) {
+                       if (interfaceType == null)
+                               throw new ArgumentNullException ("interfaceType");
+                       if (!interfaceType.IsInterface)
+                               throw new ArgumentException ("Argument must be an interface.", "interfaceType");
+                       if (IsInterface)
+                               throw new ArgumentException ("'this' type cannot be an interface itself");
+
+                       if (iface_map == null) {
+                               // Query the info in bulk
+                               GetInterfaces ();
+                               var ids = new long [ifaces.Length];
+                               for (int i = 0; i < ifaces.Length; ++i)
+                                       ids [i] = ifaces [i].Id;
+
+                               var ifacemap = vm.conn.Type_GetInterfaceMap (id, ids);
+
+                               var imap = new Dictionary<TypeMirror, InterfaceMappingMirror> ();
+                               for (int i = 0; i < ifacemap.Length; ++i) {
+                                       IfaceMapInfo info = ifacemap [i];
+
+                                       MethodMirror[] imethods = new MethodMirror [info.iface_methods.Length];
+                                       for (int j = 0; j < info.iface_methods.Length; ++j)
+                                               imethods [j] = vm.GetMethod (info.iface_methods [j]);
+
+                                       MethodMirror[] tmethods = new MethodMirror [info.iface_methods.Length];
+                                       for (int j = 0; j < info.target_methods.Length; ++j)
+                                               tmethods [j] = vm.GetMethod (info.target_methods [j]);
+
+                                       InterfaceMappingMirror map = new InterfaceMappingMirror (vm, this, vm.GetType (info.iface_id), imethods, tmethods);
+
+                                       imap [map.InterfaceType] = map;
+                               }
+
+                               iface_map = imap;
+                       }
+
+                       InterfaceMappingMirror res;
+                       if (!iface_map.TryGetValue (interfaceType, out res))
+                               throw new ArgumentException ("Interface not found", "interfaceType");
+                       return res;
+               }
+
     }
 }
index 0a19a7f717e252dd69066fc4e4700c7b45d0ff86..409d7082d8426124867ecddc67d24b9abdceba7d 100644 (file)
@@ -445,6 +445,13 @@ namespace Mono.Debugger.Soft
                        }
            }
 
+               internal TypeMirror[] GetTypes (long[] ids) {
+                       var res = new TypeMirror [ids.Length];
+                       for (int i = 0; i < ids.Length; ++i)
+                               res [i] = GetType (ids [i]);
+                       return res;
+               }
+
                Dictionary <long, ObjectMirror> objects;
                object objects_lock = new object ();
 
index 74df785454d944219f8f1040974103b32719b528..96013b73bab1356b85e949655c4ec569343add4b 100644 (file)
@@ -114,6 +114,40 @@ public struct GStruct<T> {
        }
 }
 
+interface ITest
+{
+       void Foo ();
+       void Bar ();
+}
+
+interface ITest<T>
+{
+       void Foo ();
+       void Bar ();
+}
+
+class TestIfaces : ITest
+{
+       void ITest.Foo () {
+       }
+
+       void ITest.Bar () {
+       }
+
+       TestIfaces<int> Baz () {
+               return null;
+       }
+}
+
+class TestIfaces<T> : ITest<T>
+{
+       void ITest<T>.Foo () {
+       }
+
+       void ITest<T>.Bar () {
+       }
+}
+
 public class Tests : TestsBase
 {
 #pragma warning disable 0414
index c11616c96ef07e5adb4e37e40ff008bb819e3770..5288ce8fdd099ad1579cb84242693c0bbfc1d4d1 100644 (file)
@@ -2786,4 +2786,36 @@ public class DebuggerTests
                                s.GetChars (2, 2);
                        });
        }
+
+       [Test]
+       public void GetInterfaces () {
+               var e = run_until ("arg2");
+
+               var frame = e.Thread.GetFrames () [0];
+
+               var cl1 = frame.Method.DeclaringType.Assembly.GetType ("TestIfaces");
+               var ifaces = cl1.GetInterfaces ();
+               Assert.AreEqual (1, ifaces.Length);
+               Assert.AreEqual ("ITest", ifaces [0].Name);
+
+               var cl2 = cl1.GetMethod ("Baz").ReturnType;
+               var ifaces2 = cl2.GetInterfaces ();
+               Assert.AreEqual (1, ifaces2.Length);
+               Assert.AreEqual ("ITest`1", ifaces2 [0].Name);
+       }
+
+       [Test]
+       public void GetInterfaceMap () {
+               var e = run_until ("arg2");
+
+               var frame = e.Thread.GetFrames () [0];
+
+               var cl1 = frame.Method.DeclaringType.Assembly.GetType ("TestIfaces");
+               var iface = cl1.Assembly.GetType ("ITest");
+               var map = cl1.GetInterfaceMap (iface);
+               Assert.AreEqual (cl1, map.TargetType);
+               Assert.AreEqual (iface, map.InterfaceType);
+               Assert.AreEqual (2, map.InterfaceMethods.Length);
+               Assert.AreEqual (2, map.TargetMethods.Length);
+       }
 }
index 2e0249537bfbe53b6054a4f755bc380b79b67bf3..3c2bdf673b74d24b059cd9e6f6fa987b244eeee2 100644 (file)
@@ -1643,10 +1643,10 @@ namespace System.Net.Sockets {
                }
 
                bool ConnectAsyncReal (SocketAsyncEventArgs e)
-               {
-                       IPAddress [] addresses = null;
+               {                       
                        bool use_remoteep = true;
 #if MOONLIGHT || NET_4_0
+                       IPAddress [] addresses = null;
                        use_remoteep = !GetCheckedIPs (e, out addresses);
                        bool policy_failed = (e.SocketError == SocketError.AccessDenied);
 #endif
index 7d764027592e59dc8ae9657c22b75ffd26544857..0eaa5911b1a07d5a8ec0cf3e1b991e4ec34e57a7 100644 (file)
@@ -192,7 +192,7 @@ namespace System.Net
 
                public IWebProxy Proxy {
                        get {
-                               if (proxySet)
+                               if (!proxySet)
                                        return WebRequest.DefaultWebProxy;
 
                                return proxy;
index c2ce66e7f65372b689094cee80e8027219efad54..aa88aeecd555e0629b01d98bda40a17ccef5123d 100644 (file)
@@ -332,9 +332,9 @@ namespace System.Net
                                int iProxyEnable = (int)Microsoft.Win32.Registry.GetValue ("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyEnable", 0);
 
                                if (iProxyEnable > 0) {
-                                       string strHttpProxy = "";
-                                       string[] bypassList = null;
+                                       string strHttpProxy = "";                                       
                                        bool bBypassOnLocal = false;
+                                       ArrayList al = new ArrayList ();
                                        
                                        string strProxyServer = (string)Microsoft.Win32.Registry.GetValue ("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyServer", null);
                                        string strProxyOverrride = (string)Microsoft.Win32.Registry.GetValue ("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", "ProxyOverride", null);
@@ -347,14 +347,15 @@ namespace System.Net
                                                        }
                                        } else strHttpProxy = strProxyServer;
                                        
-                                       if (strProxyOverrride != null)
-                                               bypassList = strProxyOverrride.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
-                                       
-                                       ArrayList al = new ArrayList ();
+                                       if (strProxyOverrride != null) {                                                
+                                               string[] bypassList = strProxyOverrride.Split (new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                                        
-                                       foreach (string str in bypassList) {
-                                               if (str != "<local>")al.Add (str);
-                                                       else bBypassOnLocal = true;
+                                               foreach (string str in bypassList) {
+                                                       if (str != "<local>")
+                                                               al.Add (str);
+                                                       else
+                                                               bBypassOnLocal = true;
+                                               }
                                        }
                                        
                                        return new WebProxy (strHttpProxy, bBypassOnLocal, al.ToArray (typeof(string)) as string[]);
@@ -386,20 +387,22 @@ namespace System.Net
                                                        }
                                                }
                                                
-                                               bool bBypassOnLocal = false;
-                                               string[] bypassList = null;
+                                               bool bBypassOnLocal = false;                                            
                                                ArrayList al = new ArrayList ();
                                                string bypass = Environment.GetEnvironmentVariable ("no_proxy");
                                                
                                                if (bypass == null)
                                                        bypass = Environment.GetEnvironmentVariable ("NO_PROXY");
                                                
-                                               if (bypass != null)
-                                                       bypassList = bypass.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+                                               if (bypass != null) {
+                                                       string[] bypassList = bypass.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                                
-                                               foreach (string str in bypassList) {
-                                                       if (str != "*.local")al.Add (str);
-                                                               else bBypassOnLocal = true;
+                                                       foreach (string str in bypassList) {
+                                                               if (str != "*.local")
+                                                                       al.Add (str);
+                                                               else
+                                                                       bBypassOnLocal = true;
+                                                       }
                                                }
                                                
                                                return new WebProxy (uri, bBypassOnLocal, al.ToArray (typeof(string)) as string[]);
index 33ad6d2f308333a71e4682ad0126b0469dbcd25f..a39613480e57ab243e2dbd62a636b4e289fa69fd 100644 (file)
@@ -831,11 +831,11 @@ namespace System {
                public virtual InterfaceMapping GetInterfaceMap (Type interfaceType) {
                        if (!IsSystemType)
                                throw new NotSupportedException ("Derived classes must provide an implementation.");
+                       if (interfaceType == null)
+                               throw new ArgumentNullException ("interfaceType");
                        if (!interfaceType.IsSystemType)
                                throw new ArgumentException ("interfaceType", "Type is an user type");
                        InterfaceMapping res;
-                       if (interfaceType == null)
-                               throw new ArgumentNullException ("interfaceType");
                        if (!interfaceType.IsInterface)
                                throw new ArgumentException (Locale.GetText ("Argument must be an interface."), "interfaceType");
                        if (IsInterface)
index 50c3a31dcfb45354e3b3e34ebce66ba1a67c5680..b65d544d9b5317ac49bf24cf02151b459290bbb4 100644 (file)
@@ -270,7 +270,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 10
+#define MINOR_VERSION 11
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -461,6 +461,8 @@ typedef enum {
        CMD_TYPE_GET_SOURCE_FILES_2 = 13,
        CMD_TYPE_GET_VALUES_2 = 14,
        CMD_TYPE_GET_METHODS_BY_NAME_FLAGS = 15,
+       CMD_TYPE_GET_INTERFACES = 16,
+       CMD_TYPE_GET_INTERFACE_MAP = 17,
 } CmdType;
 
 typedef enum {
@@ -784,12 +786,17 @@ mono_debugger_agent_parse_options (char *options)
        char **args, **ptr;
        char *host;
        int port;
+       char *extra;
 
 #ifndef MONO_ARCH_SOFT_DEBUG_SUPPORTED
        fprintf (stderr, "--debugger-agent is not supported on this platform.\n");
        exit (1);
 #endif
 
+       extra = getenv ("MONO_SDB_ENV_OPTIONS");
+       if (extra)
+               options = g_strdup_printf ("%s,%s", options, extra);
+
        agent_config.enabled = TRUE;
        agent_config.suspend = TRUE;
        agent_config.server = FALSE;
@@ -6754,6 +6761,27 @@ buffer_add_cattrs (Buffer *buf, MonoDomain *domain, MonoImage *image, MonoClass
        }
 }
 
+/* FIXME: Code duplication with icall.c */
+static void
+collect_interfaces (MonoClass *klass, GHashTable *ifaces, MonoError *error)
+{
+       int i;
+       MonoClass *ic;
+
+       mono_class_setup_interfaces (klass, error);
+       if (!mono_error_ok (error))
+               return;
+
+       for (i = 0; i < klass->interface_count; i++) {
+               ic = klass->interfaces [i];
+               g_hash_table_insert (ifaces, ic, ic);
+
+               collect_interfaces (ic, ifaces, error);
+               if (!mono_error_ok (error))
+                       return;
+       }
+}
+
 static ErrorCode
 type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint8 *p, guint8 *end, Buffer *buf)
 {
@@ -7074,6 +7102,64 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                g_free (name);
                break;
        }
+       case CMD_TYPE_GET_INTERFACES: {
+               MonoClass *parent;
+               GHashTable *iface_hash = g_hash_table_new (NULL, NULL);
+               MonoError error;
+               MonoClass *tclass, *iface;
+               GHashTableIter iter;
+
+               tclass = klass;
+
+               for (parent = tclass; parent; parent = parent->parent) {
+                       mono_class_setup_interfaces (parent, &error);
+                       if (!mono_error_ok (&error))
+                               return ERR_LOADER_ERROR;
+                       collect_interfaces (parent, iface_hash, &error);
+                       if (!mono_error_ok (&error))
+                               return ERR_LOADER_ERROR;
+               }
+
+               buffer_add_int (buf, g_hash_table_size (iface_hash));
+
+               g_hash_table_iter_init (&iter, iface_hash);
+               while (g_hash_table_iter_next (&iter, NULL, (void**)&iface))
+                       buffer_add_typeid (buf, domain, iface);
+               g_hash_table_destroy (iface_hash);
+               break;
+       }
+       case CMD_TYPE_GET_INTERFACE_MAP: {
+               int tindex, ioffset;
+               gboolean variance_used;
+               MonoClass *iclass;
+               int len, nmethods, i;
+               gpointer iter;
+               MonoMethod *method;
+
+               len = decode_int (p, &p, end);
+               mono_class_setup_vtable (klass);
+
+               for (tindex = 0; tindex < len; ++tindex) {
+                       iclass = decode_typeid (p, &p, end, NULL, &err);
+                       if (err)
+                               return err;
+
+                       ioffset = mono_class_interface_offset_with_variance (klass, iclass, &variance_used);
+                       if (ioffset == -1)
+                               return ERR_INVALID_ARGUMENT;
+
+                       nmethods = mono_class_num_methods (iclass);
+                       buffer_add_int (buf, nmethods);
+
+                       iter = NULL;
+                       while ((method = mono_class_get_methods (iclass, &iter))) {
+                               buffer_add_methodid (buf, domain, method);
+                       }
+                       for (i = 0; i < nmethods; ++i)
+                               buffer_add_methodid (buf, domain, klass->vtable [i + ioffset]);
+               }
+               break;
+       }
        default:
                return ERR_NOT_IMPLEMENTED;
        }
index 14bde6bfe63b4b2a928f305d719286cb5ea4fe99..5d926a930bb2fb8d454cefcdb930ba7c83462f7f 100644 (file)
@@ -25,12 +25,20 @@ gint64
 mono_100ns_ticks (void)
 {
        static LARGE_INTEGER freq;
+       static UINT64 start_time;
+       UINT64 cur_time;
        LARGE_INTEGER value;
 
-       if (!freq.QuadPart && !QueryPerformanceFrequency (&freq))
-               return mono_100ns_datetime ();
+       if (!freq.QuadPart) {
+               if (!QueryPerformanceFrequency (&freq))
+                       return mono_100ns_datetime ();
+               QueryPerformanceCounter (&value);
+               start_time = value.QuadPart;
+       }
        QueryPerformanceCounter (&value);
-       return value.QuadPart * MTICKS_PER_SEC / freq.QuadPart;
+       cur_time = value.QuadPart;
+       /* we use unsigned numbers and return the difference to avoid overflows */
+       return (cur_time - start_time) * MTICKS_PER_SEC / freq.QuadPart;
 }
 
 /*