comparison graal/com.oracle.truffle.tools.debug.engine/src/com/oracle/truffle/tools/debug/engine/DebugEngine.java @ 21890:894f82515e38

Truffle/APIs and Debugging: Evolutionary steps to integrating debugging and tool support with TruffleVM APIs - Add a version string to language registration: Language.getShortName() produces a string with both language and version - Rename SLMain --> SLLanguage (little change current machinery) - Remove DebugEngine dependence on ExecutionContext: Visualizer access migrated to TruffleLanguage - ExecutionContext now has only one method left: getCompilerOptions() - Rename SourceExecutionProvider to DebugSupportProvider, now supplied by implementing abstract TruffleLanguage.getDebugSupport() - Revise DebugEngine and its helper classes to work with the new APIs
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 09 Jun 2015 15:20:30 -0700
parents c072fbce5756
children
comparison
equal deleted inserted replaced
21889:45083be8a812 21890:894f82515e38
31 import com.oracle.truffle.api.*; 31 import com.oracle.truffle.api.*;
32 import com.oracle.truffle.api.frame.*; 32 import com.oracle.truffle.api.frame.*;
33 import com.oracle.truffle.api.instrument.*; 33 import com.oracle.truffle.api.instrument.*;
34 import com.oracle.truffle.api.nodes.*; 34 import com.oracle.truffle.api.nodes.*;
35 import com.oracle.truffle.api.source.*; 35 import com.oracle.truffle.api.source.*;
36 import com.oracle.truffle.tools.debug.engine.SourceExecutionProvider.ExecutionListener; 36 import com.oracle.truffle.api.vm.TruffleVM.Language;
37 import com.oracle.truffle.tools.debug.engine.DebugExecutionSupport.DebugExecutionListener;
37 38
38 /** 39 /**
39 * Language-agnostic engine for running Truffle languages under debugging control. 40 * Language-agnostic engine for running Truffle languages under debugging control.
40 */ 41 */
41 public final class DebugEngine { 42 public final class DebugEngine {
68 * Logs a warning that is kept until the start of the next execution. 69 * Logs a warning that is kept until the start of the next execution.
69 */ 70 */
70 void addWarning(String warning); 71 void addWarning(String warning);
71 } 72 }
72 73
74 private final Language language;
75
73 /** 76 /**
74 * The client of this engine. 77 * The client of this engine.
75 */ 78 */
76 private final DebugClient debugClient; 79 private final DebugClient debugClient;
77 80
78 private final SourceExecutionProvider sourceExecutionProvider; 81 private final DebugExecutionSupport executionSupport;
79 82
80 /** 83 /**
81 * Implementation of line-oriented breakpoints. 84 * Implementation of line-oriented breakpoints.
82 */ 85 */
83 private final LineBreakpointFactory lineBreaks; 86 private final LineBreakpointFactory lineBreaks;
92 */ 95 */
93 private DebugExecutionContext debugContext; 96 private DebugExecutionContext debugContext;
94 97
95 /** 98 /**
96 * @param debugClient 99 * @param debugClient
97 * @param sourceExecutionProvider 100 * @param language
98 */ 101 */
99 private DebugEngine(DebugClient debugClient, SourceExecutionProvider sourceExecutionProvider) { 102 private DebugEngine(DebugClient debugClient, Language language) {
100 this.debugClient = debugClient; 103 this.debugClient = debugClient;
101 this.sourceExecutionProvider = sourceExecutionProvider; 104 this.language = language;
105 this.executionSupport = new DebugExecutionSupport(language.getShortName(), language.getDebugSupport());
102 106
103 Source.setFileCaching(true); 107 Source.setFileCaching(true);
104 108
105 // Initialize execution context stack 109 // Initialize execution context stack
106 debugContext = new DebugExecutionContext(null, null); 110 debugContext = new DebugExecutionContext(null, null);
107 prepareContinue(); 111 prepareContinue();
108 debugContext.contextTrace("START EXEC DEFAULT"); 112 debugContext.contextTrace("START EXEC DEFAULT");
109 113
110 sourceExecutionProvider.addExecutionListener(new ExecutionListener() { 114 executionSupport.addExecutionListener(new DebugExecutionListener() {
111 115
112 public void executionStarted(Source source, boolean stepInto) { 116 public void executionStarted(Source source, boolean stepInto) {
113 // Push a new execution context onto stack 117 // Push a new execution context onto stack
114 DebugEngine.this.debugContext = new DebugExecutionContext(source, DebugEngine.this.debugContext); 118 DebugEngine.this.debugContext = new DebugExecutionContext(source, DebugEngine.this.debugContext);
115 if (stepInto) { 119 if (stepInto) {
144 assert debugContext != null; 148 assert debugContext != null;
145 debugContext.logWarning(warning); 149 debugContext.logWarning(warning);
146 } 150 }
147 }; 151 };
148 152
149 this.lineBreaks = new LineBreakpointFactory(sourceExecutionProvider, breakpointCallback, warningLog); 153 this.lineBreaks = new LineBreakpointFactory(executionSupport, breakpointCallback, warningLog);
150 154
151 this.tagBreaks = new TagBreakpointFactory(sourceExecutionProvider, breakpointCallback, warningLog); 155 this.tagBreaks = new TagBreakpointFactory(executionSupport, breakpointCallback, warningLog);
152 } 156 }
153 157
154 public static DebugEngine create(DebugClient debugClient, SourceExecutionProvider sourceExecutionProvider) { 158 public static DebugEngine create(DebugClient debugClient, Language language) {
155 return new DebugEngine(debugClient, sourceExecutionProvider); 159 return new DebugEngine(debugClient, language);
156 } 160 }
157 161
158 /** 162 /**
159 * Runs a script. If "StepInto" is requested, halts at the first location tagged as a 163 * Runs a script. If "StepInto" is requested, halts at the first location tagged as a
160 * {@linkplain StandardSyntaxTag#STATEMENT STATEMENT}. 164 * {@linkplain StandardSyntaxTag#STATEMENT STATEMENT}.
161 * 165 *
162 * @throws DebugException if an unexpected failure occurs 166 * @throws DebugException if an unexpected failure occurs
163 */ 167 */
164 public void run(Source source, boolean stepInto) throws DebugException { 168 public void run(Source source, boolean stepInto) throws DebugException {
165 sourceExecutionProvider.run(source, stepInto); 169 executionSupport.run(source, stepInto);
166 } 170 }
167 171
168 /** 172 /**
169 * Sets a breakpoint to halt at a source line. 173 * Sets a breakpoint to halt at a source line.
170 * 174 *
314 return debugContext == null ? null : debugContext.getFrames(); 318 return debugContext == null ? null : debugContext.getFrames();
315 } 319 }
316 320
317 /** 321 /**
318 * Evaluates code in a halted execution context, at top-level if <code>mFrame==null</code>. 322 * Evaluates code in a halted execution context, at top-level if <code>mFrame==null</code>.
319 */ 323 *
320 public Object eval(Source source, Node node, MaterializedFrame mFrame) { 324 * @throws DebugException
321 return sourceExecutionProvider.eval(source, node, mFrame); 325 */
326 public Object eval(Source source, Node node, MaterializedFrame mFrame) throws DebugException {
327 return executionSupport.evalInContext(source, node, mFrame);
322 } 328 }
323 329
324 /** 330 /**
325 * A mode of user navigation from a current code location to another, e.g "step in" vs. 331 * A mode of user navigation from a current code location to another, e.g "step in" vs.
326 * "step over". 332 * "step over".
804 private void printStack(PrintStream stream) { 810 private void printStack(PrintStream stream) {
805 getFrames(); 811 getFrames();
806 if (frames == null) { 812 if (frames == null) {
807 stream.println("<empty stack>"); 813 stream.println("<empty stack>");
808 } else { 814 } else {
809 // TODO (mlvdv) get visualizer via the (to be developed) Truffle langauge API 815 final Visualizer visualizer = language.getDebugSupport().getVisualizer();
810 final Visualizer visualizer = debugClient.getExecutionContext().getVisualizer();
811
812 for (FrameDebugDescription frameDesc : frames) { 816 for (FrameDebugDescription frameDesc : frames) {
813 final StringBuilder sb = new StringBuilder(" frame " + Integer.toString(frameDesc.index())); 817 final StringBuilder sb = new StringBuilder(" frame " + Integer.toString(frameDesc.index()));
814 sb.append(":at " + visualizer.displaySourceLocation(frameDesc.node())); 818 sb.append(":at " + visualizer.displaySourceLocation(frameDesc.node()));
815 sb.append(":in '" + visualizer.displayMethodName(frameDesc.node()) + "'"); 819 sb.append(":in '" + visualizer.displayMethodName(frameDesc.node()) + "'");
816 stream.println(sb.toString()); 820 stream.println(sb.toString());