From 3baa7d0b15f4476186aa766e9359da451151bebe Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Date: Tue, 27 Sep 2011 09:06:18 +1000
Subject: [PATCH] Add ICorDebug interface support
To: wine-patches <wine-patches@winehq.org>

---
 dlls/mscoree/Makefile.in       |    1 +
 dlls/mscoree/assembly.c        |    2 +
 dlls/mscoree/config.c          |    3 +
 dlls/mscoree/cordebug.c        |  177 ++++++++++++++++++++++++++++++++++++++++
 dlls/mscoree/corruntimehost.c  |   22 ++---
 dlls/mscoree/metadata.c        |    4 +-
 dlls/mscoree/metahost.c        |    7 +-
 dlls/mscoree/mscoree_main.c    |   45 +++++++++-
 dlls/mscoree/mscoree_private.h |   44 +++++++---
 dlls/mscoree/tests/Makefile.in |    1 +
 dlls/mscoree/tests/debugging.c |  106 ++++++++++++++++++++++++
 include/cordebug.idl           |    5 +
 include/metahost.idl           |    1 +
 13 files changed, 385 insertions(+), 33 deletions(-)
 create mode 100644 dlls/mscoree/cordebug.c
 create mode 100644 dlls/mscoree/tests/debugging.c

diff --git a/dlls/mscoree/Makefile.in b/dlls/mscoree/Makefile.in
index 914aff4..a39c696 100644
--- a/dlls/mscoree/Makefile.in
+++ b/dlls/mscoree/Makefile.in
@@ -4,6 +4,7 @@ IMPORTS   = dbghelp uuid shell32 advapi32 ole32 oleaut32 shlwapi
 C_SRCS = \
 	assembly.c \
 	config.c \
+	cordebug.c \
 	corruntimehost.c \
 	metadata.c \
 	metahost.c \
diff --git a/dlls/mscoree/assembly.c b/dlls/mscoree/assembly.c
index 40279a5..07723f9 100644
--- a/dlls/mscoree/assembly.c
+++ b/dlls/mscoree/assembly.c
@@ -27,8 +27,10 @@
 #include "winver.h"
 #include "dbghelp.h"
 #include "ole2.h"
+#include "mscoree.h"
 #include "corhdr.h"
 #include "metahost.h"
+#include "cordebug.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
 
diff --git a/dlls/mscoree/config.c b/dlls/mscoree/config.c
index 40c8378..02c11b1 100644
--- a/dlls/mscoree/config.c
+++ b/dlls/mscoree/config.c
@@ -27,7 +27,10 @@
 #include "winreg.h"
 #include "ole2.h"
 #include "msxml2.h"
+#include "mscoree.h"
+#include "corhdr.h"
 #include "metahost.h"
+#include "cordebug.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
 #include "shlwapi.h"
