Avoid a crash in SET_KEEPALIVE if the socket transport is not initialized.
[mono.git] / mono / mini / debugger-agent.c
index ff05e9c898defe463093c8984624ad9ed46fdd57..b9d5cd4491365a1ae2aa69eaccc58f9840ecae4c 100644 (file)
@@ -162,6 +162,7 @@ struct _InvokeData
        MonoMethod *method;
        gpointer *args;
        guint32 suspend_count;
+       int nmethods;
 
        InvokeData *last_invoke;
 };
@@ -276,7 +277,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 19
+#define MINOR_VERSION 22
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -359,7 +360,8 @@ typedef enum {
 
 typedef enum {
        STEP_FILTER_NONE = 0,
-       STEP_FILTER_STATIC_CTOR = 1
+       STEP_FILTER_STATIC_CTOR = 1,
+       STEP_FILTER_DEBUGGER_HIDDEN = 2
 } StepFilter;
 
 typedef enum {
@@ -401,7 +403,8 @@ typedef enum {
        CMD_VM_ABORT_INVOKE = 9,
        CMD_VM_SET_KEEPALIVE = 10,
        CMD_VM_GET_TYPES_FOR_SOURCE_FILE = 11,
-       CMD_VM_GET_TYPES = 12
+       CMD_VM_GET_TYPES = 12,
+       CMD_VM_INVOKE_METHODS = 13
 } CmdVM;
 
 typedef enum {
@@ -455,6 +458,7 @@ typedef enum {
        CMD_METHOD_GET_INFO = 6,
        CMD_METHOD_GET_BODY = 7,
        CMD_METHOD_RESOLVE_TOKEN = 8,
+       CMD_METHOD_GET_CATTRS = 9,
 } CmdMethod;
 
 typedef enum {
@@ -1093,7 +1097,7 @@ set_keepalive (void)
        struct timeval tv;
        int result;
 
-       if (!agent_config.keepalive)
+       if (!agent_config.keepalive || !conn_fd)
                return;
 
        tv.tv_sec = agent_config.keepalive / 1000;
@@ -3313,6 +3317,26 @@ create_event_list (EventKind event, GPtrArray *reqs, MonoJitInfo *ji, EventInfo
                                                (ji->method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME) &&
                                                !strcmp (ji->method->name, ".cctor"))
                                                filtered = TRUE;
+                                       if ((mod->data.filter & STEP_FILTER_DEBUGGER_HIDDEN) && ji) {
+                                               MonoCustomAttrInfo *ainfo;
+                                               static MonoClass *klass;
+
+                                               if (!klass) {
+                                                       klass = mono_class_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerHiddenAttribute");
+                                                       g_assert (klass);
+                                               }
+                                               if (!ji->dbg_hidden_inited) {
+                                                       ainfo = mono_custom_attrs_from_method (ji->method);
+                                                       if (ainfo) {
+                                                               if (mono_custom_attrs_has_attr (ainfo, klass))
+                                                                       ji->dbg_hidden = TRUE;
+                                                               mono_custom_attrs_free (ainfo);
+                                                       }
+                                                       ji->dbg_hidden_inited = TRUE;
+                                               }
+                                               if (ji->dbg_hidden)
+                                                       filtered = TRUE;
+                                       }
                                }
                        }
 
@@ -5811,9 +5835,8 @@ add_thread (gpointer key, gpointer value, gpointer user_data)
 }
 
 static ErrorCode
-do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke)
+do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke, guint8 *p, guint8 **endp)
 {
-       guint8 *p = invoke->p;
        guint8 *end = invoke->endp;
        MonoMethod *m;
        int i, err, nargs;
@@ -6012,6 +6035,7 @@ do_invoke_method (DebuggerTlsData *tls, Buffer *buf, InvokeData *invoke)
                mono_set_lmf ((gpointer)(((gssize)ext.lmf.previous_lmf) & ~3));
 #endif
 
+       *endp = p;
        // FIXME: byref arguments
        // FIXME: varargs
        return ERR_NONE;
@@ -6028,10 +6052,11 @@ invoke_method (void)
        DebuggerTlsData *tls;
        InvokeData *invoke;
        int id;
-       int i, err;
+       int i, err, mindex;
        Buffer buf;
        static void (*restore_context) (void *);
        MonoContext restore_ctx;
+       guint8 *p;
 
        if (!restore_context)
                restore_context = mono_get_restore_context ();
@@ -6059,19 +6084,29 @@ invoke_method (void)
 
        id = invoke->id;
 
-       buffer_init (&buf, 128);
+       p = invoke->p;
+       err = 0;
+       for (mindex = 0; mindex < invoke->nmethods; ++mindex) {
+               buffer_init (&buf, 128);
 
-       err = do_invoke_method (tls, &buf, invoke);
+               if (err) {
+                       /* Fail the other invokes as well */
+               } else {
+                       err = do_invoke_method (tls, &buf, invoke, p, &p);
+               }
 
-       /* Start suspending before sending the reply */
-       if (!(invoke->flags & INVOKE_FLAG_SINGLE_THREADED)) {
-               for (i = 0; i < invoke->suspend_count; ++i)
-                       suspend_vm ();
-       }
+               /* Start suspending before sending the reply */
+               if (mindex == invoke->nmethods - 1) {
+                       if (!(invoke->flags & INVOKE_FLAG_SINGLE_THREADED)) {
+                               for (i = 0; i < invoke->suspend_count; ++i)
+                                       suspend_vm ();
+                       }
+               }
 
-       send_reply_packet (id, err, &buf);
+               send_reply_packet (id, err, &buf);
        
-       buffer_free (&buf);
+               buffer_free (&buf);
+       }
 
        memcpy (&restore_ctx, &invoke->ctx, sizeof (MonoContext));
 
@@ -6267,6 +6302,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
                        tls->pending_invoke = g_new0 (InvokeData, 1);
                        tls->pending_invoke->method = exit_method;
                        tls->pending_invoke->args = args;
+                       tls->pending_invoke->nmethods = 1;
 
                        while (suspend_count > 0)
                                resume_vm ();
@@ -6294,11 +6330,12 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
                }
                break;
        }               
