Nordic Perl Workshop 2007

About
  What
  When
  Where
Information
  Call for Papers
  Sponsorship
  Presskit
  Wiki
Register
  Log in
Users
  Search
  Statistics
Presentations
  Favorite Talks
  Schedule
  iCal export
  Submit a talk proposal
Previous workshops
  NPW 2006
  NPW 2005
  NPW 2004
  SPW 2003
Related conferences
 German Perl/Raku Workshop 2025
 Perl Toolchain Summit 2025

The Perl Debugger

By Richard Foley (‎richard‎) from Munich.pm
Date: Sunday, 29 April 2007 13:30
Duration: 30 minutes
Language:


What is it?
It's a tool to help find bugs

Complementary Strategies

The print statement

Logging

DEAP

Things to do first
syntax check

use strict

use warnings and diagnostics

taint

Debugger Features
Stop the program at any executable line of code or subroutine

Stop the program on any condition

Stop the program if a variable value changes

Inspect class hierarchies

Inspect methods and code

Trace code execution

Execute a command before/after every executable line

On the fly modification of variables and code

Follow forking programs

Follow threaded programs and their variables

Save and reexecute sessions

How do I use it?
#!/usr/bin/perl -d

perl -d program.pl

perl -d -e 0

perl -dt program.pl

perl -d:ptkdb (gui)

help
DB<1> h

List/search source lines: Control script execution:
l [ln|sub] List source code T Stack trace
- or . List previous/current line s [expr] Single step [in expr]
v [line] View around line n [expr] Next, steps over subs
f filename View source in file <CR/Enter> Repeat last n or s
/pattern/ ?patt? Search forw/backw r Return from subroutine
M Show module versions c [ln|sub] Continue until position
Debugger controls: L List break/watch/actions
o [...] Set debugger options t [expr] Toggle trace [trace expr]
<[<]|{[{]|>[>] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set breakpoint
! [N|pat] Redo a previous command B ln|* Delete a/all breakpoints
H [-num] Display last num commands a [ln] cmd Do cmd before line
= [a val] Define/list an alias A ln|* Delete a/all actions
h [db_cmd] Get help on command w expr Add a watch expression
h h Complete help page W expr|* Delete a/all watch exprs
|[|]db_cmd Send output to pager ![!] syscmd Run cmd in a subprocess
q or ^D Quit R Attempt a restart
Data Examination: expr Execute perl code, also see: s,n,t expr
x|m expr Evals expr in list context, dumps the result or lists methods.
p expr Print expression (uses script's current package).
S [[!]pat] List subroutine names [not] matching pattern
V [Pk [Vars]] List Variables in Package. Vars can be ~pattern or !pattern.
X [Vars] Same as "V current_package [Vars]". i class inheritance tree.
y [n [Vars]] List lexicals in higher scope <n>. Vars same as V.
e Display thread id E Display all thread ids.
For more help, type h cmd_letter, or run man perldebug for all docs.

Commands
help - h, hh, man, perldoc

step - c, n, s, r

breakpoints - b, B

- line [condition]
- [postpone] subroutine [condition]
- compile subroutine
- load [filename]

actions - a, A

- [line] command [condition]

watches - w, W

- w [condition]

list abw - L [abw]

trace - t, T

list code - l, m, S, v, f

search code - . / ? -

inspect variables - p, V, x, X, y

threads - e, E

pre/post line commands - <, <<, >, >>, {, {{

options - depth of dumps for arrays and hashes
- frame settings, window size,

commands - H, R, rerun

system - ! !! |

save, source

Environment
PERLDB_OPTS="nonStop autoTrace lineInfo=db.out"

.perldb

sub afterinit {...}

@DB::typeahead

$DB::single 1=s, 2=n

Apache and mod_perl
#!/usr/bin/perl -d

DISPLAY='192.168.0.69:0.0' perl -d:ptkdb -e 0

httpd -X

Apache::DB - (db.pl)

Apache::DProf

Customisation
PERL5DB="{ sub DB::DB { print '.' } }"

PERL5DB="{ require 'mydb.pl' }"

Related Tools

Devel::ptkdb

Devel::Trace

Devel::ebug

Devel::DProf

Devel::*

B::Deparse

Further Reading and References
perldoc

perldebug

perldebugtut

perldebguts

perlrun

http://debugger.perl.org

Perl Debugged - Addison-Wesley - Peter Scott & Ed Wright

Perl Debugger Pocket Reference - O'Reilly

Pro Perl Debugging - Apress




LogicLab FULLRATE ActiveState
Adapt Code3 Stonehenge
Versed Solutions The Perl Review YEF
Sifira DKUUG
Copenhagen Perl Mongers Nordic Perl Workshop 2007 is organized by the Copenhagen Perl Mongers and made possible by our sponsors

Valid XHTML 1.0 Transitional