Multi-Core Real-Time Operating System RTEMS (9) – GDB Debugging System

Technical experience sharing, welcome to follow and provide guidance

The gdb tool can debug the RTEMS operating system. This article introduces how to use gdb for debugging.

1. Setting Safe-Path

There are three methods to set the safe-path, as follows:

1.1 Specify Path

We can set our desired path as the safe-path, as shown below:

# vim ~/.gdbinit
add-auto-load-safe-path /home/user

1.2 Set All Paths

Alternatively, all paths can be set as the safe-path, as shown below:

# vim ~/.gdbinit
set auto-load safe-path /

1.3 Startup Parameter Settings

The safe-path can also be set through startup parameters, as shown below:

# aarch64-rtems6-gdb -iex "set auto-load safe-path /" build/aarch64/zynqmp_qemu/testsuites/samples/ticker.exe

2. Running RTEMS

We can run RTEMS using -s, which by default will start gdb in qemu, allowing remote debugging of RTEMS, as shown below:

# qemu-system-aarch64 -no-reboot -nographic -s -serial mon:stdio -machine xlnx-zcu102 -m 4096 -kernel build/aarch64/zynqmp_qemu/testsuites/samples/ticker.exe

3. GDB Connection

After qemu starts RTEMS, it can be connected via 127.0.0.1, as shown below:

# aarch64-rtems6-gdb build/aarch64/zynqmp_qemu/testsuites/samples/ticker.exe
# target extended-remote 127.0.0.1:1234

Upon successful connection, the following information will appear:

Remote debugging using 127.0.0.1:1234
_CPU_Thread_Idle_body (ignored=0) at ../../../cpukit/score/cpu/aarch64/aarch64-thread-idle.c:46
46        while ( true ) {
(gdb) bt
#0  _CPU_Thread_Idle_body (ignored=0) at ../../../cpukit/score/cpu/aarch64/aarch64-thread-idle.c:46
#1  0x000000000001edd0 in _Thread_Handler () at ../../../cpukit/score/src/threadhandler.c:164
#2  0x000000000001ece0 in ?? ()

At this point, gdb remote loading is successful.

4. Setting Pretty-Printing

To support pretty-printing, the .debug information can be exported as follows:

# aarch64-rtems6-objdump -s -j .debug_gdb_scripts build/aarch64/zynqmp_qemu/testsuites/samples/ticker.exe

build/aarch64/zynqmp_qemu/testsuites/samples/ticker.exe:     file format elf64-littleaarch64

Contents of section .debug_gdb_scripts:
0000046764622e696e6c 696e65642d736372  .gdb.inlined-scr
00106970740a 696d706f 7274207379730a69  ipt.import sys.i
00206d706f72 74206f73 2e706174680a7379  mport os.path.sy
0030732e706174682e617070656e 64286f73  s.path.append(os
00402e706174682e6a6f 696e286764622e50  .path.join(gdb.P
00505954484f4e4449522c202772 74656d73  YTHONDIR, 'rtems
 0060 2729290a 696d706f 72742072 74656d73  ')).import rtems
00702e707072696e74657220617320707072  .pprinter as ppr
0080696e7465720a00                      inter..

Then, load it using pprint.py as follows:

(gdb) source ../out/share/gdb/python/rtems/pprinter.py

Leave a Comment