Ruby - Debugging

How do I use the ruby default debugger?

On Fri, 25 May 2007, How do I use the ruby default debugger? wrote:

How do I use the ruby default debugger?

$ ruby -rdebug /tmp/some_ruby_program.rb
Debug.rb
Emacs support available.

/tmp/k.rb:1:puts “a”
(rdb:1) help
Debugger help v.-0.002b
Commands
b[reak] [file:|class:]<line|method>
b[reak] [class.]<line|method>
set breakpoint to some position
wat[ch] set watchpoint to some expression
cat[ch] (|off) set catchpoint to an exception
b[reak] list breakpoints
cat[ch] show catchpoint
del[ete][ nnn] delete some or all breakpoints
disp[lay] add expression into display expression
list
undisp[lay][ nnn] delete one particular or all display
expressions
c[ont] run until program ends or hit breakpoint
s[tep][ nnn] step (into methods) one line or till line
nnn
n[ext][ nnn] go over one line or till line nnn
w[here] display frames
f[rame] alias for where
l[ist][ (-|nn-mm)] list program, - lists backwards
nn-mm lists given lines
up[ nn] move to higher frame
down[ nn] move to lower frame
fin[ish] return to outer frame
tr[ace] (on|off) set trace mode of current thread
tr[ace] (on|off) all set trace mode of all threads
q[uit] exit from debugger
v[ar] g[lobal] show global variables
v[ar] l[ocal] show local variables
v[ar] i[nstance] show instance variables of object
v[ar] c[onst] show constants of object
m[ethod] i[nstance] show methods of object
m[ethod] <class|module> show instance methods of class or module
th[read] l[ist] list all threads
th[read] c[ur[rent]] show current thread
th[read] [sw[itch]] switch thread context to nnn
th[read] stop stop thread nnn
th[read] resume resume thread nnn
p expression evaluate expression and print its value
h[elp] print this help
evaluate
(rdb:1)

On 5/24/07, How do I use the ruby default debugger? [email protected]
wrote:

How do I use the ruby default debugger?

Just don’t. ruby-debug is a much better alternative.

Alex

Tomas P.'s Mailing L. wrote:

On Fri, 25 May 2007, How do I use the ruby default debugger? wrote:

How do I use the ruby default debugger?

$ ruby -rdebug /tmp/some_ruby_program.rb
Debug.rb
Emacs support available.

/tmp/k.rb:1:puts “a”
(rdb:1) help
Debugger help v.-0.002b
Commands
b[reak] [file:|class:]<line|method>
b[reak] [class.]<line|method>
set breakpoint to some position
wat[ch] set watchpoint to some expression
cat[ch] (|off) set catchpoint to an exception
b[reak] list breakpoints
cat[ch] show catchpoint
del[ete][ nnn] delete some or all breakpoints
disp[lay] add expression into display expression
list
undisp[lay][ nnn] delete one particular or all display
expressions
c[ont] run until program ends or hit breakpoint
s[tep][ nnn] step (into methods) one line or till line
nnn
n[ext][ nnn] go over one line or till line nnn
w[here] display frames
f[rame] alias for where
l[ist][ (-|nn-mm)] list program, - lists backwards
nn-mm lists given lines
up[ nn] move to higher frame
down[ nn] move to lower frame
fin[ish] return to outer frame
tr[ace] (on|off) set trace mode of current thread
tr[ace] (on|off) all set trace mode of all threads
q[uit] exit from debugger
v[ar] g[lobal] show global variables
v[ar] l[ocal] show local variables
v[ar] i[nstance] show instance variables of object
v[ar] c[onst] show constants of object
m[ethod] i[nstance] show methods of object
m[ethod] <class|module> show instance methods of class or module
th[read] l[ist] list all threads
th[read] c[ur[rent]] show current thread
th[read] [sw[itch]] switch thread context to nnn
th[read] stop stop thread nnn
th[read] resume resume thread nnn
p expression evaluate expression and print its value
h[elp] print this help
evaluate
(rdb:1)

Look what happened when I did just that:

