[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to breakpoint ruby code ?

user@domain.invalid

10/16/2007 12:03:00 PM

Hello, I would like to know how I can have my ruby code stopped and an
irb invoqued which would allow me to have full access to the current
context.

I've tried this :

require 'rubygems'
require_gem 'ruby-breakpoint'

h2 = Hash.new
breakpoint

Two things are wrong :
1) after breakpoint the context is lost, and typing h2 gives
undefined local variable or method `h2' for #<Object:0xb7f8d9fc
@__bp_file="./test.rb", @__bp_line=21>

2) require_gem puts a warning (use gem instead), and using gem
'ruby-breakpoint' makes breakpoint command to be unknown :
undefined local variable or method `breakpoint' for main:Object (NameError)



Seems I'm on the very wrong way as I presume that
debugging/breakpointing is certainly a very common task with Ruby.


Thanks



Note : In fact, I would like something similar to the Rails console for
use with non Rails ruby code.
9 Answers

Rick DeNatale

10/16/2007 1:29:00 PM

0

On 10/16/07, Zouplaz <user@domain.invalid> wrote:
> Hello, I would like to know how I can have my ruby code stopped and an
> irb invoqued which would allow me to have full access to the current
> context.
>
> I've tried this :
>
> require 'rubygems'
> require_gem 'ruby-breakpoint'
>
...
> Seems I'm on the very wrong way as I presume that
> debugging/breakpointing is certainly a very common task with Ruby.

There's a much better replacement for breakpoint:

http://www.datanoise.com/r...


--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Tim Hunter

10/16/2007 1:41:00 PM

0

Zouplaz wrote:
> 2) require_gem puts a warning (use gem instead), and using gem
> 'ruby-breakpoint' makes breakpoint command to be unknown :
> undefined local variable or method `breakpoint' for main:Object
> (NameError)

require_gem is obsolete and didn't do what you think it did. It was not
a synonym for "require", it was a way to specify that you want a
specific version of a gem, which is what the "gem" method does now. In
the past "require_gem" could have the side-effect of actually requiring
the gem, but the "gem" method does not have that side-effect.

To require a gem, use "require". Nothing else.
--
Posted via http://www.ruby-....

user@domain.invalid

10/16/2007 8:40:00 PM

0

le 16/10/2007 15:41, Tim Hunter nous a dit:
> Zouplaz wrote:
>> 2) require_gem puts a warning (use gem instead), and using gem
>> 'ruby-breakpoint' makes breakpoint command to be unknown :
>> undefined local variable or method `breakpoint' for main:Object
>> (NameError)
>
> require_gem is obsolete and didn't do what you think it did. It was not
> a synonym for "require", it was a way to specify that you want a
> specific version of a gem, which is what the "gem" method does now. In
> the past "require_gem" could have the side-effect of actually requiring
> the gem, but the "gem" method does not have that side-effect.
>
> To require a gem, use "require". Nothing else.

Thanks, I will stick to "require" definitely ;-)

user@domain.invalid

10/16/2007 8:46:00 PM

0

le 16/10/2007 15:28, Rick DeNatale nous a dit:
> On 10/16/07, Zouplaz <user@domain.invalid> wrote:
>> Hello, I would like to know how I can have my ruby code stopped and an
>> irb invoqued which would allow me to have full access to the current
>> context.
>>
>> I've tried this :
>>
>> require 'rubygems'
>> require_gem 'ruby-breakpoint'
>>
> ..
>> Seems I'm on the very wrong way as I presume that
>> debugging/breakpointing is certainly a very common task with Ruby.
>
> There's a much better replacement for breakpoint:
>
> http://www.datanoise.com/r...
>
>

Seems a good tool but unfortunately didn't worked... The 'debugger'
statement producing no effect at all.

But, I re-installed ruby-breakpoint and thanks to this article
(http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...) I
have been able to breakpoint again in the code by adding
require 'breakpoint185'
after
require 'breakpoint'

Without that the first require I get a message "Breakpoints are not
currently working with Ruby 1.8.5"

So, it seems to work - And my last question is :
h1 = Hash.new
@h2 = Hash.new
breakpoint

under debugger, @h2 exist but h1 does not. Quite annoying to loose the
local vars - Is it a normal behaviour for a ruby debugger ? Should have
worked like that with ruby 1.8.4 ?


user@domain.invalid

10/16/2007 8:53:00 PM

0

Here I am, quite lost but successful !

I gave ruby-debugger a second try and now everything works like a
charm. May be because I upgrade to another minor version of Ruby 1.8.5

Don't know...

eggman2001

10/16/2007 9:01:00 PM

0

What's the difference between rdebug and the debugger that ruby comes
with?

On Oct 16, 9:28 am, "Rick DeNatale" <rick.denat...@gmail.com> wrote:
> On 10/16/07, Zouplaz <u...@domain.invalid> wrote:
>
> > Hello, I would like to know how I can have my ruby code stopped and an
> > irb invoqued which would allow me to have full access to the current
> > context.
>
> > I've tried this :
>
> > require 'rubygems'
> > require_gem 'ruby-breakpoint'
>
> ...
> > Seems I'm on the very wrong way as I presume that
> > debugging/breakpointing is certainly a very common task with Ruby.
>
> There's a much better replacement for breakpoint:
>
> http://www.datanoise.com/r...
>
> --
> Rick DeNatale
>
> My blog on Rubyhttp://talklikeaduck.denh...


user@domain.invalid

10/17/2007 1:17:00 PM

0

le 16/10/2007 23:01, eggman2001 nous a dit:
> What's the difference between rdebug and the debugger that ruby comes
> with?
>

I don't know, but launching rdebug foo.rb breakpoints on the first line
of code...

Roger Pack

10/18/2007 1:58:00 PM

0

eggman2001 wrote:
> What's the difference between rdebug and the debugger that ruby comes
> with?

the rdebug one is faster as it 'plugs itself in' to certain handles
within the interpreter (and only a few, so no watchpoints), which is
fast. The built in one is slow as molasses for whatever reason. If I
had to guess how it worked it would seem like it worked by running each
line of code and examining the state or something. Very slow.
GL.
-Roger
--
Posted via http://www.ruby-....

Jano Svitok

10/18/2007 2:08:00 PM

0

On 10/18/07, Roger Pack <rogerpack2005@gmail.com> wrote:
> eggman2001 wrote:
> > What's the difference between rdebug and the debugger that ruby comes
> > with?
>
> the rdebug one is faster as it 'plugs itself in' to certain handles
> within the interpreter (and only a few, so no watchpoints), which is
> fast. The built in one is slow as molasses for whatever reason. If I
> had to guess how it worked it would seem like it worked by running each
> line of code and examining the state or something. Very slow.
> GL.

I'll guess that they use the same mechanism, set_trace_func. While the
builtin one uses a callback written in ruby, the newer uses callbacks
from the C side.