PDA Debugger Example

To follow this example, impor the PDA Debugger sample plugins into your workspace.  Build them, and launch an Eclipse Application with these plugins.

PDA language and its interpreter

For this example, we chose an enhanced push down automata (PDA) assembly language and a simple interpreter implemented. Each line contains a single operation and any number of arguments. Our language differs from a standard PDA in two major ways:

The interpreter itself is written in Java.  When the debugger is launched a new Java process is created which executes the interpreter.

Here is an annotated example of the Fibonacci computation (note that the annotations themselves are not valid syntax in this language – in this language, all comments must start at column 1 and be the entire line):

push 6
call Fibonacci function call with one argument on the data stack
output print result to stdout
halt
#
# f(n) = f(n-1) + f(n-2)
# f(0) = 1
# f(1) = 1
#
:fibonacci
var n define variable n on control stack
pop $n get n from data stack
push $n
branch_not_zero gt0
push 1 f(0) = 1
return return with one value on data stack
:gt0
push $n
dec
branch_not_zero gt1
push 1 f(1) = 1
return return with one value on data stack
:gt1
push $n stack: n
dec stack: n-1
call fibonacci stack: f(n-1)
push $n stack: f(n-1) n
dec stack: f(n-1) n-1
dec stack: f(n-1) n-2
call Fibonacci stack: f(n-1) f(n-2)
add stack: f(n-1)+f(n-2)
return return with one value on data stack

To support the editing and viewing of the PDA laungage programs in Eclipse.  The PDA Debugger example includes a specialized PDA Editor.  The implementation of this editor is beyond the scope of the debugger APIs so it will not be described here in more detail.

PDA Editor
Image of the PDA Editor

Interpreter debug interface

Our PDA assembly language interpreter can be started in either run mode or debug mode. When started in debug mode, the interpreter listens for debug commands on a specified local TCP socket and sends debug events to a separate local TCP socket.  In our Eclipse debugger integration, each PDA debugger command and event has a corresponding object, which can be found in the org.eclipse.debug.examples.core.pda.protocol package.  Some of the comamnds and events are described below:

The commands include:

The debug events that are reported asynchronously to the second socket include:

Launching the PDA Debugger

For a quick demonstration of the PDA Debugger, launch it in your target Eclipse Application:
  1. To launch the PDA debugger you will need to have a PDA program in your workspace.  To do this simply create a new resource project, and copy a sample PDA program into it. Hint: a number of PDA program examples can be found in org.eclipse.debug.examples.pda.core/samples folder.
  2. Open the Debug Configurations dialog (Run->Debug Configurations...)
  3. Create a new PDA Application launch configuration.
  4. In the Main->Program field, enter the path to the PDA program in your workspace.
  5. Select Debug button to launch the debugger.
  6. Set a breakpoint in your program to stop the execution.

PDA Debugger Launch UI
Image of the ;aunch configuration dialog editing a PDA Debugger launch.

To see how the PDA Debugger launch logic is implemented, look at the following (in the PDA example plugins):

PDA Debug Model

The PDA example is a full featured debugger which supports threads, stack, and variables.  This is reflected in the presentation of the debug model in Debug view

PDA Debug Model in Debug view
Image of PDA Debugger elements in Debug view.


The PDA debugger presents the debug model by implementing the Eclipse Platform Debug standard debug model API.  The classes implementing these interfaces are found in the org.eclipse.debug.examples.core.pda.model package.

PDA Breakpoints

The PDA debugger supports two type of breakpoints:

Breakpoints view showing PDA Breakpoints
Image of the Breakpoints view with PDA breakpoints.

To see the PDA breakpoints implementation look at the following:
The PDA debugger also implements specialized UI elements to allow the user to create and remove the breakpoints.  For example, the user can create a PDA breakpoint by double-clicking on the editor gutter in the PDA Editor. 

Toggle Breakpoints action in PDA Editor
Image of the Toggle Breakpoint action in PDA editor.

To see how this is implemented, look at the following:

PDA Data Stack View

The PDA interpreter features Data Stack, which is a specialized feature which is not commonly found in debuggers.  To present the Data Stack to the user, the PDA debugger includes a special Data Stack view.

PDA Data Stack view
Image of the PDA Data Stack view.

To see how this view is implemented look at the the org.eclipse.debug.examples.ui.pda.views package in the example code.