Using Debugger Watch Expressions

B

Bernie Schneider

Hi,

The perldoc for the debugger's watch expression command, "w",
says "w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to be obvious."

Well, much as I hate to admit it, not all of it is obvious to
me. I've been experimenting with it, and I've learned a little,
but I still have some questions.

When I set a watch expression, nothing immediately happens, not
even an acknowledgement of the command. Then, when I enter a
command that changes something that changes the value of the
watch expression, still nothing happens. But upon entering the
_next_ command, I see the information for the changed watch
expression. Why didn't it show up when the value actually
changed? And then I'm left with some cryptic information about
an IO::Handle::DESTROY and a double angle bracket prompt. I can
get rid of the double angle prompt by entering an "r" command.
Is that the correct way to do it? Is it working as intended?

Perhaps the listing below will show more clearly what's
happening:


=======================
Watchpoint 0: $x+1 changed:
old value: '1'
new value: '100'
IO::Handle::DESTROY((eval 30)[C:/Perl/lib/perl5db.pl:619]:2):

DB<<13>> r

DB<13>
=======================


I think I'm pretty close to understanding it, but I could use a
little help from you experts. I'd appreciate any pointers.

TIA,
-- Bernie --
 
B

Bob Walton

Bernie Schneider wrote:

....
The perldoc for the debugger's watch expression command, "w",
says "w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to be obvious."

Well, much as I hate to admit it, not all of it is obvious to
me. I've been experimenting with it, and I've learned a little,
but I still have some questions.

When I set a watch expression, nothing immediately happens, not
even an acknowledgement of the command. Then, when I enter a
command that changes something that changes the value of the
watch expression, still nothing happens. But upon entering the
_next_ command, I see the information for the changed watch
expression. Why didn't it show up when the value actually
changed? And then I'm left with some cryptic information about
an IO::Handle::DESTROY and a double angle bracket prompt. I can
get rid of the double angle prompt by entering an "r" command.
Is that the correct way to do it? Is it working as intended?

Perhaps the listing below will show more clearly what's
happening:


=======================
Watchpoint 0: $x+1 changed:
old value: '1'
new value: '100'
IO::Handle::DESTROY((eval 30)[C:/Perl/lib/perl5db.pl:619]:2):

DB<<13>> r

DB<13> ....


-- Bernie --
....


I think you've probably picked up something that is unrelated to the
watch expression changing -- not sure what is kicking off the
IO::Handle::DESTROY message. Here is a very simple program and a
debugger session with a watch, which shows what it is supposed to do.
Note that the statement listed by the debugger when it gives a prompt is
the statement that will be executed next, *not* the one just executed.

D:\junk>type junk470.pl
print "hi\n";
while(1){
$a=3;
$b+=1;
}
print "bye\n";

D:\junk>perl -d junk470.pl

Loading DB routines from perl5db.pl version 1.25
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(junk470.pl:1): print "hi\n";
DB<1> w $b
DB<2> c
hi
Watchpoint 0: $b changed:
old value: ''
new value: '1'
main::(junk470.pl:3): $a=3;
DB<2> c
Watchpoint 0: $b changed:
old value: '1'
new value: '2'
main::(junk470.pl:3): $a=3;
DB<2> q
Watchpoint 0: $b changed:
old value: '2'
new value: ''
Config::DESTROY(C:/Perl/lib/Config.pm:1196):
1196: sub DESTROY { }
DB<2> q

D:\junk>

Note that the watcher picked up DESTROY's undef'ing of the watched
variable when I quit the debugger. I wonder if your mention of the
DESTROY method is the result of something similar?

HTH.
 
B

Bernie Schneider

Hi,

Thanks, Bob. You've set me straight.

I get essentially the same behavior when I run your test script.
The only (minor) difference occurs when I issue the first "q"
command. I get a slightly different message:

IO::Handle::DESTROY(C:/Perl/lib/IO/Handle.pm:326):
326: sub DESTROY {}

This could just be due to a difference in version or platform.
I'm using Windows XP, SP1, with Activestate Perl, version 5.8.3,
build 809, and perl5db.pl version 1.23. That's not quite as
current as the version you displayed.

I hadn't expected to have to use the "q" command twice, but
based on these results, everything appears to be working as
intended. Watch expressions are the neatest new addition to the
Perl debugger, and now that I understand them better, I'm sure
I'll be using them a lot.

Thanks again.

-- Bernie --

--


Bernie Schneider wrote:

...
The perldoc for the debugger's watch expression command, "w",
says "w expr Add a global watch-expression. We hope you know
what one of these is, because they're supposed to be obvious."

Well, much as I hate to admit it, not all of it is obvious to
me. I've been experimenting with it, and I've learned a little,
but I still have some questions.

When I set a watch expression, nothing immediately happens, not
even an acknowledgement of the command. Then, when I enter a
command that changes something that changes the value of the
watch expression, still nothing happens. But upon entering the
_next_ command, I see the information for the changed watch
expression. Why didn't it show up when the value actually
changed? And then I'm left with some cryptic information about
an IO::Handle::DESTROY and a double angle bracket prompt. I can
get rid of the double angle prompt by entering an "r" command.
Is that the correct way to do it? Is it working as intended?

Perhaps the listing below will show more clearly what's
happening:


=======================
Watchpoint 0: $x+1 changed:
old value: '1'
new value: '100'
IO::Handle::DESTROY((eval 30)[C:/Perl/lib/perl5db.pl:619]:2):

DB<<13>> r

DB<13> ...


-- Bernie --
...


I think you've probably picked up something that is unrelated to the
watch expression changing -- not sure what is kicking off the
IO::Handle::DESTROY message. Here is a very simple program and a
debugger session with a watch, which shows what it is supposed to do.
Note that the statement listed by the debugger when it gives a prompt is
the statement that will be executed next, *not* the one just executed.

D:\junk>type junk470.pl
print "hi\n";
while(1){
$a=3;
$b+=1;
}
print "bye\n";

D:\junk>perl -d junk470.pl

Loading DB routines from perl5db.pl version 1.25
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(junk470.pl:1): print "hi\n";
DB<1> w $b
DB<2> c
hi
Watchpoint 0: $b changed:
old value: ''
new value: '1'
main::(junk470.pl:3): $a=3;
DB<2> c
Watchpoint 0: $b changed:
old value: '1'
new value: '2'
main::(junk470.pl:3): $a=3;
DB<2> q
Watchpoint 0: $b changed:
old value: '2'
new value: ''
Config::DESTROY(C:/Perl/lib/Config.pm:1196):
1196: sub DESTROY { }
DB<2> q

D:\junk>

Note that the watcher picked up DESTROY's undef'ing of the watched
variable when I quit the debugger. I wonder if your mention of the
DESTROY method is the result of something similar?

HTH.
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top