Python Debugging

From Valve Developer Community
Revision as of 09:22, 16 September 2009 by Lodle (talk | contribs) (Created page with '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 variab…')

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

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 wingdbstub.py 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.


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++ -> General-> Additional Include Directories

..\public\python
.\server\py

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

WINGDBG

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

winglib_d.lib

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.