-       case CMD_VM_INVOKE_METHOD: {
+       case CMD_VM_INVOKE_METHOD:
+       case CMD_VM_INVOKE_METHODS: {
                int objid = decode_objid (p, &p, end);
                MonoThread *thread;
                DebuggerTlsData *tls;
-               int i, count, err, flags;
+               int i, count, err, flags, nmethods;
 
                err = get_object (objid, (MonoObject**)&thread);
                if (err)
@@ -6306,6 +6343,11 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
 
                flags = decode_int (p, &p, end);
 
+               if (command == CMD_VM_INVOKE_METHODS)
+                       nmethods = decode_int (p, &p, end);
+               else
+                       nmethods = 1;
+
                // Wait for suspending if it already started
                if (suspend_count)
                        wait_for_suspend ();
@@ -6334,6 +6376,7 @@ vm_commands (int command, int id, guint8 *p, guint8 *end, Buffer *buf)
                memcpy (tls->pending_invoke->p, p, end - p);
                tls->pending_invoke->endp = tls->pending_invoke->p + (end - p);
                tls->pending_invoke->suspend_count = suspend_count;
+               tls->pending_invoke->nmethods = nmethods;
 
                if (flags & INVOKE_FLAG_SINGLE_THREADED) {
                        resume_thread (THREAD_TO_INTERNAL (thread));
@@ -7544,6 +7587,7 @@ static ErrorCode
 method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, guint8 *p, guint8 *end, Buffer *buf)
 {
        MonoMethodHeader *header;
+       int err;
 
        switch (command) {
        case CMD_METHOD_GET_NAME: {
@@ -7863,6 +7907,20 @@ method_commands_internal (int command, MonoMethod *method, MonoDomain *domain, g
                }
                break;
        }
+       case CMD_METHOD_GET_CATTRS: {
+               MonoClass *attr_klass;
+               MonoCustomAttrInfo *cinfo;
+
+               attr_klass = decode_typeid (p, &p, end, NULL, &err);
+               /* attr_klass can be NULL */
+               if (err)
+                       return err;
+
+               cinfo = mono_custom_attrs_from_method (method);
+
+               buffer_add_cattrs (buf, domain, method->klass->image, attr_klass, cinfo);
+               break;
+       }
        default:
                return ERR_NOT_IMPLEMENTED;
        }