Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux Timesaving Techniques For Dummies.pdf
Скачиваний:
59
Добавлен:
15.03.2015
Размер:
15.98 Mб
Скачать

Debugging Perl Code with DDD 423

Debugging Perl Code with DDD

If you’ve written many Perl programs, you’re probably familiar with Perl’s source-level debugger. To run a program under the control of the Perl debugger, use the -d option, like this:

$ perl -d program.pl

After a bit of clicking and whirring, the debugger appears, waiting for commands. If you type h and press Enter, you’re greeted with a helpful page of intimidation, as shown in Listing 55-1.

Don’t panic; there’s an easier way to debug Perl. Even if you’re a hardened Perl veteran (and you have the mental scars to prove it), you’ll love DDD, the data display debugger. DDD is a graphical front end for a number of different debuggers (GDB, DBX, the Perl debugger, and even the Python debugger).

If the DDD RPM package isn’t included on your distribution media, you can download a copy of the RPM package from www.gnu.org/ software/ddd.

Examining the main window

DDD divides the main window into three panes, stacked vertically, as shown in Figure 55-1:

The top pane, named the data window, displays variable values. (The data window is empty at first, but we show you how to put stuff there in a moment.)

The middle pane, named the source window, shows the code that you’re executing. A big green arrow points to the line of code that’s about to execute.

The bottom pane, the Perl console, is where you type in debugger commands.

Installing and starting DDD

Source window

DDD is included on most distribution media, so get-

Data window

ting it up and running is simple. To install and start the DDD debugger, follow these steps:

1. Open a terminal window and give yourself superuser privileges with the su - command.

2. Insert and mount the distribution media.

3. Move to the directory containing the RPM packages and enter the following command:

# rpm -Uhv ddd-version.rpm

4. To run a Perl program under the control of the

DDD debugger, use this command: $ ddd --perl /usr/bin/xql.pl

DDD opens, displaying a Tip of the Day and an

information window in front of the main window.

Perl console

Figure 55-1: The DDD main window.

424 Technique 55: Using the DDD Graphical Debugger with Perl

LISTING 55-1: PERL DEBUGGER COMMANDS

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]”.

y

[n [Vars]]

List

lexicals in

higher scope <n>. Vars same as V.

For

more help, type h

cmd_letter,

or run man

perldebug for all docs.

 

 

 

 

 

 

 

Reviewing and stepping through source code

If displaying your code was all that DDD could do, it would be marginally useful, but not much of a timesaver. But find a Perl program that you want to dance through, and we’ll show a few of DDD’s more useful features.

In the following example, we use a script that comes with the kdeaddons RPM package, but you can use DDD to debug any Perl program.

First, fire up the debugger:

$ cd /usr/share/apps/knewsticker/scripts $ ddd --perl bbc.pl

Figure 55-2: bbc.pl, as viewed from DDD.

The DDD debugger window opens, displaying bbc.pl (see Figure 55-2).

Соседние файлы в предмете Операционные системы