diff --git a/dlls/mscoree/cordebug.c b/dlls/mscoree/cordebug.c
new file mode 100644
index 0000000..be6d604
--- /dev/null
+++ b/dlls/mscoree/cordebug.c
@@ -0,0 +1,177 @@
+/*
+ *
+ * Copyright 2011 Alistair Leslie-Hughes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#define COBJMACROS
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+
+#include "winuser.h"
+#include "winnls.h"
+#include "winreg.h"
+#include "ole2.h"
+#include "shellapi.h"
+#include "mscoree.h"
+#include "corhdr.h"
+#include "metahost.h"
+#include "cordebug.h"
+#include "wine/list.h"
+#include "mscoree_private.h"
+#include "wine/debug.h"
+
+
+WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
+
+
+static inline RuntimeHost *impl_from_ICorDebug( ICorDebug *iface )
+{
+    return CONTAINING_RECORD(iface, RuntimeHost, ICorDebug_iface);
+}
+
+/*** IUnknown methods ***/
+static HRESULT WINAPI CorDebug_QueryInterface(ICorDebug *iface, REFIID riid, void **ppvObject)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+
+    TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
+
+    if ( IsEqualGUID( riid, &IID_ICorDebug ) ||
+         IsEqualGUID( riid, &IID_IUnknown ) )
+    {
+        *ppvObject = &This->ICorDebug_iface;
+    }
+    else
+    {
+        FIXME("Unsupported interface %s\n", debugstr_guid(riid));
+        return E_NOINTERFACE;
+    }
+
+    ICorDebug_AddRef( iface );
+
+    return S_OK;
+}
+
+static ULONG WINAPI CorDebug_AddRef(ICorDebug *iface)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    return ICorRuntimeHost_AddRef(&This->ICorRuntimeHost_iface);
+}
+
+static ULONG WINAPI CorDebug_Release(ICorDebug *iface)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    return ICorRuntimeHost_Release(&This->ICorRuntimeHost_iface);
+}
+
+/*** ICorDebug methods ***/
+static HRESULT WINAPI CorDebug_Initialize(ICorDebug *iface)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p\n", This);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_Terminate(ICorDebug *iface)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p\n", This);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_SetManagedHandler(ICorDebug *iface, ICorDebugManagedCallback *pCallback)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %p\n", This, pCallback);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_SetUnmanagedHandler(ICorDebug *iface, ICorDebugUnmanagedCallback *pCallback)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %p\n", This, pCallback);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_CreateProcess(ICorDebug *iface, LPCWSTR lpApplicationName,
+            LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
+            LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles,
+            DWORD dwCreationFlags, PVOID lpEnvironment,LPCWSTR lpCurrentDirectory, 
+            LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation,
+            CorDebugCreateProcessFlags debuggingFlags, ICorDebugProcess **ppProcess)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %s %s %p %p %d %d %p %s %p %p %d %p\n", This, debugstr_w(lpApplicationName),
+            debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes,
+            bInheritHandles, dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory), 
+            lpStartupInfo, lpProcessInformation, debuggingFlags, ppProcess);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_DebugActiveProcess(ICorDebug *iface, DWORD id, BOOL win32Attach,
+            ICorDebugProcess **ppProcess)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %d %d %p\n", This, id, win32Attach, ppProcess);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_EnumerateProcesses( ICorDebug *iface, ICorDebugProcessEnum **ppProcess)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %p\n", This, ppProcess);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_GetProcess(ICorDebug *iface, DWORD dwProcessId, ICorDebugProcess **ppProcess)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %d %p\n", This, dwProcessId, ppProcess);
+    return E_NOTIMPL;
+}
+
+static HRESULT WINAPI CorDebug_CanLaunchOrAttach(ICorDebug *iface, DWORD dwProcessId, 
+            BOOL win32DebuggingEnabled)
+{
+    RuntimeHost *This = impl_from_ICorDebug( iface );
+    FIXME("stub %p %d %d\n", This, dwProcessId, win32DebuggingEnabled);
+    return E_NOTIMPL;
+}
+
+static const struct ICorDebugVtbl cordebug_vtbl =
+{
+    CorDebug_QueryInterface,
+    CorDebug_AddRef,
+    CorDebug_Release,
+    CorDebug_Initialize,
+    CorDebug_Terminate,
+    CorDebug_SetManagedHandler,
+    CorDebug_SetUnmanagedHandler,
+    CorDebug_CreateProcess,
+    CorDebug_DebugActiveProcess,
+    CorDebug_EnumerateProcesses,
+    CorDebug_GetProcess,
+    CorDebug_CanLaunchOrAttach
+};
+
+void cordebug_init(RuntimeHost *This)
+{
+    This->ICorDebug_iface.lpVtbl = &cordebug_vtbl;
+}
diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index 609b73e..e3f4976 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -32,6 +32,8 @@
 #include "cor.h"
 #include "mscoree.h"
 #include "metahost.h"
+#include "corhdr.h"
+#include "cordebug.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
 
@@ -43,18 +45,6 @@ WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
 
 DEFINE_GUID(IID__AppDomain, 0x05f696dc,0x2b29,0x3663,0xad,0x8b,0xc4,0x38,0x9c,0xf2,0xa7,0x13);
 
