2 # The system variables - those indicated will need to be changed to suit your
3 # circumstances (and callsign)
5 # Copyright (c) 1998 - Dirk Koopman G1TLH
14 @EXPORT = qw(dbginit dbg dbgadd dbgsub dbglist dbgdump isdbg dbgclose confess croak cluck);
17 use vars qw(%dbglevel $fp);
26 # Avoid generating "subroutine redefined" warnings with the following
27 # hack (from CGI::Carp):
28 if (!defined $DB::VERSION) {
30 eval qq( sub confess {
31 \$SIG{__DIE__} = 'DEFAULT';
33 DXDebug::dbg(Carp::shortmess(\@_));
37 \$SIG{__DIE__} = 'DEFAULT';
39 DXDebug::dbg(Carp::longmess(\@_));
42 sub carp { DXDebug::dbg(Carp::shortmess(\@_)); }
43 sub cluck { DXDebug::dbg(Carp::longmess(\@_)); }
46 CORE::die(Carp::shortmess($@)) if $@;
48 eval qq( sub confess { die Carp::longmess(\@_); };
49 sub croak { die Carp::shortmess(\@_); };
50 sub cluck { warn Carp::longmess(\@_); };
51 sub carp { warn Carp::shortmess(\@_); };
63 my @l = split /\n/, $r;
65 s/([\x00-\x08\x0B-\x1f\x7f-\xff])/uc sprintf("%%%02x",ord($1))/eg;
66 print "$_\n" if defined \*STDOUT;
67 $fp->writeunix($t, "$t^$_");
74 # add sig{__DIE__} handling
75 if (!defined $DB::VERSION) {
76 $SIG{__WARN__} = sub {
77 if ($_[0] =~ /Deep\s+recursion/i) {
79 dbg(Carp::longmess(@_));
83 dbg(Carp::shortmess(@_));
87 $SIG{__DIE__} = sub { dbg($@); dbg(Carp::longmess(@_)); };
90 $fp = DXLog::new('debug', 'dat', 'd');
95 $SIG{__DIE__} = $SIG{__WARN__} = 'DEFAULT';
104 if ($fp && ($dbglevel{$l} || $l eq 'err')) {
106 for (my $o = 0; $o < length $l; $o += 16) {
107 my $c = substr $l, $o, 16;
108 my $h = unpack "H*", $c;
109 $c =~ s/[\x00-\x1f\x7f-\xff]/./g;
110 my $left = 16 - length $c;
111 $h .= ' ' x (2 * $left) if $left > 0;
112 dbg($m . sprintf("%4d:", $o) . "$h $c");
113 $m = ' ' x (length $m);
123 foreach $entry (@_) {
124 $dbglevel{$entry} = 1;
132 foreach $entry (@_) {
133 delete $dbglevel{$entry};
139 return keys (%dbglevel);
145 return $dbglevel{$_[0]};
150 return Carp::shortmess(@_);
155 return Carp::longmess(@_);