Merge pull request #1412 from esdrubal/stackframe
[mono.git] / mono / mini / debugger-agent.c
index e5ca36c2692032ce17622883e734f6c053003c11..240f8419a4532cb81c55751c5b4f9965a4f7ac98 100644 (file)
@@ -290,7 +290,7 @@ typedef struct {
 #define HEADER_LENGTH 11
 
 #define MAJOR_VERSION 2
-#define MINOR_VERSION 37
+#define MINOR_VERSION 38
 
 typedef enum {
        CMD_SET_VM = 1,
@@ -515,7 +515,8 @@ typedef enum {
 typedef enum {
        CMD_STACK_FRAME_GET_VALUES = 1,
        CMD_STACK_FRAME_GET_THIS = 2,
-       CMD_STACK_FRAME_SET_VALUES = 3
+       CMD_STACK_FRAME_SET_VALUES = 3,
+       CMD_STACK_FRAME_GET_DOMAIN = 4,
 } CmdStackFrame;
 
 typedef enum {
@@ -816,6 +817,12 @@ static void
 register_socket_transport (void);
 #endif
 
+static inline gboolean
+is_debugger_thread (void)
+{
+       return GetCurrentThreadId () == debugger_thread_id;
+}
+
 static int
 parse_address (char *address, char **host, int *port)
 {
@@ -989,6 +996,9 @@ mono_debugger_agent_init (void)
 
        mono_native_tls_alloc (&debugger_tls_id, NULL);
 
+       /* Needed by the hash_table_new_type () call below */
+       mono_gc_base_init ();
+
        thread_to_tls = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC);
        MONO_GC_REGISTER_ROOT_FIXED (thread_to_tls);
 
@@ -3971,6 +3981,10 @@ appdomain_start_unload (MonoProfiler *prof, MonoDomain *domain)
 {
        DebuggerTlsData *tls;
 
+       /* This might be called during shutdown on the debugger thread from the CMD_VM_EXIT code */
+       if (is_debugger_thread ())
+               return;
+
        /*
         * Remember the currently unloading appdomain as it is needed to generate
         * proper ids for unloading assemblies.
@@ -3985,6 +3999,9 @@ appdomain_unload (MonoProfiler *prof, MonoDomain *domain)
 {
        DebuggerTlsData *tls;
 
+       if (is_debugger_thread ())
+               return;
+
        tls = mono_native_tls_get_value (debugger_tls_id);
        g_assert (tls);
        tls->domain_unloading = NULL;
@@ -8954,6 +8971,11 @@ frame_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                mono_metadata_free_mh (header);
                break;
        }
+       case CMD_STACK_FRAME_GET_DOMAIN: {
+               if (CHECK_PROTOCOL_VERSION (2, 38))
+                       buffer_add_domainid (buf, frame->domain);
+               break;
+       }
        default:
                return ERR_NOT_IMPLEMENTED;
        }
@@ -9322,7 +9344,8 @@ static const char* type_cmds_str[] = {
 static const char* stack_frame_cmds_str[] = {
        "GET_VALUES",
        "GET_THIS",
-       "SET_VALUES"
+       "SET_VALUES",
+       "GET_DOMAIN",
 };
 
 static const char* array_cmds_str[] = {