changeset 22008:02e4cf046653

Providing a bit more meaningful documentation to our recent debugging improvements
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 22 Jul 2015 14:25:03 +0200
parents 12891f4cae7a
children 130e5f69d1a6
files truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Breakpoint.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/package-info.java
diffstat 4 files changed, 91 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Breakpoint.java	Wed Jul 22 13:07:02 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Breakpoint.java	Wed Jul 22 14:25:03 2015 +0200
@@ -26,12 +26,20 @@
 
 import com.oracle.truffle.api.instrument.*;
 import com.oracle.truffle.api.source.*;
+import com.oracle.truffle.api.vm.TruffleVM;
 import java.io.IOException;
 
+/**
+ * Breakpoint in a {@link TruffleVM} with {@link com.oracle.truffle.api.debug debugging turned on}.
+ * You can ask
+ * {@link Debugger#setLineBreakpoint(int, com.oracle.truffle.api.source.LineLocation, boolean)} or
+ * {@link Debugger#setTagBreakpoint(int, com.oracle.truffle.api.instrument.SyntaxTag, boolean)} to
+ * create an instance of {@link Breakpoint}.
+ */
 public abstract class Breakpoint {
 
     /**
-     * A general model of the states occupied by a breakpoint during its lifetime.
+     * A general model of the states occupied by a {@link Breakpoint} during its lifetime.
      */
     public enum State {
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java	Wed Jul 22 13:07:02 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java	Wed Jul 22 14:25:03 2015 +0200
@@ -37,7 +37,9 @@
 import com.oracle.truffle.api.vm.TruffleVM;
 
 /**
- * Language-agnostic engine for running Truffle languages under debugging control.
+ * Represents debugging related state of a {@link TruffleVM}. Instance of this class is delivered
+ * via {@link SuspendedEvent#getDebugger()} and {@link ExecutionEvent#getDebugger()} events, once
+ * {@link com.oracle.truffle.api.debug debugging is turned on}.
  */
 public final class Debugger {
 
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java	Wed Jul 22 13:07:02 2015 +0200
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java	Wed Jul 22 14:25:03 2015 +0200
@@ -44,8 +44,8 @@
  * {@link Debugger#setLineBreakpoint(int, com.oracle.truffle.api.source.LineLocation, boolean)
  * breakpoint} or during {@link #prepareStepInto(int) stepping}. Methods in this event can only be
  * used while the handlers process the event. Then the state of the event becomes invalid and
- * subsequent calls to the event methods yield {@link IllegalStateException}.
- *
+ * subsequent calls to the event methods yield {@link IllegalStateException}. One can call
+ * {@link #getDebugger()} and keep reference to it for as long as necessary.
  */
 public final class SuspendedEvent {
     private final List<String> recentWarnings;
@@ -81,7 +81,7 @@
     }
 
     /**
-     * Debugger associated with the just suspended execution. This debuger remains valid after the
+     * Debugger associated with the just suspended execution. This debugger remains valid after the
      * event is processed, it is possible and suggested to keep a reference to it and use it any
      * time later when evaluating sources in the {@link TruffleVM}.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/package-info.java	Wed Jul 22 14:25:03 2015 +0200
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Control over {@link com.oracle.truffle.api.debug.Debugger debugging} of your {@link com.oracle.truffle.api.vm.TruffleVM}. Each {@link com.oracle.truffle.api.vm.TruffleVM}
+ * is inherently capable to run in debugging mode - there is just one thing
+ * to do - the {@link com.oracle.truffle.api.vm.TruffleVM.Builder creator of the virtual machine}
+ * needs to turn debugging on when constructing its Truffle virtual machine:
+ * <pre>
+ * vm = {@link com.oracle.truffle.api.vm.TruffleVM#newVM()}.
+ *     {@link com.oracle.truffle.api.vm.TruffleVM.Builder#onEvent(com.oracle.truffle.api.vm.EventConsumer) onEvent}(<b>new</b> {@link com.oracle.truffle.api.vm.EventConsumer EventConsumer}{@code <}{@link com.oracle.truffle.api.debug.ExecutionEvent}{@code >}() {
+ *         <b>public void</b> handle({@link com.oracle.truffle.api.debug.ExecutionEvent} ev) {
+ *             <em>// configure the virtual machine as {@link com.oracle.truffle.api.vm.TruffleVM#eval(java.net.URI) new execution} is starting</em>
+ *         }
+ *     }).
+ *     {@link com.oracle.truffle.api.vm.TruffleVM.Builder#onEvent(com.oracle.truffle.api.vm.EventConsumer) onEvent}(<b>new</b> {@link com.oracle.truffle.api.vm.EventConsumer EventConsumer}{@code <}{@link com.oracle.truffle.api.debug.SuspendedEvent}{@code >}() {
+ *         <b>public void</b> handle({@link com.oracle.truffle.api.debug.SuspendedEvent} ev) {
+ *             <em>// execution is suspended on a breakpoint or on a step - decide what next</em>
+ *         }
+ *     }).{@link com.oracle.truffle.api.vm.TruffleVM.Builder#build() build()};
+ * </pre>
+ * The debugging is controlled by events emitted by the Truffle virtual machine
+ * at important moments. The {@link com.oracle.truffle.api.debug.ExecutionEvent}
+ * is sent when a call to {@link com.oracle.truffle.api.vm.TruffleVM#eval(java.net.URI) eval(...)} 
+ * is made and allows one to configure {@link com.oracle.truffle.api.debug.Breakpoint breakpoints} and/or decide whether the
+ * program should {@link com.oracle.truffle.api.debug.ExecutionEvent#prepareStepInto() step-into} or 
+ * {@link com.oracle.truffle.api.debug.ExecutionEvent#prepareContinue() just run}. Once the execution is suspended a
+ * {@link com.oracle.truffle.api.debug.SuspendedEvent} is generated which
+ * allows one to inspect the stack and choose the further execution mode
+ * ({@link com.oracle.truffle.api.debug.SuspendedEvent#prepareStepInto(int) step-into}, {@link com.oracle.truffle.api.debug.SuspendedEvent#prepareStepOver(int) step-over}, {@link com.oracle.truffle.api.debug.SuspendedEvent#prepareStepOut() step-out}, {@link com.oracle.truffle.api.debug.SuspendedEvent#prepareContinue() continue}).
+ * <p>
+ * The events methods are only available when the event is being delivered and
+ * shouldn't be used anytime later. Both events however provide access to
+ * {@link com.oracle.truffle.api.debug.Debugger} which can be kept and used
+ * during whole existence of the {@link com.oracle.truffle.api.vm.TruffleVM}.
+ * {@link com.oracle.truffle.api.debug.Debugger} is the central class that 
+ * keeps information about {@link com.oracle.truffle.api.debug.Debugger#getBreakpoints() registered breakpoints}
+ * and allows one create new {@link com.oracle.truffle.api.debug.Breakpoint ones}.
+ * 
+ * <h4>Turning on Stepping Mode</h4>
+ * 
+ * In case you want your execution to pause on first statement, register for
+ * {@link com.oracle.truffle.api.debug.ExecutionEvent} and once delivered
+ * call {@link com.oracle.truffle.api.debug.ExecutionEvent#prepareStepInto()}.
+ *
+ * <h4>Register a {@link com.oracle.truffle.api.debug.Breakpoint}</h4>
+ * 
+ * Wait for execution to be started - which generates an
+ * {@link com.oracle.truffle.api.debug.ExecutionEvent}. Use its
+ * {@link com.oracle.truffle.api.debug.Debugger ev.getDebugger}()
+ * methods to submit breakpoints.
+ */
+package com.oracle.truffle.api.debug;
+