require 5.002; # For (defined ref)
package dumpvar;
# Needed for PrettyPrinter only:
# require 5.001; # Well, it coredumps anyway undef DB in 5.000 (not now)
# translate control chars to ^X - Randal Schwartz
# Modifications to print types by Peter Gordon v1.0
# Ilya Zakharevich -- patches after 5.001 (and some before ;-)
# Won't dump symbol tables and contents of debugged files by default
# Defaults
# $globPrint = 1;
$subdump = 1;
local %address;
local $^W=0;
(print "undef\n"), return unless defined $_[0];
push @_, -1 if @_ == 1;
}
# This one is good for variable names:
sub unctrl {
local($_) = @_;
local($v) ;
return \$_ if ref \$_ eq "GLOB";
$_;
}
sub uniescape {
join("",
map { $_ > 255 ? sprintf("\\x{%04X}", $_) : chr($_) }
unpack("U*", $_[0]));
}
sub stringify {
local($_,$noticks) = @_;
local($v) ;
return 'undef' unless defined $_ or not $printUndef;
return $_ . "" if ref \$_ eq 'GLOB';
$_ = &{'overload::StrVal'}($_)
if $bareStringify and ref $_
and %overload:: and defined &{'overload::StrVal'};
if ($tick eq 'auto') {
if (/[\000-\011\013-\037\177]/) {
$tick = '"';
}else {
$tick = "'";
}
}
if ($tick eq "'") {
s/([\'\\])/\\$1/g;
} elsif ($unctrl eq 'unctrl') {
s/([\"\\])/\\$1/g ;
# uniescape?
if $quoteHighBit;
} elsif ($unctrl eq 'quote') {
s/([\"\\\$\@])/\\$1/g if $tick eq '"';
s/\033/\\e/g;
}
$_ = uniescape($_);
($noticks || /^\d+(\.\d*)?\Z/)
? $_
}
sub ShortArray {
my $tArrayDepth = $#{$_[0]} ;
$tArrayDepth = $#{$_[0]} < $arrayDepth-1 ? $#{$_[0]} : $arrayDepth-1
unless $arrayDepth eq '' ;
my $shortmore = "";
if (!grep(ref $_, @{$_[0]})) {
$short = "0..$#{$_[0]} '" .
}
undef;
}
sub DumpElem {
if ($veryCompact && ref $_[0]
&& (ref $_[0] eq 'ARRAY' and !grep(ref $_, @{$_[0]}) )) {
my $end = "0..$#{$v} '" .
} elsif ($veryCompact && ref $_[0]
&& (ref $_[0] eq 'HASH') and !grep(ref $_, values %{$_[0]})) {
my $end = 1;
} else {
print "$short\n";
}
}
sub unwrap {
local($v) = shift ;
local($s) = shift ; # extra no of spaces
local($m) = shift ; # maximum recursion depth
return if $m == 0;
local($tHashDepth,$tArrayDepth) ;
$sp = " " x $s ;
$s += 3 ;
# Check for reused addresses
if (ref $v) {
my $val = $v;
$val = &{'overload::StrVal'}($v)
if %overload:: and defined &{'overload::StrVal'};
# Match type and address.
# Unblessed references will look like TYPE(0x...)
# Blessed references will look like Class=TYPE(0x...)
$val =~ /([^\(]+) # Keep stuff that's
# not an open paren
\( # Skip open paren
(0x[0-9a-f]+) # Save the address
\) # Skip close paren
$/x; # Should be at end now
if (!$dumpReused && defined $address) {
print "${sp}-> REUSED_ADDRESS\n" ;
return ;
}
}
} elsif (ref \$v eq 'GLOB') {
# This is a raw glob. Special handling for that.
print "${sp}*DUMPED_GLOB*\n" ;
return ;
}
}
if (ref $v eq 'Regexp') {
# Reformat the regexp to look the standard way.
my $re = "$v";
$re =~ s,/,\\/,g;
print "$sp-> qr/$re/\n";
return;
}
if ( $item_type eq 'HASH' ) {
# Hash ref or hash-based object.
my @sortKeys = sort keys(%$v) ;
undef $more ;
$tHashDepth = $#sortKeys ;
$tHashDepth = $#sortKeys < $hashDepth-1 ? $#sortKeys : $hashDepth-1
unless $hashDepth eq '' ;
$shortmore = "";
$#sortKeys = $tHashDepth ;
if ($compactDump && !grep(ref $_, values %{$v})) {
#$short = $sp .
# (join ', ',
# Next row core dumps during require from DB on 5.000, even with map {"_"}
# map {&stringify($_) . " => " . &stringify($v->{$_})}
# @sortKeys) . "'$shortmore";
my @keys;
for (@sortKeys) {
}
}
}
print "$sp empty hash\n" unless @sortKeys;
print "$sp$more" if defined $more ;
} elsif ( $item_type eq 'ARRAY' ) {
# Array ref or array-based object. Also: undef.
# See how big the array is.
$tArrayDepth = $#{$v} ;
undef $more ;
# Bigger than the max?
$tArrayDepth = $#{$v} < $arrayDepth-1 ? $#{$v} : $arrayDepth-1
# Yep. Don't show it all.
$shortmore = "";
if ($compactDump && !grep(ref $_, @{$v})) {
if ($#$v >= 0) {
join(" ",
) . "$shortmore";
} else {
}
}
#if ($compactDump && $short = ShortArray($v)) {
# print "$short\n";
# return;
#}
for $num ($[ .. $tArrayDepth) {
print "$sp$num ";
if (exists $v->[$num]) {
if (defined $v->[$num]) {
}
else {
print "undef\n";
}
} else {
print "empty slot\n";
}
}
print "$sp empty array\n" unless @$v;
print "$sp$more" if defined $more ;
} elsif ( $item_type eq 'SCALAR' ) {
unless (defined $$v) {
print "$sp-> undef\n";
return;
}
print "$sp-> ";
DumpElem $$v, $s, $m-1;
} elsif ( $item_type eq 'REF' ) {
print "$sp-> $$v\n";
return unless defined $$v;
} elsif ( $item_type eq 'CODE' ) {
# Code object or reference.
print "$sp-> ";
dumpsub (0, $v);
} elsif ( $item_type eq 'GLOB' ) {
# Glob object or reference.
if ($globPrint) {
$s += 3;
} elsif (defined ($fileno = fileno($v))) {
print( (' ' x ($s+3)) . "FileHandle({$$v}) => fileno($fileno)\n" );
}
} elsif (ref \$v eq 'GLOB') {
# Raw glob (again?)
if ($globPrint) {
} elsif (defined ($fileno = fileno(\$v))) {
print( (' ' x $s) . "FileHandle({$v}) => fileno($fileno)\n" );
}
}
}
sub matchlex {
(my $var = $_[0]) =~ s/.//;
$var eq $_[1] or
}
sub matchvar {
$_[0] eq $_[1] or
($1 eq '!') ^ (eval {($_[2] . "::" . $_[0]) =~ /$2$3/});
}
sub compactDump {
$compactDump = shift if @_;
}
sub veryCompact {
$veryCompact = shift if @_;
}
sub unctrlSet {
if (@_) {
my $in = shift;
} else {
print "Unknown value for `unctrl'.\n";
}
}
$unctrl;
}
sub quote {
if (@_ and $_[0] eq '"') {
$tick = '"';
$unctrl = 'quote';
} elsif (@_ and $_[0] eq 'auto') {
$tick = 'auto';
$unctrl = 'quote';
} elsif (@_) { # Need to set
$tick = "'";
$unctrl = 'unctrl';
}
$tick;
}
sub dumpglob {
my $fileno;
}
}
&& ($dumpPackages or $key !~ /::$/)
&& ($key !~ /^_</ or $dumpDBFiles)
}
}
if ($all) {
if (defined &entry) {
}
}
}
sub dumplex {
local %address;
my $fileno;
}
}
}
# No lexical subroutines yet...
# elsif (UNIVERSAL::isa($val,'CODE')) {
# dumpsub($off, $$val);
# }
else {
}
}
sub CvGV_name_or_bust {
my $in = shift;
return if $skipCvGV; # Backdoor to avoid problems if XS broken...
}
sub dumpsub {
my $s;
$s = $sub unless defined $s;
}
sub findsubs {
return undef unless %DB::sub;
}
$subdump = 0;
$subs{ shift() };
}
*stab = *{"main::"};
while ($package =~ /(\w+?::)/g){
}
local $TotalStrings = 0;
local $Strings = 0;
local $CompleteTotal = 0;
if ($usageOnly) {
and ref(\$val) eq 'GLOB';
} else {
}
}
if ($usageOnly) {
print "String space: $TotalStrings bytes in $Strings strings.\n";
$CompleteTotal += $TotalStrings;
print "Grand total = $CompleteTotal bytes (1 level deep) + overhead.\n";
}
}
sub scalarUsage {
my $size = length($_[0]);
$TotalStrings += $size;
$Strings++;
$size;
}
my $size = 0;
my $len = @{$_[0]};
" (data: $size bytes)\n"
if defined $_[1];
$CompleteTotal += $size;
$size;
}
my @keys = keys %{$_[0]};
my @values = values %{$_[0]};
" (keys: $keys; values: $values; total: $total bytes)\n"
if defined $_[1];
$total;
}
local *name = *{$_[0]};
$total = 0;
and $_[1] ne "DB::"; #and !($package eq "dumpvar" and $key eq "stab"));
$total;
}
sub packageUsage {
local *stab = *{"main::"};
while ($package =~ /(\w+?::)/g){
}
local $TotalStrings = 0;
local $CompleteTotal = 0;
}
print "String space: $TotalStrings.\n";
$CompleteTotal += $TotalStrings;
print "\nGrand total = $CompleteTotal bytes\n";
}
1;