http://www.perlmonks.org?node_id=1064341
davehorner's user image
User since: Nov 26, 2013 at 00:15 UTC (10 years ago)
Last here: Sep 27, 2023 at 23:53 UTC (29 weeks ago)
Experience: 300
Level:Scribe (6)
Writeups: 7
Location:Fort Wayne, Indiana
User's localtime: Apr 16, 2024 at 17:41 UTC
Scratchpad: View
For this user:Search nodes

Once an anonymous monk, now and always a simple seeker of Perl wisdom knocking at the gate.
Visit my website page on Perl Programming - Perl should stay Perl.
Oh, and it's MRHORNER to you.


PERL troubleshooting and debugging hanging camels. - Dave Horner's Website


is there no sense in regex when index will do?
do whatever makes most sense to u.


Posts by davehorner
How can I print variable contents from the debugger non-interactively? in Seekers of Perl Wisdom
6 direct replies — Read more / Contribute
by davehorner
on Jul 14, 2017 at 20:16
    I am trying to debug a perl script without modifying it.

    I'm using perl -d -w -Mdiagnostics=-verbose file.pl --args-to-file.pl 2>&1.

    This gives me great visibility into the lines of code that are being run, I can identify which lines are causing the issue and need to be investigated further but I'm not sure how to tell the debugger to print the contents of the variables. I don't care if I have to tell the debugger to print all variables (which would produce a lot of output). But what I would really prefer is to tell the debugger to print all the variable contents when executing line XXX or print variables named via regex.

    I learned how to use the diagnostics pragma -d -w -M here: http://perldoc.perl.org/diagnostics.html

    I have read the http://perldoc.perl.org/perldebug.html and see there is a $ENV{PERLDB_OPTS} that seems like it might be modified to provide such capabilities but I'm still not sure what debugger options I should be using.

    Any help would be greatly appreciated!

    Update: some feel this description is a bit vague so here's additional justification for not modifying the script and not running from an interactive debugger on the cmdline:
    I'm interested in trying to use the debugger as a diagnostic tool when the script is run non-interactively from another script/system, you can change environment variables and cmdline args but you can't easily change the script or execute the script from an interactive debugger session. Lets imagine that there's something about this machine that it is running on that is causing the issue, modifying the script and getting it on the machine require a lot of effort. Maybe it's in an air gap network and getting changes requires new physical media to be shipped to a customer and physically mounted. Meaning it could take significant time to just get a debug script (i.e. additional print lines) on the specific machine, which then requires you to get the output delivered physically out of the air gap network for analysis externally and then you'd need to send another updated script with the actual fix and prune the debug statements. This back and forth takes a lot of time and could require multiple iterations as you are placing debug statements in places you suspect where the issue to reside, it might take 3 or 4 debug scripts to nail down the actual bug.

    Changing the cmdline args and using perl -d -w -Mdiagnostics=-verbose file.pl --args-to-file.pl 2>&1 gets all the output required to understand what is actually being executed but it doesn't provide enough information about the variable contents to understand what it is about the environment/data that is causing the script to exhibit strange behavior.

    --dave