public static CorDebugManagedCallback *Alloc()
        {
            ICorDebugManagedCallbackVtable *pVtable =
                (ICorDebugManagedCallbackVtable *)Marshal.AllocHGlobal(sizeof(ICorDebugManagedCallbackVtable));

            CorDebugManagedCallback *pCallback =
                (CorDebugManagedCallback *)Marshal.AllocHGlobal(sizeof(CorDebugManagedCallback));

            pCallback->Vtable = pVtable;

            return(pCallback);
        }
        public static void Free(CorDebugManagedCallback *pCallback)
        {
            if (pCallback == default)
            {
                return;
            }

            ICorDebugManagedCallbackVtable *vtable = pCallback->Vtable;

            if (vtable != default)
            {
                Marshal.FreeHGlobal(new IntPtr(vtable));
            }

            Marshal.FreeHGlobal(new IntPtr(pCallback));
        }
        internal unsafe ManagedDebuggerCallbacks()
        {
            _queryInterface = new QueryInterfaceDelegate(QueryInterface);
            _callbacks      = CorDebugManagedCallback.Alloc();
            ICorDebugManagedCallbackVtable *vtable = _callbacks->Vtable;

            vtable->QueryInterface = (void *)Marshal.GetFunctionPointerForDelegate(_queryInterface);

            _addRef        = new AddRefDelegate(AddRef);
            vtable->AddRef = (void *)Marshal.GetFunctionPointerForDelegate(_addRef);

            _release        = new ReleaseDelegate(Release);
            vtable->Release = (void *)Marshal.GetFunctionPointerForDelegate(_release);

            _breakpoint        = new PointerDelegate3(OnBreakpoint);
            vtable->Breakpoint = (void *)Marshal.GetFunctionPointerForDelegate(_breakpoint);

            _stepComplete        = new OnStepCompleteDelegate(OnStepComplete);
            vtable->StepComplete = (void *)Marshal.GetFunctionPointerForDelegate(_stepComplete);

            _break        = new PointerDelegate2(OnBreak);
            vtable->Break = (void *)Marshal.GetFunctionPointerForDelegate(_break);

            _exception        = new OnExceptionDelegate(OnException);
            vtable->Exception = (void *)Marshal.GetFunctionPointerForDelegate(_exception);

            _evalComplete        = new PointerDelegate3(OnEvalComplete);
            vtable->EvalComplete = (void *)Marshal.GetFunctionPointerForDelegate(_evalComplete);

            _evalException        = new PointerDelegate3(OnEvalException);
            vtable->EvalException = (void *)Marshal.GetFunctionPointerForDelegate(_evalException);

            _createProcess        = new PointerDelegate1(OnCreateProcess);
            vtable->CreateProcess = (void *)Marshal.GetFunctionPointerForDelegate(_createProcess);

            _exitProcess        = new PointerDelegate1(OnExitProcess);
            vtable->ExitProcess = (void *)Marshal.GetFunctionPointerForDelegate(_exitProcess);

            _createThread        = new PointerDelegate2(OnCreateThread);
            vtable->CreateThread = (void *)Marshal.GetFunctionPointerForDelegate(_createThread);

            _exitThread        = new PointerDelegate2(OnExitThread);
            vtable->ExitThread = (void *)Marshal.GetFunctionPointerForDelegate(_exitThread);

            _loadModule        = new PointerDelegate2(OnLoadModule);
            vtable->LoadModule = (void *)Marshal.GetFunctionPointerForDelegate(_loadModule);

            _unloadModule        = new PointerDelegate2(OnUnloadModule);
            vtable->UnloadModule = (void *)Marshal.GetFunctionPointerForDelegate(_unloadModule);

            _loadClass        = new PointerDelegate2(OnLoadClass);
            vtable->LoadClass = (void *)Marshal.GetFunctionPointerForDelegate(_loadClass);

            _unloadClass        = new PointerDelegate2(OnUnloadClass);
            vtable->UnloadClass = (void *)Marshal.GetFunctionPointerForDelegate(_unloadClass);

            _debuggerError        = new OnDebuggerErrorDelegate(OnDebuggerError);
            vtable->DebuggerError = (void *)Marshal.GetFunctionPointerForDelegate(_debuggerError);

            _logMessage        = new OnLogMessageDelegate(OnLogMessage);
            vtable->LogMessage = (void *)Marshal.GetFunctionPointerForDelegate(_logMessage);

            _logSwitch        = new OnLogSwitchDelegate(OnLogSwitch);
            vtable->LogSwitch = (void *)Marshal.GetFunctionPointerForDelegate(_logSwitch);

            _createAppDomain        = new PointerDelegate2(OnCreateAppDomain);
            vtable->CreateAppDomain = (void *)Marshal.GetFunctionPointerForDelegate(_createAppDomain);

            _exitAppDomain        = new PointerDelegate2(OnExitAppDomain);
            vtable->ExitAppDomain = (void *)Marshal.GetFunctionPointerForDelegate(_exitAppDomain);

            _loadAssembly        = new PointerDelegate2(OnLoadAssembly);
            vtable->LoadAssembly = (void *)Marshal.GetFunctionPointerForDelegate(_loadAssembly);

            _unloadAssembly        = new PointerDelegate2(OnUnloadAssembly);
            vtable->UnloadAssembly = (void *)Marshal.GetFunctionPointerForDelegate(_unloadAssembly);

            _controlCTrap        = new PointerDelegate1(OnControlCTrap);
            vtable->ControlCTrap = (void *)Marshal.GetFunctionPointerForDelegate(_controlCTrap);

            _nameChange        = new PointerDelegate2(OnNameChange);
            vtable->NameChange = (void *)Marshal.GetFunctionPointerForDelegate(_nameChange);

            _updateModuleSymbols        = new PointerDelegate3(OnUpdateModuleSymbols);
            vtable->UpdateModuleSymbols = (void *)Marshal.GetFunctionPointerForDelegate(_updateModuleSymbols);

            _editAndContinueRemap        = new OnEditAndContinueRemapDelegate(OnEditAndContinueRemap);
            vtable->EditAndContinueRemap = (void *)Marshal.GetFunctionPointerForDelegate(_editAndContinueRemap);

            _breakpointSetError        = new OnBreakpointSetErrorDelegate(OnBreakpointSetError);
            vtable->BreakpointSetError = (void *)Marshal.GetFunctionPointerForDelegate(_breakpointSetError);

            _callbacks2 = CorDebugManagedCallback2.Alloc();
            ICorDebugManagedCallback2Vtable *vtable2 = _callbacks2->Vtable;

            vtable2->QueryInterface = vtable->QueryInterface;
            vtable2->AddRef         = vtable->AddRef;
            vtable2->Release        = vtable->Release;

            _functionRemapOpportunity         = new OnFunctionRemapOpportunityDelegate(OnFunctionRemapOpportunity);
            vtable2->FunctionRemapOpportunity = (void *)Marshal.GetFunctionPointerForDelegate(_functionRemapOpportunity);

            _createConnection         = new OnCreateConnectionDelegate(OnCreateConnection);
            vtable2->CreateConnection = (void *)Marshal.GetFunctionPointerForDelegate(_createConnection);

            _changeConnection         = new OnChangeConnectionDelegate(OnChangeConnection);
            vtable2->ChangeConnection = (void *)Marshal.GetFunctionPointerForDelegate(_changeConnection);

            _destroyConnection         = new OnDestroyConnectionDelegate(OnDestroyConnection);
            vtable2->DestroyConnection = (void *)Marshal.GetFunctionPointerForDelegate(_destroyConnection);

            _exception2        = new OnException2Delegate(OnException2);
            vtable2->Exception = (void *)Marshal.GetFunctionPointerForDelegate(_exception2);

            _exceptionUnwind         = new OnExceptionUnwindDelegate(OnExceptionUnwind);
            vtable2->ExceptionUnwind = (void *)Marshal.GetFunctionPointerForDelegate(_exceptionUnwind);

            _functionRemapComplete         = new PointerDelegate3(OnFunctionRemapComplete);
            vtable2->FunctionRemapComplete = (void *)Marshal.GetFunctionPointerForDelegate(_functionRemapComplete);

            _mDANotification         = new PointerDelegate3(OnMDANotification);
            vtable2->MDANotification = (void *)Marshal.GetFunctionPointerForDelegate(_mDANotification);
        }