Debugging proposal

Thanks! Somehow I did not spot this...

I'll give it another go then.

Cheers,
Max

···

-----Original Message-----
From: Mauricio Julio Fernández Pradier [mailto:ferferse@telefonica.net] On Behalf Of Mauricio Fernandez
Sent: Thursday, 6 July 2006 5:08 PM
To: ruby-talk ML
Subject: Re: debugging proposal

On Thu, Jul 06, 2006 at 09:50:22AM +0900, Max Muermann wrote:

Ideally, I would like to stick all this stuff in maybe a singleton
Debugger class. I am however unsure on how to do this and would really
like some help with that. The breakpoint_func is implemented using an
event_hook, like trace_func, which requires me to implement it inside
eval.c, as this functionality is (sensibly) not exposed.
Unfortunately, this prevents me from implementing the debug support in
a regular extension.

It is exposed (ruby-prof uses it, and I'm using it too in rcov).
Just #include <node.h>.

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

I went ahead and simplified the code + made an extension (you can find it
attached).
[Florian, are you reading this?]

BTW, it now works with ruby 1.8 too (just remove the File.expand_path calls in
dbg.rb).

$ ruby19 -rrdebug dbg.rb
[["/home/batsman/mess/2006/27/rdebug/debugee.rb", 7], ["/home/batsman/mess/2006/27/rdebug/debugee.rb", 3]]
Dbg.rb
Breakpoint /home/batsman/mess/2006/27/rdebug/debugee.rb:3 (Debugee#hello)
(Dbg):caller
["(eval):1:in `Debugee#hello'", "dbg.rb:36"]
(Dbg):c
Dbg.rb
Breakpoint /home/batsman/mess/2006/27/rdebug/debugee.rb:7 (Debugee#say)
Local variables:
what: "World"
(Dbg):what = "foooo"
"foooo"
(Dbg):c
"Hello foooo"

$ cat debugee.rb
class Debugee
        def hello
                say "World"
        end

        def say( what )
                p "Hello #{what}"
        end
end
$ cat dbg.rb
require "debugee"

set_breakpoint_func proc { |event, file, line, id, binding, klass, *rest|
  puts "Dbg.rb"
  prompt = true
  puts "Breakpoint #{file}:#{line} (#{klass}##{id})"
  lvars = eval("local_variables", binding)
  unless lvars.empty?
    puts "Local variables:"
    lvars.each{|x| val = eval(x, binding); puts "#{x}: #{val.inspect}" }
  end
  print "(Dbg):"
  while prompt and input = readline.chomp
    next if input == ""
    case input
    when "c"
      prompt = false
    else
      begin
        res =eval(input,binding)
        p res
      rescue Exception, StandardError, ScriptError => e
        p e
        nil
      end
    end
    print "(Dbg):" if prompt
  end
}

add_breakpoint File.expand_path("./debugee.rb"), 3
add_breakpoint File.expand_path("./debugee.rb"), 7
p breakpoints

c = Debugee.new
c.hello

extconf.rb (41 Bytes)

rdebug.c (4.77 KB)

···

On Thu, Jul 06, 2006 at 04:24:41PM +0900, Max Muermann wrote:

Thanks! Somehow I did not spot this...

I'll give it another go then.

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

Mauricio Fernandez wrote:

I went ahead and simplified the code + made an extension (you can find it
attached).
[Florian, are you reading this?]

Yup, and I'm wondering if I could use this for implementing fast stepping support in ruby-breakpoint.

Anything else I'm missing that this might buy me? It would be nice if I could get away from the Ruby implementation of Binding.of_caller() soon.

Thank you!

···

--
http://flgr.0x42.net/

My ruby-debug extension is doing precisely that. It keeps track of bindings
along the program execution and allows fast stepping. Basically it's a
standard debug.rb library with a small native extension which uses new
Ruby C API calls rb_add_event_hook/rb_remove_event_hook to keep track of
method execution and to check for breakpoints.

Kent

···

On 7/8/06, Florian Gross <florgro@gmail.com> wrote:

Mauricio Fernandez wrote:

> I went ahead and simplified the code + made an extension (you can find
it
> attached).
> [Florian, are you reading this?]

Yup, and I'm wondering if I could use this for implementing fast
stepping support in ruby-breakpoint.

Anything else I'm missing that this might buy me? It would be nice if I
could get away from the Ruby implementation of Binding.of_caller() soon.

Thank you!

--
http://flgr.0x42.net/

--
Kent
---