home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / perl / !Perl / Manual / perldebug < prev    next >
Encoding:
Text File  |  1995-04-18  |  7.4 KB  |  257 lines

  1. <!-- $RCSfile$$Revision$$Date$ -->
  2. <!-- $Log$ -->
  3. <HTML>
  4. <TITLE> PERLDEBUG </TITLE>
  5. <h2>NAME</h2>
  6. perldebug - Perl debugging
  7. <p><h2>DESCRIPTION</h2>
  8. First of all, have you tried using the 
  9. <A HREF="perlrun.html#perlrun_362">-w</A>
  10.  switch?
  11. <p><h3>Debugging</h3>
  12. If you invoke Perl with a 
  13. <A HREF="perlrun.html#perlrun_346">-d</A>
  14.  switch, your script will be run under the
  15. debugger.  However, the Perl debugger is not a separate program as it is
  16. in a C environment.  Instead, the 
  17. <A HREF="perlrun.html#perlrun_346">-d</A>
  18.  flag tells the compiler to insert
  19. source information into the pseudocode it's about to hand to the
  20. interpreter.  (That means your code must compile correctly for the
  21. debugger to work on it.)  Then when the interpreter starts up, it
  22. pre-loads a Perl library file containing the debugger itself.  The program
  23. will halt before the first executable statement (but see below) and ask
  24. you for one of the following commands:
  25. <p>
  26. <dl>
  27. <dt><B>h</B>
  28. <dd>
  29. Prints out a help message.
  30. <p></dd>
  31. <dt><B>T</B>
  32. <dd>
  33. Stack trace.
  34. If you do bizarre things to your @_ arguments in a subroutine, the stack
  35. backtrace will not always show the original values.
  36. <p></dd>
  37. <dt><B>s</B>
  38. <dd>
  39. Single step.  Executes until it reaches the beginning of another
  40. statement.
  41. <p></dd>
  42. <dt><B>n</B>
  43. <dd>
  44. Next.  Executes over subroutine calls, until it reaches the beginning
  45. of the next statement.
  46. <p></dd>
  47. <dt><B>f</B>
  48. <dd>
  49. Finish.  Executes statements until it has finished the current
  50. subroutine.
  51. <p></dd>
  52. <dt><B>c</B>
  53. <dd>
  54. Continue.  Executes until the next breakpoint is reached.
  55. <p></dd>
  56. <dt><B>c line</B>
  57. <dd>
  58. Continue to the specified line.  Inserts a one-time-only breakpoint at
  59. the specified line.
  60. <p></dd>
  61. <dt><B><CR></B>
  62. <dd>
  63. Repeat last n or s.
  64. <p></dd>
  65. <dt><B>l min+incr</B>
  66. <dd>
  67. List incr+1 lines starting at min.  If min is omitted, starts where
  68. last listing left off.  If incr is omitted, previous value of incr is
  69. used.
  70. <p></dd>
  71. <dt><B>l min-max</B>
  72. <dd>
  73. List lines in the indicated range.
  74. <p></dd>
  75. <dt><B>l line</B>
  76. <dd>
  77. List just the indicated line.
  78. <p></dd>
  79. <dt><B>l</B>
  80. <dd>
  81. List next window.
  82. <p></dd>
  83. <dt><B>-</B>
  84. <dd>
  85. List previous window.
  86. <p></dd>
  87. <dt><B>w line</B>
  88. <dd>
  89. List window (a few lines worth of code) around line.
  90. <p></dd>
  91. <dt><B>l subname</B>
  92. <dd>
  93. List subroutine.  If it's a long subroutine it just lists the
  94. beginning.  Use "l" to list more.
  95. <p></dd>
  96. <dt><B>/pattern/</B>
  97. <dd>
  98. Regular expression search forward in the source code for pattern; the
  99. final / is optional.
  100. <p></dd>
  101. <dt><B>?pattern?</B>
  102. <dd>
  103. Regular expression search backward in the source code for pattern; the
  104. final ? is optional.
  105. <p></dd>
  106. <dt><B>L</B>
  107. <dd>
  108. List lines that have breakpoints or actions.
  109. <p></dd>
  110. <dt><B>S</B>
  111. <dd>
  112. Lists the names of all subroutines.
  113. <p></dd>
  114. <dt><B>t</B>
  115. <dd>
  116. Toggle trace mode on or off.
  117. <p></dd>
  118. <dt><B>b line [ condition ]</B>
  119. <dd>
  120. Set a breakpoint.  If line is omitted, sets a breakpoint on the line
  121. that is about to be executed.  If a condition is specified, it is
  122. evaluated each time the statement is reached and a breakpoint is taken
  123. only if the condition is true.  Breakpoints may only be set on lines
  124. that begin an executable statement.  Conditions don't use <B>if</B>:
  125. <p></dd>
  126. <pre>
  127.         b 237 $x > 30
  128.         b 33 /pattern/i
  129. </pre>
  130. <dt><B>b subname [ condition ]</B>
  131. <dd>
  132. Set breakpoint at first executable line of subroutine.
  133. <p></dd>
  134. <dt><B>d line</B>
  135. <dd>
  136. Delete breakpoint.  If line is omitted, deletes the breakpoint on the
  137. line that is about to be executed.
  138. <p></dd>
  139. <dt><B>D</B>
  140. <dd>
  141. Delete all breakpoints.
  142. <p></dd>
  143. <dt><B>a line command</B>
  144. <dd>
  145. Set an action for line.  A multiline command may be entered by
  146. backslashing the newlines.  This command is Perl code, not another
  147. debugger command.
  148. <p></dd>
  149. <dt><B>A</B>
  150. <dd>
  151. Delete all line actions.
  152. <p></dd>
  153. <dt><B>< command</B>
  154. <dd>
  155. Set an action to happen before every debugger prompt.  A multiline
  156. command may be entered by backslashing the newlines.
  157. <p></dd>
  158. <dt><B>> command</B>
  159. <dd>
  160. Set an action to happen after the prompt when you've just given a
  161. command to return to executing the script.  A multiline command may be
  162. entered by backslashing the newlines.
  163. <p></dd>
  164. <dt><B>V package [symbols]</B>
  165. <dd>
  166. Display all (or some) variables in package (defaulting to the <B>main</B>
  167. package) using a data pretty-printer (hashes show their keys and values so
  168. you see what's what, control characters are made printable, etc.).  Make
  169. sure you don't put the type specifier (like $) there, just the symbol
  170. names, like this:
  171. <p></dd>
  172. <pre>
  173.         V DB filename line 
  174. </pre>
  175. <dt><B>X [symbols] </B>
  176. <dd>
  177. Same as as "V" command, but within the current package.  
  178. <p></dd>
  179. <dt><B>! number</B>
  180. <dd>
  181. Redo a debugging command.  If number is omitted, redoes the previous
  182. command.
  183. <p></dd>
  184. <dt><B>! -number</B>
  185. <dd>
  186. Redo the command that was that many commands ago.
  187. <p></dd>
  188. <dt><B>H -number</B>
  189. <dd>
  190. Display last n commands.  Only commands longer than one character are
  191. listed.  If number is omitted, lists them all.
  192. <p></dd>
  193. <dt><B>q or ^D</B>
  194. <dd>
  195. Quit.  ("quit" doesn't work for this.)
  196. <p></dd>
  197. <dt><B>command</B>
  198. <dd>
  199. Execute command as a Perl statement.  A missing semicolon will be
  200. supplied.
  201. <p></dd>
  202. <dt><B>p expr</B>
  203. <dd>
  204. Same as <B>print DB::OUT expr</B>.  The DB::OUT filehandle is opened to
  205. /dev/tty, regardless of where STDOUT may be redirected to.
  206. <p></dd>
  207.  
  208. </dl>
  209.  
  210. Any command you type in that isn't recognized by the debugger will be
  211. directly executed (
  212. <A HREF="perlfunc.html#perlfunc_101">eval</A>
  213. 'd) as Perl code.  Leading white space will
  214. cause the debugger to think it's <B>NOT</B> a debugger command.
  215. <p>If you have any compile-time executable statements (code within a BEGIN 
  216. block or a 
  217. <A HREF="perlfunc.html#perlfunc_263">use</A>
  218.  statement), these will <I>NOT</I> be stopped by debugger,
  219. although 
  220. <A HREF="perlfunc.html#perlfunc_205">require</A>
  221. s will.  From your own code, however, you can transfer
  222. control back to the debugger using the following statement, which is harmless
  223. if the debugger is not running:
  224. <p><pre>
  225.         $DB::single = 1;
  226. </pre>
  227. <h3>Customization</h3>
  228. If you want to modify the debugger, copy <I>perl5db.pl</I> from the Perl
  229. library to another name and modify it as necessary.  You'll also want
  230. to set environment variable PERL5DB to say something like this:
  231. <p><pre>
  232.         BEGIN { require "myperl5db.pl" }
  233. </pre>
  234. You can do some customization by setting up a <I>.perldb</I> file which
  235. contains initialization code.  For instance, you could make aliases
  236. like these (the last one in particular most people seem to expect to 
  237. be there):
  238. <p><pre>
  239.         $DB::alias{'len'} = 's/^len(.*)/p length($1)/';
  240.         $DB::alias{'stop'} = 's/^stop (at|in)/b/';
  241.         $DB::alias{'.'} = 's/^\./p '
  242.                     . '"\$DB::sub(\$DB::filename:\$DB::line):\t"'
  243.                     . ',\$DB::dbline[\$DB::line]/' ;
  244. </pre>
  245. <h3>Other resources</h3>
  246. You did try the 
  247. <A HREF="perlrun.html#perlrun_362">-w</A>
  248.  switch, didn't you?
  249. <p><h2>BUGS</h2>
  250. If your program exit()s or die()s, so does the debugger.
  251. <p>There's no builtin way to restart the debugger without exiting and coming back
  252. into it.  You could use an alias like this:
  253. <p><pre>
  254.         $DB::alias{'rerun'} = 'exec "perl -d $DB::filename"';
  255. </pre>
  256. But you'd lose any pending breakpoint information, and that might not
  257. be the right path, etc.<p>