Add debug to help info

Is it just me or is how to debug a ruby script unnecessarily hidden?

Can I suggest adding to the output of ruby -h something to indicate how
to debug.

With 1.68:

C:>ruby -h
Usage: ruby [switches] [–] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into $F)
-c check syntax only
-Cdirectory cd to directory, before executing your script
-d set debugging flags (set $DEBUG to true)
-e ‘command’ one line of script. Several -e’s allowed. Omit
[programfile]
-Fpattern split() pattern for autosplit (-a)
-i[extension] edit ARGV files in place (make backup if extension
supplied)
-Idirectory specify $LOAD_PATH directory (may be used more than
once)
-Kkcode specifies KANJI (Japanese) code-set
-l enable line ending processing
-n assume ‘while gets(); … end’ loop around your script
-p assume loop like -n but print line also like sed
-rlibrary require the library, before executing your script
-s enable some switch parsing for switches after script
name
-S look for the script using PATH environment variable
-T[level] turn on tainting checks
-v print version number, then turn on verbose mode
-w turn warnings on for your script
-x[directory] strip off text before #!ruby line and perhaps cd to
directory
–copyright print the copyright
–version print the version

First off, I was confused by the -d option. It seemed to have no effect.
It then took some searching around to find out that “ruby -rdebug” was
what I needed.

Perhaps the output could be modified to:

-d set debugging flags (set $DEBUG to true)
Note to debug your script use “-rdebug”

Just out of curiosity, what does setting the $DEBUG flag do??

···


Robert Cowham

I’d like to second this. I was trying to debug something last night, and I
had to open up the pickaxe book to see how to actually start the debugger.

I would also be interested to know what the $DEBUG flag does.

···

On Fri, 25 Jul 2003 08:43:44 +0000, Robert Cowham wrote:

Is it just me or is how to debug a ruby script unnecessarily hidden?

Can I suggest adding to the output of ruby -h something to indicate how to
debug.

With 1.68:

C:>ruby -h
Usage: ruby [switches] [–] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument) -a
autosplit mode with -n or -p (splits $_ into $F) -c
check syntax only
-Cdirectory cd to directory, before executing your script -d
set debugging flags (set $DEBUG to true) -e ‘command’ one line
of script. Several -e’s allowed. Omit
[programfile]
-Fpattern split() pattern for autosplit (-a) -i[extension] edit
ARGV files in place (make backup if extension
supplied)
-Idirectory specify $LOAD_PATH directory (may be used more than
once)
-Kkcode specifies KANJI (Japanese) code-set -l
enable line ending processing -n assume ‘while gets(); …
end’ loop around your script -p assume loop like -n but
print line also like sed -rlibrary require the library, before
executing your script -s enable some switch parsing for
switches after script
name
-S look for the script using PATH environment variable
-T[level] turn on tainting checks -v print version
number, then turn on verbose mode -w turn warnings on for
your script -x[directory] strip off text before #!ruby line and
perhaps cd to
directory
–copyright print the copyright
–version print the version

First off, I was confused by the -d option. It seemed to have no effect.
It then took some searching around to find out that “ruby -rdebug” was
what I needed.

Perhaps the output could be modified to:

-d set debugging flags (set $DEBUG to true)
Note to debug your script use “-rdebug”

Just out of curiosity, what does setting the $DEBUG flag do??


Tim Kynerd Sundbyberg (småstan i storstan), Sweden tkynerd@spamcop.net
Sunrise in Stockholm today: 4:20
Sunset in Stockholm today: 21:27
My rail transit photos at http://www.kynerd.nu

Hi,

I would also be interested to know what the $DEBUG flag does.

It changes two behaviors.

Reports exceptions at raised.

$ ruby -e ‘raise rescue p $!’
RuntimeError

$ ruby -d -e ‘raise rescue p $!’
Exception `RuntimeError’ at -e:1 -
RuntimeError

Exits main thread when any thread aborted by exceptions.

$ ruby -e ‘Thread.new{raise};sleep 1’
$ ruby -d -e ‘Thread.new{raise};sleep 1’
Exception RuntimeError' at -e:1 - -e:1: unhandled exception from -e:1:in initialize’
from -e:1:in `new’
from -e:1

···

At Fri, 25 Jul 2003 18:38:13 +0900, Tim Kynerd wrote:


Nobu Nakada

While we’re on the subject, I hunted around in /usr/lib/ruby/1.6 and found:

tk.rb: p ‘create_self has no arg’ if $DEBUG
tempfile.rb: print “done\n” if $DEBUG
tcltk.rb: print(“mainloop: start\n”) if $DEBUG
cgi.rb: $stderr.printf(“name:%s value:%s\n”, name, value) if $DEBUG

and:

