I have a script that redirects STDIN/STDOUT to a file normally. But, debugging is a lot more efficient if it doesn't do that. Is there a $DB:xxx variable or something that lets the script know so it can behave differently?
I have a script that redirects STDIN/STDOUT to a file normally. But, debugging is a lot more efficient if it doesn't do that. Is there a $DB:xxx variable or something that lets the script know so it can behave differently?
I didn't find any way of determining if they debugger is running directly, but you could check if well-known debugger variable $DB::single exists using the following:
if ($DB::{single}) {
say "Debugging";
}
Another approach would be to check if the debugger module is loaded.
if ($INC{"perl5db.pl"}) {
say "Debugging";
}
Readnig through the perl source code of DB.pm (perldoc -m DB), I noticed that $SIG{INT} is globally set at the end.
This seems to work, at least for a trivial program:
if (\&DB::catch && $SIG{'INT'} && $SIG{'INT'} == \&DB::catch) {
say "Debugging ?"
}
If it's not applicable, I guess it's possible to subclass DB.pm and create a simple debugger which overrides cont and does extra bookkeeping...