3.7 Machine code inspection

Psyco works by directly emitting machine code for the processor. Typically, it will write a large number of small blocks of code, with numerous jumps from one to the other.

As you can guess, debugging this machine code with traditional tools was difficult, so I had to write helpers. They can be found in the py-utils subdirectory. You need a version of Psyco compiled in debugging mode; see section 1.4 for instructions on how to build it.

dumpcodebuf( )
This function (to be called near the end of your program) dumps all the machine code and supporting data structures into a file psyco.dump. This function has no effect if Psyco was not compiled in debugging mode.

Run the script httpxam.py with as argument the name of the directory which contains the psyco.dump file to examine. This script formats the data as HTML pages and presents them via a web server built on Python's standard SimpleHTTPServer. When it is running, point your browser to

httpxam.py probably only works on Linux. It requires the programs objdump or ndisasm to disassemble the code and nm to list symbol addresses in the Python and Psyco executables.

The cross-calling code buffers are presented as cross-linked HTML pages. Bold lines show the targets of another jump. If preceeded by a blank line, a bold line shows that another code buffer jumps directly at this position. The end of the buffer is often garbage; it is not code, but data added there (typically for the promotion of a value). There are various kind of code buffers, depending (only) on why Psyco produced it:

normal mainstream compilation
execution jumps here when an error occurs, but never did so yet
replaces a respawn buffer when execution has jumped here
small buffer whose purpose is to jump back to an existing one
called when a change is detected in a global variable
not yet compiled, will be compiled if execution jumps here