- Debugging Options in the MoSync IDE
- Setting up the Debugger
- Setting a Breakpoint
- Running the Debugger
Debugging Options in the MoSync IDE
General guides and tutorials related to the debugging and troubleshooting of applications can be found in our online documentation in the section called Debugging, Testing, Performance.
Setting up the Debugger
- Set the current build configuration to “Debug”.
- Make sure that the build setting Use Debug Runtimes in Project > Properties > MoSync Project > Build Settings > Packaging is selected.
Setting a Breakpoint
- Line breakpoints (in .js and .html files) — lets you stop program execution at the line number you select.
- Script load breakpoints — lets you stop execution when a script loads. The execution will stop before the first line of the script is executed.
- Suspend upon exception — when enabled, suspends the script whenever an exception is thrown in the code.
The debugger also supports breakpoint conditions and hit counts.
Setting a Line Breakpoint
To set a line breakpoint, double-click the margin of the line you want to set a breakpoint at.
Setting a Script Load Breakpoint
To set a script load breakpoint, click the script load breakpoint icon in the Breakpoints view.
(If you cannot see the breakpoints view, open the Debug perspective: Window > Open Perspective > Other... > Debug. Unless the IDE has been configured otherwise, you will be asked to open this perspective when a breakpoint is hit.)
Enabling Exception Breakpoints
Setting Breakpoint Conditions and Hitcounts
To set conditions and hitcounts for a line breakpoint, right-click on the breakpoint marker in the line margin.
For script load breakpoint you can set conditions in the “Breakpoints” view.
When set, the hitcount will stop the breakpoint to suspend execution until it has been hit the specified number of times.
If a condition is set, the breakpoint will suspend execution only if this condition is met. There is an option to suspend execution if the condition either a) evaluates to true, or b) it changed since last time the breakpoint was hit.
Running the Debugger
To start the debugger, make sure that debugging is enabled as per the instructions above in “Setting up the Debugger”.
Next, the device must be able to connect to the debug server. For emulators, this is usually not a problem since they run on the same computer as the debug server. For devices sharing say a Wi-Fi connection with the computer the debug server runs on should be enough. You may need to enable Wi-Fi on your device.
Start the app by clicking either the Send to Device button (for on-device debugging, for more information see http://www.mosync.com/documentation/manualpage/sending-device):
Or the Debug (for on-simulator debugging) button:
Follow the on-screen instructions, if any.
If a breakpoint hits, you will see something like the image below. The red arrow points to a where the breakpoint was hit and execution suspended.
Once execution suspends, you may inspect the variable scope at that point in the program. Just open the Variables view (which by default is visible as a tab to the right in the Debug perspective).
All the variables in the local scope are visible, including local variables and arguments to functions. The content of structures and arrays can be expanded by pressing the + sign next to them.
By clicking a stack frame you will be able to inspect the scope at any stack depth of the execution.
Once a breakpoint is hit, you may perform these special debugger actions:
- Step Into executes the next line in the program, regardless of where this line is located.
- Step Over — If the next line to execute enters a function, the execution will suspend once that function has exited.
- Step Return executes the rest of the function and returns to the caller.
- Drop to Frame rewinds execution to a previous point in the program. To use Drop To Frame, select one of the stack frames (where the red arrow points in the image above) and press the corresponding tool icon. The execution will rewind to the start of the function being suspended.
These actions can be performed by pressing the corresponding icons in the toolbar (in the same order as the list above):
To suspend execution at any point of time, press the Suspend icon:
To terminate the program being debugged, press the Terminate icon:
This will terminate the program on the device.
Hot code replace
To refresh and reload even though Do Nothing is selected, select the current launch in the Debug view and press the corresponding Reload toolbar icon:
- “I cant debug at all” — Check that the device is connected to the same network as the debug server. If it is not and if you can’t connect it, you could try to debug using an emulator instead of a real device.
- “My program seems to hang on the device but no breakpoint has been hit in the debugger” — Sometimes the client and server gets out of sync. Try to reload the program as described in the section Hot code replace.
- "I just went to grab some coffee and now I get some error dialog saying my session timed out" — If something causes the app being debugged is sent to the background, the IDE will lose its connection and within half a minute or so it will time out.