blogs-debugging-article3.pod 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. In the first B::C debugging article we stepped into the B::C comnpiler with Od.
  2. In the second B::C debugging article we stepped the c code with gdb.
  3. We saw that the compiler is missing a sub in a seperate package, the most a typical
  4. problem with the compiler.
  5. We have a cool workaround for this, the -u option.
  6. <b>-udummy<b> forces all symbols in the package dummy to be dumped.
  7. <tt>'package dummy;sub meth{print "ok"};package main;dummy->meth'</tt> as ccode35.pl
  8. <pre>
  9. $ <b>perl -MO=C,-Do,-v,-udummy,-occode35.c ccode35.pl</b>
  10. Starting compile
  11. Walking tree
  12. walkoptree: 0. LISTOP (0x1471a20) leave
  13. walkoptree: 1. OP (0x1471a48) enter
  14. walkoptree: 1. COP (0x14719e0) nextstate
  15. walkoptree: 1. UNOP (0x1471998) entersub
  16. walkoptree: 2. OP (0x14719c0) pushmark
  17. walkoptree: 2. SVOP (0x1472000) const
  18. walkoptree: 2. SVOP (0x1471978) method_named
  19. done main optree, walking symtable for extras
  20. Prescan for unused subs
  21. Saving unused subs
  22. walkoptree: 0. UNOP (0x164a6c0) leavesub
  23. walkoptree: 1. LISTOP (0x164a698) lineseq
  24. walkoptree: 2. COP (0x1472a00) nextstate
  25. walkoptree: 2. LISTOP (0x1472d48) print
  26. walkoptree: 3. OP (0x1523598) pushmark
  27. walkoptree: 3. SVOP (0x147fad8) const
  28. save context:
  29. curpad names:
  30. curpad syms:
  31. %INC and @INC:
  32. amagic_generation = 1
  33. Writing output
  34. Total number of OPs processed: 13
  35. NULLOP count: 0
  36. Loaded Cwd
  37. Loaded B
  38. Loaded IO
  39. Loaded Fcntl
  40. Loaded B::C
  41. ccode35.pl syntax OK
  42. </pre>
  43. Here it is!
  44. 0. UNOP (0x164a6c0) leavesub
  45. 1. LISTOP (0x164a698) lineseq
  46. 2. COP (0x1472a00) nextstate
  47. 2. LISTOP (0x1472d48) print
  48. 3. OP (0x1523598) pushmark
  49. 3. SVOP (0x147fad8) const
  50. is indeed our missing &dummy::meth
  51. $ perl -MO=Concise,dummy::meth ccode35.pl
  52. dummy::meth:
  53. 5 <1> leavesub[1 ref] K/REFC,1 ->(end)
  54. - <@> lineseq KP ->5
  55. 1 <;> nextstate(dummy 1 ccode35.pl:1) v ->2
  56. 4 <@> print sK ->5
  57. 2 <0> pushmark s ->3
  58. 3 <$> const(PV "ok") s ->4
  59. Any sub argument to B::Concise dumps the optree for this sub, not just main.