Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 005c980ffcd2
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 538df4df8f0f
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 4, 2017

  1. Copy the full SHA
    4975495 View commit details

Commits on Jan 5, 2017

  1. Copy the full SHA
    538df4d View commit details
66 changes: 66 additions & 0 deletions spec/truffle/specs/truffle/debug_sepc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../ruby/spec_helper'

require 'digest'

module TruffleDebugSpecFixtures

def self.subject(a, b)
c = a + b
c * 2
end

ADD_LINE = 16
MUL_LINE = 17

end

describe "Truffle::Debug" do

it "can add and remove breakpoints" do
breaks = []

breakpoint = Truffle::Debug.break __FILE__, TruffleDebugSpecFixtures::ADD_LINE do |binding|
breaks << [:break]
end

TruffleDebuggerSpecFixtures.subject(14, 2)
TruffleDebuggerSpecFixtures.subject(16, 4)

breakpoint.remove

TruffleDebuggerSpecFixtures.subject(18, 9)

breaks.should == [:break]
end

it "can observe local variables in a breakpoint" do
breaks = []

breakpoint = Truffle::Debug.break __FILE__, TruffleDebugSpecFixtures::ADD_LINE do |binding|
breaks << [binding.local_variable_get(:a), binding.local_variable_get(:b)]
end

breakpoint = Truffle::Debug.break __FILE__, TruffleDebugSpecFixtures::MUL_LINE do |binding|
breaks << [binding.local_variable_get(:c)]
end

TruffleDebugSpecFixtures.subject(14, 2)
TruffleDebugSpecFixtures.subject(16, 4)

breakpoint.remove

TruffleDebugSpecFixtures.subject(18, 9)

breaks.should == [14, 2, 14 + 2, 16, 4, 16 + 4]
end


end
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1709,6 +1709,7 @@ public Object getTruffleKernelModule() {
"/core/truffle/ffi/ffi_struct.rb",
"/core/truffle/support.rb",
"/core/truffle/boot.rb",
"/core/truffle/debug.rb",
"/core/io.rb",
"/core/immediate.rb",
"/core/string_mirror.rb",
Original file line number Diff line number Diff line change
@@ -13,11 +13,17 @@
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.EventBinding;
import com.oracle.truffle.api.instrumentation.ExecutionEventNode;
import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.truffle.Layouts;
import org.jruby.truffle.RubyLanguage;
import org.jruby.truffle.builtins.CoreClass;
import org.jruby.truffle.builtins.CoreMethod;
import org.jruby.truffle.builtins.CoreMethodArrayArgumentsNode;
@@ -27,6 +33,7 @@
import org.jruby.truffle.language.backtrace.BacktraceFormatter;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.shared.SharedObjects;
import org.jruby.truffle.language.yield.YieldNode;
import org.jruby.truffle.platform.UnsafeGroup;
import org.jruby.truffle.tools.simpleshell.SimpleShell;

@@ -36,6 +43,50 @@
@CoreClass("Truffle::Debug")
public abstract class TruffleDebugNodes {

@CoreMethod(names = "break_handle", onSingleton = true, required = 2, needsBlock = true)
public abstract static class BreakNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isRubyString(file)")
public DynamicObject setBreak(DynamicObject file, int line, final DynamicObject block) {
final String fileString = StringOperations.decodeUTF8(file);

final SourceSectionFilter filter = SourceSectionFilter.newBuilder()
.mimeTypeIs(RubyLanguage.MIME_TYPE)
.sourceIs(source -> source != null && source.getPath() != null && source.getPath().equals(fileString))
.lineIs(line)
.tagIs(StandardTags.StatementTag.class)
.build();

final EventBinding<?> breakpoint = getContext().getInstrumenter().attachFactory(filter,
eventContext -> new ExecutionEventNode() {

@Child private YieldNode yieldNode = new YieldNode();

@Override
protected void onEnter(VirtualFrame frame) {
yieldNode.dispatch(frame, block, Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), frame.materialize()));
}

});

return Layouts.HANDLE.createHandle(coreLibrary().getHandleFactory(), breakpoint);
}

}

@CoreMethod(names = "remove_handle", onSingleton = true, required = 1)
public abstract static class RemoveNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isHandle(handle)")
public DynamicObject remove(DynamicObject handle) {
EventBinding.class.cast(Layouts.HANDLE.getObject(handle)).dispose();
return nil();
}

}

@CoreMethod(names = "java_class_of", onSingleton = true, required = 1)
public abstract static class JavaClassOfNode extends CoreMethodArrayArgumentsNode {

27 changes: 27 additions & 0 deletions truffle/src/main/ruby/core/truffle/debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module Truffle::Debug

class Breakpoint

def initialize(handle)
@handle = handle
end

def remove
Truffle::Debug.remove_handle @handle
end

end

def self.break(file, line, &block)
Breakpoint.new(break_handle(File.expand_path(file), line, &block))
end

end