This example models a single thread of execution that can execute a simple instruction to increment a value. The value is initialized with a minimum value (1) and is incremented to a maximum value (100). When the value overflows, it is reset to the minimum value. The debug model consists of a debug target with a single thread. The thread's stack frames are based on the current count value. The number of frames (stack depth) corresponds to the current count value with the highest number on the top of the stack.
For simplicity, counting executes the same process as the Eclipse SDK, in a separate thread. The increment instruction increments a value and sleeps for 100ms (just so each instruction takes a non-zero amount of time). The model allows the user to suspend, resume, and step. A step executes a single instruction. Resuming causes the counter to execute instructions until suspended, terminated, or a breakpoint is hit. A breakpoint can be set for a specific value.
To see how the debug model is implemented, look at the following classes in the org.eclipse.debug.examples.counter.model
package. The majority of the model's logic is implemented in the thread object. The target and stack frame implementations delegate to the thread to perform all suspend, resume, step, and terminate actions.
CounterDebugTarget
CounterThread
CounterStackFrame
Image of the launch configuration
dialog editing a Counter launch.
counter.launchType
declaration (org.eclipse.debug.core.launchConfigurationTypes
extension point) in org.eclipse.debug.examples.counter/plugin.xml
org.eclipse.debug.examples.counter.model.CounterLaunchDelegate
implementationcounter.tabGroup
declaration (org.eclipse.debug.ui.launchConfigurationTabGroups
extension point)
Image of the Breakpoints view with
Limit breakpoints.
markerType.limit
declaration (org.eclipse.core.resources.markers
extension point) in org.eclipse.debug.examples.counter/plugin.xml
counter.limitBreakpoint
declaration (org.eclipse.debug.core.breakpoints
extension point) in org.eclipse.debug.examples.counter/plugin.xml
org.eclipse.debug.examples.counter.breakpoints.LimitBreakpoint
breakpoint object implementing the standard
debug mode breakpoints APIA limit breakpoint is created by selecting a Counter debug target, thread, or stack frame and selecting the Run > Toggle Breakpoint (Ctrl+Shift+B) action. A dialog prompts for the limit value.
Image of Limit breakpoint dialog that prompts for breakpoint value..
An adapter is contributed for the Counter debug elements to retarget the Toggle Breakpoint action. To see how this is implemented, look at the following:
org.eclipse.debug.examples.counter.breakpoints.CounterAdapterFactory
and its declaration (org.eclipse.core.runtime.adapters
extension point) in org.eclipse.debug.examples.counter/plugin.xml
org.eclipse.debug.examples.counter.breakpoints.CounterToggleBreakpointsTarget
adapter object implementing IToggleBreakpointsTargetExtension