use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.
the class DebuggerExampleTest method testStepOver.
@Test
@SuppressWarnings("hiding")
public void testStepOver() throws IOException {
Source source = lines(// 1
"ROOT(", // 2
"DEFINE(foo,STATEMENT),", // 3
"DEFINE(bar", // 4
",STATEMENT", // 5
",STATEMENT(CALL(foo))", // 6
",STATEMENT),", /**/
"STATEMENT(CALL(bar)))");
// 7
final AtomicBoolean allStepped = new AtomicBoolean();
debugger.installBreakpoint(4, new Callback() {
public void halted(DebuggerController debugger, EventContext haltedAt) {
assertLineAt(haltedAt, 4);
debugger.stepOver(new Callback() {
public void halted(DebuggerController debugger, EventContext haltedAt) {
assertLineAt(haltedAt, 5);
debugger.stepOver(new Callback() {
public void halted(DebuggerController debugger, EventContext haltedAt) {
assertLineAt(haltedAt, 6);
allStepped.set(true);
debugger.stepOver(new Callback() {
public void halted(DebuggerController debugger, EventContext haltedAt) {
throw new AssertionError();
}
});
}
});
}
});
}
});
run(source);
Assert.assertTrue(allStepped.get());
}
use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.
the class SLInstrumentTest method testLexicalScopes.
@Test
public void testLexicalScopes() throws Exception {
String code = "function test(n) {\n" + // 2
" a = 1;\n" + " if (a > 0) {\n" + " b = 10;\n" + // 5
" println(b);\n" + " }\n" + " if (a == 1) {\n" + " b = 20;\n" + " a = 0;\n" + // 10
" c = 1;\n" + " if (b > 0) {\n" + " a = 4;\n" + " b = 5;\n" + " c = 6;\n" + // 15
" d = 7;\n" + " println(d);\n" + " }\n" + " }\n" + " println(b);\n" + // 20
" println(a);\n" + "}\n" + "function main() {\n" + " test(\"n_n\");\n" + "}";
Source source = Source.newBuilder("sl", code, "testing").build();
List<Throwable> throwables;
try (Engine engine = Engine.newBuilder().out(new java.io.OutputStream() {
// null output stream
@Override
public void write(int b) throws IOException {
}
}).build()) {
Instrument envInstr = engine.getInstruments().get("testEnvironmentHandlerInstrument");
TruffleInstrument.Env env = envInstr.lookup(Environment.class).env;
throwables = new ArrayList<>();
env.getInstrumenter().attachExecutionEventListener(SourceSectionFilter.newBuilder().lineIn(1, source.getLineCount()).build(), new ExecutionEventListener() {
@Override
public void onEnter(EventContext context, VirtualFrame frame) {
Node node = context.getInstrumentedNode();
Iterable<Scope> lexicalScopes = env.findLocalScopes(node, null);
Iterable<Scope> dynamicScopes = env.findLocalScopes(node, frame);
try {
verifyLexicalScopes(lexicalScopes, dynamicScopes, context.getInstrumentedSourceSection().getStartLine(), frame.materialize());
} catch (ThreadDeath t) {
throw t;
} catch (Throwable t) {
CompilerDirectives.transferToInterpreter();
PrintStream lsErr = System.err;
lsErr.println("Line = " + context.getInstrumentedSourceSection().getStartLine());
lsErr.println("Node = " + node + ", class = " + node.getClass().getName());
t.printStackTrace(lsErr);
throwables.add(t);
}
}
@Override
public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
}
@Override
public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
}
});
Context.newBuilder().engine(engine).build().eval(source);
}
assertTrue(throwables.toString(), throwables.isEmpty());
}
use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.
the class Profiler method reset.
// Reconfigure what's being collected; does not affect collected data
private void reset() {
if (binding != null) {
binding.dispose();
binding = null;
}
if (isCollecting) {
final Builder filterBuilder = SourceSectionFilter.newBuilder();
if (mimeTypes != null) {
filterBuilder.mimeTypeIs(mimeTypes);
}
final SourceSectionFilter filter = filterBuilder.tagIs(StandardTags.RootTag.class).sourceIs(notInternal).build();
binding = instrumenter.attachExecutionEventFactory(filter, new ExecutionEventNodeFactory() {
public ExecutionEventNode create(EventContext context) {
return createCountingNode(context);
}
});
}
}
use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.
the class InstrumentationEventTest method setUp.
@Before
public final void setUp() {
this.context = Context.create();
this.instrument = context.getEngine().getInstruments().get(InputFilterTestInstrument.ID).lookup(InputFilterTestInstrument.class);
this.instrumenter = instrument.environment.getInstrumenter();
this.events = new ArrayList<>();
this.factory = new ExecutionEventNodeFactory() {
public ExecutionEventNode create(EventContext c) {
return new ExecutionEventNode() {
{
for (int i = 0; i < getInputCount(); i++) {
Assert.assertNotNull(getInputContext(i));
}
}
@Override
protected void onInputValue(VirtualFrame frame, EventContext inputContext, int inputIndex, Object inputValue) {
saveInputValue(frame, inputIndex, inputValue);
assertTrue(inputIndex < getInputCount());
assertSame(inputContext, getInputContext(inputIndex));
events.add(new Event(EventKind.INPUT_VALUE, c, frame, null, null, inputIndex, inputValue, createInputContexts()));
}
@Override
public void onEnter(VirtualFrame frame) {
events.add(new Event(EventKind.ENTER, c, frame, null, null, -1, null, createInputContexts()));
}
@Override
protected void onReturnValue(VirtualFrame frame, Object result) {
events.add(new Event(EventKind.RETURN_VALUE, c, frame, getSavedInputValues(frame), result, -1, null, createInputContexts()));
}
private EventContext[] createInputContexts() {
EventContext[] inputContexts = new EventContext[getInputCount()];
for (int i = 0; i < getInputCount(); i++) {
Assert.assertNotNull(getInputContext(i));
inputContexts[i] = getInputContext(i);
}
return inputContexts;
}
};
}
};
}
use of com.oracle.truffle.api.instrumentation.EventContext in project graal by oracle.
the class InstrumentationMultiThreadingTest method createDummyBindings.
private static EventBinding<?>[] createDummyBindings(Instrumenter instrumenter) {
EventBinding<?>[] bindings = new EventBinding<?>[5];
int bi = 0;
ExecutionEventListener dummyListener = new ExecutionEventListener() {
public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
}
public void onEnter(EventContext context, VirtualFrame frame) {
}
};
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), dummyListener);
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), dummyListener);
bindings[bi++] = instrumenter.attachLoadSourceListener(SourceFilter.ANY, new LoadSourceListener() {
public void onLoad(LoadSourceEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
return bindings;
}
Aggregations