IDebugProgramProvider2::WatchForProviderEvents
Permite que o processo seja notificado de eventos de porta.
Sintaxe
int WatchForProviderEvents(
enum_PROVIDER_FLAGS Flags,
IDebugDefaultPort2 pPort,
AD_PROCESS_ID ProcessId,
CONST_GUID_ARRAY EngineFilter,
ref Guid guidLaunchingEngine,
IDebugPortNotify2 pEventCallback
);
Parâmetros
Flags
[em] Uma combinação de sinalizadores da enumeração PROVIDER_FLAGS . Os seguintes sinalizadores são típicos para esta chamada:
Sinalizador | Descrição |
---|---|
PFLAG_REMOTE_PORT |
O chamador está sendo executado na máquina remota. |
PFLAG_DEBUGGEE |
O chamador está sendo depurado no momento (informações adicionais sobre marshalling são retornadas para cada nó). |
PFLAG_ATTACHED_TO_DEBUGGEE |
O chamador foi anexado, mas não iniciado pelo depurador. |
PFLAG_REASON_WATCH |
O chamador quer ficar atento aos acontecimentos. Se esse sinalizador não estiver definido. Em seguida, o evento de retorno de chamada é removido e o chamador não recebe mais notificações. |
pPort
[em] A porta em que o processo de chamada está sendo executado.
processId
[em] Uma estrutura AD_PROCESS_ID que contém a ID do processo que contém o programa em questão.
EngineFilter
[em] Uma matriz de GUIDs de mecanismos de depuração associados ao processo.
guidLaunchingEngine
[em] GUID do mecanismo de depuração que iniciou esse processo (se houver).
pEventCallback
[em] Um objeto IDebugPortNotify2 que recebe as notificações de evento.
Valor de retorno
Se tiver êxito, retornará S_OK
. Caso contrário, retornará um código de erro.
Comentários
Quando um chamador deseja remover um manipulador de eventos que foi estabelecido com uma chamada anterior para esse método, o chamador passa os mesmos parâmetros que fez na primeira vez, mas deixa o PFLAG_REASON_WATCH
sinalizador.
Exemplo
O exemplo a seguir mostra como implementar esse método para um objeto CDebugEngine que expõe a interface 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;
}