"global watch-expressions" in perldb?

"global watch-expressions" in perldb?

am 03.01.2008 17:50:19 von 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
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

Re: "global watch-expressions" in perldb?

am 03.01.2008 18:25:30 von Purl Gurl

kj wrote:

(snipped)

> What *exactly* is a "global watch-expression" in the context of
> the perl debugger?

> 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.


Typical documentation comment written by a blithering idiot.

My presumption is you have discovered this idiotic comment
shows up just about everywhere you research.

I have read much worse. Perl is noted for having the worst
of documentation. Perl FAQ documentation was once entirely
laughable but improvements are being made. Nonetheless, do
not expect Perl documentation nor FAQ to be of much help.

Do make use of Perl documentation and FAQ, but keep in mind
a lot of this material is written by people who would not
be considered the brightest colors in the Crayon box.

This is a page which will introduce you to watch expressions
and will provide some detailed examples. This is a fairly
decent discussion of the debugger,

http://obsidianrook.com/web/perldb_talk.html

About 1/4 down the page, look for:

"watch expression. With a watch expression, you can tell the
perl debugger to keep an eye on something like the value of a
variable, and stop and tell you whenever it changes."

Clear code examples are provided right after those comments.

You will do well to simply start at the beginning of this page
and read your way down through the discussion. You will find
good information there.

Again, be careful about Perl documentation and FAQ. Some of
this documentation is good, some of this documentation is
clearly written by blithering idiots; ignorant illiterates.


--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: "global watch-expressions" in perldb?

am 07.01.2008 20:45:20 von glex_no-spam

kj wrote:
> 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.

Re: "global watch-expressions" in perldb?

am 08.01.2008 21:44:16 von jl_post

On Jan 3, 9:50 am, kj wrote:
>
> 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

Re: "global watch-expressions" in perldb?

am 09.01.2008 17:28:47 von jl_post

On Jan 8, 1:44 pm, "jl_p...@hotmail.com" wrote:
>
> 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