HOW-TO:Debug python scripts with WinPDB

From Official Kodi Wiki
Jump to: navigation, search
Home icon grey.png   ▶ Development ▶ Add-on development ▶ Python development ▶ HOW-TO:Debug python scripts with WinPDB

You can easily debug python scripts running inside XBMC in a few simple steps using WinPDB!

1 Requirements

  • XBMC installed on Linux or Windows (should also work fine on Mac)
  • Install WinPDB. Download the binary installer for Windows or Mac, use this command for Linux:
    $ sudo apt-get install winpdb
  • On Mac, Windows and some Linux distros you will also need to install wxPython. If you are using 32-bit python, use the 32-bit version. Always get the unicode version

2 Create a symlink for the debugger

How to make a symlink in Linux

  • Assuming your script's name is Foo
$ cd /home/<user>/.xbmc/scripts/Foo
$ ln -s `find /usr/lib/pymodules -name`

How to make a symlink in Windows

  • At Command Prompt type the equivalent of this, with your own paths:

For Windows 7

mklink "C:\Program Files (x86)\XBMC\addons\\" "C:\Python27\Scripts\"

For Windows XP, Vista

fsutil hardlink "C:\Program Files (x86)\XBMC\addons\\" "C:\Python27\Scripts\"

The first path makes the link in your addon folder, the second path tells the link to point to where the original file can be found.

3 Modify your script to enable debugger

  • Edit /home/<user>/.xbmc/scripts/Foo/ and add the following code to the top
import rpdb2 

4 How to start WinPDB

  • Linux: (Desktop Menu Bar -> Applications -> Programming -> Winpdb)
  • Windows/Mac: Execute For a quicker launch, make shortcut on desktop for (example location:)

5 Start debugging session

  • From within XBMC, start your script (it will appear to sit there and hang)
  • Start WinPDB
  • In WinPDB, select File->Password and enter "pw" (no quotes)
  • Select File->Attach. You should see your running script in the list box along with its PID and filename.
  • Select your script and click OK. The debugger is now attached to your script.

6 Setting breakpoints


7 Screenshot


8 See also