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

Making Stop Signs: Using Breakpoints to Watch Code

425

The source window shows you the source code for bbc.pl, and a big green arrow points to the first executable line of code in the program. The green arrow always points to the line of code that’s about to execute.

To step through the source code one line at a time, press F5 (or click the Step button on the pop-up menu). DDD then executes a single line of code in your Perl program and moves the green arrow to the next executable line of code.

Making Stop Signs: Using Breakpoints to Watch Code

When you debug your program, you can use breakpoints to stop the execution of the code at a given moment during the programs execution for a closer examination of the state of the program. This is, of course, assuming your program executes for long enough to reach the breakpoint.

Setting a breakpoint

In the source window, find some code that you want to watch and right-click in the blank area to the left of the code (in other words, right-click in the left margin). A pop-up menu appears showing the following options:

Set Breakpoint: Sets a permanent breakpoint at that line. The debugger will stop when your program reaches that statement.

Set Temporary Breakpoint: Sets a temporary breakpoint at that line. The debugger will stop when your program reaches that statement and then will delete the breakpoint.

Continue Until Here: Sets a temporary breakpoint and then immediately continues the program.

That last option (Set Execution Position) doesn’t work with Perl programs — sorry.

When you set a breakpoint, a little red stop sign appears to the left of the code.

Modifying a breakpoint

In the process of debugging your program, you may find you want to temporarily disable or completely remove a breakpoint. To modify a breakpoint, rightclick on a stop sign and choose Properties. The Properties: Breakpoint dialog opens (see Figure 55-3).

Figure 55-3: The Properties: Breakpoint dialog.

From the Properties: Breakpoint dialog, you can enable, disable, or delete the breakpoint by clicking the appropriate button. You can also assign a condition to the breakpoint or associate commands with the breakpoint, as described next.

Assigning a condition to a breakpoint

You can assign a condition to the breakpoint to streamline its functionality. For example, if you want to break only when $headline is undefined, type the following command into the Condition field and then click Apply:

!defined( $headline )

Set Execution Position: Moves the point of execution (that is, the big green arrow) to the line you’re pointing at.

426 Technique 55: Using the DDD Graphical Debugger with Perl

You can build complex breakpoint conditions with the usual Perl and, or, and not operators.

Associating debugger commands with a breakpoint

You can associate debugger commands with a breakpoint to display variable values or display a stacktrace. Click the Edit button and then enter a list of commands for DDD to execute each time the breakpoint fires. When you assign a command to a breakpoint, you have to use commands supported by the Perl debugger (refer to Listing 55-1) and surround them with double quotes. For example, to print the value of the $headline variable when a breakpoint is hit, click Edit and type the following command into the box provided:

“x $headline”

Then click Apply or Close when you’re finished.

Tracking Variable Values

in the Data Window

The next example shows the functionality and timesaving values in DDD. This example takes a couple of steps to set up, but it’s worth the time.

The Perl script ./stock.pl is a stock value tracker. You need to install a few extra Perl programs before you can run stock.pl, but the MCPAN shell can handle that for you easily:

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

#perl -MCPAN -e “install Finance::Quote”

2. When the installation program asks if you would like it to satisfy the program dependencies, press Enter to answer yes.

MCPAN takes a few moments to download and install the stock.pl prerequisites.

To start the DDD debugger and step through the stock.pl script, enter the following command:

# ddd --perl ./stock.pl

The DDD debugger opens, displaying the source code for stock.pl, as shown in Figure 55-4.

Figure 55-4: DDD displaying the stock.pl script.

Opening the data window

To open the data window, choose View Data Window. The data window opens at the top of the display.

The data window makes quick work of keeping an eye on the value of variables as you step through a Perl script.

Adding a variable to the data window

To add a variable to the data window, right-click on the variable and choose Display Variable from the pop-up menu. The variable is added to the data window, with the current value displayed beneath the header.

Tracking Variable Values in the Data Window

427

You can also add variable displays to the data window by entering commands in the Perl console. To add the fields to the data window as shown in Figure 55-5, use the following three commands:

graph display @tickers graph display %quotes

graph display $quote->{“TIMEOUT”}

Figure 55-5: Variables and their values in the data window.

As you step through the code, the values of the variables change in the data window (see Figure 55-6).

Use the Step button to step into functions and subroutines. The Next button steps over the function (executing the function) but doesn’t display the activities within the function line-by-line.

When the code executes, the TIMEOUT variable is assigned a value, as shown in Figure 55-7.

Figure 55-6: Timeout is currently undefined.

Figure 55-7: Timeout now has a value of 10.

Changing the display to a table

If the data displayed is hard to read in a row format, you can change the display to a table. Right-click on the header for the data display and choose Rotate from the pop-up menu to change the orientation of the data display.

428 Technique 55: Using the DDD Graphical Debugger with Perl

Using the Backtrace feature

The Backtrace feature makes it easy to find the current point of execution when debugging nested subroutines. Choose Status Backtrace to open the Backtrace dialog, shown in Figure 55-8.

Using the Help menu

Click the Help button in the upper-right corner to open a drop-down menu of help options. One noteworthy option on the Help menu is What Now. Click the What Now option to open a handy dialog with suggestions of how you might want to proceed, as shown in Figure 55-9.

Figure 55-8: The Backtrace dialog.

With a quick glance of the Backtrace dialog, you can

see the contents of your current call stack.

Figure 55-9: What Now?

The DDD Reference menu choice on the Help menu opens the DDD documentation. This is a quick way to get up to speed on using the DDD debugger with Perl.

Part XI

The Scary (Or Fun!) Stuff

56 Burning CD-Rs

without Getting

Technique Burned

Save Time By

Making your own distribution CDs

Writing CDs or DVDs without creating ISO images first

Creating ISO-formatted images when you need to

This technique is all about writing CDs and DVDs. Burning your own CDs is a quick and easy way to keep the information you use over and over again at your fingertips. Keep backups of your public/

private key pairs, downloaded RPM packages, and data files on CD to save time and money. CDs are small, inexpensive, portable, and easy to create, and with a little care, they last practically forever.

Burning a DVD is just like burning a CD, except that DVDs hold a lot more data and you need a DVD burner to do it. In this technique, if you see a reference to burning a CD, you can safely assume that the technique also works for a DVD.

As we mention throughout this book, one timesaving set of CDs you’ll want to make is a copy of your distribution discs. In this technique, we walk you through making a set of Fedora distribution media from downloaded disc images by using cdrecord at the command line. The same technique applies to any version of Linux distributed with ISO images — just burn each ISO image to a separate CD.

You can find a ton of open-source software on the Web, free for downloading. If you find a package you like, keep an installable copy of the RPM package on CD because open-source projects are known to come and go. Even if worldwide enthusiasm for the software you like disappears, you’ll still have a copy on CD.

You can save time by writing backup files to CD without making an ISO disc image first, but if you want to write CDs to save RPMs for later use, saving them in ISO image format is much more convenient. You can mount an ISO-formatted disc and explore the contents without using custom software. The ISO file system is an industry standard, so if you want to share programs with a friend, save them on an ISO-formatted disc, which your friend’s machine will have a better chance of understanding. In this technique, we show you how to create discs with or without ISO formatting.

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