As part of the Flex SDK, Adobe includes FDB, a free command-line debugger. This debugger is fully featured, although usually you will opt to use the Flex Builder debugger if available. With that said, it is great to have access to a free debugging tool included as part of the SDK. This allows developers who do not want to purchase Flex Builder access to a fully featured debugger. We won’t be covering FDB in depth, but we will discuss the basics and some of the possible benefits it has to offer.
You launch FDB from the command line as you would any other
command-line application. Once it is started, you will be prompted with
the FDB prompt (fdb
). You can type
help
at the prompt for a list of
available commands.
The starting point for a debug session with FDB is to launch an
.swf compiled with debugging enabled
in the Debug Player and establish a connection with FDB. You do this by
first executing the run
command at the
FDB prompt. Once the command is executed, FDB will confirm that it is
waiting for the player to connect. To connect Flash Player to FDB, open a
debug-enabled .swf with the Debug
Player. When a debug-enabled
.swf is opened, the player will
attempt to auto-connect to the local debugger, if available. If you open
an application without the debugger listening for a connection from the
player, the Flash Debug Player will prompt you to select the debugger you
want to use. Although typically a user will be running the application and
the debugger on the same machine, which means you may never receive the
prompt requesting you to select the debugger, it is possible to initiate a
remote debugging session. Remote debugging allows you to execute an application on a
machine that is separate from the debugger, allowing you to debug problems
that are reproducible on only certain machines, or even debug across
platforms wherein a Mac OS X machine executes an application with the
debugger running on a Windows machine. For this purpose, all debugging
communication occurs through TCP on port 7935. We cover remote debugging
later in this chapter.
Once a connection is established, you can set breakpoints or
instruct the debugger to continue execution of the application. To continue execution you can issue the continue
command. Application trace messages are shown in the debugger as they are
encountered.
Breakpoints can be set using several methods. The most typical
method of setting a breakpoint is to specify the class and line number for
the breakpoint, which you can achieve by issuing the break
command. For example, if you wanted to
insert a breakpoint in line 56 of the class MainApp
, you would input the command break MainApp.mxml:56
. If you want a breakpoint
when a button is pressed but you are not sure of the method that will be
called when the event occurs, you could enter break button
. This will return a list of
methods that begin with the word button. From the
list, you should see buttonPressed
and
the location of the method. With that information, you could set the
breakpoint by calling break
buttonPressed
. Once you do that, you will need to call the
command continue
, which will tell the
debugger to allow the player to continue executing the application. There
are other methods of setting breakpoints with FDB, which you can find by
issuing the command help
breakpoint
.
When an application is executing, the debugger will inform you when
it encounters a breakpoint. Once a breakpoint is encountered, you have
several options. You can issue the continue
command, which will continue execution
of the application, step through the application using the step
command, and set the value of a variable
using the set
command. When done
debugging, you can exit FDB to end the debugging session, which will
automatically end the active connection with the Debug Player, or you can
execute the kill
command.
As discussed, FDB makes it easy to search for methods on which you
want to set breakpoints. Some of the other nice features of FDB that Flex
Builder’s debugger doesn’t support are the ability to set conditional
breakpoints using the condition
command, and the ability to review a list of all the loaded types and
functions with the info functions
command.
FDB can be a powerful tool and is worth exploring, but as you will see in the next section, Flex Builder provides a more practical method of application debugging, which you will likely opt for over FDB.