none
windbg event callback ChangeEngineState crash RRS feed

  • Question

  • hi all:

    I tried to set a callback in windbg extension, it works well on any other methos except ChangeEngineState, once I register ChangeEngineState,

    and stop debugging(shift+F5), it will cause an exception like:

    c0000005 Exception in debugger client IDebugEventCallbacks::ChangeEngineState callback.
    PC: ?00000000`57d13a7d?  VA: ?00000000`6941a20c?  R/W: 0  Parameter: ?00000000`00000000?
    My code is quite simpe as below, ca anybody help?

    Thanks in advance!(*^__^*)

    //
    
    #include "stdafx.h"
    #define KDEXT_64BIT
    #include <wdbgexts.h>
    #include <dbgeng.h>
    
    //----------------------------------------------------------------------------
    //
    // Event callbacks.
    //
    //----------------------------------------------------------------------------
    
    class EventCallbacks : public DebugBaseEventCallbacks
    {
    public:
    	// IUnknown.
    	STDMETHOD_(ULONG, AddRef)(
    		THIS
    		);
    	STDMETHOD_(ULONG, Release)(
    		THIS
    		);
    
    	// IDebugEventCallbacks.
    	STDMETHOD(GetInterestMask)(
    		THIS_
    		OUT PULONG Mask
    		);
    
    	STDMETHOD(ChangeEngineState)(
    		THIS_
    		IN ULONG Flags,
    		IN ULONG64 Argument
    		);
    
    	STDMETHODIMP QueryInterface(THIS_ IN REFIID InterfaceId, OUT PVOID* Interface)
    	{
    		*Interface = 0;
    
    		if (IsEqualIID(InterfaceId, __uuidof(IDebugEventCallbacks)))
    			*Interface = (IDebugEventCallbacks *) this;
    
    		if (*Interface)
    			return S_OK;
    
    		return E_NOINTERFACE;	
    	}
    
    };
    
    STDMETHODIMP_(ULONG)
    EventCallbacks::AddRef(
    					   THIS
    					   )
    {
    	// This class is designed to be static so
    	// there's no true refcount.
    	return 1;
    }
    
    STDMETHODIMP_(ULONG)
    EventCallbacks::Release(
    						THIS
    						)
    {
    	// This class is designed to be static so
    	// there's no true refcount.
    	return 0;
    }
    
    STDMETHODIMP
    EventCallbacks::GetInterestMask(
    								THIS_
    								OUT PULONG Mask
    								)
    {
    	*Mask = DEBUG_EVENT_CHANGE_ENGINE_STATE;
    	return S_OK;
    }
    
    STDMETHODIMP
    EventCallbacks::ChangeEngineState(
    								  THIS_
    								  IN ULONG Flags,
    								  IN ULONG64 Argument
    								  )
    {
    
    	return S_OK;
    }
    
    EventCallbacks g_EventCb;
    PDEBUG_CLIENT g_pNewClient;
    
    PDEBUG_EXTENSION_CALL start(PDEBUG_CLIENT client, PCSTR args)
    {
    	CoInitializeEx(0, COINIT_MULTITHREADED);
    
    	HRESULT hr = client->CreateClient(&g_pNewClient);
    	if (S_OK != hr)
    		return 0;
    
    	g_pNewClient->SetEventCallbacks(&g_EventCb);
    	return S_OK;
    }
    
    
    
    
    HRESULT CALLBACK DebugExtensionInitialize(PULONG version, PULONG flags)
    {
    	*version = DEBUG_EXTENSION_VERSION(1, 0);
    	*flags = 0;
    	return S_OK;
    }
    extern "C" void CALLBACK DebugExtensionUninitialize(void) {
    	ULONG ulExitCode = 0;
    
    	return;
    }
    
    

    Monday, April 9, 2012 7:49 AM