Strange "ruby -r debug t.rb" for PickAxe ver. 2's Fibonacci example

Following are two examples of using ruby-debug on PickAxe ver. 2
Fibonacci example:

  1. t.rb executed with “ruby -t debug t.rb”, which lists ruby_debug.rb
    code rather than t.rb code; and
  2. t2,rb (with embedded “require ‘ruby-debug’”) run with “ruby t2.rb”
    and correctly lists t2.rb code.

I’m running:
ruby 1.8.6
ruby-debug 0.10.3 (I believe; I list the gem info below)
WinXP-PRo/SP3

I hope the two listing present the issue clearly.

Thanks in Advance,
Richard

Command Window execution #1 for “ruby -t debug t.rb”

K:\Temp\Test>dir *.rb/b
t.rb
t2.rb

K:\Temp\Test>type t.rb
def fact(n)
if n <= 0
1
else
n * fact(n-1)
end
end

p fact(5)

K:\Temp\Test>ruby t.rb
120

K:\Temp\Test>ruby -r debug t.rb
Debug.rb
Emacs support available.

K:/_Utilities/ruby186-26_rc2/ruby/lib/ruby/site_ruby/1.8/ubygems.rb:
10:require ‘rubygems’
(rdb:1) list 1-20
[1, 20] in K:/_Utilities/ruby186-26_rc2/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.
5 # All rights reserved.
6 # See LICENSE.txt for permissions.
7 #++
8
9
=> 10 require ‘rubygems’
(rdb:1) q
Really quit? (y/n) y

K:\Temp\Test>“ruby -t debug t.rb”

Command window #2 for “ruby t2.rb” with "require ‘ruby-debug’
K:\Temp\Test>ruby -v
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

K:\Temp\Test>gem list ruby-debug

*** LOCAL GEMS ***

ruby-debug (0.10.3, 0.10.1, 0.10.0)
ruby-debug-base (0.10.3, 0.10.1, 0.10.0)
ruby-debug-ide (0.4.9, 0.1.10)

K:\Temp\Test>cd \

K:>:===================================
K:>:
K:>cd K:\Temp\Test

K:\Temp\Test>type t2.rb
require ‘ruby-debug’

def fact(n)
if n <= 0
1
else
debugger
n * fact(n-1)
end
end

p fact(5)

K:\Temp\Test>ruby t2.rb
t2.rb:8
n * fact(n-1)
(rdb:1) list 1-20
[1, 20] in t2.rb
1 require ‘ruby-debug’
2
3 def fact(n)
4 if n <= 0
5 1
6 else
7 debugger
=> 8 n * fact(n-1)
9 end
10 end
11
12 p fact(5)
(rdb:1) q
Really quit? (y/n) y

K:\Temp\Test>

The Ruby program debug.rb which comes with Ruby 1.x is what you get when
you run “ruby -rdebug t.rb” or “ruby -r debug t.rb”. (You have a typo in
the first example with the flag -t).

ruby-debug, which installs a bin/rdebug to invoke the debugger from the
outset, is something totally different. In contrast to debug.rb,
ruby-debug is not part of the standard Ruby distribution. That is why
you install it as a gem as you list above.

The pickaxe books talk about debug.rb, not the ruby-debug gem. I think
it safe to say that most folks who use any sort of debugger are nowadays
using ruby-debug. (Even the IDE’s like the ones from Eclipse, JetBrains,
or Aptana use common code from ruby-debug and none import any code from
debug.rb)

ruby-debug commands are largely a superset of the debug.rb command
listed in the Pickaxe book. However more complete information on
ruby-debug can be found at http://bashdb.sourceforge.net/ruby-debug.html

I realize all of this is confusing. Unfortunately it is a bit too late
to change this in any significant way.

In the next round of debuggers, the “trepanning” debuggers, (e.g.
http://github.com/rocky/rb-trepanning and
http://github.com/rocky/rbx-trepanning) I’ve tried to make the
distinction
more clear. The command-line invocation is not “rdebug” which can be
confused with the command-line option -rdebug. And the prompt which had
been (rdb) is now different.

On Feb 3, 8:05pm, “Rocky B.” [email protected] wrote:

it safe to say that most folks who use any sort of debugger are nowadays

In the next round of debuggers, the “trepanning” debuggers,
(e.g.http://github.com/rocky/rb-trepanningandhttp://github.com/rbx-trepanning)
I’ve tried to make the distinction
more clear. The command-line invocation is not “rdebug” which can be
confused with the command-line option -rdebug. And the prompt which had
been (rdb) is now different.


Posted viahttp://www.ruby-forum.com/.

Wow, Rocky,

That’s a great explanation (that I’ve got to study) for the anomalies
I encountered. There were other discrepancies I had noticed but
didn’t include. Your explanation and the links you supplied should
let me get my brain around this issue!

BTW, the “-t” typo was only in my introduction to my first example.
The code correctly used “-r”. That’s why I like to post real code,
rather than my human sloppiness :slight_smile:

Thank you very, very much,
Richard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs