pythonvisual-c++swigquantlib-swig

How to Debug QuantLib-Python module in Visual Studio


QuantLib-Python is a SWIG-generated python module allowing access to QuantLib (C++) functionality. I wish to debug the core QuantLib source code from within Visual Studio debugger (by attaching to a python process). In the past I was able to do this on Visual Studio 2015 without much issue, using the steps below. However, on Visual Studio 2017 (and 2019) the debug symbols are not being loaded into Visual Studio from the PDB file.

  1. Build QuantLib C++ code in visual studio (Debug|x64)
  2. Add the following to the quantlib.i SWIG file (to combine debug C++ with release python)
        %begin %{
        #ifdef _MSC_VER
        #define SWIG_PYTHON_INTERPRETER_NO_DEBUG
        #endif
        %}
  1. python setup.py wrap
  2. python setup.py build --debug
  3. python setup.py install
  4. Launch a python session and import QuantLib
  5. In Visual Studio, attach the debugger to the python process
  6. Set a breakpoint.
  7. Execute a statement in python that should hit above breakpoint (in VS2019 this breakpoint is not being hit).

I can see from the modules window that no symbols are being loaded for QuantLib. If I look at my QuantLib folder in site-packages I can see that the PDB file does indeed exist.

Has anyone else encountered this problem before? Any idea what might be causing the issue here?


Solution

  • I think I have figured this out now. One needs to ensure that "Native Code" is selected as the type of code to debug. This option can be set using the "Select" button, under "Debug > Attach To Process".

    Debug > Attach To Process