Traditional Debugging
Debugging refers to finding and fixing bugs such as abnormal operations or logic errors in the application program. Due to the nature of development that cannot produce perfect results from the beginning, the debugging process continues from the beginning to the end.
The easiest debugging method for developers to use is to display objects or variables that need to be checked on the screen. The record left in the output window is called log, and you can use the trace method in Nexacro. trace, as per its meaning or tracing, is the function of logging so that the developer can trace the flow of logic or the value of variables. If described in text format as follows, information is output in the Output window and log file.
The alert method is used as much as the trace in the development process. Trace involve the hassle of having to find and check the part that it needs in the left log, but it has the advantage of being convenient because the alert is opened as pop-ups on the screen and only necessary results can be checked.
trace and alert have the advantage of being easy to use, but if the project consists of many files or if the code is long and complex, then they make debugging more complicated. Also, when outputting information on multiple variables or objects, there are many space limitations and it is inconvenient to check the information. Furthermore, you have to manually code with the script, and after debugging, the developer has to delete it directly, which may cause new problems in the process.
In Nexacro Studio, its own debug function is included to help developers debug more efficiently. This chapter describes the debug functions provided in Nexacro Studio and how to use them.
Debugging with Debug Functions
The trace and alert methods described above are easy to use but have limitations in checking the flow of the process or the object containing a lot of information. Also, it is difficult to clearly understand what is wrong with the current code. However, using the debug function makes it easier to keep track of specific information, such as where the problem came from and through what path.
The debug function of Nexacro Studio consists of the menu and the toolbar where you can execute commands, and the debug information window where you can view information such as objects, functions, and logs.
Debug Menu & Toolbar
In the debug menu and toolbar of Nexacro Studio, you can use the commands necessary for debugging. The configuration of the debug menu and toolbar is the same, except for commands related to the conditional breakpoint.
Item | Description | |
---|---|---|
1 | Start Debugging (F5) Continue (F5) | Starts debugging the application. Continues debugging. (When debugging starts, the Start Debugging menu switches to the Continue menu) |
2 | Start Form Debugging (F6) | Starts debugging the current form. |
3 | Stop Debugging (Shift + F5) | Ends debugging. |
4 | Restart (Ctrl + Shift + F5) | Restarts after ending debugging. |
5 | Step Into (F11) | Executes the code line by line. If the function is called in the middle, then it is moved to the corresponding function and executes the code. |
6 | Step Over (F10) | Executes code on the function basis. |
7 | Step Out (Shift + F11) | Exits from the function. |
8 | Run to Cursor (Shift + F10) | Executes from the current location to the location of the cursor. |
9 | Toggle Breakpoint (F9) | Specifies or deletes the breakpoint. |
10 | Set Conditional Breakpoint | Specifies the conditional breakpoint. |
11 | Edit Breakpoint | Sets the condition at the specified breakpoint. |
12 | Delete All Breakpoints (Ctrl + Shift + F9) | Deletes all specified breakpoints. |
13 | Go to Source Code | Moves to the source location of the breakpoint in the list of breakpoints in the Breakpoints window. |
14 | Enable/Disable Breakpoint (Ctrl + F9) | Enables or disables the specified breakpoint. |
15 | Enable/Disable All Breakpoints | Enables or disables all specified breakpoints. |
The main debug commands support shortcut keys. In actual debugging, it is much more effective in terms of speed to use shortcut keys rather than selecting debug commands from the menu or toolbar.
Debug Information Window
Function | Description |
---|---|
Debug | Displays messages that occur in debugging mode. |
Breakpoints | Can specify the location to pause in the debugging mode in the script code. The location specified as the breakpoint can be checked in the form of the list in the Breakpoints window. |
Call Stack | Displays the functions that have transmitted through to the current state. Double-clicking the function moves to the location of the course. |
Variables | Searches the status values of variables and objects that can be checked in the current state. In the case of the variable, the value is displayed, and in the case of the object, the properties of the object can be searched in the tree format. |
Watch | Can register the value of a specific variable or object and observe the changing value. This is especially useful when using the step function. |
Using Debug Functions
Running/Ending Application in Debugging Mode
Debugging mode provides the environment in which errors in the application can be traced and resolved by using the debug function as the execution form of the application for debugging.
Debugging mode can be executed by selecting [Start Debugging] or [Start Form Debugging] from the Debug menu. [Start Debugging] is used when executing the entire project and [Start Form Debugging] is used to execute only the currently open form.
To end debugging mode, select [Stop Debugging] from the Debug menu.
You can run the application in debugging mode without setting breakpoints. However, the execution itself is meaningless because debug functions are not available. Therefore, set the breakpoint first and then run it in debugging mode.
Adding/Deleting Breakpoints
Breakpoints are used to specify where to pause in debugging mode. This specified location can be found in the script editing window and the Breakpoints window. In the script editing window, a marker is stamped next to the line number on the left side of the code, so you can check the setting status of the breakpoint. In the Breakpoints window, breakpoints are displayed in the form of the list, and double-clicking on them allows you to move to the source location where the breakpoint is marked.
Once you specify the breakpoint, it remains there until the user deletes it, even when Nexacro Studio is ended.
What is a marker?
It is a kind of marker that tells you that the breakpoint has been specified. It has the following four shapes depending on the setting status of the breakpoint.
(Enable): Stops execution at the line where you specified the breakpoint.
(Disable): Disables the breakpoint. Ignored when executing the application.
(Conditional Enable): Stops execution only when the conditions set in the breakpoint are met.
(Conditional Disable): Disables the conditional breakpoint. Ignored when executing the application.
When you specify the breakpoint, a marker is added before the line and the breakpoint information is registered in the Breakpoints window. Also, once the breakpoint is specified, it remains as-is until the user deletes it, even when Nexacro Studio is ended.
Here is an example of how to add/delete breakpoints.
1
Select line 20 in the script editing window.
2
The breakpoint is specified by clicking the line number of line 20 or selecting [Toggle Breakpoint] from the menu. When specified as the breakpoint, a marker is displayed next to the line number.
To delete the breakpoint, click the line number of the location you want to delete or select [Toggle Breakpoint] of the toolbar. Selecting [Delete Breakpoint] will give you the same result. When the breakpoint is deleted, the market next to the line number will disappear and the breakpoint information in the Breakpoints window will disappear as well.
To delete all specified breakpoints at once, select [Delete All Breakpoints] from the menu or toolbar.
Adding/Deleting Conditional Breakpoints
The user can set the breakpoint to only hit specific conditions as needed. Breakpoints in which conditions are set in this way are called conditional breakpoints.
If you set the conditional expression, then the breakpoint is only hit when the set condition is met when the application execution reaches that line. If you set the number of ignores, then the breakpoint is ignored even when the code execution reaches that line, and hits are made after the number of times you set is exceeded.
The basic usage of conditional breakpoints is the same as breakpoints, except that you can set Conditional Expressions and Numbers of Ignore.
Here is an example of how to add/delete conditional breakpoints.
1
Click the script editing window to enable it.
2
Select line 19 in the script editing window and select [Set Conditional Breakpoint] from the toolbar or the Breakpoints window.
3
Add Conditional Breakpoint pop-up opens, enter the conditional expression in Conditional Expression.
Name | Description | |
---|---|---|
1 | Conditional Expression | Sets the conditional expression to hit the breakpoint. |
2 | Number of ignore | Ignores the breakpoint for the set number of times. |
When the input is completed, you will see the orange marker next to the line number, and you can check the setting information in the Breakpoints window as follows.
To delete the conditional breakpoint, click the line number of the location you want to delete or select [Toggle Breakpoint] of the toolbar. Selecting [Delete Breakpoint] will give you the same result. When the breakpoint is deleted, the market next to the line number will disappear and the breakpoint information in the Breakpoints window will disappear as well.
To delete all specified breakpoints at once, select [Delete All Breakpoints] from the menu or toolbar.
Even if the line has already been specified as the breakpoint, it is changed to the conditional breakpoint by setting the conditional expression or the number of ignore values using [Edit Breakpoint] of the toolbar.
Enabling/Disabling Breakpoints
The specified breakpoints can be set to be enabled or disabled as needed. This function can be used to temporarily disable the breakpoint for the next time you need to use it again.
When you enable or disable the breakpoint, the marker of the line and the breakpoint information in the Breakpoints window are changed according to the state.
Here is an example of how to enable/disable breakpoints.
1
Specify the breakpoint on line 38 in the script editing window.
2
Select line 38 where the breakpoint is specified and select [Enable/Disable Breakpoint] from the toolbar.
To re-enable the disabled breakpoint, select [Enable/Disable Breakpoint] of the toolbar. To enable or disable all specified breakpoints at once, select [Enable/Disable All Breakpoints] from the toolbar.
Executing Code in Debugging Mode (Continue)
To continue executing code in debugging mode, use the Continue command. Running Continue will execute the code between the current breakpoint and the next breakpoint and then stops at the next breakpoint.
Here is an example of how to execute the code with the Continue command.
1
Specify the breakpoints on lines 34 and 44 in the script editing window.
2
If you run the application in debugging mode, then the code is executed up to line 34 and stops.
3
At this time, if you select [Continue] from the menu or toolbar, the codes from line 35 to 43 are all executed and it is stopped at the next breakpoint, line 44.
Executing Code with Step Command (Step Into, Step Over, Step Out)
When using breakpoints, it is good to use them only where you need them. When debugging the application with long and complex code, if you overuse breakpoints too much, then the execution efficiency will decrease because the user must manually enter the Continue command the number of times the breakpoints are specified. Therefore, if you execute the code line by line in a specific part and need debugging, then it is convenient to use the Step command.
The Step command functions as a temporary breakpoint. In other words, it can be used when debugging by stopping application execution in the location where you do not specify the breakpoint. The Step command is divided into Step Into, Step Over, and Step Out according to the operation method.
Even when debugging using the Step command, if the breakpoint exists in the middle of the process, then execution stops at the breakpoint position, regardless of the Step command.
The following is an example sample that receives two numbers from the user and outputs the result of adding them. The btn_calc_onclick function is the event function that occurs through a button click, and it is assumed that the function is called when the user inputs the numbers 17 and 2 and clicks the operation button.
The following is an example sample that receives two numbers from the user and outputs the result of adding them. How to run the code with the Step command is shown with this example.
How to Use Step Into
Execute the code line by line. When encountering the function call, move inside the corresponding function and execute the code line by line.
1
Specify the breakpoint on line 20 in the script editing window.
2
When you run the application in debugging mode, the code runs up to line 20 and then stops.
3
Selecting [Step Into] from the menu or toolbar moves to the first line of the fn_validate function as shown below. If you select [Step Into] once more, then line 3 is executed, and the isNumeric function is called again, so it moves to the first line of the isNumeric function.
How to Use Step Over
Execute the code line by line. When encountering the function call, do not move inside the corresponding function, execute the function, and move to the next line.
1
Specify the breakpoint on line 20 in the script editing window.
2
When you run the application in debugging mode, the code runs up to line 20 and then stops.
3
Selecting [Step Over] from the menu or toolbar executes the fn_validate function in line 21 and moves to line 27. If you select [Step Over] once more, the code in line 27 is executed, and then it moves to the next line, line 28, and stops.
How to Use Step Out
Execute the rest of the code in the currently executing function, return to where the function was called, move to the next line, and stop.
Step Out is used with Step Into rather than independently. It performs Step Into and is used to skip debugging in the function when you do not need to look at it anymore while performing the code by moving to the inside of the function.
1
Specify the breakpoint on line 20 in the script editing window.
2
When you run the application in debugging mode, the code runs up to line 20 and then stops.
3
If you select [Step Into] from the menu or toolbar, then line 21 is executed. Since the fn_validate function is called here, it moves to the first line of the fn_validate function.
4
If you select [Step Out] from the menu or toolbar, then it executes from line 3 to line 5, which is the end of the fn_validate function, and it moves to line 21 of the btn_calc_onclick function that called the fn_validate function.
Executing Code at Once to Cursor Location (Run to Cursor)
Stop after executing code from the currently hit breakpoint to the cursor location. If there is another breakpoint between the current breakpoint and the cursor, then execution stops at that breakpoint. Also, if the cursor location is the location that cannot be reached on a branch, then it stops after executing to the next breakpoint.
Here is an example of how to execute the code with the Run to Cursor command.
1
Specify the breakpoint on line 34 in the script editing window.
2
Run the application in debugging mode. The execution stops at line 34 when input and the button click are performed.
3
Place the cursor on line 43 and select [Run to Cursor] from the menu or toolbar. Then the code from lines 35 to 42 is executed, and execution stops at line 43.
Checking Variable Value (Variables)
The most basic of debugging is checking the value of the object or variable. This information can be found in the Variables window.
Variables display the value of the object or variable that is accessible from where the breakpoint is hit. For objects containing members, you can expand or collapse the details with the +/- button in the list. Items with changed values are displayed in bold red. Variables operate automatically when debugging mode is enabled.
Here is an example of how to check variable value with Variables.
1
Specify the breakpoint on line 34 to check the values of three variables x, y, and result.
2
Run the application in debugging mode. The execution stops at line 34 when input and the button click are performed. At this time, if you look at the Variables window, then you can check the x, y, and result values as follows.
Checking Variable Value (Script Editor)
The script editor provides Assist Tip and Inline Assist Variable functions to intuitively check object/variable values during debugging.
Assist Tip is the function that displays the information in a pop-up form when you place the mouse cursor over the object or variable for which you want to check the value in the script editor. If the item is the variable, then only the value is displayed, and if it is the object, then the members and the values are displayed in the tree format.
Inline Assist Variable is the function that displays the values of all objects and variables existing between the function declaration part and the currently hit breakpoint next to each line in the script editor. In addition, not only the function to which the hit breakpoint belongs, but also the function on the Call Stack associated with it displays the object and variable values before the function is called.
Here is an example of how to check the variable value in the script editor.
1
Specify the breakpoint on line 34 to check the values of three variables x, y, and result.
2
Run the application in debugging mode. The execution stops at line 34 when input and the button click are performed. At this time, Inline Asist Variable is displayed in the form of 'Variable = Value' next to the line of code above the hit breakpoint. If you want to check only a specific variable value with Asist Tip, then move the mouse cursor over the object or variable name to display the value in a square box.
You can set whether to use Assist Tip and Inline Assist Variable functions in [Options > Debug > Assistance].
Observing Changes in Variable Value (Watch)
You can register a specific object or variable in Watch and observe the change in its value while debugging is in progress. Items with changed values are displayed in bold red.
Once the object/variable is registered to Watch, the list will remain until the user deletes it, even if Nexacro Studio is ended.
Here is an example of how to observe variable value with Watch.
1
Specify the breakpoint on line 34 and 44 to observe the change in the result variable value in the script editing window.
2
Run the application in debugging mode. The execution stops at line 34 when input and the button click are performed. Then, after selecting the Watch window, click the + button or double-click the last row (Input Expression) to register the result variable as follows.
You can also add it from the script editor. First, drag and drop the object name or variable name to select it, then drag and drop it on the Watch window, or right-click and select [Add Text to Watch] from the context menu.
3
Run the code using the Continue command. When execution stops at line 44, which is the second breakpoint, check the Watch window again to see how the result value has changed.
When you add the object or variable to Watch, it remains until the user deletes it. To delete the variable registered in Watch, select the item you want to delete in the Watch window and click the - button or press the Delete key on the keyboard.
Checking Function Call Information (Call Stack)
When debugging complex code with a mixture of objects and functions, it is important to understand the relationships between functions. If you can understand at a glance which function the code you are looking at exists, in which function it is being called from, etc., then it is very helpful to understand the flow.
Call Stack provides the function call history, allowing you to check the call relationships between functions. Functions called up to the current location are displayed in reverse order. If you double-click the function name of the item, then you can move to the code of the called location.
Call Stack operates automatically when debugging mode is executed, and function call information is updated according to the flow of code execution.
Here is an example of how to check function call information.
1
Specify the breakpoint on line 26 within the fn_add function to check the function call information in the script editing window.
2
Run the application in debugging mode. The execution stops at line 26 when input and the button click are performed. At this time, if you check the function call information in the Call Stack window, it is as follows.
The fn_add function, which is the current location, is located at the top, followed by the btn_calc_onclick function that called the fn_add function. You can also see several functions below it, and these are functions used inside Nexacro, so you do not need to worry about them unless in special cases.
Depending on the script function definition type, the function name may not be displayed in the Call Stack window. For example, in the function declared as follows, then the function name is not displayed, only the arguments are displayed in the form of (a, b).
function myFunc(a, b) { }
Therefore, if the function name is not normally displayed on Call Stack, please use the following form.
var myFunction = function(a, b) { }