C:\Users\jbucaran>ruby -rdebug
c:\users\jbucaran\desktop\demo2.rb
Debug.rb
Emacs support available.

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
‘rubygems’
(rdb:1)

Help me I am clueless!

http://blog.nanorails.com/articles/2006/07/14/a-better-rails-debugger-ruby-debug

On 25 May 2007, at 11:37, Jorge Domenico Bucaran R. wrote:

(rdb:1) help
Debugger help v.-0.002b
Commands

[snip]

‘rubygems’
(rdb:1)

Help me I am clueless!

The debugger is running and now you need to use it. Type help (as
shown above) to get a list of commands. You probably want to set
breakpoints at certain places in your script and then continue to
there using ‘c’ before you step through using ‘n’ or ‘s’. Googling
for ‘ruby debugger’ gives me the Pickaxe chapter on debugging which
is a good starting point if none of this makes sense.

Alex G.

Bioinformatics Center
Kyoto University

Also, why does it shows this:

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
‘rubygems’

Not that I care much about it, since all I want to be able to debug, but
I’d like to know what is it.

Alex G. wrote:

On 25 May 2007, at 11:37, Jorge Domenico Bucaran R. wrote:

(rdb:1) help
Debugger help v.-0.002b
Commands

[snip]

‘rubygems’
(rdb:1)

Help me I am clueless!

The debugger is running and now you need to use it. Type help (as
shown above) to get a list of commands. You probably want to set
breakpoints at certain places in your script and then continue to
there using ‘c’ before you step through using ‘n’ or ‘s’. Googling
for ‘ruby debugger’ gives me the Pickaxe chapter on debugging which
is a good starting point if none of this makes sense.

Alex G.

Bioinformatics Center
Kyoto University

I prefer using the Ruby default debugger since I am planning to build a
GUI for it, the minimal functionality. I try to use the debugger but it
just seems to be in the wrong file look at this:

C:\Users\jbucaran>ruby -rdebug c:\users\jbucaran\desktop\demo2.rb
Debug.rb
Emacs support available.

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
‘rubygems’
(rdb:1) list
[5, 14] in C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb
5 # All rights reserved.
6 # See LICENSE.txt for permissions.
7 #++
8
9
=> 10 require ‘rubygems’
(rdb:1) list all
[-5, 4] in C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb
1 # This file allows for the running of rubygems with a nice
2 # command line look-and-feel: ruby -rubygems foo.rb
3 #–
4 # Copyright 2006 by Chad F., Rich Kilmer, Jim W. and
others.
(rdb:1)

Is it necessary to load the rubygems when debugging? Why do I need this?
If not really necessary how do I remove it from my enviroment settings?

It is not working look at this:

C:\Users\jbucaran>ruby -rdebug c:\users\jbucaran\desktop\demo2.rb
Debug.rb
Emacs support available.

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
‘rubygems’
(rdb:1) help
Debugger help v.-0.002b
Commands
b[reak] [file:|class:]<line|method>
b[reak] [class.]<line|method>
set breakpoint to some position
wat[ch] set watchpoint to some expression
cat[ch] (|off) set catchpoint to an exception
b[reak] list breakpoints
cat[ch] show catchpoint
del[ete][ nnn] delete some or all breakpoints
disp[lay] add expression into display expression list
undisp[lay][ nnn] delete one particular or all display
expressions
c[ont] run until program ends or hit breakpoint
s[tep][ nnn] step (into methods) one line or till line
nnn
n[ext][ nnn] go over one line or till line nnn
w[here] display frames
f[rame] alias for where
l[ist][ (-|nn-mm)] list program, - lists backwards
nn-mm lists given lines
up[ nn] move to higher frame
down[ nn] move to lower frame
fin[ish] return to outer frame
tr[ace] (on|off) set trace mode of current thread
tr[ace] (on|off) all set trace mode of all threads
q[uit] exit from debugger
v[ar] g[lobal] show global variables
v[ar] l[ocal] show local variables
v[ar] i[nstance] show instance variables of object
v[ar] c[onst] show constants of object
m[ethod] i[nstance] show methods of object
m[ethod] <class|module> show instance methods of class or module
th[read] l[ist] list all threads
th[read] c[ur[rent]] show current thread
th[read] [sw[itch]] switch thread context to nnn
th[read] stop stop thread nnn
th[read] resume resume thread nnn
p expression evaluate expression and print its value
h[elp] print this help
evaluate
(rdb:1) b c:\users\jbucaran\desktop\demo2.rb
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:compile error
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10: syntax
error, unexpe
cted $undefined, expecting tSTRING_CONTENT or tSTRING_DBEG or
tSTRING_DVAR or tS
TRING_END
c:\users\jbucaran\desktop\demo2
^
(rdb:1) Set breakpoint 1 at c:\users\jbucaran\desktop\demo2.rb:1
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10: warning:
parenthesiz
e argument(s) for future version
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:compile error
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10: syntax
error, unexpe
cted tIDENTIFIER, expecting $end
Set breakpoint 1 at c:\users\jbucaran\desktop\demo2.rb:1
^
(rdb:1)

