Source code of Windows XP (NT5)
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.7 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::LOGOP::debug {
  32. my ($op) = @_;
  33. $op->B::UNOP::debug();
  34. printf "\top_other\t0x%x\n", ${$op->other};
  35. }
  36. sub B::CONDOP::debug {
  37. my ($op) = @_;
  38. $op->B::UNOP::debug();
  39. printf "\top_true\t0x%x\n", ${$op->true};
  40. printf "\top_false\t0x%x\n", ${$op->false};
  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. sub B::PMOP::debug {
  48. my ($op) = @_;
  49. $op->B::LISTOP::debug();
  50. printf "\top_pmreplroot\t0x%x\n", ${$op->pmreplroot};
  51. printf "\top_pmreplstart\t0x%x\n", ${$op->pmreplstart};
  52. printf "\top_pmnext\t0x%x\n", ${$op->pmnext};
  53. printf "\top_pmregexp->precomp\t%s\n", cstring($op->precomp);
  54. printf "\top_pmflags\t0x%x\n", $op->pmflags;
  55. $op->pmshort->debug;
  56. $op->pmreplroot->debug;
  57. }
  58. sub B::COP::debug {
  59. my ($op) = @_;
  60. $op->B::OP::debug();
  61. my ($filegv) = $op->filegv;
  62. printf <<'EOT', $op->label, ${$op->stash}, $$filegv, $op->seq, $op->arybase, $op->line;
  63. cop_label %s
  64. cop_stash 0x%x
  65. cop_filegv 0x%x
  66. cop_seq %d
  67. cop_arybase %d
  68. cop_line %d
  69. EOT
  70. $filegv->debug;
  71. }
  72. sub B::SVOP::debug {
  73. my ($op) = @_;
  74. $op->B::OP::debug();
  75. printf "\top_sv\t\t0x%x\n", ${$op->sv};
  76. $op->sv->debug;
  77. }
  78. sub B::PVOP::debug {
  79. my ($op) = @_;
  80. $op->B::OP::debug();
  81. printf "\top_pv\t\t0x%x\n", $op->pv;
  82. }
  83. sub B::GVOP::debug {
  84. my ($op) = @_;
  85. $op->B::OP::debug();
  86. printf "\top_gv\t\t0x%x\n", ${$op->gv};
  87. $op->gv->debug;
  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 ($gv) = $sv->GV;
  165. my ($filegv) = $sv->FILEGV;
  166. printf <<'EOT', $$stash, $$start, $$root, $$gv, $$filegv, $sv->DEPTH, $padlist, ${$sv->OUTSIDE};
  167. STASH 0x%x
  168. START 0x%x
  169. ROOT 0x%x
  170. GV 0x%x
  171. FILEGV 0x%x
  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. $filegv->debug if $filegv;
  180. $padlist->debug if $padlist;
  181. }
  182. sub B::AV::debug {
  183. my ($av) = @_;
  184. $av->B::SV::debug;
  185. my(@array) = $av->ARRAY;
  186. print "\tARRAY\t\t(", join(", ", map("0x" . $$_, @array)), ")\n";
  187. printf <<'EOT', scalar(@array), $av->MAX, $av->OFF, $av->AvFLAGS;
  188. FILL %d
  189. MAX %d
  190. OFF %d
  191. AvFLAGS %d
  192. EOT
  193. }
  194. sub B::GV::debug {
  195. my ($gv) = @_;
  196. if ($done_gv{$$gv}++) {
  197. printf "GV %s::%s\n", $gv->STASH->NAME, $gv->NAME;
  198. return;
  199. }
  200. my ($sv) = $gv->SV;
  201. my ($av) = $gv->AV;
  202. my ($cv) = $gv->CV;
  203. $gv->B::SV::debug;
  204. 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->FILEGV, $gv->GvFLAGS;
  205. NAME %s
  206. STASH %s (0x%x)
  207. SV 0x%x
  208. GvREFCNT %d
  209. FORM 0x%x
  210. AV 0x%x
  211. HV 0x%x
  212. EGV 0x%x
  213. CV 0x%x
  214. CVGEN %d
  215. LINE %d
  216. FILEGV 0x%x
  217. GvFLAGS 0x%x
  218. EOT
  219. $sv->debug if $sv;
  220. $av->debug if $av;
  221. $cv->debug if $cv;
  222. }
  223. sub B::SPECIAL::debug {
  224. my $sv = shift;
  225. print $specialsv_name[$$sv], "\n";
  226. }
  227. sub compile {
  228. my $order = shift;
  229. if ($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