home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _96ba3390f252a1c769e8dc7f40a251dd < prev    next >
Text File  |  2000-03-15  |  6KB  |  275 lines

  1. package B::Debug;
  2. use strict;
  3. use B qw(peekop class walkoptree walkoptree_exec
  4.          main_start main_root cstring sv_undef);
  5. use B::Asmdata qw(@specialsv_name);
  6.  
  7. my %done_gv;
  8.  
  9. sub B::OP::debug {
  10.     my ($op) = @_;
  11.     printf <<'EOT', class($op), $$op, ${$op->next}, ${$op->sibling}, $op->ppaddr, $op->targ, $op->type, $op->seq, $op->flags, $op->private;
  12. %s (0x%lx)
  13.     op_next        0x%x
  14.     op_sibling    0x%x
  15.     op_ppaddr    %s
  16.     op_targ        %d
  17.     op_type        %d
  18.     op_seq        %d
  19.     op_flags    %d
  20.     op_private    %d
  21. EOT
  22. }
  23.  
  24. sub B::UNOP::debug {
  25.     my ($op) = @_;
  26.     $op->B::OP::debug();
  27.     printf "\top_first\t0x%x\n", ${$op->first};
  28. }
  29.  
  30. sub B::BINOP::debug {
  31.     my ($op) = @_;
  32.     $op->B::UNOP::debug();
  33.     printf "\top_last\t\t0x%x\n", ${$op->last};
  34. }
  35.  
  36. sub B::LOGOP::debug {
  37.     my ($op) = @_;
  38.     $op->B::UNOP::debug();
  39.     printf "\top_other\t0x%x\n", ${$op->other};
  40. }
  41.  
  42. sub B::LISTOP::debug {
  43.     my ($op) = @_;
  44.     $op->B::BINOP::debug();
  45.     printf "\top_children\t%d\n", $op->children;
  46. }
  47.  
  48. sub B::PMOP::debug {
  49.     my ($op) = @_;
  50.     $op->B::LISTOP::debug();
  51.     printf "\top_pmreplroot\t0x%x\n", ${$op->pmreplroot};
  52.     printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
  53.     printf "\top_pmnext\t0x%x\n", ${$op->pmnext};
  54.     printf "\top_pmregexp->precomp\t%s\n", cstring($op->precomp);
  55.     printf "\top_pmflags\t0x%x\n", $op->pmflags;
  56.     $op->pmshort->debug;
  57.     $op->pmreplroot->debug;
  58. }
  59.  
  60. sub B::COP::debug {
  61.     my ($op) = @_;
  62.     $op->B::OP::debug();
  63.     printf <<'EOT', $op->label, $op->stashpv, $op->file, $op->seq, $op->arybase, $op->line, ${$op->warnings};
  64.     cop_label    %s
  65.     cop_stashpv    %s
  66.     cop_file    %s
  67.     cop_seq        %d
  68.     cop_arybase    %d
  69.     cop_line    %d
  70.     cop_warnings    0x%x
  71. EOT
  72. }
  73.  
  74. sub B::SVOP::debug {
  75.     my ($op) = @_;
  76.     $op->B::OP::debug();
  77.     printf "\top_sv\t\t0x%x\n", ${$op->sv};
  78.     $op->sv->debug;
  79. }
  80.  
  81. sub B::PVOP::debug {
  82.     my ($op) = @_;
  83.     $op->B::OP::debug();
  84.     printf "\top_pv\t\t0x%x\n", $op->pv;
  85. }
  86.  
  87. sub B::PADOP::debug {
  88.     my ($op) = @_;
  89.     $op->B::OP::debug();
  90.     printf "\top_padix\t\t%ld\n", $op->padix;
  91. }
  92.  
  93. sub B::CVOP::debug {
  94.     my ($op) = @_;
  95.     $op->B::OP::debug();
  96.     printf "\top_cv\t\t0x%x\n", ${$op->cv};
  97. }
  98.  
  99. sub B::NULL::debug {
  100.     my ($sv) = @_;
  101.     if ($$sv == ${sv_undef()}) {
  102.     print "&sv_undef\n";
  103.     } else {
  104.     printf "NULL (0x%x)\n", $$sv;
  105.     }
  106. }
  107.  
  108. sub B::SV::debug {
  109.     my ($sv) = @_;
  110.     if (!$$sv) {
  111.     print class($sv), " = NULL\n";
  112.     return;
  113.     }
  114.     printf <<'EOT', class($sv), $$sv, $sv->REFCNT, $sv->FLAGS;
  115. %s (0x%x)
  116.     REFCNT        %d
  117.     FLAGS        0x%x
  118. EOT
  119. }
  120.  
  121. sub B::PV::debug {
  122.     my ($sv) = @_;
  123.     $sv->B::SV::debug();
  124.     my $pv = $sv->PV();
  125.     printf <<'EOT', cstring($pv), length($pv);
  126.     xpv_pv        %s
  127.     xpv_cur        %d
  128. EOT
  129. }
  130.  
  131. sub B::IV::debug {
  132.     my ($sv) = @_;
  133.     $sv->B::SV::debug();
  134.     printf "\txiv_iv\t\t%d\n", $sv->IV;
  135. }
  136.  
  137. sub B::NV::debug {
  138.     my ($sv) = @_;
  139.     $sv->B::IV::debug();
  140.     printf "\txnv_nv\t\t%s\n", $sv->NV;
  141. }
  142.  
  143. sub B::PVIV::debug {
  144.     my ($sv) = @_;
  145.     $sv->B::PV::debug();
  146.     printf "\txiv_iv\t\t%d\n", $sv->IV;
  147. }
  148.  
  149. sub B::PVNV::debug {
  150.     my ($sv) = @_;
  151.     $sv->B::PVIV::debug();
  152.     printf "\txnv_nv\t\t%s\n", $sv->NV;
  153. }
  154.  
  155. sub B::PVLV::debug {
  156.     my ($sv) = @_;
  157.     $sv->B::PVNV::debug();
  158.     printf "\txlv_targoff\t%d\n", $sv->TARGOFF;
  159.     printf "\txlv_targlen\t%u\n", $sv->TARGLEN;
  160.     printf "\txlv_type\t%s\n", cstring(chr($sv->TYPE));
  161. }
  162.  
  163. sub B::BM::debug {
  164.     my ($sv) = @_;
  165.     $sv->B::PVNV::debug();
  166.     printf "\txbm_useful\t%d\n", $sv->USEFUL;
  167.     printf "\txbm_previous\t%u\n", $sv->PREVIOUS;
  168.     printf "\txbm_rare\t%s\n", cstring(chr($sv->RARE));
  169. }
  170.  
  171. sub B::CV::debug {
  172.     my ($sv) = @_;
  173.     $sv->B::PVNV::debug();
  174.     my ($stash) = $sv->STASH;
  175.     my ($start) = $sv->START;
  176.     my ($root) = $sv->ROOT;
  177.     my ($padlist) = $sv->PADLIST;
  178.     my ($file) = $sv->FILE;
  179.     my ($gv) = $sv->GV;
  180.     printf <<'EOT', $$stash, $$start, $$root, $$gv, $file, $sv->DEPTH, $padlist, ${$sv->OUTSIDE};
  181.     STASH        0x%x
  182.     START        0x%x
  183.     ROOT        0x%x
  184.     GV        0x%x
  185.     FILE        %s
  186.     DEPTH        %d
  187.     PADLIST        0x%x                   
  188.     OUTSIDE        0x%x
  189. EOT
  190.     $start->debug if $start;
  191.     $root->debug if $root;
  192.     $gv->debug if $gv;
  193.     $padlist->debug if $padlist;
  194. }
  195.  
  196. sub B::AV::debug {
  197.     my ($av) = @_;
  198.     $av->B::SV::debug;
  199.     my(@array) = $av->ARRAY;
  200.     print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
  201.     printf <<'EOT', scalar(@array), $av->MAX, $av->OFF, $av->AvFLAGS;
  202.     FILL        %d    
  203.     MAX        %d
  204.     OFF        %d
  205.     AvFLAGS        %d
  206. EOT
  207. }
  208.     
  209. sub B::GV::debug {
  210.     my ($gv) = @_;
  211.     if ($done_gv{$$gv}++) {
  212.     printf "GV %s::%s\n", $gv->STASH->NAME, $gv->NAME;
  213.     return;
  214.     }
  215.     my ($sv) = $gv->SV;
  216.     my ($av) = $gv->AV;
  217.     my ($cv) = $gv->CV;
  218.     $gv->B::SV::debug;
  219.     printf <<'EOT', $gv->NAME, $gv->STASH->NAME, $gv->STASH, $$sv, $gv->GvREFCNT, $gv->FORM, $$av, ${$gv->HV}, ${$gv->EGV}, $$cv, $gv->CVGEN, $gv->LINE, $gv->FILE, $gv->GvFLAGS;
  220.     NAME        %s
  221.     STASH        %s (0x%x)
  222.     SV        0x%x
  223.     GvREFCNT    %d
  224.     FORM        0x%x
  225.     AV        0x%x
  226.     HV        0x%x
  227.     EGV        0x%x
  228.     CV        0x%x
  229.     CVGEN        %d
  230.     LINE        %d
  231.     FILE        %s
  232.     GvFLAGS        0x%x
  233. EOT
  234.     $sv->debug if $sv;
  235.     $av->debug if $av;
  236.     $cv->debug if $cv;
  237. }
  238.  
  239. sub B::SPECIAL::debug {
  240.     my $sv = shift;
  241.     print $specialsv_name[$$sv], "\n";
  242. }
  243.  
  244. sub compile {
  245.     my $order = shift;
  246.     B::clearsym();
  247.     if ($order eq "exec") {
  248.         return sub { walkoptree_exec(main_start, "debug") }
  249.     } else {
  250.         return sub { walkoptree(main_root, "debug") }
  251.     }
  252. }
  253.  
  254. 1;
  255.  
  256. __END__
  257.  
  258. =head1 NAME
  259.  
  260. B::Debug - Walk Perl syntax tree, printing debug info about ops
  261.  
  262. =head1 SYNOPSIS
  263.  
  264.     perl -MO=Debug[,OPTIONS] foo.pl
  265.  
  266. =head1 DESCRIPTION
  267.  
  268. See F<ext/B/README>.
  269.  
  270. =head1 AUTHOR
  271.  
  272. Malcolm Beattie, C<mbeattie@sable.ox.ac.uk>
  273.  
  274. =cut
  275.