jcode.rb: printf STDERR, “feel free for some warnings:\n” if $VERBOSE
net/http.rb: $stderr.puts “WARNING: duplicated HTTP header: #{k}” if
$VERBOSE
net/http.rb: $stderr.puts ‘Content-Type did not set; using
application/x-www-form-urlencoded’ if $VERBOSE

For my own code, I’ve wrapped debug prints to save keystrokes. Do other
people do this, or do you all just append “if $DEBUG” or “if $VERBOSE” to the
end of your statements?

Is there any interest in a standard Ruby module that does debug prints, debug
block runs, and other standard debugging things? Does anybody already have
their own that they’d like to share?

I like Log4r and use it, but sometimes I’d like something a little simpler and
more lightweight.

Ben

···

On Fri July 25 2003 5:38 am, Tim Kynerd wrote:

I would also be interested to know what the $DEBUG flag does.

nobu.nokada@softhome.net wrote in news:200307250950.h6P9oUxL026371
@sharui.nakada.kanuma.tochigi.jp:

Hi,

I would also be interested to know what the $DEBUG flag does.

It changes two behaviors.

Reports exceptions at raised.

$ ruby -e ‘raise rescue p $!’
RuntimeError

$ ruby -d -e ‘raise rescue p $!’
Exception `RuntimeError’ at -e:1 -
RuntimeError

Exits main thread when any thread aborted by exceptions.

$ ruby -e ‘Thread.new{raise};sleep 1’
$ ruby -d -e ‘Thread.new{raise};sleep 1’
Exception RuntimeError' at -e:1 - -e:1: unhandled exception from -e:1:in initialize’
from -e:1:in `new’
from -e:1

That’s interesting.

Given the compatibility of Ruby with various Perl flags (-ane for
example), -d for debug seems more important to me than the above
behaviour (for the average person…).

Just a thought (and would correspond to least surprise principle too!!)

···

At Fri, 25 Jul 2003 18:38:13 +0900, > Tim Kynerd wrote:


Robert Cowham

Is there any interest in a standard Ruby module that does debug prints, debug
block runs, and other standard debugging things? Does anybody already have
their own that they’d like to share?

I like Log4r and use it, but sometimes I’d like something a little simpler and
more lightweight.

I think this would be absolutely great to have included. A nice,
quick, standard way to print out different debugging levels. I’d say
keep it similar to log4r. Have info() warn() etc that print out
depending on the debugging level set. It might be nice to not need to
create an object for it thought. Rather than create a global $debug =
Debug.new, it might be nicer to just be able to call Debug.info(‘hey,
i’m a debugging statement’). You shouldn’t ever need more than one
debugging instance at once anyway.

Hi,

···

At Sat, 26 Jul 2003 08:23:10 +0900, Robert Cowham wrote:

Given the compatibility of Ruby with various Perl flags (-ane for
example), -d for debug seems more important to me than the above
behaviour (for the average person…).

I have no particular idea about this. NaHi may do something.

One I thought, this -D option would be nice.

-D[number/list] set debugging flags (argument is a bit mask or alphabets)


Nobu Nakada

Hi,

From: “Zachary P. Landau” kapheine@hypa.net
Sent: Wednesday, July 30, 2003 11:20 AM

Is there any interest in a standard Ruby module that does debug prints, debug
block runs, and other standard debugging things? Does anybody already have
their own that they’d like to share?

I like Log4r and use it, but sometimes I’d like something a little simpler and
more lightweight.

I use [RAA:devel-logger]. (disclaimer from its author)

I think this would be absolutely great to have included. A nice,
quick, standard way to print out different debugging levels. I’d say
keep it similar to log4r. Have info() warn() etc that print out
depending on the debugging level set.

Agreed.

// NaHi

sligthly related: I’ve been thinking if could be possibe a
-v<warn_level|warning_class*> that would set $VERBOSE to something
(i.e an hash ) instead of plain true.
This won’t even break code with checks like
if $VERBOSE.

This way, for example , one could still look for unreachable
statements but forget uninitialized variables, or enable warnings for
changes beetween 1.6 and 1.8, or ‘for future version’ warnings…

or possibly this already happens ?

···

il Sun, 27 Jul 2003 22:55:17 +0900, nobu.nokada@softhome.net ha scritto::

Hi,

At Sat, 26 Jul 2003 08:23:10 +0900, >Robert Cowham wrote:

Given the compatibility of Ruby with various Perl flags (-ane for
example), -d for debug seems more important to me than the above
behaviour (for the average person…).

I have no particular idea about this. NaHi may do something.

One I thought, this -D option would be nice.

-D[number/list] set debugging flags (argument is a bit mask or alphabets)

I meant -w not -v, sorry

···

il Sun, 27 Jul 2003 15:26:58 GMT, gabriele renzi surrender_it@remove.yahoo.it ha scritto::