May 7, 2012

The MorphX Tools - Debugger


                                                                                      Debugger
        The debugger is a stand-alone application, not part of the Dynamics AX shell like the rest of the tools . As a stand-alone application, the debugger allows you to debug X++ in any of the Dynamics AX components in the following list:
Microsoft Dynamics AX client :

        Click the Microsoft Dynamics AX drop-down menu, point to Tools and then Options. On the Development tab, select When Breakpoint in the Debug Mode list.
Application Object Server (AOS) :

         Open the Microsoft Dynamics AX Server Configuration utility under Start\Administrative Tools. Create a new configuration (if necessary), and select the check box labeled Enable Breakpoints To Debug X++ Code Running On This Server. 

        For Batch jobs, open the Microsoft Dynamics AX Server Configuration utility under Start\Administrative Tools. Create a new configuration (if necessary), and select the check box labeled Enable Global Breakpoints To Debug X++ Code Running In Batch Jobs.

Enterprise Portal and Business Connector:

        Open the Microsoft Dynamics AX Configuration utility under Start\Administrative Tools. Select one of two check boxes on the Developer tab: Enable User Breakpoints For Debugging Code Running In The Business Connector or Enable Global Breakpoints For Debugging Code Running In The Business Connector Or Client. The latter is useful for debugging incoming Web requests.

Note : Do not enable any of the debugging capabilities in a live environment. If we do, execution will stop when it hits a breakpoint, and users will experience a hanging client.

By pressing F9 we can set or remove " Breakpoint ".
You can enable or disable a breakpoint by pressing Ctrl+F9. For a list of all breakpoints, press Shift+F9.

                                                           Debugger Interface

        The main window in the debugger initially shows the point in the code where a breakpoint was hit. We can control execution one step at a time while variables and other aspects are inspected. Figure 1 shows the debugger opened to a breakpoint with all the windows enabled.
Figure 1. Debugger with all windows enabled

        In the following subsections, we briefly describe the debugger’s various windows and some of its other features.
Main Window :
       The main debugger window shows the current X++ code. Each variable has a ScreenTip that reveals its value. You can drag the next-statement pointer in the left margin. This pointer is particularly useful if the execution path isn’t what you expected or if you want to repeat a step.
Variables Window :
        In this window, local, global, and member variables are shown. Local variables are variables in scope at the current execution point. Global variables are the global classes that are always instantiated: Appl,InfologClassFactory, and VersionControl. Member variables make sense only on classes, and they show the class member variables.
     The Variables window shows the name, value, and type of each variable. If a variable is changed during execution stepping, it is marked in red. Each variable is shown associated with a client or server icon. You can modify the value of a variable by double-clicking the value.

Tip :  As a developer, we might want to provide more information in the value field than what is provided by default. For a class, the defaults are New and Null. You can change the defaults by overriding the toString method. If your class doesn’t explicitly extend object (the base class of all classes), you must add a new method named toString, returning str and taking no parameters, to implement this functionality.
   
Call Stack Window :
      
       The Call Stack window shows the code path followed to arrive at a particular execution point. Clicking a line in the Call Stack window opens the code in the Code window and updates the local Variables window. A client or server icon indicates the tier on which the code is executed.
Watch Window :
     In the Watch window, you can inspect variables without the scope limitations of the Variables window. You can drag a variable here from the Code window or the Variables window.
    The Watch window shows the name, value, and type of the variables. Five different Watch windows are available. You can use these to group the variables you’re watching in the way that you prefer.
Breakpoints Window :
      The Breakpoints window lists all your breakpoints. You can delete, enable, and disable the breakpoints via this window.
Output Window :
       The Output window shows the traces that are enabled and the output sent to the Infolog application framework. The Output window includes the following pages:
  • Debug You can instrument your X++ code to trace to this page by using the printDebug static method on the Debug class.
  • Infolog This page contains messages in the queue for the Infolog.
  • Database, Client/Server, and ActiveX Trace Any traces enabled on the Development tab in the Options dialog box appear on these pages.
Status Bar :
        The status bar at the bottom of the debugger offers the following important context information:
  • Current user The ID of the user who is logged on to the system. This information is especially useful when you are debugging incoming Web requests.
  • Current session The ID of the session on the AOS.
  • Current company accounts The ID of the current company accounts.
  • Transaction level The current transaction level. When reaching zero, the transaction is committed.
Debugger Shortcut Keys
Table lists the most important shortcut keys available in the debugger.

 Debugger Shortcut Keys

ActionShortcutDescription
RunF5Continue execution
Stop debuggingShift+F5Break execution
Step overF10Step over next statement
Run to cursorCtrl+F10Continue execution but break at the cursor’s position
Step intoF11Step into next statement
Step outShift+F11Step out of method
Toggle breakpointShift+F9Insert or remove breakpoint
Variables windowCtrl+Alt+VOpen or close Variables window
Call Stack windowCtrl+Alt+COpen or close Call Stack window
Watch windowCtrl+Alt+WOpen or close Watch window
Breakpoints windowCtrl+Alt+BOpen or close Breakpoints window
Output windowCtrl+Alt+OOpen or close Output window