On 25 May 2007, at 13:18, Jorge Domenico Bucaran R. wrote:

[snip]

(rdb:1) Set breakpoint 1 at c:\users\jbucaran\desktop\demo2.rb:1
(rdb:1)


Posted via http://www.ruby-forum.com/.

It’s telling you that there is a syntax error in the way you
specified the filename. I don’t use Windows so I can’t test exactly,
but it looks like enclosing the filename in quotes might help.
Alternatively substitute backslash for forward slash. E.g:

b “c:\users\jbucaran\desktop\demo2.rb”:1

Also, don’t type in this line:

Set breakpoint 1 at c:\users\jbucaran\desktop\demo2.rb:1

That is output from the debugger.

As to your question about whether it is necessary to run rubygems to
use the debugger then the answer is ‘it depends’. If your script uses
gems then it is necessary, otherwise it isn’t. I don’t know anything
about environment variables in Windows, so someone else will have to
help you there. I would have thought that you should be able to get
some information from Google.

Alex G.

Bioinformatics Center
Kyoto University

C:\Users\jbucaran>ruby -rdebug c:\users\jbucaran\desktop\demo2.rb
Debug.rb
Emacs support available.

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
‘rubygems’
(rdb:1) b “c:\users\jbucaran\desktop\demo2.rb”
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:compile error
C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10: unterminated
string
meets end of file
(rdb:1)

I am sorry to bother like this, but is there any way I could get serious
documentation on how to use this, a good tutorial, maybe you can help me
here with a fine start. Please I can’t believe it is so hard to do this.

On 25 May 2007, at 12:18, Jorge Domenico Bucaran R. wrote:

Posted via http://www.ruby-forum.com/.

You’ve told it (via your environment settings from looking at that
line) to load rubygems. Loading rubygems executes Ruby code. The
debugger is preparing to debug that code. Once you are past that code
you can start to debug your program.

As I said, you need to set breakpoints in your script and jump to
those breakpoints. E.g:

[alexg@powerbook]/Users/alexg/Desktop(7): cat test.rb
a=1
puts a
[alexg@powerbook]/Users/alexg/Desktop(8): ruby -rdebug -rubygems test.rb
Debug.rb
Emacs support available.

/usr/local/lib/ruby/site_ruby/1.8/ubygems.rb:10:require ‘rubygems’
(rdb:1) b test.rb:1
Set breakpoint 1 at test.rb:1
(rdb:1) c
Breakpoint 1, toplevel at test.rb:1
test.rb:1:a=1
(rdb:1) list
[-4, 5] in test.rb
=> 1 a=1
2 puts a
(rdb:1)

Alex G.

Bioinformatics Center
Kyoto University

On 25 May 2007, at 15:42, Tomas P.'s Mailing L. wrote:

error
here with a fine start. Please I can’t believe it is so hard to do
this.

Did you ask Google?

In your example above a file named “ubygems” is being parsed. Looks
like non-sense to me?
*t

ubygems.rb is the way rubygems is loaded when you run:

ruby -rubygems

I don’t think that is anything to do with the problem Jorge is
having. I’m not sure what the problem is do with though and I can’t
reproduce it on my system. Sorry I can’t be off more help. The only
tutorial I know of is the Pickaxe chapter on debugging - but there’s
not much to it to be honest:

