winebus.sys: Add missing keyboard free_device callback.
[wine.git] / dlls / mscoree / cordebug.c
blob15e7fad8fa50a730abd0f6309d157f995dc12583
1 /*
3 * Copyright 2011 Alistair Leslie-Hughes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "ole2.h"
31 #include "shellapi.h"
32 #include "mscoree.h"
33 #include "corhdr.h"
34 #include "metahost.h"
35 #include "cordebug.h"
36 #include "wine/list.h"
37 #include "mscoree_private.h"
38 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
43 typedef struct DebugProcess
45 ICorDebugProcess ICorDebugProcess_iface;
47 CorDebug *cordebug;
49 DWORD dwProcessID;
50 HANDLE handle;
51 HANDLE thread;
53 LONG ref;
54 } DebugProcess;
56 static inline CorDebug *impl_from_ICorDebug( ICorDebug *iface )
58 return CONTAINING_RECORD(iface, CorDebug, ICorDebug_iface);
61 static inline CorDebug *impl_from_ICorDebugProcessEnum( ICorDebugProcessEnum *iface )
63 return CONTAINING_RECORD(iface, CorDebug, ICorDebugProcessEnum_iface);
66 static inline DebugProcess *impl_from_ICorDebugProcess( ICorDebugProcess *iface )
68 return CONTAINING_RECORD(iface, DebugProcess, ICorDebugProcess_iface);
71 /* ICorDebugProcess Interface */
72 static HRESULT WINAPI cordebugprocess_QueryInterface(ICorDebugProcess *iface,
73 REFIID riid, void **ppvObject)
75 DebugProcess *This = impl_from_ICorDebugProcess(iface);
77 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
79 if ( IsEqualGUID( riid, &IID_ICorDebugProcess ) ||
80 IsEqualGUID( riid, &IID_ICorDebugController ) ||
81 IsEqualGUID( riid, &IID_IUnknown ) )
83 *ppvObject = &This->ICorDebugProcess_iface;
85 else
87 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
88 return E_NOINTERFACE;
91 ICorDebugProcess_AddRef(iface);
93 return S_OK;
96 static ULONG WINAPI cordebugprocess_AddRef(ICorDebugProcess *iface)
98 DebugProcess *This = impl_from_ICorDebugProcess(iface);
99 ULONG ref = InterlockedIncrement(&This->ref);
101 TRACE("%p ref=%u\n", This, ref);
103 return ref;
106 static ULONG WINAPI cordebugprocess_Release(ICorDebugProcess *iface)
108 DebugProcess *This = impl_from_ICorDebugProcess(iface);
109 ULONG ref = InterlockedDecrement(&This->ref);
111 TRACE("%p ref=%u\n", This, ref);
113 if (ref == 0)
115 if(This->handle)
116 CloseHandle(This->handle);
118 if(This->thread)
119 CloseHandle(This->thread);
121 if(This->cordebug)
122 ICorDebug_Release(&This->cordebug->ICorDebug_iface);
124 HeapFree(GetProcessHeap(), 0, This);
127 return ref;
130 static HRESULT WINAPI cordebugprocess_Stop(ICorDebugProcess *iface, DWORD dwTimeoutIgnored)
132 DebugProcess *This = impl_from_ICorDebugProcess(iface);
133 FIXME("stub %p\n", This);
134 return E_NOTIMPL;
137 static HRESULT WINAPI cordebugprocess_Continue(ICorDebugProcess *iface, BOOL fIsOutOfBand)
139 DebugProcess *This = impl_from_ICorDebugProcess(iface);
140 TRACE("%p\n", This);
142 if(This->thread)
143 ResumeThread(This->thread);
145 return S_OK;
148 static HRESULT WINAPI cordebugprocess_IsRunning(ICorDebugProcess *iface, BOOL *pbRunning)
150 DebugProcess *This = impl_from_ICorDebugProcess(iface);
151 FIXME("stub %p\n", This);
152 return E_NOTIMPL;
155 static HRESULT WINAPI cordebugprocess_HasQueuedCallbacks(ICorDebugProcess *iface,
156 ICorDebugThread *pThread, BOOL *pbQueued)
158 DebugProcess *This = impl_from_ICorDebugProcess(iface);
159 FIXME("stub %p\n", This);
160 return E_NOTIMPL;
163 static HRESULT WINAPI cordebugprocess_EnumerateThreads(ICorDebugProcess *iface,
164 ICorDebugThreadEnum **ppThreads)
166 DebugProcess *This = impl_from_ICorDebugProcess(iface);
167 FIXME("stub %p\n", This);
168 return E_NOTIMPL;
171 static HRESULT WINAPI cordebugprocess_SetAllThreadsDebugState(ICorDebugProcess *iface,
172 CorDebugThreadState state, ICorDebugThread *pExceptThisThread)
174 DebugProcess *This = impl_from_ICorDebugProcess(iface);
175 FIXME("stub %p\n", This);
176 return E_NOTIMPL;
179 static HRESULT WINAPI cordebugprocess_Detach(ICorDebugProcess *iface)
181 DebugProcess *This = impl_from_ICorDebugProcess(iface);
182 FIXME("stub %p\n", This);
183 return E_NOTIMPL;
186 static HRESULT WINAPI cordebugprocess_Terminate(ICorDebugProcess *iface, UINT exitCode)
188 DebugProcess *This = impl_from_ICorDebugProcess(iface);
189 BOOL ret = TRUE;
191 TRACE("%p\n", This);
193 if(This->handle)
195 ret = TerminateProcess(This->handle, exitCode);
196 CloseHandle(This->handle);
197 This->handle = NULL;
199 return ret ? S_OK : E_FAIL;
202 static HRESULT WINAPI cordebugprocess_CanCommitChanges(ICorDebugProcess *iface,
203 ULONG cSnapshots, ICorDebugEditAndContinueSnapshot * pSnapshots[],
204 ICorDebugErrorInfoEnum **pError)
206 DebugProcess *This = impl_from_ICorDebugProcess(iface);
207 FIXME("stub %p\n", This);
208 return E_NOTIMPL;
211 static HRESULT WINAPI cordebugprocess_CommitChanges(ICorDebugProcess *iface,
212 ULONG cSnapshots, ICorDebugEditAndContinueSnapshot * pSnapshots[],
213 ICorDebugErrorInfoEnum **pError)
215 DebugProcess *This = impl_from_ICorDebugProcess(iface);
216 FIXME("stub %p\n", This);
217 return E_NOTIMPL;
220 static HRESULT WINAPI cordebugprocess_GetID(ICorDebugProcess *iface, DWORD *pdwProcessId)
222 DebugProcess *This = impl_from_ICorDebugProcess(iface);
223 TRACE("%p\n", This);
225 if(!pdwProcessId)
226 return E_INVALIDARG;
228 *pdwProcessId = This->dwProcessID;
230 return S_OK;
233 static HRESULT WINAPI cordebugprocess_GetHandle(ICorDebugProcess *iface, HPROCESS *phProcessHandle)
235 DebugProcess *This = impl_from_ICorDebugProcess(iface);
236 TRACE("%p\n", This);
238 if(!phProcessHandle)
239 return E_INVALIDARG;
241 *phProcessHandle = This->handle;
243 return S_OK;
246 static HRESULT WINAPI cordebugprocess_GetThread(ICorDebugProcess *iface, DWORD dwThreadId,
247 ICorDebugThread **ppThread)
249 DebugProcess *This = impl_from_ICorDebugProcess(iface);
250 FIXME("stub %p\n", This);
251 return E_NOTIMPL;
254 static HRESULT WINAPI cordebugprocess_EnumerateObjects(ICorDebugProcess *iface,
255 ICorDebugObjectEnum **ppObjects)
257 DebugProcess *This = impl_from_ICorDebugProcess(iface);
258 FIXME("stub %p\n", This);
259 return E_NOTIMPL;
262 static HRESULT WINAPI cordebugprocess_IsTransitionStub(ICorDebugProcess *iface,
263 CORDB_ADDRESS address, BOOL *pbTransitionStub)
265 DebugProcess *This = impl_from_ICorDebugProcess(iface);
266 FIXME("stub %p\n", This);
267 return E_NOTIMPL;
270 static HRESULT WINAPI cordebugprocess_IsOSSuspended(ICorDebugProcess *iface,
271 DWORD threadID, BOOL *pbSuspended)
273 DebugProcess *This = impl_from_ICorDebugProcess(iface);
274 FIXME("stub %p\n", This);
275 return E_NOTIMPL;
278 static HRESULT WINAPI cordebugprocess_GetThreadContext(ICorDebugProcess *iface,
279 DWORD threadID, ULONG32 contextSize, BYTE context[])
281 DebugProcess *This = impl_from_ICorDebugProcess(iface);
282 FIXME("stub %p\n", This);
283 return E_NOTIMPL;
286 static HRESULT WINAPI cordebugprocess_SetThreadContext(ICorDebugProcess *iface,
287 DWORD threadID, ULONG32 contextSize, BYTE context[])
289 DebugProcess *This = impl_from_ICorDebugProcess(iface);
290 FIXME("stub %p\n", This);
291 return E_NOTIMPL;
294 static HRESULT WINAPI cordebugprocess_ReadMemory(ICorDebugProcess *iface,
295 CORDB_ADDRESS address, DWORD size, BYTE buffer[],
296 SIZE_T *read)
298 DebugProcess *This = impl_from_ICorDebugProcess(iface);
299 FIXME("stub %p\n", This);
300 return E_NOTIMPL;
303 static HRESULT WINAPI cordebugprocess_WriteMemory(ICorDebugProcess *iface,
304 CORDB_ADDRESS address, DWORD size, BYTE buffer[],
305 SIZE_T *written)
307 DebugProcess *This = impl_from_ICorDebugProcess(iface);
308 FIXME("stub %p\n", This);
309 return E_NOTIMPL;
312 static HRESULT WINAPI cordebugprocess_ClearCurrentException(ICorDebugProcess *iface,
313 DWORD threadID)
315 DebugProcess *This = impl_from_ICorDebugProcess(iface);
316 FIXME("stub %p\n", This);
317 return E_NOTIMPL;
320 static HRESULT WINAPI cordebugprocess_EnableLogMessages(ICorDebugProcess *iface,
321 BOOL fOnOff)
323 DebugProcess *This = impl_from_ICorDebugProcess(iface);
324 FIXME("stub %p\n", This);
325 return E_NOTIMPL;
328 static HRESULT WINAPI cordebugprocess_ModifyLogSwitch(ICorDebugProcess *iface,
329 WCHAR *pLogSwitchName, LONG lLevel)
331 DebugProcess *This = impl_from_ICorDebugProcess(iface);
332 FIXME("stub %p\n", This);
333 return E_NOTIMPL;
336 static HRESULT WINAPI cordebugprocess_EnumerateAppDomains(ICorDebugProcess *iface,
337 ICorDebugAppDomainEnum **ppAppDomains)
339 DebugProcess *This = impl_from_ICorDebugProcess(iface);
340 FIXME("stub %p\n", This);
341 return E_NOTIMPL;
344 static HRESULT WINAPI cordebugprocess_GetObject(ICorDebugProcess *iface,
345 ICorDebugValue **ppObject)
347 DebugProcess *This = impl_from_ICorDebugProcess(iface);
348 FIXME("stub %p\n", This);
349 return E_NOTIMPL;
352 static HRESULT WINAPI cordebugprocess_ThreadForFiberCookie(ICorDebugProcess *iface,
353 DWORD fiberCookie, ICorDebugThread **ppThread)
355 DebugProcess *This = impl_from_ICorDebugProcess(iface);
356 FIXME("stub %p\n", This);
357 return E_NOTIMPL;
360 static HRESULT WINAPI cordebugprocess_GetHelperThreadID(ICorDebugProcess *iface,
361 DWORD *pThreadID)
363 DebugProcess *This = impl_from_ICorDebugProcess(iface);
364 FIXME("stub %p\n", This);
365 return E_NOTIMPL;
369 /***************************************/
370 static const ICorDebugProcessVtbl cordebugprocessVtbl = {
371 cordebugprocess_QueryInterface,
372 cordebugprocess_AddRef,
373 cordebugprocess_Release,
374 cordebugprocess_Stop,
375 cordebugprocess_Continue,
376 cordebugprocess_IsRunning,
377 cordebugprocess_HasQueuedCallbacks,
378 cordebugprocess_EnumerateThreads,
379 cordebugprocess_SetAllThreadsDebugState,
380 cordebugprocess_Detach,
381 cordebugprocess_Terminate,
382 cordebugprocess_CanCommitChanges,
383 cordebugprocess_CommitChanges,
384 cordebugprocess_GetID,
385 cordebugprocess_GetHandle,
386 cordebugprocess_GetThread,
387 cordebugprocess_EnumerateObjects,
388 cordebugprocess_IsTransitionStub,
389 cordebugprocess_IsOSSuspended,
390 cordebugprocess_GetThreadContext,
391 cordebugprocess_SetThreadContext,
392 cordebugprocess_ReadMemory,
393 cordebugprocess_WriteMemory,
394 cordebugprocess_ClearCurrentException,
395 cordebugprocess_EnableLogMessages,
396 cordebugprocess_ModifyLogSwitch,
397 cordebugprocess_EnumerateAppDomains,
398 cordebugprocess_GetObject,
399 cordebugprocess_ThreadForFiberCookie,
400 cordebugprocess_GetHelperThreadID
404 static HRESULT CorDebugProcess_Create(CorDebug *cordebug, IUnknown** ppUnk, LPPROCESS_INFORMATION lpProcessInformation)
406 DebugProcess *This;
408 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
409 if ( !This )
410 return E_OUTOFMEMORY;
412 if(!DuplicateHandle(GetCurrentProcess(), lpProcessInformation->hProcess,
413 GetCurrentProcess(), &This->handle, 0, FALSE, DUPLICATE_SAME_ACCESS))
415 ERR("Failed to duplicate process handle\n");
416 HeapFree(GetProcessHeap(), 0, This);
417 return E_FAIL;
419 if(!DuplicateHandle(GetCurrentProcess(), lpProcessInformation->hThread,
420 GetCurrentProcess(), &This->thread, 0, FALSE, DUPLICATE_SAME_ACCESS))
422 CloseHandle(This->handle);
424 ERR("Failed to duplicate thread handle\n");
425 HeapFree(GetProcessHeap(), 0, This);
426 return E_FAIL;
429 This->ICorDebugProcess_iface.lpVtbl = &cordebugprocessVtbl;
430 This->ref = 1;
431 This->cordebug = cordebug;
432 This->dwProcessID = lpProcessInformation->dwProcessId;
434 if(This->cordebug)
435 ICorDebug_AddRef(&This->cordebug->ICorDebug_iface);
437 *ppUnk = (IUnknown*)&This->ICorDebugProcess_iface;
439 return S_OK;
442 /* ICorDebugProcessEnum Interface */
443 static HRESULT WINAPI process_enum_QueryInterface(ICorDebugProcessEnum *iface, REFIID riid, void **ppvObject)
445 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
447 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
449 if ( IsEqualGUID( riid, &IID_ICorDebugProcessEnum ) ||
450 IsEqualGUID( riid, &IID_ICorDebugEnum ) ||
451 IsEqualGUID( riid, &IID_IUnknown ) )
453 *ppvObject = &This->ICorDebugProcessEnum_iface;
455 else
457 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
458 return E_NOINTERFACE;
461 ICorDebugProcessEnum_AddRef(iface);
463 return S_OK;
466 static ULONG WINAPI process_enum_AddRef(ICorDebugProcessEnum *iface)
468 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
469 TRACE("%p ref=%u\n", This, This->ref);
471 return ICorDebug_AddRef(&This->ICorDebug_iface);
474 static ULONG WINAPI process_enum_Release(ICorDebugProcessEnum *iface)
476 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
477 TRACE("%p ref=%u\n", This, This->ref);
479 return ICorDebug_Release(&This->ICorDebug_iface);
482 static HRESULT WINAPI process_enum_Skip(ICorDebugProcessEnum *iface, ULONG celt)
484 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
485 FIXME("stub %p\n", This);
486 return E_NOTIMPL;
489 static HRESULT WINAPI process_enum_Reset(ICorDebugProcessEnum *iface)
491 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
492 FIXME("stub %p\n", This);
493 return E_NOTIMPL;
496 static HRESULT WINAPI process_enum_Clone(ICorDebugProcessEnum *iface, ICorDebugEnum **ppEnum)
498 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
499 FIXME("stub %p %p\n", This, ppEnum);
500 return E_NOTIMPL;
503 static HRESULT WINAPI process_enum_GetCount(ICorDebugProcessEnum *iface, ULONG *pcelt)
505 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
506 TRACE("stub %p %p\n", This, pcelt);
508 if(!pcelt)
509 return E_INVALIDARG;
511 *pcelt = list_count(&This->processes);
513 return S_OK;
516 static HRESULT WINAPI process_enum_Next(ICorDebugProcessEnum *iface, ULONG celt,
517 ICorDebugProcess * processes[], ULONG *pceltFetched)
519 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
520 FIXME("stub %p %d %p %p\n", This, celt, processes, pceltFetched);
521 return E_NOTIMPL;
524 static const struct ICorDebugProcessEnumVtbl processenum_vtbl =
526 process_enum_QueryInterface,
527 process_enum_AddRef,
528 process_enum_Release,
529 process_enum_Skip,
530 process_enum_Reset,
531 process_enum_Clone,
532 process_enum_GetCount,
533 process_enum_Next
536 /*** IUnknown methods ***/
537 static HRESULT WINAPI CorDebug_QueryInterface(ICorDebug *iface, REFIID riid, void **ppvObject)
539 CorDebug *This = impl_from_ICorDebug( iface );
541 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
543 if ( IsEqualGUID( riid, &IID_ICorDebug ) ||
544 IsEqualGUID( riid, &IID_IUnknown ) )
546 *ppvObject = &This->ICorDebug_iface;
548 else
550 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
551 return E_NOINTERFACE;
554 ICorDebug_AddRef( iface );
556 return S_OK;
559 static ULONG WINAPI CorDebug_AddRef(ICorDebug *iface)
561 CorDebug *This = impl_from_ICorDebug( iface );
562 ULONG ref = InterlockedIncrement(&This->ref);
564 TRACE("%p ref=%u\n", This, ref);
566 return ref;
569 static ULONG WINAPI CorDebug_Release(ICorDebug *iface)
571 CorDebug *This = impl_from_ICorDebug( iface );
572 ULONG ref = InterlockedDecrement(&This->ref);
574 TRACE("%p ref=%u\n", This, ref);
576 if (ref == 0)
578 if(!list_empty(&This->processes))
579 ERR("Processes haven't been removed Correctly\n");
581 if(This->runtimehost)
582 ICLRRuntimeHost_Release(This->runtimehost);
584 if(This->pCallback2)
585 ICorDebugManagedCallback2_Release(This->pCallback2);
587 if(This->pCallback)
588 ICorDebugManagedCallback_Release(This->pCallback);
590 HeapFree(GetProcessHeap(), 0, This);
593 return ref;
596 /*** ICorDebug methods ***/
597 static HRESULT WINAPI CorDebug_Initialize(ICorDebug *iface)
599 CorDebug *This = impl_from_ICorDebug( iface );
600 FIXME("stub %p\n", This);
601 return S_OK;
604 static HRESULT WINAPI CorDebug_Terminate(ICorDebug *iface)
606 struct CorProcess *cursor, *cursor2;
607 CorDebug *This = impl_from_ICorDebug( iface );
608 TRACE("stub %p\n", This);
610 LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->processes, struct CorProcess, entry)
612 if(cursor->pProcess)
614 ICorDebugProcess_Terminate(cursor->pProcess, 0);
615 ICorDebugProcess_Release(cursor->pProcess);
618 list_remove(&cursor->entry);
619 HeapFree(GetProcessHeap(), 0, cursor);
622 return S_OK;
625 static HRESULT WINAPI CorDebug_SetManagedHandler(ICorDebug *iface, ICorDebugManagedCallback *pCallback)
627 CorDebug *This = impl_from_ICorDebug( iface );
628 HRESULT hr;
629 ICorDebugManagedCallback2 *pCallback2;
631 TRACE("%p (%p)\n", This, pCallback);
633 if(!pCallback)
634 return E_INVALIDARG;
636 hr = ICorDebugManagedCallback_QueryInterface(pCallback, &IID_ICorDebugManagedCallback2, (void**)&pCallback2);
637 if(hr == S_OK)
639 if(This->pCallback2)
640 ICorDebugManagedCallback2_Release(This->pCallback2);
642 if(This->pCallback)
643 ICorDebugManagedCallback_Release(This->pCallback);
645 This->pCallback = pCallback;
646 This->pCallback2 = pCallback2;
648 ICorDebugManagedCallback_AddRef(This->pCallback);
650 else
652 WARN("Debugging without interface ICorDebugManagedCallback2 is currently not supported.\n");
655 return hr;
658 static HRESULT WINAPI CorDebug_SetUnmanagedHandler(ICorDebug *iface, ICorDebugUnmanagedCallback *pCallback)
660 CorDebug *This = impl_from_ICorDebug( iface );
661 FIXME("stub %p %p\n", This, pCallback);
662 return E_NOTIMPL;
665 static HRESULT WINAPI CorDebug_CreateProcess(ICorDebug *iface, LPCWSTR lpApplicationName,
666 LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
667 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
668 DWORD dwCreationFlags, PVOID lpEnvironment,LPCWSTR lpCurrentDirectory,
669 LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation,
670 CorDebugCreateProcessFlags debuggingFlags, ICorDebugProcess **ppProcess)
672 CorDebug *This = impl_from_ICorDebug( iface );
673 ICorDebugProcess *pDebugProcess;
674 HRESULT hr;
676 TRACE("stub %p %s %s %p %p %d %d %p %s %p %p %d %p\n", This, debugstr_w(lpApplicationName),
677 debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes,
678 bInheritHandles, dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory),
679 lpStartupInfo, lpProcessInformation, debuggingFlags, ppProcess);
681 if(CreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
682 bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory,
683 lpStartupInfo, lpProcessInformation))
685 hr = CorDebugProcess_Create(This, (IUnknown**)&pDebugProcess, lpProcessInformation);
686 if(hr == S_OK)
688 struct CorProcess *new_process = HeapAlloc( GetProcessHeap(), 0, sizeof(CorProcess) );
690 new_process->pProcess = pDebugProcess;
691 list_add_tail(&This->processes, &new_process->entry);
693 ICorDebugProcess_AddRef(pDebugProcess);
694 *ppProcess = pDebugProcess;
696 if(This->pCallback)
697 ICorDebugManagedCallback_CreateProcess(This->pCallback, pDebugProcess);
699 else
701 TerminateProcess(lpProcessInformation->hProcess, 0);
704 else
705 hr = E_FAIL;
707 return hr;
710 static HRESULT WINAPI CorDebug_DebugActiveProcess(ICorDebug *iface, DWORD id, BOOL win32Attach,
711 ICorDebugProcess **ppProcess)
713 CorDebug *This = impl_from_ICorDebug( iface );
714 FIXME("stub %p %d %d %p\n", This, id, win32Attach, ppProcess);
715 return E_NOTIMPL;
718 static HRESULT WINAPI CorDebug_EnumerateProcesses( ICorDebug *iface, ICorDebugProcessEnum **ppProcess)
720 CorDebug *This = impl_from_ICorDebug( iface );
721 TRACE("stub %p %p\n", This, ppProcess);
723 if(!ppProcess)
724 return E_INVALIDARG;
726 *ppProcess = &This->ICorDebugProcessEnum_iface;
727 ICorDebugProcessEnum_AddRef(*ppProcess);
729 return S_OK;
732 static HRESULT WINAPI CorDebug_GetProcess(ICorDebug *iface, DWORD dwProcessId, ICorDebugProcess **ppProcess)
734 CorDebug *This = impl_from_ICorDebug( iface );
735 FIXME("stub %p %d %p\n", This, dwProcessId, ppProcess);
736 return E_NOTIMPL;
739 static HRESULT WINAPI CorDebug_CanLaunchOrAttach(ICorDebug *iface, DWORD dwProcessId,
740 BOOL win32DebuggingEnabled)
742 CorDebug *This = impl_from_ICorDebug( iface );
743 FIXME("stub %p %d %d\n", This, dwProcessId, win32DebuggingEnabled);
744 return S_OK;
747 static const struct ICorDebugVtbl cordebug_vtbl =
749 CorDebug_QueryInterface,
750 CorDebug_AddRef,
751 CorDebug_Release,
752 CorDebug_Initialize,
753 CorDebug_Terminate,
754 CorDebug_SetManagedHandler,
755 CorDebug_SetUnmanagedHandler,
756 CorDebug_CreateProcess,
757 CorDebug_DebugActiveProcess,
758 CorDebug_EnumerateProcesses,
759 CorDebug_GetProcess,
760 CorDebug_CanLaunchOrAttach
763 HRESULT CorDebug_Create(ICLRRuntimeHost *runtimehost, IUnknown** ppUnk)
765 CorDebug *This;
767 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
768 if ( !This )
769 return E_OUTOFMEMORY;
771 This->ICorDebug_iface.lpVtbl = &cordebug_vtbl;
772 This->ICorDebugProcessEnum_iface.lpVtbl = &processenum_vtbl;
773 This->ref = 1;
774 This->pCallback = NULL;
775 This->pCallback2 = NULL;
776 This->runtimehost = runtimehost;
778 list_init(&This->processes);
780 if(This->runtimehost)
781 ICLRRuntimeHost_AddRef(This->runtimehost);
783 *ppUnk = (IUnknown*)&This->ICorDebug_iface;
785 return S_OK;