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

In reply to How can I print variable contents from the debugger non-interactively? by davehorner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.