Python Debugging

From Valve Developer Community
Revision as of 02:31, 16 September 2009 by Lodle (talk | contribs) (Wing IDE Setup)
Jump to: navigation, search

Often debugging scripting languages means 100's of printfs to work out whats going on how ever for python, you can attach a proper debugger to it and have breakpoints, see variable values and much more.

This tutorial assumes you have all ready completed the Adding Python Tutorial and also you have the latest svn checkout (in that tutorial also).

Needed Software

The debugger that we will be using to day is called Wing IDE. The version you need is the personal one (or pro) as we need the ability to connect remotely to the python instance as its embedded inside the source engine. Now its not free but the amount of effort that it will save you is worth the money. You can also use the trail for 30 days to play around with it if needed.

Make sure you install it once you have downloaded it.

Getting Started

Wing IDE Setup

You will need enable remote debugging in wing for this to work. Goto Preferences (edit menu) --> Debugging --> External/Remote and enable Passive listening

You will also need to copy some files from the wing install into your python scripts folder. Open the Wing Install folder (default is: C:\Program Files (x86)\Wing IDE 3.2) and copy the file to your mod/scripts/python folder. You will also need to grab wingdebugpw from c:\Users\${username}\AppData\Roaming\Wing IDE 3 (for xp its c:\Documents and Settings\${username}\Application Data\Wing IDE 3) and copy it to the same folder.

Once that is done edit and set kEmbedded to 1.

Source SDK Setup

In the server project settings you need to add some settings so it compile correctly. You will need to add theses to debug only.

Add these to: Configure properties -> c++ -> Preprocesser -> Preprocesser defines


Add these to: Configure properties -> Linker -> Input -> Additional Dependencies


Ready to Rumble

Once you have completed the above steps you should be ready to go. Make sure Wing IDE is open (and be nice to load the mod/scripts/python folder) and then run your mod in debug mode from visual studio and it should connect to wing, break on break points and break on python exceptions.

You can tell if SourceSDK is connected to the Wing IDE as the bottom left icon should turn green.