30 July 2007
Knowledge of Eclipse IDE and ColdFusion administrator.
Intermediate
If you are a veteran ColdFusion programmer you may remember a little-known feature of ColdFusion 4.5 and 5. Before ColdFusion MX was redesigned to take advantage of the J2EE platform, ColdFusion Studio (the official ColdFusion IDE from Allaire Corporation) included a step-through debugger. In the early days of ColdFusion development, the step-through debugger was essential in identifying how your code was being executed.
The need for the code debugger was greatly diminished in ColdFusion 5 with the addition of the cfdump tag. The cfdump tag offered developers an simple way to debug variables at any stage of execution by displaying variables inline as HTML. Today, developers are defining the next generation of rich Internet applications with ColdFusion, Flex, and Ajax. Most of these service-based applications may never generate HTML at all; thus, you need something more than the cfdump tag for complex debugging.
Adobe ColdFusion 8 reintroduces step-through debugging with a free extension for Eclipse. Originally developed by IBM, the open-source Eclipse project offers developers the freedom to customize their development environment. Adobe Flex Builder 2 is also built on Eclipse, which means you can integrate the ColdFusion 8 step-through debugger directly into Flex Builder or into a stand-alone installation of Eclipse.
Step-through debugging allows you to place a breakpoint on any line of CFML code. Upon execution, ColdFusion will pause the request when it reaches the breakpoint and report the current values of the existing variables along with other diagnostic information. You can step through multiple breakpoints to analyze the request at different lines of execution.
Because step-through debugging is integrated directly into the ColdFusion 8 server, you may have multiple debug sessions running concurrently, a feature not supported by other third-party debugging tools for ColdFusion. Another feature of the ColdFusion 8 step-through debugger is the ability to trigger debug sessions from outside of the IDE. This means you can set a breakpoint in a CFC that is being called from a rich Internet application such as Adobe Flex, Adobe Flash, and Ajax applications. The ColdFusion debug session will be triggered when Adobe Flash Player calls the CFC and reaches the breakpoint. You can also debug CFCs called as web services regardless of where the request originated from.
In this article you will learn how to set up and use the new ColdFusion 8 step-through debugger for Eclipse, as well as learn how to set breakpoints and step though your code.
Configuring ColdFusion to use the step-through debugger requires that you allow line debugging through the ColdFusion 8 Administrator; it may also be a good idea to enable a longer timeout limit for requests. To do so, use the following steps.
To install the ColdFusion Eclipse Extensions (download these from the Requirements section. Once you have downloaded the extensions, use the following steps to install them.
Note: If you installed ColdFusion 8 with the default setup, there is a folder under c:\coldfusion8\extras that contains this file.
Configuring ColdFusion to use the step-through debugger requires that you allow line debugging through the ColdFusion 8 Administrator; it may also be a good idea to enable a longer timeout limit for requests. To do so, use the following steps.
Note: Running a ColdFusion server in Debug mode in a production environment is not recommended as a best practice. However, since ColdFusion 8 supports multiple debug sessions, you are able to debug in production without hindering application availability. This is an important benefit as third-party debugging tools for ColdFusion only allow one debug session at a time.
Now you have to tell Eclipse where your ColdFusion server is located. You have the ability to add as many servers as you wish. They can be local (your machine) or a remote server(s). The servers against which you wish to debug must all have debugging enabled, and you must have RDS access as well.
Note: If you installed ColdFusion in multiserver configuration locally with JRun, your default ColdFusion instance port will be 8300.
Now that you have connected to your ColdFusion 8 server, you can view the defined data sources and browse database tables, view all CFCs available to you, and take advantage of the ColdFusion wizards for rapid application development.
Now you have to set up the ColdFusion server you wish to debug code against. In the menu at the top of the Eclipse editor you will see a debug icon that looks like a small bug (see Figure 5).
If Eclipse did not switch or ask you to switch to the debug view, use the following steps:
You should now be in the Debug perspective and see the following in the Debug window (see Figure 9).
See that Eclipse is connected to your ColdFusion server. If it isn't, click the down arrow next to the debug button, and then click the name of the debug setting you gave when you set up the debug mappings (see Figure 8).
Now, you will test the debugger by writing some code and setting breakpoints.
<cfset message = "Hello World!"><br />
<cfset message = "Hi!"><br />
<cfset session.myName = "Brian"/>
<cfset a = arraynew(1)><br />
<cfset a[1] = "Slot 1"><br />
<cfset a[2] = "Slot 2"><br />
<cfset a[3] = "Slot 3"><br />
<cfset a[4] = "Slot 4"><br />
<cfset session.slots = a/>
<cfloop from="1" to="#arrayLen(a)#" index="i"/>
<cfset item = a[i]/>
</cfloop/>
If you wish to see more variables than just the local variables, request variables, and argument variables, you must enable additional scopes:
After enabling more scopes for inspection, run your code again to see the changes. Figure 13 shows an example Variables view after enabling the application, server, and session scopes.
In the top of your Debug view (see Figure 14) you will see the following icons that enable you to control how the debugger steps through the code.
![]()
Clicking this icon resumes processing, meaning the application will continue to run until the request is completed or reaches another breakpoint that you have set in your code.
![]()
During debugging you can click this icon to terminate the debugging session.
![]()
This icon steps into the code after you have hit a breakpoint. It will execute subsequent code line by line, and the changes to your application's variables will be reflected in the Variables view. Using step-into will debug line by line any CFCs, UDFs, or includes and the like.
![]()
This icon is the step-over icon. Just like the step-into icon, it processes subsequent code line by line; however, it will exclude CFCs, UDFs, includes, and the like.
Now that you are all hooked up, you can easily use the step-though debugger to get important insight into how your ColdFusion applications are executing.
With everything configured, the next time you start Eclipse, your settings will be in place so that you can start debugging your ColdFusion code right away.
Tutorials & Samples |
ColdFusion Blogs |
More |
ColdFusion Cookbooks |
More |