Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

4.1.3.5.1. nios2-gdb-server Usage Example

The Nios® II SBT for Eclipse and most of the other available debuggers use the nios2-gdb-server and nios2-elf-gdb commands for debugging. You should never have to use these tools at this low level. However, in case you prefer to do so, this section includes instructions to start a GDB debugger session using these commands, and an example GDB debugging session.

You can perform the following steps to start a GDB debugger session:

  1. Open a Nios® II command shell.
  2. In the command shell, type the following command to start the GDB server on the machine that is connected through a JTAG interface to the Nios® II system you wish to debug:
    nios2-gdb-server --tcpport 2342 --tcppersist

    If the transfer control protocol port 2342 is already in use, use a different port.

    Following is the system response:

    Using cable "
                   Intel® FPGA Download Cable [USB-0]", device 1, instance 0x00
    Pausing target processor: OK
    Listening on port 2342 for connection from GDB:

    Now you can connect to your server (locally or remotely) and start debugging.

  3. Type the following command to start a GDB client that targets your .elf file:
    nios2-elf-gdb <file>.elf

Sample Debugging Session

GNU gdb 6.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-cygwin --target=nios2-elf"...
(gdb) target remote <your_host>:2342
Remote debugging using <your_host>:2342
OS_TaskIdle (p_arg=0x0) at sys/alt_irq.h:127
127 {
(gdb) load
Loading section .exceptions, size 0x1b0 lma 0x1000020
Loading section .text, size 0x3e4f4 lma 0x10001d0
Loading section .rodata, size 0x4328 lma 0x103e6c4
Loading section .rwdata, size 0x2020 lma 0x10429ec
Start address 0x10001d0, load size 281068
Transfer rate: 562136 bits/sec, 510 bytes/write.
(gdb) step
.
.
.
(gdb) quit

Possible commands include the standard debugger commands load, step, continue, run, and quit. Press Ctrl+c to terminate your GDB server session.