With the board connected, click on the Debug on Board button on the toolbar. This will start a GNAT Studio debug session and launch the necessary tools required to debug the program on the board from GNAT Studio. The program will also be automatically loaded onto the microcontroller. Debugging a program on a board through GNAT Studio is similar to debugging a native program:

GNAT Studio also provides a Debugger Console view that allows shell access to the underlying GDB client that is debugging the program. The GDB commands that correspond to the above debugging tasks can be entered into the console directly if desired.

The program can be restarted by either using the black reset button on the board or via the Debugger Console with the command:

The debugging session can be exited via the Debug/Terminate menu or issuing the quit command in the Debugger Console .

Debugging Walkthrough¶

If you do not have an active GNAT Studio debug session, click on the Debug on Board button on the toolbar. (Remember that you can hover the mouse cursor over the buttons to see their names, and that there is a preference in General/Custom Styles to have the button names displayed along with the button icons on the toolbar.) When the GNAT Studio session loads, the editor will switch to the main procedure in led_flasher.adb and the Debugger Console will report the initial output of gdb:

file / GNAT / share / examples / gnat - cross / led_flasher - stm32f4 / obj / led_flasher Reading symbols from GNAT / share / examples / gnat - cross / led_flasher - stm32f4 / obj / led_flasher ... done . remote debugging using localhost : 4242 ( gdb ) load Loading section . text , size 0xafa4 lma 0x8000000 Loading section . ARM . extab , size 0x8c0 lma 0x800afa4 Loading section . ARM . exidx , size 0xf28 lma 0x800b864 Loading section . rodata , size 0x1ff4 lma 0x800c790 Loading section . data , size 0xe3c lma 0x800e784 Start address 0x80036fc , load size 62908 Transfer rate : 14 KB / sec , 8986 bytes / write . ( gdb ) monitor reset halt

Here GDB has loaded the example program led_flasher and connected to the remote GDB server (the program relaying the debugging commands from GDB to the board). Once GDB is connected with the board, GNAT Studio issues the load command to load the program onto the board and follows with the monitor reset halt command to reset the microcontroller to a debuggable state. If the Debugging Console does not display the above, there is a communication problem with the board. If this occurs, quit GNAT Studio and reconnect the Developer Kit to your computer.

Staying within the Debugger View , at the GDB command prompt (gdb) type

c

to run the program. The LEDs on the Developer Kit will flash at different speeds. Press the blue User button to change the speed of the LEDs.

Now press <ctrl>-\ to interrupt the program. When you do this the program on the microcontroller stops running and the Debugger Console will report the instruction address and subprogram the microcontroller has stopped on:

Program received signal SIGTRAP , Trace / breakpoint trap . 0x080035ec in __gnat_sys_tick_trap ()

GNAT Studio will switch the Editor view to the line of code where the program stopped if it can locate the source files. Since led_flasher program is compiled with the debug flag this will occur when the debugger stops inside the program code. However, in the above case the program has stopped in the run-time code that has not been compiled with the debug flag and thus GNAT Studio will not switch to the run-time source code.

We will now stop the debugger in a line in the example’s source code. With the Project view visible expand the src directory and open lights.adb . Scroll to line 47 and click on the line number. A mark will appear over the line number to indicate that the breakpoint has been set. You can also confirm the breakpoint in the Breakpoints View on the lower left of the GNAT Studio window.

You can also add breakpoints from the Breakpoints view. In the view, click on the plus icon. In the Breakpoint editor windows that appears, enter button.adb into the file field and change the line field to 29 . Click the OK button to close the window and to add the breakpoint. Double-clicking on the new breakpoint in the Breakpoints view will open the Button package and highlight the line the breakpoint is set on. For now in the Breakpoints view deselect the Enable checkbox next to the newly created breakpoint 2.

In the Debugger Console enter the command c to run the program to the next break point or press the continue button on the toolbar. The program will run to the selected breakpoint and GNAT Studio will switch the editor to the file location the program has stopped on ( lights.adb:47 in this case). With the program stopped, you can query parts of the program state. For example, you can query the value of the local Divider object on line 51 by placing the cursor over the variable name. The value of the object will appear in a tooltip next to the variable (in this case it will show 1 ). You can also query the state of the protected object Speed_Button on line 47 by the same method, where it will show the Speed_State component as normal .

Now press the blue User button on the board and continue the program. When the program stops, look at the state of the protected object: it should now be double .

You can step through the statements of the program by pressing the step or next statement buttons on the GNAT Studio toolbar or by entering the s n commands into Debugger Console . Step (s) cause the debugger to stop at a new line of source code, while Next (n) will cause the debugger to step over subprogram calls. Try using these commands now and notice how the editor highlights the current position of the program.

We will now change how long one of the LEDs on the board stay on for. First delete the breakpoints we created by selecting the breakpoints in the Breakpoints view and pressing the minus button on the view’s toolbar. Next, open lights.ads and go to line 45. This task object declaration creates a task that flashes the user LED PG13 . Change the On_Time discriminate of the task to 75. Build the application again using the build button on the toolbar. Once the program has been built, we now need to load the updated program onto the microcontroller. Go back to the Debugger Console view and enter at the GDB prompt:

load

If the program has been successfully downloaded the console will print

`/GNAT/share/examples/gnat-cross/led_flasher-stm32f4/obj/led_flasher' has changed; re-reading symbols. Loading section .text, size 0xafa4 lma 0x8000000 Loading section .ARM.extab, size 0x8c0 lma 0x800afa4 Loading section .ARM.exidx, size 0xf28 lma 0x800b864 Loading section .rodata, size 0x1ff4 lma 0x800c790 Loading section .data, size 0xe3c lma 0x800e784 Start address 0x80036fc, load size 62908 Transfer rate: 14 KB/sec, 8986 bytes/write.

Now you can reset the microcontroller and run the program by entering the following:

monitor reset c