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
36 #include "wine/list.h"
37 #include "mscoree_private.h"
38 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
43 static inline CorDebug *impl_from_ICorDebug( ICorDebug *iface )
45 return CONTAINING_RECORD(iface, CorDebug, ICorDebug_iface);
48 static inline CorDebug *impl_from_ICorDebugProcessEnum( ICorDebugProcessEnum *iface )
50 return CONTAINING_RECORD(iface, CorDebug, ICorDebugProcessEnum_iface);
53 static HRESULT WINAPI process_enum_QueryInterface(ICorDebugProcessEnum *iface, REFIID riid, void **ppvObject)
55 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
57 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
59 if ( IsEqualGUID( riid, &IID_ICorDebugProcessEnum ) ||
60 IsEqualGUID( riid, &IID_ICorDebugEnum ) ||
61 IsEqualGUID( riid, &IID_IUnknown ) )
63 *ppvObject = &This->ICorDebugProcessEnum_iface;
67 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
71 ICorDebug_AddRef(iface);
76 static ULONG WINAPI process_enum_AddRef(ICorDebugProcessEnum *iface)
78 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
79 TRACE("%p ref=%u\n", This, This->ref);
81 return ICorDebug_AddRef(&This->ICorDebug_iface);
84 static ULONG WINAPI process_enum_Release(ICorDebugProcessEnum *iface)
86 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
87 TRACE("%p ref=%u\n", This, This->ref);
89 return ICorDebug_Release(&This->ICorDebug_iface);
92 static HRESULT WINAPI process_enum_Skip(ICorDebugProcessEnum *iface, ULONG celt)
94 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
95 FIXME("stub %p\n", This);
99 static HRESULT WINAPI process_enum_Reset(ICorDebugProcessEnum *iface)
101 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
102 FIXME("stub %p\n", This);
106 static HRESULT WINAPI process_enum_Clone(ICorDebugProcessEnum *iface, ICorDebugEnum **ppEnum)
108 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
109 FIXME("stub %p %p\n", This, ppEnum);
113 static HRESULT WINAPI process_enum_GetCount(ICorDebugProcessEnum *iface, ULONG *pcelt)
115 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
116 TRACE("stub %p %p\n", This, pcelt);
121 *pcelt = list_count(&This->processes);
126 static HRESULT WINAPI process_enum_Next(ICorDebugProcessEnum *iface, ULONG celt,
127 ICorDebugProcess * processes[], ULONG *pceltFetched)
129 CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
130 FIXME("stub %p %d %p %p\n", This, celt, processes, pceltFetched);
134 static const struct ICorDebugProcessEnumVtbl processenum_vtbl =
136 process_enum_QueryInterface,
138 process_enum_Release,
142 process_enum_GetCount,
146 /*** IUnknown methods ***/
147 static HRESULT WINAPI CorDebug_QueryInterface(ICorDebug *iface, REFIID riid, void **ppvObject)
149 CorDebug *This = impl_from_ICorDebug( iface );
151 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
153 if ( IsEqualGUID( riid, &IID_ICorDebug ) ||
154 IsEqualGUID( riid, &IID_IUnknown ) )
156 *ppvObject = &This->ICorDebug_iface;
160 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
161 return E_NOINTERFACE;
164 ICorDebug_AddRef( iface );
169 static ULONG WINAPI CorDebug_AddRef(ICorDebug *iface)
171 CorDebug *This = impl_from_ICorDebug( iface );
172 ULONG ref = InterlockedIncrement(&This->ref);
174 TRACE("%p ref=%u\n", This, ref);
179 static ULONG WINAPI CorDebug_Release(ICorDebug *iface)
181 CorDebug *This = impl_from_ICorDebug( iface );
182 ULONG ref = InterlockedDecrement(&This->ref);
184 TRACE("%p ref=%u\n", This, ref);
188 if(!list_empty(&This->processes))
189 ERR("Processes haven't been removed Correctly\n");
191 if(This->runtimehost)
192 ICLRRuntimeHost_Release(This->runtimehost);
195 ICorDebugManagedCallback2_Release(This->pCallback2);
198 ICorDebugManagedCallback_Release(This->pCallback);
200 HeapFree(GetProcessHeap(), 0, This);
206 /*** ICorDebug methods ***/
207 static HRESULT WINAPI CorDebug_Initialize(ICorDebug *iface)
209 CorDebug *This = impl_from_ICorDebug( iface );
210 FIXME("stub %p\n", This);
214 static HRESULT WINAPI CorDebug_Terminate(ICorDebug *iface)
216 struct CorProcess *cursor, *cursor2;
217 CorDebug *This = impl_from_ICorDebug( iface );
218 FIXME("stub %p\n", This);
220 LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->processes, struct CorProcess, entry)
223 ICorDebugProcess_Release(cursor->pProcess);
225 list_remove(&cursor->entry);
226 HeapFree(GetProcessHeap(), 0, cursor);
232 static HRESULT WINAPI CorDebug_SetManagedHandler(ICorDebug *iface, ICorDebugManagedCallback *pCallback)
234 CorDebug *This = impl_from_ICorDebug( iface );
236 ICorDebugManagedCallback2 *pCallback2;
238 TRACE("%p (%p)\n", This, pCallback);
243 hr = ICorDebugManagedCallback_QueryInterface(pCallback, &IID_ICorDebugManagedCallback2, (void**)&pCallback2);
247 ICorDebugManagedCallback2_Release(This->pCallback2);
250 ICorDebugManagedCallback_Release(This->pCallback);
252 This->pCallback = pCallback;
253 This->pCallback2 = pCallback2;
255 ICorDebugManagedCallback_AddRef(This->pCallback);
259 WARN("Debugging without interface ICorDebugManagedCallback2 is currently not supported.\n");
265 static HRESULT WINAPI CorDebug_SetUnmanagedHandler(ICorDebug *iface, ICorDebugUnmanagedCallback *pCallback)
267 CorDebug *This = impl_from_ICorDebug( iface );
268 FIXME("stub %p %p\n", This, pCallback);
272 static HRESULT WINAPI CorDebug_CreateProcess(ICorDebug *iface, LPCWSTR lpApplicationName,
273 LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
274 LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
275 DWORD dwCreationFlags, PVOID lpEnvironment,LPCWSTR lpCurrentDirectory,
276 LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation,
277 CorDebugCreateProcessFlags debuggingFlags, ICorDebugProcess **ppProcess)
279 CorDebug *This = impl_from_ICorDebug( iface );
280 FIXME("stub %p %s %s %p %p %d %d %p %s %p %p %d %p\n", This, debugstr_w(lpApplicationName),
281 debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes,
282 bInheritHandles, dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory),
283 lpStartupInfo, lpProcessInformation, debuggingFlags, ppProcess);
287 static HRESULT WINAPI CorDebug_DebugActiveProcess(ICorDebug *iface, DWORD id, BOOL win32Attach,
288 ICorDebugProcess **ppProcess)
290 CorDebug *This = impl_from_ICorDebug( iface );
291 FIXME("stub %p %d %d %p\n", This, id, win32Attach, ppProcess);
295 static HRESULT WINAPI CorDebug_EnumerateProcesses( ICorDebug *iface, ICorDebugProcessEnum **ppProcess)
297 CorDebug *This = impl_from_ICorDebug( iface );
298 TRACE("stub %p %p\n", This, ppProcess);
303 *ppProcess = &This->ICorDebugProcessEnum_iface;
304 ICorDebugProcessEnum_AddRef(*ppProcess);
309 static HRESULT WINAPI CorDebug_GetProcess(ICorDebug *iface, DWORD dwProcessId, ICorDebugProcess **ppProcess)
311 CorDebug *This = impl_from_ICorDebug( iface );
312 FIXME("stub %p %d %p\n", This, dwProcessId, ppProcess);
316 static HRESULT WINAPI CorDebug_CanLaunchOrAttach(ICorDebug *iface, DWORD dwProcessId,
317 BOOL win32DebuggingEnabled)
319 CorDebug *This = impl_from_ICorDebug( iface );
320 FIXME("stub %p %d %d\n", This, dwProcessId, win32DebuggingEnabled);
324 static const struct ICorDebugVtbl cordebug_vtbl =
326 CorDebug_QueryInterface,
331 CorDebug_SetManagedHandler,
332 CorDebug_SetUnmanagedHandler,
333 CorDebug_CreateProcess,
334 CorDebug_DebugActiveProcess,
335 CorDebug_EnumerateProcesses,
337 CorDebug_CanLaunchOrAttach
340 HRESULT CorDebug_Create(ICLRRuntimeHost *runtimehost, IUnknown** ppUnk)
344 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
346 return E_OUTOFMEMORY;
348 This->ICorDebug_iface.lpVtbl = &cordebug_vtbl;
349 This->ICorDebugProcessEnum_iface.lpVtbl = &processenum_vtbl;
351 This->pCallback = NULL;
352 This->pCallback2 = NULL;
353 This->runtimehost = runtimehost;
355 list_init(&This->processes);
357 if(This->runtimehost)
358 ICLRRuntimeHost_AddRef(This->runtimehost);
360 *ppUnk = (IUnknown*)This;