First remember to enable debug symbols on your firmware, otherwise GDB will not find the function names:

$ make menuconfig
Build Setup  --->
    Debug Options  --->
        [*] Generate Debug Symbols

Now you can compile normally.

Inside your nuttx/ root directory run OpenOCD (I’m using STLINK-V3SET) passing these parameters:

$ openocd -f interface/stlink.cfg -f target/stm32f7x.cfg

Show you see something like:

Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V3J8M3B5S1 (API v3) VID:PID 0483:374F
Info : Target voltage: 3.211155
Info : stm32f7x.cpu: hardware has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f7x.cpu on 3333
Info : Listening on port 3333 for gdb connections

Open another terminal and enter inside that same nuttx/ root directory and run:

$ gdb-multiarch nuttx

In the “(gdb)” prompt type the command to connect to the OpenOCD server:

(gdb) target remote :3333
Remote debugging using :3333
up_idle () at common/arm_idle.c:63
63	}
(gdb)

You can put a breakpoint at the function you want to stop:

(gdb) b stm32_dmasetup
Breakpoint 1 at 0x8008de4: file chip/stm32_dma.c, line 593.
Note: automatically using hardware breakpoints for read-only addresses.
(gdb)

You can reset the CPU using this command:

(gdb) mon reset halt
Unable to match requested speed 2000 kHz, using 1000 kHz
Unable to match requested speed 2000 kHz, using 1000 kH
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080001f8 msp: 0x20021ce0
(gdb)

Finally to type “c” to continue the executing from start:

(gdb) c
Continuing.

When your code reach that function you will see something like this:

Breakpoint 1, stm32_dmasetup (handle=0x200201f0 <g_dma+196>, paddr=1073756172, maddr=536871016, ntransfers=2128, scr=scr@entry=11328) at chip/stm32_dma.c:593
593	  dmainfo("paddr: %08" PRIx32 " maddr: %08" PRIx32
(gdb)

And to see the backtrace run “bt”

(gdb) bt
#0  stm32_dmasetup (handle=0x200201f0 <g_dma+196>, paddr=1073756172, 
    maddr=536871016, ntransfers=2128, scr=scr@entry=11328)
    at chip/stm32_dma.c:593
#1  0x08008166 in i2s_txdma_setup (priv=0x2007da20) at chip/stm32_i2s.c:1436
#2  i2s_txdma_setup (priv=priv@entry=0x2007da20) at chip/stm32_i2s.c:1382
#3  0x08008392 in stm32_i2s_send (dev=0x2007da20, apb=<optimized out>, 
    callback=0x80041a1 <cs4344_senddone>, arg=0x2007dcc0, timeout=55)
    at chip/stm32_i2s.c:2140
#4  0x080044d6 in cs4344_sendbuffer (priv=priv@entry=0x2007dcc0)
    at audio/cs4344.c:856
#5  0x0800459a in cs4344_workerthread (pvarg=0x2007dcc0, 
    pvarg@entry=<error reading variable: value has been optimized out>)
    at audio/cs4344.c:1300
#6  0x080063a4 in pthread_startup (entry=<optimized out>, arg=<optimized out>)
    at pthread/pthread_create.c:59
#7  0x08017b28 in pthread_start () at pthread/pthread_create.c:140
#8  0x00000000 in ?? ()
(gdb)