Accessibility

Table of Contents

Using the ColdFusion 8 step-through debugger for Eclipse

Debugging against ColdFusion Server

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).

The Debug icon
Figure 5. The Debug icon

  1. Click the down arrow next to the debug icon and select "Debug" (see Figure 6).

    Selecting Debug mode

    Figure 6. Selecting Debug mode

  2. Select ColdFusion Application. Next, click the New Launch Configuration button (see Figure 7).

    Selecting a new launch configuration for a ColdFusion application

    Figure 7. Selecting a new launch configuration for a ColdFusion application

  3. Enter a name for your ColdFusion server (see Figure 8). Set the debug homepage URL to http://localhost:8500 if you are running ColdFusion in the stand-alone configuration, or http://localhost:8300 for the default ColdFusion multiple server instance configuration.
  4. Click Apply and then click Debug.

    Naming your ColdFusion Server

    Figure 8. Naming your ColdFusion Server

If Eclipse did not switch or ask you to switch to the debug view, use the following steps:

  1. Select Window > Open Perspective > Other.
  2. Select Debug and click OK.

You should now be in the Debug perspective and see the following in the Debug window (see Figure 9).

Your local ColdFusion Server in the Eclipse Debug window
Figure 9. Your local ColdFusion Server in the Eclipse Debug window

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.

  1. Put a file on the root of your ColdFusion server.
  2. Enter some test code such as the following:

    <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/>
    
  3. Double-click or right-click next to a line of code, and then select "Toggle breakpoint" (see Figure 10). This halts processing at the line, enabling you to inspect variables at that point in the processing of your ColdFusion template. A small blue dot will appear on each line you set a breakpoint to. To remove a breakpoint, simply double-click the breakpoint dot.

    Toggling a breakpoint

    Figure 10. Toggling a breakpoint

  4. Browse to the file you just created. In your Eclipse Debug perspective, in the Variables view, you will see output like that shown in Figure 11 when the breakpoint is hit. Here you see all variables that have been created up to the breakpoint you set.

    Variables created up to the breakpoint

    Figure 11. Variables created up to the breakpoint

    If you wish to see more variables than just the local variables, request variables, and argument variables, you must enable additional scopes:

  5. Select Window > Preferences.
  6. In the tree on the left side, expand the ColdFusion node and select Debug Settings. See the screen shown in Figure 12.

The Eclipse Debug Settings screen
Figure 12. The Eclipse Debug Settings screen

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.

The Variables view at the breakpoint with the application, server, and session scopes enabled
Figure 13. The Variables view at the breakpoint with the application, server, and session scopes enabled

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.

Debug control icons in the top of the Debug view.
Figure 14. Debug control icons in the top of the Debug view.

icon 1

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.

icon 2

During debugging you can click this icon to terminate the debugging session.

icon 3

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.

icon 4

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.

Conclusion

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.