benibenj / vscode-pythonCpp

A Visual Studio Code Debug Extension for debugging mixed Python and C++ code. The extension starts a Python debug session and attaches the C++ debugger to it. This extension is useful for debugging Python programs that call functions from shared libraries (.so/.dll).
Other
47 stars 7 forks source link

Breakpoint in C++ does not work #12

Closed pascalzeugin closed 1 year ago

pascalzeugin commented 1 year ago

I am currently trying to get the minimal working example running under Windows 10 with the MSYS2 gdb.exe. Here's my C++ source code;

image

I'm compiling the code with the mingw64 g++ compiler:

Found ninja-1.10.0 at C:\msys64\mingw64\bin\ninja.EXE
[1/2] "C:/msys64/mingw64/bin/g++" "-Ilibpxfdc8.dll.p" "-I." "-I.." "-I..\include" "-fdiagnostics-color=always" "-pipe" "-D_FILE_OFFSET_BITS=64" "-Wall" "-Winvalid-pch" "-Wnon-virtual-dtor" "-Wextra" "-Wpedantic" "-std=c++2a" "-g" "-Wa,-mbig-obj" -MD -MQ libpxfdc8.dll.p/src_session_pybind.cpp.obj -MF "libpxfdc8.dll.p\src_session_pybind.cpp.obj.d" -o libpxfdc8.dll.p/src_session_pybind.cpp.obj "-c" ../src/sessiontic" "-std=c++2a" "-g" "-Wa,-mn_pybind.cpp
[2/2] "C:/msys64/mingw64/bin/g++"  -o libpxfdc8.dll libpxfdc8.dll.p/src_session_pybind.cpp.obj "-Wl,--allow-shlib-undefined" "-shared" "-Wl,--start-group" "-Wl,--out-implib=libpxfdc8.dll.a" "-lkernel32" "-luser32" "-lgdi32" "-lwinspool" user32" "-lgdi32" "-lwinspool" "-lshell32" "-lole32" "-loleaut32" "-luuid" "-lcomdlg32" "-ladvapi32" "-Wl,--end-group"

The buildtype is "debug" as indicated by the "-g" flag.

The python file I'm trying to debug is shown subsequently:

image

My launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python C++ Debug",
      "type": "pythoncpp",
      "request": "launch",
      "pythonConfig": "default",
      "cppAttachName": "C++ attach (Windows)",
    },
    {
      "name": "C++ attach (Windows)",
      "type": "cppdbg",
      "request": "attach",
      "processId": "",
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
    }
  ]
}

Both the Python and the C++ debugging process start correctly, however if I hit continue when arriving at the Python breakpoint it just jumps over the C++ part giving the correct result of 5+1 = 6 at the end.

image

It seems the the debugger does not find the sourcecode of the DLL? The files all lie in the same directory:

Any ideas what I'm missing here?

yangwang201911 commented 1 year ago

Hi @pascalzeugin. I found a workaround for this issue refer to this link.

Maybe this issue is caused by Python C++ Debugger attached to incorrect Pid of python app.

pascalzeugin commented 1 year ago

Hi @pascalzeugin. I found a workaround for this issue refer to this link.

Maybe this issue is caused by Python C++ Debugger attached to incorrect Pid of python app.

Hi @yangwang201911 and thank you for your response. I've have already ruled out this issue, see my post on stackoverflow

axelande commented 1 year ago

Could it be related to this? https://github.com/MicrosoftDocs/visualstudio-docs/issues/8621 "There's a known general issue with mixed-mode debugging and venvs due to the fact that Python for Windows uses a stub python.exe for venvs "

pascalzeugin commented 1 year ago

Hi @axelande and thanks for your response. I think these issues are not related as I neither use a virtual environment nor do I use the debugger from visual studio.

benibenj commented 1 year ago

Closing this issue as it's not an issue with the extension. I recommend trying to run your code on WSL. Compiling and linking the code correctly can be hard and frustrating on Windows.