Debug the boards with GDB

This section requires the embedXcode+ edition and a board with a built-in or with an optional external hardware debugger compatible with GDB.

This section applies for all the boards compatible with GDB, using a proprietary driver like MSPDebug or the OpenOCD driver.

For more information about the debugging tools,

Configure specific boards

Some boards require a specific hardware or software configuration before debugging.

Configure the LaunchPad CC3200 WiFi

The LaunchPad CC3200 WiFi requires a specific hardware configuration.

  • Unplug the LaunchPad CC3200 WiFi board.

  • Remove the wire from JTAG J8 (emulator side) to SOP 2 (CC3200) side.

  • Place the TCK J8 jumper.

  • Place the SOP 2 jumper.

Debugging requires TCK and SOP 2 jumpers placed on

  • Plug the LaunchPad CC3200 WiFi board.

The project is uploaded into SRAM and is lost in case the power is disconnected. For more information,

  • Please refer to Upload to LaunchPad CC3200 WiFi.

The Segger J-Link provides a JTAG 2x10 2.54 mm 0.1" connector while the Arduino Due features a 2x5 1.27 mm 0.05" SWD connector.

If the software suite for the Segger J-Link isn't installed, follow the procedure at Install the Segger J-Link Software Suite.

  • Double-check the orientation of the SWD connector on the Arduino Due schematics.

Arduino Due, SWD to JTAG adaptor, Segger J-Link

Select the USB Port for the Arduino M0 Pro

  • Connect the USB cable to the Programmer USB Port is order to perform debugging. The native USB port doesn't feature debugging.

  • Use the USB Programming port

Accept incoming connection

For the Arduino M0 Pro board, some of the utilities used for debugging may prompt a window for authorisation.

  • Click on Allow to proceed.

Launch a debugging session

Before launching a debugging session, select the connection, either though a USB cable or over-the-air through WiFi or Ethernet over USB.

To launch a debugging session,

  • Select the Debug target and press Run.

embedXcode builds and links the project, uploads it to the board, open a first Terminal window for the serial console, and then opens two Terminal windows for debugging.

Identify two Terminal windows

The first Terminal window hosts the server. The server connects to the board and answers the requests from the debugger.

The second Terminal window is the client, actually the active debugger. It downloads all the breakpoints defined previously and starts running the project.

The client can't run without a valid server.

Run and stop the sketch execution

Here are the most common commands to run, stop and continue the execution of the sketch in a debugging session:

  • Enter the commands after the (gdb) prompt and validate it by pressing the Enter key.
  • When the debugger stops, type continue or simply c to continue till the next breakpoint.
(gdb) continue
(gdb) c
  • To run the sketch one step to the next line of code to be executed, including the sub-functions called by the current function, type step or simply s.
(gdb) step
(gdb) s
  • To run the sketch to the next line of the current function, without stopping at the sub-functions, type next or simply n.
(gdb) next
(gdb) n
  • To stop the sketch, press Ctrl+C.

  • To list the breakpoints defined and loaded, type info break.

(gdb) info break
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x000044b2 in loop() at embed1.ino:115
    breakpoint already hit 2 times
        printf "i = %d\n",i
        echo Blink\n
2       breakpoint     keep y   0x00004468 in blink(uint8_t, uint8_t, uint16_t) at LocalLibrary.cpp:25
    breakpoint already hit 2 times

For more information about the GDB commands,

Change the value of a variable

To get the value of a variable,

  • Type the command print and the name of the variable.
(gdb) print i
$1 = 7 '\a'

To change the value of a variable,

  • Type first the command set variable or set var, then the name of the variable and the = sign, and finally the new value.
(gdb) set var i = 4
(gdb) print i
$2 = 4 '\004'

Display the registers

To display the registers,

  • Type the command info registers or i r.
(gdb) info registers
r0             0x20002708   536880904
r1             0x20002708   536880904
r2             0x0  0
r3             0x200026f8   536880888
r4             0x651    1617
r5             0xffffffff   -1
r6             0xffffffff   -1
r7             0xffffffff   -1
r8             0xffffffff   -1
r9             0xffffffff   -1
r10            0xffffffff   -1
r11            0xffffffff   -1
r12            0x0  0
sp             0x20002f20   0x20002f20
lr             0x637    1591
pc             0x652    0x652 <loop()+2>
xPSR           0x61000000   1627389952

The example above comes from the MSP432P401R.

To display all the registers,

  • Type the command info all-registers or i all-r.

Display the call stack

To display the stack of the calls,

  • Type the command backtrace or bt.
(gdb) backtrace
#0  blink (pin=43 '+', times=2 '\002', ms=500) at LocalLibrary.cpp:25
#1  0x000044c8 in loop () at embed1.ino:115
#2  0x0000444e in main () at main.cpp:164

The blink() function is called by the function loop(), and loop() is called by the main function main().

The backtrace command also provides the details of the parameters and values passed by loop() on to blink().

Here, values are pin=43, times=2, ms=500.

(gdb) print RED_LED
$1 = 43 '+'

Value 43 does correspond to constant RED_LED.

Display specific layouts

To enable GDB Text User Interface with a layout for source,

  • Type the command layout src or tui enable.
(gdb) layout src
(gdb) tui enable

To display a layout for assembler,

  • Type the command layout asm.
(gdb) layout asm

To display also the registers,

  • Type the command layout regs.
(gdb) layout regs

For more information on the GDB Text User Interface,

Get help

To display the help,

  • Type the command help or h.
(gdb) help
List of classes of commands:

aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands

Type "help" followed by a class name for a list of commands in that class.
Type "help all" for the list of all commands.
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.

End and quit a debugging session

To end and quit the debugging session,

  • On the client window, type monitor shutdown to close the server.
(gdb) monitor shutdown
shutdown command invoked

On the client window, type quit or simply q or press ctrl-D, and confirm by y.

(gdb) quit

(gdb) q
A debugging session is active.

    Inferior 1 [Remote target] will be killed.

Quit anyway? (y or n) y
  • On the server window, press Ctrl+C to stop the server if it hasn't already terminated.
Info : halted: PC: 0x00000422
Info : dropped 'gdb' connection

  • Always quit and close the two Terminal windows: the active debugging session and the server session.

End and quit a debugging session on the Intel Edison board

On the Intel Edison board, terminating the debugging session closes the remote server.

  • On the client window, type quit or simply q or press ctrl-D, and confirm by y.
(gdb) quit
(gdb) q
A debugging session is active.

    Inferior 1 [process 376] will be killed.

Quit anyway? (y or n) y

    Inferior 1 [Remote target] will be killed.

Quit anyway? (y or n) y

The client automatically stops the remote server.

Process /home/root/Projects/e_edison_yocto/embeddedcomputing created; pid = 376
Listening on port 1234
Remote debugging from host
Killing all inferiors
*** Done
  • Always quit and close the two Terminal windows: the active debugging session and the server session.