http://www.rubycentral.com/book/trouble.html

Alex G.

Bioinformatics Center
Kyoto University

On Fri, 25 May 2007, Alex G. wrote:

(rdb:1) b “c:\users\jbucaran\desktop\demo2.rb”
Did you ask Google?

In your example above a file named “ubygems” is being parsed. Looks like
non-sense to me?
*t

ubygems.rb is the way rubygems is loaded when you run:

ruby -rubygems

Where “-rXYZ” means: “Please ruby, load the library XYZ first please,
before loading the actual program”. And as can be seen above, ruby does
actually find a file/library named “ubygems” at
“C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb” which doesn’t
make any sense to me because (AFAIK) there doesn’t exist and library
named
“ubygems” unless Jorge did something strange and placed something there.

Or am I misstaken?
*t

On Fri, 25 May 2007, Jorge Domenico Bucaran R. wrote:

meets end of file
(rdb:1)

I am sorry to bother like this, but is there any way I could get serious
documentation on how to use this, a good tutorial, maybe you can help me
here with a fine start. Please I can’t believe it is so hard to do this.

Did you ask Google?

In your example above a file named “ubygems” is being parsed. Looks like
non-sense to me?
*t

On Fri, 25 May 2007, Alex G. wrote:

C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb:10:require
Did you ask Google?
actually find a file/library named “ubygems” at
ruby -rubygems foo.rb

As well as:

ruby -rrubygems foo.rb

Note the double rr in the second one. Every installation of rubygems includes
ubygems.rb as far as I know. Try “locate ‘/ubygems.rb’” on your system.

Ah, you’re right, somehow I had missed that the last time I had run
locate '/ubygems.rb.

Thanks for the enlightening,
*t

Yes I googled it and I have found no help. I can’t believe none can
actually provide a serious explanation on this. And I say this with base
because the very short section in the Pickaxe barely touches the subject
with an extensive example that fails providing a good start. It helps
only if you have actually debugged previously. As you can see in my
humble try before the “list” command does not return the list of my
demo2.rb program which is only

a = 2
puts a
a = 3
puts a

I need help getting it started, I can get it my own later, so focus your
help on that. Thank you.

P.S: I promise to myself that if I ever get this running I will provide
a simple tutorial on using the Ruby debugger for dummies like me.

On 25 May 2007, at 16:50, Tomas P.'s Mailing L. wrote:

(rdb:1) b “c:\users\jbucaran\desktop\demo2.rb”
help me

Where “-rXYZ” means: “Please ruby, load the library XYZ first
please, before loading the actual program”. And as can be seen
above, ruby does actually find a file/library named “ubygems” at
“C:/Program Files/Ruby/lib/ruby/site_ruby/1.8/ubygems.rb” which
doesn’t make any sense to me because (AFAIK) there doesn’t exist
and library named “ubygems” unless Jorge did something strange and
placed something there.

Or am I misstaken?
*t

ubygems is rubygems. This is getting off-topic, but ubygems.rb is
the reason you can write the aesthetically pleasing:

ruby -rubygems foo.rb

As well as:

ruby -rrubygems foo.rb

Note the double rr in the second one. Every installation of rubygems
includes ubygems.rb as far as I know. Try “locate ‘/ubygems.rb’” on
your system.

Alex G.

Bioinformatics Center
Kyoto University

On 5/25/07, Leslie V. [email protected] wrote:

cted $undefined, expecting tSTRING_CONTENT or tSTRING_DBEG or
error, unexpe
debugger is not expecting a colon in the path.

Try just “b 1” to set a breakpoint on line 1.

Les

Some tests show that this doesn’t help you much.
And I see ruby-breakpoint is currently broken for Windows… sorry!

To be honest, I have never really used the debugger in Ruby, and most
people
I know don’t use it either -
perhaps because of problems like this. I use ruby-breakpoint from time
to
time on Linux. Other than that
I find that a few small unit tests and the occasional ‘p variable; exit’
somewhere in my code are all I need to
figure out what the problem is.

Les