Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
5.9 KiB

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