Zoltan Kemenczy of Research In Motion Ltd. contributed changes
to $PTII/bin/ptinvoke.in
that use
the Emacs gud.el file
to provide source level debugging of Ptolemy II.
Christopher Hylands modified Zoltan's original notes.
Note that the debugger works best on distributions of Ptolemy II that include the Ptolemy II source files. The Windows installer and the WebStart versions of Ptolemy II do not include source files, so the debugger will be of little use under WebStart. Because the Windows installer and the WebStart editions do not include the source files, some of the hyperlinks below may be invalid.
See also the Ptolemy II Eclipse Page.
jdb
and GNU Emacs to debug Java code.
GNU Emacs is a powerful and complex editing and development environment. If you are unfamiliar with GNU Emacs, you should try running the GNU Emacs tutorial. In theory, it should be possible to debug Ptolemy using other debuggers, but we have not tried them.
The gud.el
file included in Ptolemy II
requires a version of GNU emacs more recent than Emacs-20.7.1.
The gud.el
file
will not work with Emacs-20.7.1 because M-x jdb
results in:
Symbol's function definition is void: easy-mmode-define-keymapWe have tested the interface under Emacs-21.2.1.
Below are the steps necessary to install Emacs under Windows.
ftp://ftp.gnu.org/gnu/windows/emacs/latest
The file to download isemacs-xx.x-bin-i386.tar.gz
c:\Program Files
so
that c:\Program Files\emacs-xx.xx
is created
c:\Program Files\emacs-xx.xx\README.W32
file
says:
To install Emacs, simply unpack all the files into a directory of your choice, but note that you might encounter minor problems if there is a space anywhere in the directory name. To complete the installation process, you can optionally run the program addpm.exe in the bin subdirectory. This will add some entries to the registry that tell Emacs where to find its support files, and put an icon for Emacs in the Start Menu under "Start -> Programs -> Gnu Emacs -> Emacs".So, go ahead and click on the
addpm.exe
icon, which
will add an Emacs icon to the start menu.
The GNU Emacs FAQ For Windows 95/98/ME/NT/XP and 2000 can be found at
http://www.gnu.org/software/emacs/windows/ntemacs.html
$HOME/.emacs
at start up time.
Under Windows 2000, you set the environment variables via
the Environment tab of the System control panel
(Start Menu
-> Settings
->
Control Panels
-> System
->
Advanced
-> Environment Variables
The HOME
variable name your home directory using
the DOS drive name with backslashes. For example, if your
home directory is in c:\users\yourname
, then you would
enter the value c:\users\yourname
While you are editing environment variables, be sure that
$PTII
is set. For details, see
Set the value of the PTII
environment variable
The GNU Emacs FAQ For Windows 95/98/ME/NT/XP and 2000
at http://www.gnu.org/software/emacs/windows/ntemacs.html
discusses
the .emacs
file further.
To debug Ptolemy II, Emacs needs to be told where to find the
gud.el
file. Start up Emacs by using
Start -> Programs -> Gnu Emacs -> Emacs
and add the following to your $HOME/.emacs
file.
(setq load-path (append (list (expand-file-name (concat (getenv "PTII") "/util/lisp"))) load-path ))A more complete example
.emacs
file can be found at
$PTII/util/lisp/ptemacs.el
If you wish, you can copy this file to your $HOME/.emacs
file. This file includes support for
M-x shell
This feature is especially nice while running a vergil -debug
session from within emacs and the user wants to set a breakpoint in an
actor or director. Typical, one starts up vergil with vergil
-debug
Control-x SPACE to set a break point.
To do this, you need to have Gnuserv installed and do some other set up.
http://www.gnu.org/software/emacs/windows/faq2.html#assoc
discusses how to install gnuserv/gnuclient
http://www.wyrdrune.com/Files/gnuserv.zip
c:/tmp/gnuserv
gnuserv.el
into emacs' load-path, in this case
cd c:/tmp/gnuserv cp gnuserv.el $PTII/util/lisp
cp Release/*.exe $PTII/bin
$PTII/bin
is in your path.
$PTII/bin
(Under Windows XP, you set the environment variable via
the Environment tab of the System control panel
(Start Menu
->
Control Panels
-> System
->
Advanced
-> Environment Variables
)
%PTII%\binor you should expand
PTII
by hand
c:\ptII\bin
(load "gnuserv") (gnuserv-start)to your
~/.emacs
file
$PTII/bin/ptinvoke.in
and uncomment the line
USERJAVAPROPERTIES=-Dptolemy.user.texteditor=emacsand then run
maketo update
$PTII/bin/vergil
etc.
vergil
and try File -> New -> Text Editor.
$PTII/bin
have the following options that interact with the debugger.
bash -C
:
cd %PTI% bash -C ptolemy -debug ptolemy/domains/sdf/demo/Butterfly/Butterfly.xml
-debug
Notes:
-jdb
ptolemy -jdb .../my.xml
-q
-q
with -jdb
within
Emacs. If you do, then the Emacs GUD mode will not be able to get the
classpath.
-profiler
These have already been submitted to Richard Stallman and incorporated into the www.gnu.org Emacs CVS, but there are not yet in 21.2
The following is a useful addition to a user's .emacs file (for the Windows shared memory attach) (setq gud-jdb-command-name "jdb -attach javadebug")
The documentation of changes is in the gud-jdb-use-classpath and gud-jdb-classpath (and other gud-jdb-xxx) variables. The new method of finding java source files through the classpath of the JVM is automatically enabled so no special setup is needed.
There are two primary ways to use the Emacs interface to debug Ptolemy:
-debug
option is more commonly used than -jdb
because with -debug
, you can attach the debugger at any
point during the run.
To use -debug
, just start your vergil from a bash or Emacs shell
with:
vergil -debug &You should see a message:
Listening for transport dt_shmem at address: javadebugand the vergil window should come up.
when you'd like to debug (e.g set breakpoints or catch exceptions), start jdb from Emacs by:
M-x jdbThen type
jdb -attach javadebugif you're on windows (on Unix "javadebug" would be replaced by the JVM debug server socket port number).
You should get a buffer named *gud-...* with the Initializing jdb... message. After that switch to any Emacs buffer holding a source and go to a function that will be used during a run (e.g. Manager.run()). On a source line, press C-x SPACE. In the *gud-...* buffer, a breakpoint command is automatically entered for you (this is GUD at work).
Now run the model... When the breakpoint is hit the source file (Manager.java) will be positioned at the breakpoint with a "=>" at the beginning of the line where the stop occurred. Now you can use C-c C-n (for "next" or "step-over") or C-c C-s (for "step" or "step-into") and a bunch of other short-cuts (like call stack browsing up/down)... An the "=>" follows your steps and brings up source files as needed (GUD again...:).
Most of the standard gud-style commands are supported (check out the "GUD" menu in the *gud-..*
-debug
and -jdb
is
that
-jdb
can be used to debug initialization code that would
have already been run by the time the application comes up.
You can start ptolemy -jdb
from a bash shell within Emacs, but that doesn't get you into GUD
mode, which allows for easy breakpoint setting etc.
To start vergil or ptolemy (or other) with jdb instead of java, enter start jdb from Emacs by:
M-x jdband then type:
bash -C ptolemy -jdb ptolemy/domains/sdf/demo/Butterfly/Butterfly.xml
Don't use the -q flag here because that will prevent GUD from getting the classpath (it finds it in the command line echo provided by ptinvoke. If you used a manual way of starting jdb (instead of ptinvoke), you would normally have to provide a -classpath argument which is what GUD is looking for).
The windows version of Emacs is not cygwin-aware and it uses its own win32 api to start any subprocess and this looks for an ".exe" (or .bat)... This is why we have to insert "bash -C" (which is an exe in the path) to make sure that the ptolemy link will be caught and processed...
If you then switch to a java source (that is in the classpath and/or sourcepath) and do C-x SPC, a breakpoint will be set.
M-x shell
. In Emacs, M-x
means
Esc
key and then the x
key."
*shell*
. In
this buffer, start up vergil with
$PTII/bin/vergil -debug $PTII/ptolemy/domains/sdf/demo/Spectrum/Spectrum.xml
View
-> Run
-> Go
M-x jdb
.
If your .emacs
file contains:
(setq gud-jdb-command-name "jdb -attach javadebug")then after typing
M-x jdb
, the following lines should
appear in the minibuffer at the bottom of the emacs window:
Run jdb (like this): jdb -attach javadebugIf
jdb -attach javadebug
does not appear, then type it
in.
After the minibuffer contains jdb -attach javadebug
hit Enter
and jdb starts up.
iterate()
method
of the Ramp actor. To do this, type in the following in
the *gud-javadebug*
buffer
stop in ptolemy.actor.lib.Ramp.iterate
View
-> Run
-> Go
iterate()
method
C-x C-f
and then $PTII/ptolemy/actor/lib/Ramp.java
In Emacs documentation, C-x
means
Control
key down and then hit the x
key"
and then typing
up down wherein the
*gud-javadebug*
buffer
next
print variable name
next
twice, and
then viewed the value of the i
variable:
[7] java.lang.Thread.run (Thread.java:536) Thread-5[1] next > Step completed: "thread=Thread-5", ptolemy.actor.lib.Ramp.iterate(), line=186 bci=17 186 for (int i = 0; i < count; i++) { Thread-5[1] next > Step completed: "thread=Thread-5", ptolemy.actor.lib.Ramp.iterate(), line=187 bci=22 187 _resultArray[i] = _stateToken; Thread-5[1] print i i = 0 Thread-5[1]
To get further help with jdb
, type help
while in the *gud-javadebug*
buffer.
For further information about jdb
, see
JavaTM Platform Debugger Architecture.
For further information about the Emacs Grand Unified Debugger (GUD) Interface, use the GNU Emacs Info help system.
Help
menu, or type M-x info
Emacs
line and type a m
followed by hitting the Enter
key.
Starting GUD
line and
type a m
and hit return