Debugging on a mobile device

Basics

When an app was created with debug mode and is running in on a device, it is possible to switch the runtime system in debug mode, by using the fgldb command tool with the -m option.
Important: The app must have be created in debug mode. Apps created in release mode cannot be debugged with the fgldb tool. For more details, check how to build mobile apps with debug mode in the Deploying mobile apps section.
Important: On iOS devices, after installing the app, you need to enable the debug port in the app settings, otherwise the app will not listen to the debug port.
The fgldb command line tool takes two arguments: The host (or IP address) of the mobile device, and an optional TCP port number to connect to. For mobile devices, the debug TCP port is 6400. Note that this is the same port the mobile front-end is listening to for GUI connection, when working in GUI client/server mode.
Note: Before starting a debug session, make sure that you fulfill the prerequisites for debugging.

Debugging an app running on a physical device

Considering the mobile device IP address is "192.168.1.23", and the application is running locally on a physical mobile device, you can open a debug session from the development machine as follows:
$ fgldb -m 192.168.1.23:6400
108	    DISPLAY ARRAY contlist TO sr.*
(fgldb)
The (fgldb) prompt indicates that you are now connected to the fglrun process on mobile device, and the program flow is suspended. To continue with the program flow, enter the "continue" debugger command:
(fgldb) continue
Continuing.
The application will then resume on the mobile device. To suspend the program again and enter debugger commands, press CTRL-C in the debug console: fgldb will show the interrupt message and give you the control back:
...
Continuing.
^CINTERRUPT
108	    DISPLAY ARRAY contlist TO sr.*
(fgldb)
At this point, you can for example set a break point and continue until the break point is reached:
(fgldb) b 427
Breakpoint 2 at 0x00000000: file contacts.4gl, line 427.
(fgldb) continue 
Continuing.
Breakpoint 2, edit_contact() at contacts.4gl:427
427	    IF new THEN
(fgldb)
To finish the debug session, close the connection with the "detach" debugger command:
(fgldb) detach
Connection closed by foreign host.

Debugging an app running on an Android device emulator

When the mobile application is executing on an Android device emulator in the same machine as the development environment, you must first redirect the 6400 TCP port.

First you must connect to the emulator terminal, using the telnet TCP port 5554:
$ telnet localhost 5554
When connected on the device emulator, redirect the port 6400 as follows:
$ redir add tcp:6400:6400
$ quit
You may also want to redirect the port 6480, to be able to show GMA service debug information from a browser with the http://localhost:6480 URL:
$ redir add tcp:6480:6480
Finally, quit the device emulator telnet session with:
$ quit