-struct RuntimeHost
-{
-    ICorRuntimeHost ICorRuntimeHost_iface;
-    ICLRRuntimeHost ICLRRuntimeHost_iface;
-    const CLRRuntimeInfo *version;
-    loaded_mono *mono;
-    struct list domains;
-    MonoDomain *default_domain;
-    CRITICAL_SECTION lock;
-    LONG ref;
-};
-
 struct DomainEntry
 {
     struct list entry;
@@ -796,6 +786,9 @@ HRESULT RuntimeHost_Construct(const CLRRuntimeInfo *runtime_version,
 
     This->ICorRuntimeHost_iface.lpVtbl = &corruntimehost_vtbl;
     This->ICLRRuntimeHost_iface.lpVtbl = &CLRHostVtbl;
+
+    cordebug_init(This);
+
     This->ref = 1;
     This->version = runtime_version;
     This->mono = loaded_mono;
@@ -831,6 +824,11 @@ HRESULT RuntimeHost_GetInterface(RuntimeHost *This, REFCLSID clsid, REFIID riid,
         if (FAILED(hr))
             return hr;
     }
+    else if (IsEqualGUID(clsid, &CLSID_CLRDebuggingLegacy))
+    {
+        unk = (IUnknown*)&This->ICorDebug_iface;
+        IUnknown_AddRef(unk);
+    }
     else
         unk = NULL;
 
diff --git a/dlls/mscoree/metadata.c b/dlls/mscoree/metadata.c
index 5c343f0..9ca0d93 100644
--- a/dlls/mscoree/metadata.c
+++ b/dlls/mscoree/metadata.c
@@ -29,8 +29,10 @@
 #include "winbase.h"
 #include "winreg.h"
 #include "ole2.h"
-
 #include "cor.h"
+#include "mscoree.h"
+#include "corhdr.h"
+#include "cordebug.h"
 #include "metahost.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index d69bf13..d9e36a8 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -32,9 +32,12 @@
 #include "ole2.h"
 
 #include "corerror.h"
+#include "cor.h"
 #include "mscoree.h"
-#include "fusion.h"
+#include "corhdr.h"
+#include "cordebug.h"
 #include "metahost.h"
+#include "fusion.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
 
@@ -1002,7 +1005,7 @@ static BOOL parse_runtime_version(LPCWSTR version, DWORD *major, DWORD *minor, D
         return FALSE;
 }
 
-static HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface,
+HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface,
     LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime)
 {
     int i;
diff --git a/dlls/mscoree/mscoree_main.c b/dlls/mscoree/mscoree_main.c
index 9e37eae..839e964 100644
--- a/dlls/mscoree/mscoree_main.c
+++ b/dlls/mscoree/mscoree_main.c
@@ -35,11 +35,13 @@
 
 #include "initguid.h"
 #include "msxml2.h"
-#include "cor.h"
 #include "corerror.h"
+#include "cor.h"
 #include "mscoree.h"
-#include "fusion.h"
+#include "corhdr.h"
+#include "cordebug.h"
 #include "metahost.h"
+#include "fusion.h"
 #include "wine/list.h"
 #include "mscoree_private.h"
 
@@ -444,10 +446,43 @@ HRESULT WINAPI CreateConfigStream(LPCWSTR filename, IStream **stream)
     return E_NOTIMPL;
 }
 
-HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppIUnk)
+HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppv)
 {
-    FIXME("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppIUnk);
-    return E_NOTIMPL;
+    const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
+    HRESULT hr = E_FAIL;
+
+    if(nDebugVersion < 1 || nDebugVersion > 4)
+        return E_INVALIDARG;
+
+    TRACE("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppv);
+
+    if(!ppv)
+        return E_INVALIDARG;
+
+    *ppv = NULL;
+
+    if(strcmpW(version, v2_0) != 0)
+    {
+        FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version));
+        return E_INVALIDARG;
+    }
+    
+    if(nDebugVersion != 3)
+        return E_INVALIDARG;
+
+    ICLRRuntimeInfo *runtimeinfo;
+    hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)&runtimeinfo);
+    if(hr == S_OK)
+    {
+        hr = ICLRRuntimeInfo_GetInterface(runtimeinfo, &CLSID_CLRDebuggingLegacy, &IID_ICorDebug, (void**)ppv);
+
+        ICLRRuntimeInfo_Release(runtimeinfo);
+    }
+
+    if(!*ppv)
+        return E_FAIL;
+
+    return hr;
 }
 
 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index 5cbf8df..a253262 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -33,6 +33,18 @@ HRESULT assembly_create(ASSEMBLY **out, LPCWSTR file) DECLSPEC_HIDDEN;
 HRESULT assembly_release(ASSEMBLY *assembly) DECLSPEC_HIDDEN;
 HRESULT assembly_get_runtime_version(ASSEMBLY *assembly, LPSTR *version) DECLSPEC_HIDDEN;
 
