Tech:Open Source/Running/Debugging Hints
From Cyclopath
Contents |
[edit] Debugging Hints
[edit] Tracing Services
There are a number of logfiles it's convenient to watch.
Apache maintains two logs, the access log and the error log; PostgreSQL has one log; and the three Cyclopath applications -- pyserver, routed, and tilecache -- each have their own log.
You can watch them altogther and interleaved with the tail command.
By default, some of the logs cannot be read unless root, so use sudo.
sudo tail -F /var/log/apache2/access.log \
/var/log/apache2/error.log \
/var/log/postgresql/postgresql-8.3-main.log \
/tmp/pyserver.apache.log \
/tmp/pyserver.routed.log \
/tmp/pyserver.tilecache.log
Here are simple commands to add to thw ec file, for a quick took at any log file:
e1='sudo tail /var/log/apache2/access.log' e2='sudo tail /var/log/apache2/error.log' e3='sudo tail /var/log/postgresql/postgresql-8.3-main.log' e4='sudo tail /tmp/pyserver.apache.log' e5='sudo tail /tmp/pyserver.routed.log' e6='sudo tail /tmp/pyserver.tilecache.log' e7='tail ~/.macromedia/Flash_Player/Logs/flashlog.txt'
If you don't have sudo access, you can choose not to watch certain logs, or you can ask someone with sudo access to change the group permissions on the logfiles in question.
[edit] Debugging Flash
[edit] Tracing Flash
Flash sends application trace() output to ~/.macromedia/Flash_Player/Logs/flashlog.txt. You can watch it live with the tail command
tail -F ~/.macromedia/Flash_Player/Logs/flashlog.txt
[edit] Walking Flex Code
[edit] Adobe Flex Builder
Some people are eligble to download a free Flex builder application from Adobe.
https://freeriatools.adobe.com/flex/
FIXME Document application process, downloading, installing and running
FIXME Are there alternatives to Flex Builder for walking code?
[edit] Debugging with Flex Builder
[edit] Debugging Python
[edit] Winpdb
Winpdb is a cross-platform remote Python debugger. I.e., something you can use to debug mod_python code!
[edit] Download Winpdb
Download the source from http://winpdb.org/ (here's the direct link for Version 1.4.6).
Winpdb says you need wxPython, but that's only for the GUI client. I'm happier debugging from a command prompt, so don't bother getting wxPython (I couldn't get it to compile, anyway =).
First, unpack the winpdb source and copy the winpdb directory into your pyserver directory (and rename it 'winpdb').
cd /export/scratch/checkout wget http://winpdb.googlecode.com/files/winpdb-1.4.6.tar.gz tar xvf winpdb-1.4.6.tar.gz cp winpdb-1.4.6 /export/scratch/$USER/cp/pyserver/
Don't forget to change permissions so Apache can get at these files.
cd /export/scratch/$USER/cp/pyserver/ ./fixperms.sh
[edit] Configure Apache
Next, reconfigure Apache to only use one thread, otherwise Winpdb may not function properly.
Open the Cyclopath sites-available file
vi /etc/apache2/sites-available/cyclopath
and add the following inside the VirtualHost section
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 1
MaxClients 1
MaxRequestsPerChild 1000
</IfModule>
Also add the path to Winpdb to your mod_python system path. E.g,
PythonPath "['/export/scratch/landonb/cp/pyserver'] + ['/export/scratch/landonb/cp/pyserver/winpdb'] + sys.path"
Save and close the file.
[edit] Configure Your Code
Add the following to your python code where you'd like to set a breakpoint.
import rpdb2; rpdb2.start_embedded_debugger('password', fAllowRemote=True)
Restart Apache.
[edit] Break Into Your Code
Refresh the User Agent; it should hang, waiting for a debugger to attach.
Run the remote debugging script
python rpdb2.py
Set the password
password password
View the list of matching processes
attach
Attach to your process
attach <PID>
Debug away!
[edit] Winpdb Hints
- For help, consult Winpdb's inline help. I.e., just type help from the Python prompt
help
- For whatever reason, Winpdb doesn't use the 'p' command to 'print' variables. Instead, use the eval command, or simply 'v'.
- Use exec (or 'x') to execute arbitrary Python code.
FIXME Show an example of v and x
[edit] Pylint
In the source code, you'll find pylint.sh.
FIXME The pylint.sh script is currently broken. Bug #?
Linting your Python code is a good idea and can catch a lot of errors upfront. To run the script, change to your pyserver directory and run the script from there.
cd pyserver ../scripts/pylint.sh
