Is there any reasonable way to monitor the state when debugging Perl code?

I tried using the w perl -d command, giving it a condition like w ($root =~ /something/) to stop when $root changes, but it has the habit of stopping even if the variable just goes out of scope. So it is useless to me. I tried to add something like w (!$root || $root =~ /something/) , but this apparently leads to some weird behavior like random stop and random sub s. And in any case, even if this last one worked, it will stop if the new area contains a variable with the same name, so I would prefer not to use it.

So, is there another way to get real-time hourly observations using the Perl debugger? Or is there another console debugger for Perl that provides this?

+4
source share
1 answer

I don’t believe that there is anything to be done in the debugger, but I turned my own attached scalar class and set a breakpoint in the routine "ScalarSnoop :: STORE".

Here's the class:

 package ScalarSnoop; use strict; use base qw(Tie::Scalar); sub TIESCALAR { my $class = shift; my $value = shift; return bless \$value, $class; } sub FETCH { my $self = shift; return $$self; } sub STORE { my $self = shift; my $newvalue = shift; $$self = $newvalue; } 1; 

And here is the script that uses it:

 #!/usr/bin/env perl use v5.14.0; use strict; use warnings; use lib qw(.); use ScalarSnoop; my ($first, $second, $third); tie $second, 'ScalarSnoop'; $first = 'hey'; $second = 'there'; $third = 'dude'; # Changing the iterator variable changes the original since # it is an alias foreach my $variable (($first, $second, $third)) { $variable = "like, ${variable}"; say "$variable"; } 

Launch the debugger and set a breakpoint using b postpone ScalarSnoop::STORE . Keep working and the debugger will stop when someone stores the value in your scalar. Then you can reset the stack trace and see who it was.

+1
source

Source: https://habr.com/ru/post/1488597/


All Articles