+/* Mono embedding */
+typedef struct _MonoDomain MonoDomain;
+typedef struct _MonoAssembly MonoAssembly;
+typedef struct _MonoAssemblyName MonoAssemblyName;
+typedef struct _MonoType MonoType;
+typedef struct _MonoImage MonoImage;
+typedef struct _MonoClass MonoClass;
+typedef struct _MonoObject MonoObject;
+typedef struct _MonoMethod MonoMethod;
+typedef struct _MonoProfiler MonoProfiler;
+
+typedef struct loaded_mono loaded_mono;
 typedef struct RuntimeHost RuntimeHost;
 
 typedef struct CLRRuntimeInfo
@@ -48,6 +60,19 @@ typedef struct CLRRuntimeInfo
     struct RuntimeHost *loaded_runtime;
 } CLRRuntimeInfo;
 
+struct RuntimeHost
+{
+    ICorRuntimeHost ICorRuntimeHost_iface;
+    ICLRRuntimeHost ICLRRuntimeHost_iface;
+    ICorDebug       ICorDebug_iface;
+    const CLRRuntimeInfo *version;
+    loaded_mono *mono;
+    struct list domains;
+    MonoDomain *default_domain;
+    CRITICAL_SECTION lock;
+    LONG ref;
+};
+
 extern HRESULT get_runtime_info(LPCWSTR exefile, LPCWSTR version, LPCWSTR config_file,
     DWORD startup_flags, DWORD runtimeinfo_flags, BOOL legacy, ICLRRuntimeInfo **result) DECLSPEC_HIDDEN;
 
@@ -70,17 +95,6 @@ extern HRESULT parse_config_file(LPCWSTR filename, parsed_config_file *result) D
 
 extern void free_parsed_config_file(parsed_config_file *file) DECLSPEC_HIDDEN;
 
