IDebugProgramProvider2::WatchForProviderEvents
Permite que el proceso reciba una notificación de eventos de puerto.
Sintaxis
int WatchForProviderEvents(
enum_PROVIDER_FLAGS Flags,
IDebugDefaultPort2 pPort,
AD_PROCESS_ID ProcessId,
CONST_GUID_ARRAY EngineFilter,
ref Guid guidLaunchingEngine,
IDebugPortNotify2 pEventCallback
);
Parámetros
Flags
[in] Combinación de marcas de la enumeración PROVIDER_FLAGS . Las marcas siguientes son típicas para esta llamada:
Marca | Descripción |
---|---|
PFLAG_REMOTE_PORT |
El autor de la llamada se ejecuta en una máquina remota. |
PFLAG_DEBUGGEE |
Actualmente se está depurando el autor de la llamada (se devuelve información adicional sobre la serialización de cada nodo). |
PFLAG_ATTACHED_TO_DEBUGGEE |
El depurador ha asociado al autor de la llamada, pero no lo ha iniciado. |
PFLAG_REASON_WATCH |
El autor de la llamada quiere ver los eventos. Si no se establece esta marca. a continuación, se quita el evento de devolución de llamada y el autor de la llamada ya no recibe notificaciones. |
pPort
[in] Puerto en el que se ejecuta el proceso de llamada.
processId
[in] Estructura AD_PROCESS_ID que contiene el identificador del proceso que contiene el programa en cuestión.
EngineFilter
[in] Matriz de GUID de motores de depuración asociados al proceso.
guidLaunchingEngine
[in] GUID del motor de depuración que inició este proceso (si existe).
pEventCallback
[in] Objeto IDebugPortNotify2 que recibe las notificaciones de eventos.
Valor devuelto
Si la operación se realiza correctamente, devuelve S_OK
; de lo contrario, devuelve un código de error.
Comentarios
Cuando un llamador quiere quitar un controlador de eventos que se estableció con una llamada anterior a este método, el autor de la llamada pasa los mismos parámetros que hizo la primera vez, pero deja fuera de la PFLAG_REASON_WATCH
marca.
Ejemplo
En el ejemplo siguiente se muestra cómo implementar este método para un objeto CDebugEngine que expone la interfaz IDebugProgramProvider2 .
STDMETHODIMP CDebugEngine::WatchForProviderEvents(
PROVIDER_FLAGS Flags,
IDebugDefaultPort2 *pPort,
AD_PROCESS_ID processId,
CONST_GUID_ARRAY EngineFilter,
REFGUID guidLaunchingEngine,
IDebugPortNotify2 *pPortNotify)
{
HRESULT hRes = E_FAIL;
if (EVAL(pPort != NULL) && EVAL(pPortNotify != NULL))
{
// We will only watch/send events about the process if the debugger
// is actually debugging the process, and only if this is an attach or a LoRIE launch
if (IsFlagSet(Flags, PFLAG_DEBUGGEE) &&
guidLaunchingEngine == GUID_NULL &&
processId.ProcessIdType == AD_PROCESS_ID_SYSTEM)
{
// We don't support WatchForProviderEvents when in interop mode
if (m_fInterop)
{
ASSERT(!"Shouldn't ever be called in interop mode");
hRes = E_FAIL;
}
else
{
if (IsFlagSet(Flags, PFLAG_REASON_WATCH))
{
// QI to get IDebugEventCallback2 which is required.
CComQIPtr<IDebugEventCallback2> pCallback(pPortNotify);
ASSERT(pCallback != NULL);
if ( pCallback != NULL )
{
// Register the callback
hRes = this->InitDebugSession(pCallback);
if ( S_OK == hRes )
{
// Get the IDebugProcess2 from the port and call AttachImpl
CComPtr<IDebugProcess2> spProcess;
hRes = pPort->GetProcess(processId, &spProcess);
if (HREVAL(S_OK, hRes))
{
hRes = AttachImpl(spProcess, NULL, NULL, processId.ProcessId.dwProcessId, ATTACH_REASON_USER, NULL);
if ( FAILED(hRes) && (!m_pPidList || 0 == m_pPidList->GetCount()) )
this->Cleanup();
}
}
else
this->Cleanup();
}
else
hRes = E_FAIL;
}
else
{
// Detach will be done by SDM calling on programs directly if there are managed programs.
// This handling is the case where no managed code ever ran.
if ( this->IsProcessBeingDebugged(processId.ProcessId.dwProcessId) )
{
ProgramList *pProgList = this->GetProgramListCopy();
if ( EVAL(pProgList) )
{
if ( pProgList->GetCount() == 0)
{
CComPtr<ICorDebugProcess> pCorProcess;
hRes = this->GetCorProcess(processId.ProcessId.dwProcessId, &pCorProcess);
if (HREVAL(S_OK, hRes) )
{
hRes = pCorProcess->Stop(INFINITE);
if ( HREVAL(S_OK, hRes) )
hRes = pCorProcess->Detach();
}
// Tell the engine that it should unregister this process from com+
this->UnregisterProcess(processId.ProcessId.dwProcessId);
// If there are no more pids left then cleanup everything.
if ( 0 == m_pPidList->GetCount() )
this->Cleanup();
}
// This is needed for cases where the SDM has not yet received program create
// by the time that we need to detach (example: the managed attach succeeds,
// but some other attach step fails).
else
{
PROGNODE *pProgNode = NULL;
while ( pProgNode = pProgList->Next(pProgNode) )
{
CDebugProgram * pProgram = ((CDebugProgram *)pProgNode->data);
hRes = pProgram->Detach();
}
}
delete pProgList;
}
}
else
hRes = S_OK;
}
}
}
else
{
hRes = S_FALSE;
}
}
else
{
hRes = E_INVALIDARG;
}
return hRes;
}