Ejecución con el Depurador

También podemos usar el depurador para ejecutar el programa paso a paso. El depurador de Perl se activa usando la opción -d del intérprete:

 1 $ perl -d hola.pl
 2 
 3 Loading DB routines from perl5db.pl version 1.25
 4 Editor support available.
 5 
 6 Enter h or `h h' for help, or `man perldebug' for more help.
 7 
 8 main::(hola.pl:2):      print "hola!\n";
 9   DB<1> h
10 List/search source lines:               Control script execution:
11   l [ln|sub]  List source code            T           Stack trace
12   - or .      List previous/current line  s [expr]    Single step [in expr]
13   v [line]    View around line            n [expr]    Next, steps over subs
14   f filename  View source in file         <CR/Enter>  Repeat last n or s
15   /pattern/ ?patt?   Search forw/backw    r           Return from subroutine
16   M           Show module versions        c [ln|sub]  Continue until position
17 Debugger controls:                        L           List break/watch/actions
18   o [...]     Set debugger options        t [expr]    Toggle trace [trace expr]
19   <[<]|{[{]|>[>] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set breakpoint
20   ! [N|pat]   Redo a previous command     B ln|*      Delete a/all breakpoints
21   H [-num]    Display last num commands   a [ln] cmd  Do cmd before line
22   = [a val]   Define/list an alias        A ln|*      Delete a/all actions
23   h [db_cmd]  Get help on command         w expr      Add a watch expression
24   h h         Complete help page          W expr|*    Delete a/all watch exprs
25   |[|]db_cmd  Send output to pager        ![!] syscmd Run cmd in a subprocess
26   q or ^D     Quit                        R           Attempt a restart
27 Data Examination:     expr     Execute perl code, also see: s,n,t expr
28   x|m expr       Evals expr in list context, dumps the result or lists methods.
29   p expr         Print expression (uses script's current package).
30   S [[!]pat]     List subroutine names [not] matching pattern
31   V [Pk [Vars]]  List Variables in Package.  Vars can be ~pattern or !pattern.
32   X [Vars]       Same as "V current_package [Vars]".  i class inheritance tree.
33   y [n [Vars]]   List lexicals in higher scope <n>.  Vars same as V.
34 For more help, type h cmd_letter, or run man perldebug for all docs.
35   DB<1> l
36 2==>    print "hola!\n";
37   DB<1> n
38 hola!
39 Debugged program terminated.  Use q to quit or R to restart,
40   use O inhibit_exit to avoid stopping after program termination,
41   h q, h R or h O to get additional info.
42   DB<1> q
43 $

Consulte el libro de Foley y Lester [4] para saber mas sobre el depurador. También podemos consultar http://debugger.perl.org/. En http://refcards.com/docs/forda/perl-debugger/perl-debugger-refcard-a4.pdf se puede encontrar una página de referencia (PDF).

Casiano Rodríguez León
Licencia de Creative Commons
Principios de Programación Imperativa, Funcional y Orientada a Objetos Una Introducción en Perl/Una Introducción a Perl
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=43.
2012-06-19