Saturday, 12 April 2014

Using the Microsoft Dynamics AX Debugger

When a debugging session begins, the Microsoft Dynamics AX Debugger is automatically started by either the Microsoft Dynamics AX Client or the Microsoft Dynamics AX Business Connector, if the debugger has been enabled. For more information about enabling the debugger, see Enabling the Debugger.
All information shown in the debugger is retrieved directly from the client or the Business Connector. The debugger has no connection to the database, the application, or the Application Object Server (AOS).
When you want to debug X++ code, you must first set a breakpoint in the source code by using the code editor in the client. For information about setting breakpoints, see Using Breakpoints. When the code is run and the line where a breakpoint is set has been reached, execution is suspended and the debugger is automatically started. The debugger shows the location in the source code where code execution was stopped.
You can insert, remove, enable, or disable breakpoints in both the code window and the Breakpoints Window. Breakpoints are preserved between debugging sessions.
When the code execution has been stopped at a breakpoint, you can continue, end, or single-step through the source code.
Single stepping commands are:
  • Step Into – The execution steps into the current line if it contains a function or a method call.
  • Step Over – The execution steps to the next line of code in the current function or method.
  • Step Out – The execution steps out of the current function or method.
Run to Cursor executes code until it reaches the location of the cursor in the code window. Conceptually, it is similar to a temporary breakpoint.
Show Next Statement displays the location of the current execution point. The feature is helpful when you have been browsing in other source code windows in the debugger, and the location of the current execution point is not obvious.
Set Next Statement allows the user to choose which line of code is run next. This is denoted by the yellow arrow in the gutter. Choosing which line of code runs next can be done only inside the uppermost method on the call stack.
There are three ways to use this functionality:
  • Position the cursor on the line that you want to set as the current statement, and on the Debug menu, click Set Next Statement.
  • Right-click the line that you want to be the current statement, and on the shortcut menu, click Set Next Statement.
  • Drag the yellow arrow in the gutter of the code window to the line that you want to set as current. A blinking red arrow indicates the line that is the current target of the Set Next Statement action.
You can use Set Next Statement only on lines with executable X++ statements on them—blank lines, lines with only braces or semicolons, and variable declarations are not valid targets.
Shortcut menu items for copying the contents of a debugger window to the Clipboard have been added. You can choose Copy Selected Line(s) or Copy All Lines. The Call Stack, Variables, and Watch windows have this capability. Additionally, in the Variables window you can copy only the Value column by pressing CTRL+C with one or more rows selected. The Copy Selected Lines action executes.
When a row is copied, the text is placed on the Clipboard in the following formats:
  • Variable window format and Watch window format:
<Name text padded to 50 characters with spaces><tab><Value text><tab><Type text><new line>
If the Name text is longer than 50 characters, it is truncated. If the Value text is longer than 2,048 characters, it is also truncated. In the Variables window, the text of the Value column is not truncated if the user chooses Copy Selected Value.
  • Call Stack window format:
<[S] or [C]><4 spaces><Path text padded to 100 characters with spaces><tab><line number><new line>
The [S] and [C] represent whether the code is running on the server or on the client.



Using Breakpoints
In the Microsoft Dynamics AX Debugger, breakpoints allow you to suspend code execution where and when you need to. This allows you to run code until it comes to a breakpoint rather than traversing through the code, line-by-line. A breakpoint does not terminate the code execution, but instead suspends it. When the debugger has reached a breakpoint and the code execution is suspended, the debugger is said to be in break mode.
Breakpoints can be set from both the debugger and the code editor in the client. The effect of a breakpoint is similar to a Stop statement in Microsoft Visual Basic.
Breakpoints are persisted on a per-user basis. For example, if a breakpoint is inserted by user 1, user 2 cannot see the breakpoints that user 1 has set. This is true regardless of where the code with the breakpoint is running.
You can set breakpoints in the debugger and in the code editor.
To set a breakpoint:
  1. Position the cursor where you want to insert the breakpoint.
  2. Click the Insert/Remove Breakpoint icon on the debugger toolbar, or press F9.
When a breakpoint is inserted, in the code editor, the entire line changes color to indicate that there is a breakpoint in the line. In the debugger, a red dot appears in the gutter to the left of the line.
NoteNote
Setting breakpoints can be performed only on lines with executable X++ statements on them. Blank lines, lines with only braces or semicolons, and variable declarations are not valid lines for setting breakpoints.
  • To see a list of breakpoints from the Microsoft Dynamics AX client, click Breakpoints on the Edit menu, or press SHIFT+F9. In the debugger, the breakpoints are listed in the Breakpoints window.
  • To enable or disable a breakpoint, press CTRL+F9, or click the Enable/Disable Breakpoint icon on the debugger toolbar. Disabling a breakpoint is an alternative to removing one. Disabling makes the breakpoint inactive, but it remains in the list of existing breakpoints. There is no need to remove a breakpoint if it might be needed later.
  • To insert or remove a breakpoint, you can press F9, click the Insert/Remove Breakpoint icon on the debugger toolbar, or right-click in the gray margin in the Output window and click Insert or Remove. Breakpoints can also be removed from the Breakpoints window by right-clicking and then clicking Remove Breakpoint.


No comments:

Post a Comment