Python Debugging

From Valve Developer Community
Jump to: navigation, search
Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024
Icon-broom.png
This article or section needs to be cleaned up to conform to a higher standard of quality.
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

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).

Note: Due to the way debugging works this will only work on a debug build of the source sdk because of security issues.

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.

You will also need to install python 2.6.2 as wing ide uses this for a number of things.

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.

Once that is done edit wingdbstub.py 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

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.

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