<type>documentation</type>
<domain>scripting</domain>
<id>example</id>
<title>Debugging Extension Scripts</title>
<date>$Date$</date>
<version>$Revision$</version>
<product>per+</product>

Wing can debug extension scripts that you develop for the IDE. This is done by setting up
a new project from Wing's ``Project`` menu.  Select the default project type and for
``Python Executable`` select ``Custom`` and then enter the full path to the Python
executable that Wing uses to run itself.  This located below the ``Install Directory``
listed in Wing's `About box <script:about-application>`__, as follows:

  **OS X:** ``Contents/Resources/bin/__os__/osx/runtime-python2.7/bin/python``
    
  **Linux:** ``bin/__os__/linux-x64/runtime-python2.7/bin/python``
    
  **Windows:** ``bin\__os__\win32\runtime-python2.7\bin\python.exe``

Be sure to use the *full path* to the executable and not the above partial paths.

Press ``OK`` in the ``New Project`` dialog to create the project, then select 
``Add Existing Directory`` from the ``Project`` menu and add the ``Install Directory``.

Next navigate to ``bootstrap/wing.py`` in the ``Project`` tool, right click on it, and 
select ``Set As Main Entry Point``.

Finally, on OS X only, you will need to open ``Project Properties`` from the ``Project`` 
menu, select ``Add To inherited environment`` under ``Environment``, and paste in the
following::

  INSTALLDIR=/Applications/WingPro.app/Contents/Resources
  RUNTIMES=${INSTALLDIR}/bin/__os__/osx
  QTVERSION=qt5.10
  QTRUNTIME=${RUNTIMES}/runtime-${QTVERSION}
  SCIRUNTIME=${RUNTIMES}/runtime-scintillaedit-${QTVERSION}
  DYLD_LIBRARY_PATH=${QTRUNTIME}/lib:${SCIRUNTIME}/lib
  DYLD_FRAMEWORK_PATH=${DYLD_LIBRARY_PATH}

If you didn't install Wing in the ``/Applications`` folder then you will need to edit
the first line to specify the correct ``Install Dir``.

Then save your project to disk.

You should now be able to select ``Start/Continue`` from the ``Debug`` menu to start up a
copy of Wing in the debugger. Any breakpoints set in scripts that you have added in the
``scripts`` directory will be reached as you work with the debugged copy of Wing. You will
see and can navigate the entire stack, but Wing will not be able to show files for most of
Wing's code. If you need to see the source code of Wing itself, you will have to obtain
the source code as described in `Advanced Scripting <ref:scripting/advanced>`__.

