http://qs321.pair.com?node_id=1182217


in reply to Re: Debugger Questions - Variable Scope (source++)
in thread Debugger Questions - Variable Scope

Almost 3 years later, I actually tried this. It does not appear to work: execution does not stop when the variable changes value, and the L command does not show the watchpoint. My Perl version is 5.8.8; that might be important.

You're right, the solution is pretty simple. Create a ref to the variable of interest and make the watchpoint the dereferenced value. This has the very slight disadvantage of having to wait until the variable of interest has been created, but avoiding the maddening interruptions is wonderful!

Program slightly modified for demonstration purposes:

use strict; my $t = 14; print "$t\n"; $t = 15; print "$t\n"; blah(); print "$t\n"; sub blah { my $t = 42; print "$t\n"; }

Debug session - Was:

DB<1> w $t DB<2> c Watchpoint 0: $t changed: old value: '' new value: '14' main::(dbt.pl:4): print "$t\n"; DB<2> c 14 Watchpoint 0: $t changed: old value: '14' new value: '15' main::(dbt.pl:6): print "$t\n"; DB<2> c 15 Watchpoint 0: $t changed: <<<<< the bane of my existence old value: '15' new value: '42' main::blah(dbt.pl:12): print "$t\n"; DB<2> c 42 Watchpoint 0: $t changed: <<<<< just more bane old value: '42' new value: '15' main::(dbt.pl:8): print "$t\n"; DB<2> c 15 Watchpoint 0: $t changed: old value: '15' new value: '' Debugged program terminated.

Now:

DB<1> w $t DB<2> c Watchpoint 0: $t changed: old value: '' new value: '14' main::(dbt.pl:4): print "$t\n"; DB<2> W $t DB<3> $z=\$t DB<4> w $$z DB<5> c 14 Watchpoint 0: $$z changed: old value: '14' new value: '15' main::(dbt.pl:6): print "$t\n"; DB<5> c 15 42 15 Watchpoint 0: $$z changed: old value: '15' new value: '' Debugged program terminated.
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)