The Allwinner T113 is a processor designed for embedded applications, part of Allwinner's T-series product line. The chip features a dual-core Cortex-A7 CPU architecture with a frequency of up to 1.2 GHz, an integrated ARM Mali400 MP2 GPU, and support for 1080p video encoding and decoding. It is suitable for low-power applications such as industrial control, smart homes, and IoT.
Debugging tools are essential for development. Instead of using gdbserver, this guide demonstrates how to cross-compile GDB to run directly on the target board.
Download GDB Source Code
Download the GDB source package from the official GNU website. Using a stable version is recommended for compatibility; this guide uses version 10.2. You can download it with the following command:
wget https://ftp.gnu.org/gnu/gdb/gdb-10.2.tar.gz
tar xzf gdb-10.2.tar.gz
cd gdb-10.2
../gdb-10.2/configure CC=arm-htnice-linux-gnueabihf-gcc --enable-static CFLAGS="-g -O2 -I /home/users/xxx/code/gdb/termcap" LDFLAGS="-L/home/users/xxx/code/gdb/termcap" --prefix=`pwd`/install --target=arm-htnice-linux-gnueabihf --host=arm-htnice-linux-gnueabihf --program-prefix=arm-htnice-linux-gnueabihf
make
GDB depends on the termcap library, and the paths to this library are specified in the configure command above.
Resolving Compilation Errors
During compilation, the following error may occur:
In file included from ../../gdb-10.2/gdbserver/gdb_proc_service.h:22,
from ../../gdb-10.2/gdbserver/linux-low.h:27,
from ../../gdb-10.2/gdbserver/linux-aarch32-low.cc:21:
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:179:12: 错误: ‘ps_get_thread_area’ was not declared in this scope; did you mean ‘target_thread_name’?
179 | PS_EXPORT (ps_get_thread_area);
| ^~~~~~~~~~~~~~~~~~
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:177:51: 附注: in definition of macro ‘PS_EXPORT’
177 | __attribute__((visibility ("default"))) typeof (SYM) SYM
| ^~~
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:182:12: 错误: ‘ps_lgetfpregs’ was not declared in this scope; did you mean ‘ps_lgetregs’?
182 | PS_EXPORT (ps_lgetfpregs);
| ^~~~~~~~~~~~~
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:177:51: 附注: in definition of macro ‘PS_EXPORT’
177 | __attribute__((visibility ("default"))) typeof (SYM) SYM
| ^~~
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:184:12: 错误: ‘ps_lsetfpregs’ was not declared in this scope; did you mean ‘ps_lgetfpregs’?
184 | PS_EXPORT (ps_lsetfpregs);
| ^~~~~~~~~~~~~
../../gdb-10.2/gdbserver/../gdbsupport/gdb_proc_service.h:177:51: 附注: in definition of macro ‘PS_EXPORT’
177 | __attribute__((visibility ("default"))) typeof (SYM) SYM
| ^~~
make[2]: *** [Makefile:542:linux-aarch32-low.o] 错误 1
make[2]: 离开目录“/home/users/xxxx/code/gdb/gdbserver”
make[1]: *** [Makefile:10001:all-gdbserver] 错误 2
make[1]: 离开目录“/home/users/xxxx/code/gdb/”
Solution
To resolve this, add the following code to the `gdb-10.2/gdbsupport/gdb_proc_service.h` file:
// Add missing declarations
EXTERN_C_PUSH
extern ps_err_e ps_get_thread_area(struct ps_prochandle*, lwpid_t, int, psaddr_t*);
extern ps_err_e ps_lgetfpregs(struct ps_prochandle*, lwpid_t, prfpregset_t*);
extern ps_err_e ps_lsetfpregs(struct ps_prochandle*, lwpid_t, const prfpregset_t*);
EXTERN_C_POP
#endif
After successful compilation, the GDB executable will be located in the specified installation directory.
Verifying the Cross-Compilation Result
Copy the generated GDB binary to the Allwinner T113 development board and run it to verify its functionality:
./gdb test
After launching, type `r` to start the program. The `test` program should run correctly. Next, set a breakpoint using `b`. If the program execution halts at the breakpoint, GDB is working as expected.