ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

cordebug.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright 2011 Alistair Leslie-Hughes
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #define COBJMACROS
00021 
00022 #include <stdarg.h>
00023 
00024 #include "windef.h"
00025 #include "winbase.h"
00026 
00027 #include "winuser.h"
00028 #include "winnls.h"
00029 #include "winreg.h"
00030 #include "ole2.h"
00031 #include "shellapi.h"
00032 #include "mscoree.h"
00033 #include "corhdr.h"
00034 #include "metahost.h"
00035 #include "cordebug.h"
00036 #include "wine/list.h"
00037 #include "mscoree_private.h"
00038 #include "wine/debug.h"
00039 
00040 
00041 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
00042 
00043 typedef struct DebugProcess
00044 {
00045     ICorDebugProcess ICorDebugProcess_iface;
00046 
00047     CorDebug *cordebug;
00048 
00049     DWORD dwProcessID;
00050     HANDLE handle;
00051     HANDLE thread;
00052 
00053     LONG ref;
00054 } DebugProcess;
00055 
00056 static inline CorDebug *impl_from_ICorDebug( ICorDebug *iface )
00057 {
00058     return CONTAINING_RECORD(iface, CorDebug, ICorDebug_iface);
00059 }
00060 
00061 static inline CorDebug *impl_from_ICorDebugProcessEnum( ICorDebugProcessEnum *iface )
00062 {
00063     return CONTAINING_RECORD(iface, CorDebug, ICorDebugProcessEnum_iface);
00064 }
00065 
00066 static inline DebugProcess *impl_from_ICorDebugProcess( ICorDebugProcess *iface )
00067 {
00068     return CONTAINING_RECORD(iface, DebugProcess, ICorDebugProcess_iface);
00069 }
00070 
00071 /* ICorDebugProcess Interface */
00072 static HRESULT WINAPI cordebugprocess_QueryInterface(ICorDebugProcess *iface,
00073                 REFIID riid, void **ppvObject)
00074 {
00075     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00076 
00077     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
00078 
00079     if ( IsEqualGUID( riid, &IID_ICorDebugProcess ) ||
00080          IsEqualGUID( riid, &IID_ICorDebugController ) ||
00081          IsEqualGUID( riid, &IID_IUnknown ) )
00082     {
00083         *ppvObject = &This->ICorDebugProcess_iface;
00084     }
00085     else
00086     {
00087         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
00088         return E_NOINTERFACE;
00089     }
00090 
00091     ICorDebug_AddRef(iface);
00092 
00093     return S_OK;
00094 }
00095 
00096 static ULONG WINAPI cordebugprocess_AddRef(ICorDebugProcess *iface)
00097 {
00098     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00099     ULONG ref = InterlockedIncrement(&This->ref);
00100 
00101     TRACE("%p ref=%u\n", This, ref);
00102 
00103     return ref;
00104 }
00105 
00106 static ULONG WINAPI cordebugprocess_Release(ICorDebugProcess *iface)
00107 {
00108     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00109     ULONG ref = InterlockedDecrement(&This->ref);
00110 
00111     TRACE("%p ref=%u\n", This, ref);
00112 
00113     if (ref == 0)
00114     {
00115         if(This->handle)
00116             CloseHandle(This->handle);
00117 
00118         if(This->thread)
00119             CloseHandle(This->thread);
00120 
00121         if(This->cordebug)
00122             ICorDebug_Release(&This->cordebug->ICorDebug_iface);
00123 
00124         HeapFree(GetProcessHeap(), 0, This);
00125     }
00126 
00127     return ref;
00128 }
00129 
00130 static HRESULT WINAPI cordebugprocess_Stop(ICorDebugProcess *iface, DWORD dwTimeoutIgnored)
00131 {
00132     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00133     FIXME("stub %p\n", This);
00134     return E_NOTIMPL;
00135 }
00136 
00137 static HRESULT WINAPI cordebugprocess_Continue(ICorDebugProcess *iface, BOOL fIsOutOfBand)
00138 {
00139     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00140     TRACE("%p\n", This);
00141 
00142     if(This->thread)
00143         ResumeThread(This->thread);
00144 
00145     return S_OK;
00146 }
00147 
00148 static HRESULT WINAPI cordebugprocess_IsRunning(ICorDebugProcess *iface, BOOL *pbRunning)
00149 {
00150     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00151     FIXME("stub %p\n", This);
00152     return E_NOTIMPL;
00153 }
00154 
00155 static HRESULT WINAPI cordebugprocess_HasQueuedCallbacks(ICorDebugProcess *iface,
00156                 ICorDebugThread *pThread, BOOL *pbQueued)
00157 {
00158     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00159     FIXME("stub %p\n", This);
00160     return E_NOTIMPL;
00161 }
00162 
00163 static HRESULT WINAPI cordebugprocess_EnumerateThreads(ICorDebugProcess *iface,
00164                 ICorDebugThreadEnum **ppThreads)
00165 {
00166     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00167     FIXME("stub %p\n", This);
00168     return E_NOTIMPL;
00169 }
00170 
00171 static HRESULT WINAPI cordebugprocess_SetAllThreadsDebugState(ICorDebugProcess *iface,
00172                 CorDebugThreadState state, ICorDebugThread *pExceptThisThread)
00173 {
00174     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00175     FIXME("stub %p\n", This);
00176     return E_NOTIMPL;
00177 }
00178 
00179 static HRESULT WINAPI cordebugprocess_Detach(ICorDebugProcess *iface)
00180 {
00181     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00182     FIXME("stub %p\n", This);
00183     return E_NOTIMPL;
00184 }
00185 
00186 static HRESULT WINAPI cordebugprocess_Terminate(ICorDebugProcess *iface, UINT exitCode)
00187 {
00188     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00189     BOOL ret = TRUE;
00190 
00191     TRACE("%p\n", This);
00192 
00193     if(This->handle)
00194     {
00195         ret = TerminateProcess(This->handle, exitCode);
00196         CloseHandle(This->handle);
00197         This->handle = NULL;
00198     }
00199     return ret ? S_OK : E_FAIL;
00200 }
00201 
00202 static HRESULT WINAPI cordebugprocess_CanCommitChanges(ICorDebugProcess *iface,
00203                 ULONG cSnapshots, ICorDebugEditAndContinueSnapshot * pSnapshots[],
00204                 ICorDebugErrorInfoEnum **pError)
00205 {
00206     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00207     FIXME("stub %p\n", This);
00208     return E_NOTIMPL;
00209 }
00210 
00211 static HRESULT WINAPI cordebugprocess_CommitChanges(ICorDebugProcess *iface,
00212                 ULONG cSnapshots, ICorDebugEditAndContinueSnapshot * pSnapshots[],
00213                 ICorDebugErrorInfoEnum **pError)
00214 {
00215     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00216     FIXME("stub %p\n", This);
00217     return E_NOTIMPL;
00218 }
00219 
00220 static HRESULT WINAPI cordebugprocess_GetID(ICorDebugProcess *iface, DWORD *pdwProcessId)
00221 {
00222     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00223     TRACE("%p\n", This);
00224 
00225     if(!pdwProcessId)
00226         return E_INVALIDARG;
00227 
00228     *pdwProcessId = This->dwProcessID;
00229 
00230     return S_OK;
00231 }
00232 
00233 static HRESULT WINAPI cordebugprocess_GetHandle(ICorDebugProcess *iface, HPROCESS *phProcessHandle)
00234 {
00235     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00236     TRACE("%p\n", This);
00237 
00238     if(!phProcessHandle)
00239         return E_INVALIDARG;
00240 
00241     *phProcessHandle = This->handle;
00242 
00243     return S_OK;
00244 }
00245 
00246 static HRESULT WINAPI cordebugprocess_GetThread(ICorDebugProcess *iface, DWORD dwThreadId,
00247                 ICorDebugThread **ppThread)
00248 {
00249     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00250     FIXME("stub %p\n", This);
00251     return E_NOTIMPL;
00252 }
00253 
00254 static HRESULT WINAPI cordebugprocess_EnumerateObjects(ICorDebugProcess *iface,
00255                 ICorDebugObjectEnum **ppObjects)
00256 {
00257     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00258     FIXME("stub %p\n", This);
00259     return E_NOTIMPL;
00260 }
00261 
00262 static HRESULT WINAPI cordebugprocess_IsTransitionStub(ICorDebugProcess *iface,
00263                 CORDB_ADDRESS address, BOOL *pbTransitionStub)
00264 {
00265     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00266     FIXME("stub %p\n", This);
00267     return E_NOTIMPL;
00268 }
00269 
00270 static HRESULT WINAPI cordebugprocess_IsOSSuspended(ICorDebugProcess *iface,
00271                 DWORD threadID, BOOL *pbSuspended)
00272 {
00273     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00274     FIXME("stub %p\n", This);
00275     return E_NOTIMPL;
00276 }
00277 
00278 static HRESULT WINAPI cordebugprocess_GetThreadContext(ICorDebugProcess *iface,
00279                 DWORD threadID, ULONG32 contextSize, BYTE context[])
00280 {
00281     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00282     FIXME("stub %p\n", This);
00283     return E_NOTIMPL;
00284 }
00285 
00286 static HRESULT WINAPI cordebugprocess_SetThreadContext(ICorDebugProcess *iface,
00287                 DWORD threadID, ULONG32 contextSize, BYTE context[])
00288 {
00289     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00290     FIXME("stub %p\n", This);
00291     return E_NOTIMPL;
00292 }
00293 
00294 static HRESULT WINAPI cordebugprocess_ReadMemory(ICorDebugProcess *iface,
00295                 CORDB_ADDRESS address, DWORD size, BYTE buffer[],
00296                 SIZE_T *read)
00297 {
00298     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00299     FIXME("stub %p\n", This);
00300     return E_NOTIMPL;
00301 }
00302 
00303 static HRESULT WINAPI cordebugprocess_WriteMemory(ICorDebugProcess *iface,
00304                 CORDB_ADDRESS address, DWORD size, BYTE buffer[],
00305                 SIZE_T *written)
00306 {
00307     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00308     FIXME("stub %p\n", This);
00309     return E_NOTIMPL;
00310 }
00311 
00312 static HRESULT WINAPI cordebugprocess_ClearCurrentException(ICorDebugProcess *iface,
00313                 DWORD threadID)
00314 {
00315     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00316     FIXME("stub %p\n", This);
00317     return E_NOTIMPL;
00318 }
00319 
00320 static HRESULT WINAPI cordebugprocess_EnableLogMessages(ICorDebugProcess *iface,
00321                 BOOL fOnOff)
00322 {
00323     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00324     FIXME("stub %p\n", This);
00325     return E_NOTIMPL;
00326 }
00327 
00328 static HRESULT WINAPI cordebugprocess_ModifyLogSwitch(ICorDebugProcess *iface,
00329                 WCHAR *pLogSwitchName, LONG lLevel)
00330 {
00331     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00332     FIXME("stub %p\n", This);
00333     return E_NOTIMPL;
00334 }
00335 
00336 static HRESULT WINAPI cordebugprocess_EnumerateAppDomains(ICorDebugProcess *iface,
00337                 ICorDebugAppDomainEnum **ppAppDomains)
00338 {
00339     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00340     FIXME("stub %p\n", This);
00341     return E_NOTIMPL;
00342 }
00343 
00344 static HRESULT WINAPI cordebugprocess_GetObject(ICorDebugProcess *iface,
00345                 ICorDebugValue **ppObject)
00346 {
00347     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00348     FIXME("stub %p\n", This);
00349     return E_NOTIMPL;
00350 }
00351 
00352 static HRESULT WINAPI cordebugprocess_ThreadForFiberCookie(ICorDebugProcess *iface,
00353                 DWORD fiberCookie, ICorDebugThread **ppThread)
00354 {
00355     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00356     FIXME("stub %p\n", This);
00357     return E_NOTIMPL;
00358 }
00359 
00360 static HRESULT WINAPI cordebugprocess_GetHelperThreadID(ICorDebugProcess *iface,
00361                 DWORD *pThreadID)
00362 {
00363     DebugProcess *This = impl_from_ICorDebugProcess(iface);
00364     FIXME("stub %p\n", This);
00365     return E_NOTIMPL;
00366 }
00367 
00368 
00369 /***************************************/
00370 static const ICorDebugProcessVtbl cordebugprocessVtbl = {
00371     cordebugprocess_QueryInterface,
00372     cordebugprocess_AddRef,
00373     cordebugprocess_Release,
00374     cordebugprocess_Stop,
00375     cordebugprocess_Continue,
00376     cordebugprocess_IsRunning,
00377     cordebugprocess_HasQueuedCallbacks,
00378     cordebugprocess_EnumerateThreads,
00379     cordebugprocess_SetAllThreadsDebugState,
00380     cordebugprocess_Detach,
00381     cordebugprocess_Terminate,
00382     cordebugprocess_CanCommitChanges,
00383     cordebugprocess_CommitChanges,
00384     cordebugprocess_GetID,
00385     cordebugprocess_GetHandle,
00386     cordebugprocess_GetThread,
00387     cordebugprocess_EnumerateObjects,
00388     cordebugprocess_IsTransitionStub,
00389     cordebugprocess_IsOSSuspended,
00390     cordebugprocess_GetThreadContext,
00391     cordebugprocess_SetThreadContext,
00392     cordebugprocess_ReadMemory,
00393     cordebugprocess_WriteMemory,
00394     cordebugprocess_ClearCurrentException,
00395     cordebugprocess_EnableLogMessages,
00396     cordebugprocess_ModifyLogSwitch,
00397     cordebugprocess_EnumerateAppDomains,
00398     cordebugprocess_GetObject,
00399     cordebugprocess_ThreadForFiberCookie,
00400     cordebugprocess_GetHelperThreadID
00401 };
00402 
00403 
00404 static HRESULT CorDebugProcess_Create(CorDebug *cordebug, IUnknown** ppUnk, LPPROCESS_INFORMATION lpProcessInformation)
00405 {
00406     DebugProcess *This;
00407 
00408     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
00409     if ( !This )
00410         return E_OUTOFMEMORY;
00411 
00412     if(!DuplicateHandle(GetCurrentProcess(), lpProcessInformation->hProcess,
00413                     GetCurrentProcess(), &This->handle, 0, FALSE, DUPLICATE_SAME_ACCESS))
00414     {
00415         ERR("Failed to duplicate process handle\n");
00416         HeapFree(GetProcessHeap(), 0, This);
00417         return E_FAIL;
00418     }
00419     if(!DuplicateHandle(GetCurrentProcess(), lpProcessInformation->hThread,
00420                     GetCurrentProcess(), &This->thread, 0, FALSE, DUPLICATE_SAME_ACCESS))
00421     {
00422         CloseHandle(This->handle);
00423 
00424         ERR("Failed to duplicate thread handle\n");
00425         HeapFree(GetProcessHeap(), 0, This);
00426         return E_FAIL;
00427     }
00428 
00429     This->ICorDebugProcess_iface.lpVtbl = &cordebugprocessVtbl;
00430     This->ref = 1;
00431     This->cordebug = cordebug;
00432     This->dwProcessID = lpProcessInformation->dwProcessId;
00433 
00434     if(This->cordebug)
00435         ICorDebug_AddRef(&This->cordebug->ICorDebug_iface);
00436 
00437     *ppUnk = (IUnknown*)This;
00438 
00439     return S_OK;
00440 }
00441 
00442 /* ICorDebugProcessEnum Interface */
00443 static HRESULT WINAPI process_enum_QueryInterface(ICorDebugProcessEnum *iface, REFIID riid, void **ppvObject)
00444 {
00445     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00446 
00447     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
00448 
00449     if ( IsEqualGUID( riid, &IID_ICorDebugProcessEnum ) ||
00450          IsEqualGUID( riid, &IID_ICorDebugEnum ) ||
00451          IsEqualGUID( riid, &IID_IUnknown ) )
00452     {
00453         *ppvObject = &This->ICorDebugProcessEnum_iface;
00454     }
00455     else
00456     {
00457         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
00458         return E_NOINTERFACE;
00459     }
00460 
00461     ICorDebug_AddRef(iface);
00462 
00463     return S_OK;
00464 }
00465 
00466 static ULONG WINAPI process_enum_AddRef(ICorDebugProcessEnum *iface)
00467 {
00468     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00469     TRACE("%p ref=%u\n", This, This->ref);
00470 
00471     return ICorDebug_AddRef(&This->ICorDebug_iface);
00472 }
00473 
00474 static ULONG WINAPI process_enum_Release(ICorDebugProcessEnum *iface)
00475 {
00476     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00477     TRACE("%p ref=%u\n", This, This->ref);
00478 
00479     return ICorDebug_Release(&This->ICorDebug_iface);
00480 }
00481 
00482 static HRESULT WINAPI process_enum_Skip(ICorDebugProcessEnum *iface, ULONG celt)
00483 {
00484     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00485     FIXME("stub %p\n", This);
00486     return E_NOTIMPL;
00487 }
00488 
00489 static HRESULT WINAPI process_enum_Reset(ICorDebugProcessEnum *iface)
00490 {
00491     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00492     FIXME("stub %p\n", This);
00493     return E_NOTIMPL;
00494 }
00495 
00496 static HRESULT WINAPI process_enum_Clone(ICorDebugProcessEnum *iface, ICorDebugEnum **ppEnum)
00497 {
00498     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00499     FIXME("stub %p %p\n", This, ppEnum);
00500     return E_NOTIMPL;
00501 }
00502 
00503 static HRESULT WINAPI process_enum_GetCount(ICorDebugProcessEnum *iface, ULONG *pcelt)
00504 {
00505     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00506     TRACE("stub %p %p\n", This, pcelt);
00507 
00508     if(!pcelt)
00509         return E_INVALIDARG;
00510 
00511     *pcelt = list_count(&This->processes);
00512 
00513     return S_OK;
00514 }
00515 
00516 static HRESULT WINAPI process_enum_Next(ICorDebugProcessEnum *iface, ULONG celt,
00517             ICorDebugProcess * processes[], ULONG *pceltFetched)
00518 {
00519     CorDebug *This = impl_from_ICorDebugProcessEnum(iface);
00520     FIXME("stub %p %d %p %p\n", This, celt, processes, pceltFetched);
00521     return E_NOTIMPL;
00522 }
00523 
00524 static const struct ICorDebugProcessEnumVtbl processenum_vtbl =
00525 {
00526     process_enum_QueryInterface,
00527     process_enum_AddRef,
00528     process_enum_Release,
00529     process_enum_Skip,
00530     process_enum_Reset,
00531     process_enum_Clone,
00532     process_enum_GetCount,
00533     process_enum_Next
00534 };
00535 
00536 /*** IUnknown methods ***/
00537 static HRESULT WINAPI CorDebug_QueryInterface(ICorDebug *iface, REFIID riid, void **ppvObject)
00538 {
00539     CorDebug *This = impl_from_ICorDebug( iface );
00540 
00541     TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
00542 
00543     if ( IsEqualGUID( riid, &IID_ICorDebug ) ||
00544          IsEqualGUID( riid, &IID_IUnknown ) )
00545     {
00546         *ppvObject = &This->ICorDebug_iface;
00547     }
00548     else
00549     {
00550         FIXME("Unsupported interface %s\n", debugstr_guid(riid));
00551         return E_NOINTERFACE;
00552     }
00553 
00554     ICorDebug_AddRef( iface );
00555 
00556     return S_OK;
00557 }
00558 
00559 static ULONG WINAPI CorDebug_AddRef(ICorDebug *iface)
00560 {
00561     CorDebug *This = impl_from_ICorDebug( iface );
00562     ULONG ref = InterlockedIncrement(&This->ref);
00563 
00564     TRACE("%p ref=%u\n", This, ref);
00565 
00566     return ref;
00567 }
00568 
00569 static ULONG WINAPI CorDebug_Release(ICorDebug *iface)
00570 {
00571     CorDebug *This = impl_from_ICorDebug( iface );
00572     ULONG ref = InterlockedDecrement(&This->ref);
00573 
00574     TRACE("%p ref=%u\n", This, ref);
00575 
00576     if (ref == 0)
00577     {
00578         if(!list_empty(&This->processes))
00579             ERR("Processes haven't been removed Correctly\n");
00580 
00581         if(This->runtimehost)
00582             ICLRRuntimeHost_Release(This->runtimehost);
00583 
00584         if(This->pCallback)
00585             ICorDebugManagedCallback2_Release(This->pCallback2);
00586 
00587         if(This->pCallback)
00588             ICorDebugManagedCallback_Release(This->pCallback);
00589 
00590         HeapFree(GetProcessHeap(), 0, This);
00591     }
00592 
00593     return ref;
00594 }
00595 
00596 /*** ICorDebug methods ***/
00597 static HRESULT WINAPI CorDebug_Initialize(ICorDebug *iface)
00598 {
00599     CorDebug *This = impl_from_ICorDebug( iface );
00600     FIXME("stub %p\n", This);
00601     return S_OK;
00602 }
00603 
00604 static HRESULT WINAPI CorDebug_Terminate(ICorDebug *iface)
00605 {
00606     struct CorProcess *cursor, *cursor2;
00607     CorDebug *This = impl_from_ICorDebug( iface );
00608     TRACE("stub %p\n", This);
00609 
00610     LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, &This->processes, struct CorProcess, entry)
00611     {
00612         if(cursor->pProcess)
00613         {
00614             ICorDebugProcess_Terminate(cursor->pProcess, 0);
00615             ICorDebugProcess_Release(cursor->pProcess);
00616         }
00617 
00618         list_remove(&cursor->entry);
00619         HeapFree(GetProcessHeap(), 0, cursor);
00620     }
00621 
00622     return S_OK;
00623 }
00624 
00625 static HRESULT WINAPI CorDebug_SetManagedHandler(ICorDebug *iface, ICorDebugManagedCallback *pCallback)
00626 {
00627     CorDebug *This = impl_from_ICorDebug( iface );
00628     HRESULT hr;
00629     ICorDebugManagedCallback2 *pCallback2;
00630 
00631     TRACE("%p (%p)\n", This, pCallback);
00632 
00633     if(!pCallback)
00634         return E_INVALIDARG;
00635 
00636     hr = ICorDebugManagedCallback_QueryInterface(pCallback, &IID_ICorDebugManagedCallback2, (void**)&pCallback2);
00637     if(hr == S_OK)
00638     {
00639         if(This->pCallback2)
00640             ICorDebugManagedCallback2_Release(This->pCallback2);
00641 
00642         if(This->pCallback)
00643             ICorDebugManagedCallback_Release(This->pCallback);
00644 
00645         This->pCallback = pCallback;
00646         This->pCallback2 = pCallback2;
00647 
00648         ICorDebugManagedCallback_AddRef(This->pCallback);
00649     }
00650     else
00651     {
00652         WARN("Debugging without interface ICorDebugManagedCallback2 is currently not supported.\n");
00653     }
00654 
00655     return hr;
00656 }
00657 
00658 static HRESULT WINAPI CorDebug_SetUnmanagedHandler(ICorDebug *iface, ICorDebugUnmanagedCallback *pCallback)
00659 {
00660     CorDebug *This = impl_from_ICorDebug( iface );
00661     FIXME("stub %p %p\n", This, pCallback);
00662     return E_NOTIMPL;
00663 }
00664 
00665 static HRESULT WINAPI CorDebug_CreateProcess(ICorDebug *iface, LPCWSTR lpApplicationName,
00666             LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
00667             LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
00668             DWORD dwCreationFlags, PVOID lpEnvironment,LPCWSTR lpCurrentDirectory,
00669             LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation,
00670             CorDebugCreateProcessFlags debuggingFlags, ICorDebugProcess **ppProcess)
00671 {
00672     CorDebug *This = impl_from_ICorDebug( iface );
00673     ICorDebugProcess *pDebugProcess;
00674     HRESULT hr;
00675 
00676     TRACE("stub %p %s %s %p %p %d %d %p %s %p %p %d %p\n", This, debugstr_w(lpApplicationName),
00677             debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes,
00678             bInheritHandles, dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory),
00679             lpStartupInfo, lpProcessInformation, debuggingFlags, ppProcess);
00680 
00681     if(CreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
00682             bInheritHandles, dwCreationFlags | CREATE_SUSPENDED, lpEnvironment, lpCurrentDirectory,
00683             lpStartupInfo, lpProcessInformation))
00684     {
00685         hr = CorDebugProcess_Create(This, (IUnknown**)&pDebugProcess, lpProcessInformation);
00686         if(hr == S_OK)
00687         {
00688             struct CorProcess *new_process = HeapAlloc( GetProcessHeap(), 0, sizeof(CorProcess) );
00689 
00690             new_process->pProcess = pDebugProcess;
00691             list_add_tail(&This->processes, &new_process->entry);
00692 
00693             ICorDebugProcess_AddRef(pDebugProcess);
00694             *ppProcess = pDebugProcess;
00695 
00696             if(This->pCallback)
00697                 ICorDebugManagedCallback_CreateProcess(This->pCallback, pDebugProcess);
00698         }
00699         else
00700         {
00701             TerminateProcess(lpProcessInformation->hProcess, 0);
00702         }
00703     }
00704     else
00705         hr = E_FAIL;
00706 
00707     return hr;
00708 }
00709 
00710 static HRESULT WINAPI CorDebug_DebugActiveProcess(ICorDebug *iface, DWORD id, BOOL win32Attach,
00711             ICorDebugProcess **ppProcess)
00712 {
00713     CorDebug *This = impl_from_ICorDebug( iface );
00714     FIXME("stub %p %d %d %p\n", This, id, win32Attach, ppProcess);
00715     return E_NOTIMPL;
00716 }
00717 
00718 static HRESULT WINAPI CorDebug_EnumerateProcesses( ICorDebug *iface, ICorDebugProcessEnum **ppProcess)
00719 {
00720     CorDebug *This = impl_from_ICorDebug( iface );
00721     TRACE("stub %p %p\n", This, ppProcess);
00722 
00723     if(!ppProcess)
00724         return E_INVALIDARG;
00725 
00726     *ppProcess = &This->ICorDebugProcessEnum_iface;
00727     ICorDebugProcessEnum_AddRef(*ppProcess);
00728 
00729     return S_OK;
00730 }
00731 
00732 static HRESULT WINAPI CorDebug_GetProcess(ICorDebug *iface, DWORD dwProcessId, ICorDebugProcess **ppProcess)
00733 {
00734     CorDebug *This = impl_from_ICorDebug( iface );
00735     FIXME("stub %p %d %p\n", This, dwProcessId, ppProcess);
00736     return E_NOTIMPL;
00737 }
00738 
00739 static HRESULT WINAPI CorDebug_CanLaunchOrAttach(ICorDebug *iface, DWORD dwProcessId,
00740             BOOL win32DebuggingEnabled)
00741 {
00742     CorDebug *This = impl_from_ICorDebug( iface );
00743     FIXME("stub %p %d %d\n", This, dwProcessId, win32DebuggingEnabled);
00744     return S_OK;
00745 }
00746 
00747 static const struct ICorDebugVtbl cordebug_vtbl =
00748 {
00749     CorDebug_QueryInterface,
00750     CorDebug_AddRef,
00751     CorDebug_Release,
00752     CorDebug_Initialize,
00753     CorDebug_Terminate,
00754     CorDebug_SetManagedHandler,
00755     CorDebug_SetUnmanagedHandler,
00756     CorDebug_CreateProcess,
00757     CorDebug_DebugActiveProcess,
00758     CorDebug_EnumerateProcesses,
00759     CorDebug_GetProcess,
00760     CorDebug_CanLaunchOrAttach
00761 };
00762 
00763 HRESULT CorDebug_Create(ICLRRuntimeHost *runtimehost, IUnknown** ppUnk)
00764 {
00765     CorDebug *This;
00766 
00767     This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
00768     if ( !This )
00769         return E_OUTOFMEMORY;
00770 
00771     This->ICorDebug_iface.lpVtbl = &cordebug_vtbl;
00772     This->ICorDebugProcessEnum_iface.lpVtbl = &processenum_vtbl;
00773     This->ref = 1;
00774     This->pCallback = NULL;
00775     This->pCallback2 = NULL;
00776     This->runtimehost = runtimehost;
00777 
00778     list_init(&This->processes);
00779 
00780     if(This->runtimehost)
00781         ICLRRuntimeHost_AddRef(This->runtimehost);
00782 
00783     *ppUnk = (IUnknown*)This;
00784 
00785     return S_OK;
00786 }

Generated on Fri May 25 2012 04:22:54 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.