u-boot runs on QEMU ARM model , we can start GDB server on QEMU with command line parameters '-s -S' as following:
chunxie@chunxie-VirtualBox:~/uboot-mainline/u-boot$ qemu-system-arm -M vexpress-a9 -nographic -m 512 -kernel u-boot -s -S
Then in another terminal, we can start gdb to connect to GDB server(TCP port local:1234) as following:
chunxie@chunxie-VirtualBox:~/uboot-mainline/u-boot$ /opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-gdb
GNU gdb (Linaro GDB 2016.02) 7.10.1.20160210-cvs
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.launchpad.net/gcc-linaro>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) file u-boot
Reading symbols from u-boot...done.
(gdb) target remote:1234
Remote debugging using :1234
warning: remote target does not support file transfer, attempting to access files from local filesystem.
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
_start () at arch/arm/lib/vectors.S:54
54 b reset
(gdb) l
49
50 #ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
51 .word CONFIG_SYS_DV_NOR_BOOT_CFG
52 #endif
53
54 b reset
55 ldr pc, _undefined_instruction
56 ldr pc, _software_interrupt
57 ldr pc, _prefetch_abort
58 ldr pc, _data_abort
(gdb)
Here we can see gdb commands 'target' can connect to GDB server. Now we can do normal GDB debug.