Module: Truffle::Debug
- Defined in:
- truffle/src/main/ruby/core/truffle/debug.rb
Overview
Debug utilities specific to Truffle.
Class Method Summary (collapse)
-
+ (nil) break(file = nil, line = nil, condition = nil)
Break and enter an interactive shell, or set a line breakpoint to enter the shell.
-
+ (Object) clear(file, line)
Remove a breakpoint set in #break.
Class Method Details
+ (nil) break(file = nil, line = nil, condition = nil)
Break and enter an interactive shell, or set a line breakpoint to enter the shell.
Examples
Truffle::Debug.break
Enter the shell immediately.
Truffle::Debug.break 'foo.rb', 59
Enter the shell every time the program reaches line 59 in
foo.rb
(see #clear).
Shell Usage
In the shell you can type normal Ruby expressions and have them evaluated
in the current frame. Results will be printed via #inspect
,
like in IRB.
Extra commands available are:
-
continue
leave the interactive shell and continue execution -
exit
exit the VM -
backtrace
print a backtrace, with numbered frames -
frame n
make the nth frame active for expressions that you type into the shell (seebacktrace
to find the frame you want)
Example
In your ruby code call Truffle::Debug.break
where you want to
break. When that method is called you will see the shell:
> backtrace
▶ at Truffle::Primitive#simple_shell
1 at core:/core/truffle/debug.rb:14:in 'break'
2 at test.rb:4:in 'foo'
3 at test.rb:9:in 'bar'
4 at test.rb:12:in '<main>'
> frame 2
> x + y
110
> frame 3
> a
99
> continue
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'truffle/src/main/ruby/core/truffle/debug.rb', line 66 def self.break(file = nil, line = nil, condition = nil) if line.nil? raise 'must specify both a file and a line, or neither' unless file.nil? Truffle::Primitive.simple_shell elsif not condition.nil? Truffle::Primitive.attach file, line do |binding| if binding.eval(condition) Truffle::Primitive.simple_shell end end elsif block_given? Truffle::Primitive.attach file, line do |binding| if yield binding Truffle::Primitive.simple_shell end end else Truffle::Primitive.attach file, line do |binding| Truffle::Primitive.simple_shell end end end |
+ (Object) clear(file, line)
Remove a breakpoint set in #break.
90 91 92 |
# File 'truffle/src/main/ruby/core/truffle/debug.rb', line 90 def self.clear(file, line) Truffle::Primitive.detach file, line end |