-/* Mono embedding */
-typedef struct _MonoDomain MonoDomain;
-typedef struct _MonoAssembly MonoAssembly;
-typedef struct _MonoAssemblyName MonoAssemblyName;
-typedef struct _MonoType MonoType;
-typedef struct _MonoImage MonoImage;
-typedef struct _MonoClass MonoClass;
-typedef struct _MonoObject MonoObject;
-typedef struct _MonoMethod MonoMethod;
-typedef struct _MonoProfiler MonoProfiler;
-
 typedef enum {
 	MONO_IMAGE_OK,
 	MONO_IMAGE_ERROR_ERRNO,
@@ -92,7 +106,7 @@ typedef MonoAssembly* (*MonoAssemblyPreLoadFunc)(MonoAssemblyName *aname, char *
 
 typedef void (*MonoProfileFunc)(MonoProfiler *prof);
 
-typedef struct loaded_mono
+struct loaded_mono
 {
     HMODULE mono_handle;
     HMODULE glib_handle;
@@ -126,7 +140,7 @@ typedef struct loaded_mono
     void (CDECL *mono_thread_pool_cleanup)(void);
     void (CDECL *mono_thread_suspend_all_other_threads)(void);
     void (CDECL *mono_threads_set_shutting_down)(void);
-} loaded_mono;
+};
 
 /* loaded runtime interfaces */
 extern void unload_all_runtimes(void) DECLSPEC_HIDDEN;
@@ -145,4 +159,8 @@ extern HRESULT RuntimeHost_CreateManagedInstance(RuntimeHost *This, LPCWSTR name
 
 extern HRESULT RuntimeHost_Destroy(RuntimeHost *This) DECLSPEC_HIDDEN;
 
+HRESULT WINAPI CLRMetaHost_GetRuntime(ICLRMetaHost* iface, LPCWSTR pwzVersion, REFIID iid, LPVOID *ppRuntime) DECLSPEC_HIDDEN;
+
+extern void cordebug_init(RuntimeHost *This);
+
 #endif   /* __MSCOREE_PRIVATE__ */
diff --git a/dlls/mscoree/tests/Makefile.in b/dlls/mscoree/tests/Makefile.in
index e336f0d..20dfd88 100644
--- a/dlls/mscoree/tests/Makefile.in
+++ b/dlls/mscoree/tests/Makefile.in
@@ -2,6 +2,7 @@ TESTDLL   = mscoree.dll
 IMPORTS   = shlwapi
 
 C_SRCS = \
+	debugging.c \
 	metahost.c \
 	mscoree.c
 
diff --git a/dlls/mscoree/tests/debugging.c b/dlls/mscoree/tests/debugging.c
new file mode 100644
index 0000000..ca35843
--- /dev/null
+++ b/dlls/mscoree/tests/debugging.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2011 Alistair Leslie-Hughes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#define COBJMACROS
+
+#include "windows.h"
+#include "ole2.h"
+#include "corerror.h"
+#include "mscoree.h"
+#include "corhdr.h"
+
+#include "wine/test.h"
+
+#include "initguid.h"
+#include "cordebug.h"
+
+static HMODULE hmscoree;
+
+static HRESULT (WINAPI *pCreateDebuggingInterfaceFromVersion)(int, LPCWSTR, IUnknown **);
+
+const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
+
+static BOOL init_functionpointers(void)
+{
+    hmscoree = LoadLibraryA("mscoree.dll");
+
+    if (!hmscoree)
+    {
+        win_skip("mscoree.dll not available\n");
+        return FALSE;
+    }
+
+    pCreateDebuggingInterfaceFromVersion = (void *)GetProcAddress(hmscoree, "CreateDebuggingInterfaceFromVersion");
+
+    if (!pCreateDebuggingInterfaceFromVersion)
+    {
+        win_skip("functions not available\n");
+        FreeLibrary(hmscoree);
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static void test_createDebugger(void)
+{
+    HRESULT hr;
+    IUnknown *pUnk;
+    ICorDebug *pCorDebug;
+
+    hr = pCreateDebuggingInterfaceFromVersion(0, v2_0, &pUnk);
+    ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
+
+    hr = pCreateDebuggingInterfaceFromVersion(1, v2_0, &pUnk);
+    ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
+
+    hr = pCreateDebuggingInterfaceFromVersion(2, v2_0, &pUnk);
+    ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
+
+    hr = pCreateDebuggingInterfaceFromVersion(4, v2_0, &pUnk);
+    ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
+
+    hr = pCreateDebuggingInterfaceFromVersion(3, v2_0, NULL);
+    ok(hr == E_INVALIDARG, "CreateDebuggingInterfaceFromVersion returned %08x\n", hr);
+
+    hr = pCreateDebuggingInterfaceFromVersion(3, v2_0, &pUnk);
+    if(hr == S_OK)
+    {
+        hr = IUnknown_QueryInterface(pUnk, &IID_ICorDebug, (void**)&pCorDebug);
+        todo_wine ok(hr == S_OK, "expected S_OK got %08x\n", hr);
+        if(hr == S_OK)
+        {
+            ICorDebug_Release(pCorDebug);
+        }
+        IUnknown_Release(pUnk);
+    }
+    else
+    {
+        skip(".NET 2.0 or mono not installed.\n");
+    }
+}
+
+START_TEST(debugging)
+{
+    if (!init_functionpointers())
+        return;
+
+    test_createDebugger();
+
+    FreeLibrary(hmscoree);
+}
diff --git a/include/cordebug.idl b/include/cordebug.idl
index 9cde077..9b46276 100644
--- a/include/cordebug.idl
+++ b/include/cordebug.idl
@@ -19,6 +19,10 @@
 import "unknwn.idl";
 import "objidl.idl";
 
+cpp_quote("#ifdef WINE_NO_UNICODE_MACROS")
+cpp_quote("#undef CreateProcess")
+cpp_quote("#endif")
+
 interface ICorDebugAppDomain;
 interface ICorDebugAppDomainEnum;
 interface ICorDebugAssembly;
@@ -51,6 +55,7 @@ interface ICorDebugStepper;
 interface ICorDebugStepperEnum;
 interface ICorDebugThreadEnum;
 interface ICorDebugUnmanagedCallback;
+interface ICorDebugValue;
 interface ICorDebugValueBreakpoint;
 
 
diff --git a/include/metahost.idl b/include/metahost.idl
index a352556..bd19c48 100644
--- a/include/metahost.idl
+++ b/include/metahost.idl
@@ -88,6 +88,7 @@ typedef void (__stdcall *RuntimeLoadedCallbackFnPtr)(
     CallbackThreadSetFnPtr pfnCallbackThreadSet,
     CallbackThreadUnsetFnPtr pfnCallbackThreadUnset);
 
+cpp_quote("DEFINE_GUID(CLSID_CLRDebuggingLegacy, 0xDF8395B5,0xA4BA,0x450b,0xA7,0x7C,0xA9,0xA4,0x77,0x62,0xC5,0x20);")
 cpp_quote("DEFINE_GUID(CLSID_CLRMetaHost, 0x9280188d,0x0e8e,0x4867,0xb3,0x0c,0x7f,0xa8,0x38,0x84,0xe8,0xde);")
 
 [
-- 
1.7.4.1
