"global watch-expressions" in perldb?

K

kj

What *exactly* is a "global watch-expression" in the context of
the perl debugger? And what exactly needs to happen for a global
watch-expression to stop the execution of the program? Does
"localizing" a global do it? Can one use a global watch-expression
when detect when a method has been overridden by the run-time
definition of the overriding method in a subclass?

Of course, I tried to RTFM, but all it says is this:

w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to
be obvious.

TIA!

kj
 
J

J. Gleixner

kj said:
What *exactly* is a "global watch-expression" in the context of
the perl debugger? And what exactly needs to happen for a global
watch-expression to stop the execution of the program? Does
"localizing" a global do it? Can one use a global watch-expression
when detect when a method has been overridden by the run-time
definition of the overriding method in a subclass?

Of course, I tried to RTFM, but all it says is this:

w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to
be obvious.

When RTFM doesn't work, try using your favorite Internet search engine.
Using one, I found the following, which might show you how to use it.

http://coding.derkeiler.com/Archive/Perl/comp.lang.perl.misc/2004-07/1231.html

Basically, it'll display when the 'expr' changes value. You can test
what it detects and displays pretty easily.
 
J

jl_post

What *exactly* is a "global watch-expression" in the context of
the perl debugger? And what exactly needs to happen for a global
watch-expression to stop the execution of the program?

Of course, I tried to RTFM, but all it says is this:

w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to
be obvious.


For once, I kind of agree with Purl Gurl's rant. For years, I
misunderstood what a watch-expression was because of this explanation,
and it wasn't until I was studying Ruby with the Ruby "Pickaxe" book
(that is, "Programming Ruby" by Dave Thomas) that I understood it by
reading the following:

wat[ch] expr Break when expression becomes true.

It even provides an example:

(rdb:1) watch n==1

With this watch-expression the debugger will break as soon as the
expression "n==1" evaluates to true (which is when n equals 1).

In Perl, however, it seems like the debugger breaks whenever the
expression changes (and not necessarily when it becomes true). So if
you have this script:

/usr/bin/perl
$n = 1;
$n = 2;
$n = 3;
$n = 4;
$n = 5;
$n = 6;
$n = 7;
__END__

and you run the debugger with:

perl -d script.pl

and set a watch expression like this:

DB<1> w $n == 3

then continue with the "c" command, you'll see it breaks AFTER having
set $n to 3 (because now "$n == 3" evaluates to true). If you re-
continue (again with the "c" command), you'll break at the very next
line (after setting $n to 4), because now "$n == 3" evaluates to
false.

If you continue again, you'll run to the end of the script, because
the expression "$n == 3" never changes.

If you used this instead:

DB<1> w $n

the debugger would break at every line because $n evaluates to
something different at every line.

I hope this explanation helps. Personally, I think it would be a
lot easier to just have written:

w expr Halts program execution whenever the value
of the expression changes.

instead of writing "We hope you know what one of these is...". The
first way is not only blatantly unhelpful, but also fosters
misconceptions if the programmer happens to thinks he/she understands
when in fact he/she really does not.

Ironically, it was an explanation in a Ruby book that helped me
understand what the Perl documentation should have explained. (And it
did it using less words, too, since it didn't bother explaining that
it should already be obvious.)

-- Jean-Luc
 
J

jl_post

Ironically, it was an explanation in a Ruby book that helped me
understand what the Perl documentation should have explained. (And it
did it using less words, too, since it didn't bother explaining that
it should already be obvious.)


Hmmm... looking back at my earlier post, it makes it look like I
think that Perl documentation is sub-standard. That wasn't what I
meant at all.

To clarify, I meant to say that I think that Perl documentation is
very well done, both in the Camel book and in the perldocs. (I've
even consulted Perl documentation for C behavior, it's that good!)
It's just that I felt that the explanation in "perldoc perldebug" of
the debugger's "w expr" command was a surprising departure from the
comprehensive documentation I had come to expect and enjoy.

Sometimes I take Perl documentation for granted, which I've
discovered when I've tried to learn new languages -- few programming
languages (scripting or otherwise) have documentation that is anywhere
near as helpful (or comprehensive) as Perl's. And when I'm used to
pulling up the Perl documentation I want literally within seconds,
it's frustrating learning "the great new programming language" when I
spend hours trying to find documentation needed to use specific code
in this new language.

(In other words, I make the mistake thinking that just because Perl
has great documentation, all other programming languages should, too.
In reality, that's often far from the truth.)

-- Jean-Luc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,208
Messages
2,571,083
Members
47,683
Latest member
AustinFairchild

Latest Threads

Top