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

abdan has asked for the wisdom of the Perl Monks concerning the following question:

How to make Perl debug automatically show modified variables values each time n, s debug step is done ?

Replies are listed 'Best First'.
Re: Have Perl debug automatically show modified values
by Fletch (Bishop) on Nov 19, 2021 at 07:40 UTC

    You're prossibly interested in watch expressions set with something along the lines of w $var which will show the old and new value whenever the watched expression changes values (and that can be an expression, not just a single variable; whenever the value of that expression is different the watch triggers). There's not much extra detail in the docs but if you search perldebug you can find this and play with a short test script:

    w expr Add a global watch-expression. Whenever a watched glob +al changes the debugger will stop and display the old and + new values.

    Alternately you might be interested in a conditional breakpoint which will only drop into the debugger if a supplied expression evaluates to true (unlike the typical unconditional breakpoint you get with the normal b LINE that always stops at line number LINE).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Have Perl debug automatically show modified values (updated)
by LanX (Sage) on Nov 19, 2021 at 09:50 UTC
    > show modified variables values each time n, s debug step is done ?

    Have a look at < and { command family, IIRC you can tell them what to do for each prompt while stepping thru code

    update

    DB<1> h > ? List Perl commands to run after each prompt. expr Define Perl command to run after each prompt. > expr Add to the list of Perl commands to run after each promp +t. * Delete the list of Perl commands to run after each prompt. DB<2> h } is not a debugger command. DB<3> h { db_command Define debugger command to run before each prompt. ? List debugger commands to run before each prompt. { db_command Add to the list of debugger commands to run before eac +h prompt. * Delete the list of debugger commands to run before each + prompt. DB<4> h < ? List Perl commands to run before each prompt. expr Define Perl command to run before each prompt. < expr Add to the list of Perl commands to run before each prom +pt. * Delete the list of perl commands to run before each +prompt. DB<5>

    "Perl commands" => Perl code

    "debugger commands" => those one letter commands listed with h h

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery