Author: Tim Felgentreff <timfelgentr...@gmail.com>
Branch: 
Changeset: r89900:a64ec5d7ebcb
Date: 2017-02-02 11:07 +0100
http://bitbucket.org/pypy/pypy/changeset/a64ec5d7ebcb/

Log:    make attach_gdb work on Windows (with Visual Studio Debugger)

diff --git a/rpython/rlib/debug.py b/rpython/rlib/debug.py
--- a/rpython/rlib/debug.py
+++ b/rpython/rlib/debug.py
@@ -446,8 +446,85 @@
             time.sleep(1)  # give the GDB time to attach
 
 else:
+    def make_vs_attach_eci():
+        # The COM interface to the Debugger has to be compiled as a .cpp file 
by
+        # Visual C. So we generate the source and then add a commandline switch
+        # to treat this source file as C++
+        import os
+        eci = ExternalCompilationInfo(post_include_bits=["""
+#ifdef __cplusplus
+extern "C" {
+#endif
+RPY_EXPORTED void AttachToVS();
+#ifdef __cplusplus
+}
+#endif
+                                      """],
+                                      separate_module_sources=["""
+#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") 
raw_interfaces_only named_guids
+extern "C" RPY_EXPORTED void AttachToVS() {
+    CoInitialize(0);
+    HRESULT hr;
+    CLSID Clsid;
+
+    CLSIDFromProgID(L"VisualStudio.DTE", &Clsid);
+    IUnknown *Unknown;
+    if (FAILED(GetActiveObject(Clsid, 0, &Unknown))) {
+        puts("Could not attach to Visual Studio (is it not running?");
+        return;
+    }
+
+    EnvDTE::_DTE *Interface;
+    hr = Unknown->QueryInterface(&Interface);
+    if (FAILED(GetActiveObject(Clsid, 0, &Unknown))) {
+        puts("Could not open COM interface to Visual Studio (no 
permissions?)");
+        return;
+    }
+
+    EnvDTE::Debugger *Debugger;
+    puts("Waiting for Visual Studio Debugger to become idle");
+    while (FAILED(Interface->get_Debugger(&Debugger)));
+
+    EnvDTE::Processes *Processes;
+    while (FAILED(Debugger->get_LocalProcesses(&Processes)));
+
+    long Count = 0;
+    if (FAILED(Processes->get_Count(&Count))) {
+        puts("Cannot query Process count");
+    }
+
+    for (int i = 0; i <= Count; i++) {
+        EnvDTE::Process *Process;
+        if (FAILED(Processes->Item(variant_t(i), &Process))) {
+            continue;
+        }
+
+        long ProcessID;
+        while (FAILED(Process->get_ProcessID(&ProcessID)));
+
+        if (ProcessID == GetProcessId(GetCurrentProcess())) {
+            printf("Found process ID %d\\n", ProcessID);
+            Process->Attach();
+            Debugger->Break(false);
+            CoUninitialize();
+            return;
+        }
+    }
+}
+                                      """]
+        )
+        eci = eci.convert_sources_to_files()
+        d = eci._copy_attributes()
+        cfile = d['separate_module_files'][0]
+        cppfile = cfile.replace(".c", "_vsdebug.cpp")
+        os.rename(cfile, cppfile)
+        d['separate_module_files'] = [cppfile]
+        return ExternalCompilationInfo(**d)
+
+    ll_attach = rffi.llexternal("AttachToVS", [], lltype.Void,
+                                compilation_info=make_vs_attach_eci())
     def impl_attach_gdb():
-        print "Don't know how to attach GDB on Windows"
+        ll_attach()
 
 register_external(attach_gdb, [], result=None,
                   export_name="impl_attach_gdb", llimpl=impl_attach_gdb)
diff --git a/rpython/translator/platform/windows.py 
b/rpython/translator/platform/windows.py
--- a/rpython/translator/platform/windows.py
+++ b/rpython/translator/platform/windows.py
@@ -379,9 +379,9 @@
             no_precompile = []
             for f in list(no_precompile_cfiles):
                 f = m.pathrel(py.path.local(f))
-                if f not in no_precompile and f.endswith('.c'):
+                if f not in no_precompile and (f.endswith('.c') or 
f.endswith('.cpp')):
                     no_precompile.append(f)
-                    target = f[:-1] + 'obj'
+                    target = f[:f.rfind('.')] + '.obj'
                     rules.append((target, f,
                         '$(CC) /nologo $(CFLAGS) $(CFLAGSEXTRA) '
                         '/Fo%s /c %s $(INCLUDEDIRS)' %(target, f)))
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to