Questioning about the "target triplet" <CPU>-<vendor>-<OS> used by the GNU build system to describe a target

When building gdb targeting a different platform, one must choose --host, --build, and --target parameters.

The target parameter has the following format [1]:


You can get the target of your gcc with:

gcc -dumpmachine

As examples:

x86_64-linux-gnu        (Intel laptop running Ubuntu)
arm-linux-gnueabihf     (Raspberry Pi running Raspbian)

What is the meaning of each field?

Based on information found at [2].

|      |         |
|      |         | operating system
|      |         | (+ ABI sometimes, e.g., gnueabihf = GNU EABI Hard Float)
|      |
|      | vendor
|      | mostly irrelevant, often just 'unknown' or unused
|      | do not mistake 'linux-gnu' for <vendor>-<os>, when it is in reality just the <os> field
| CPU architecture
| definitions are found in <prefix>/config/cpu/<cpu>

There is a long shell script (config.sub) to disambiguate target triplets.

Build gdb

We build gdb [3] on a Raspberry Pi 3 targeting x86_64 debugging:

sudo apt-get install libncurses5-dev
sudo apt-get install libexpat1-dev
sudo apt-get install python-dev
mkdir build; cd build
../gdb-7.9.1/configure --target=x86_64-unknown-linux --with-expat --with-python
make -j4

Then to start debugging:

gdb/gdb /path/to/my/x86/bin/with/symbols
(gdb) set sysroot /path/to/my/x86/lib/ld-linux.so

It is obvious that gdb is unable to run the binary locally. Debugging can only be remote.

Alternatively, you can also use the target directly to load the shared libraries with (but better be the network connection fast):

(gdb) set sysroot remote:/

Note: if you do not activate expat with --with-expat, XML support will not be available in gdb, and you will get the warning:

warning: Can not parse XML target description; XML support was disabled at compile time

The consequence is that gdb will fail to load dynamic libraries even if you set the right sysroot and the ld breakpoint is correct.

Update 2016.12.11 When building gdb-7.12, make complains that makeinfo is not found (to build .texi docs). From an idea of [4], you can create a dummy makeinfo. Additional required packages:

sudo apt-get install bison


If your target can only be reached via IPv6 local-link, an SSH tunnel must be created since gdb does not support IPv6 yet:

ssh root@fe80::250:b6ff:fe0e:23d9%eth1 -L 3333:localhost:3333
gdbserver /path/to/my/x86/bin/without/symbols

...and inside gdb:

target remote :3333

IPv6 local-link is easy to use because the MAC address of the target is automatically converted into a local-link address. An online converter is [5].

Too many symbols?

The Raspberry Pi only has 1GB of RAM, and loading large binary requires larger amount of memory.

If only the function names in the backtrace are needed, the debug data can be dropped:

cp myBinaryWithFullDebugData myBinaryWithJustFunctionSymbols
strip -g myBinaryWithJustFunctionSymbols

save gdb-index keeps all the debug data, but loads faster and consumes less memory. See the shell script from the Chromium project at [6].

Not finding any dynamically loaded libraries?

[7] [8]

Not using a binary?

Tell gdb which architecture to expect with:

set architecture i386:x86_64:intel

gdb multiarch

As gdb is independent from the compiler used in the binary, it can also be built with multiple target supports. This is known as gdb multiarch [9].

For gdb without ncurses interface and with all possible targets:

../gdb-7.9.1/configure --with-expat --with-python --without-ncurses --enable-targets=all --prefix=/opt/gdb

Note --enable-targets-all does nothing and generates no error.

If you succeeded to build all architectures, here is what you get when trying to auto-complete architecture:

(gdb) set architecture
Display all 311 possibilities? (y or n)

See appendix for a list.

Corrupted stack? Really?

When gdb is unable to find the debug symbols of libc6, it is unable to unwind the stack.

(gdb) bt
#0  0x762b7f70 in raise () from /mnt/target/lib/arm-linux-gnueabihf/libc.so.6
#1  0x762b9324 in abort () from /mnt/target/lib/arm-linux-gnueabihf/libc.so.6
#2  0x00000020 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Check the value of debug-file-directory:

(gdb) show set debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".

It seems that setting the sysroot does not set this path accordingly.

(gdb) set debug-file-directory /mnt/target/usr/lib/debug


[1]GDB Wiki, "building GDB and GDBserver for cross debugging", https://sourceware.org/gdb/wiki/BuildingCrossGDBandGDBserver
[2]OSDev, Target Triplet, http://wiki.osdev.org/Target_Triplet
[3]GDB releases, ftp://sourceware.org/pub/gdb/releases/
[4]Dummy makeinfo, https://sourceware.org/bugzilla/show_bug.cgi?id=18113
[5]Ben's blog, MAC address to IPv6 link-local address online converter, http://ben.akrin.com/?p=1347
[6]Chromium, gdb-add-index, https://chromium.googlesource.com/chromium/chromium/+/master/build/gdb-add-index
[7]Faye Williams, GDB: Unable to find dynamic linker breakpoint function, http://www.fayewilliams.com/2013/01/31/gdb-unable-to-find-dynamic-linker-breakpoint-function/
[8]Sysprogs, Resolving library symbol load errors when debugging with cross-toolchains, https://sysprogs.com/w/resolving-library-symbol-load-errors-when-debugging-with-cross-toolchains/
[9]Neil Williams, https://lists.debian.org/debian-embedded/2011/01/msg00012.html

Appendix - gdb architectures

Available arguments to set architecture:

arm, armv2, armv2a, armv3, armv3m, armv4, armv4t, armv5, armv5t, armv5te, xscale, ep9312,
iwmmxt, iwmmxt2, arm_any, avr, avr:1, avr:2, avr:25, avr:3, avr:31, avr:35, avr:4, avr:5,
avr:51, avr:6, avr:100, avr:101, avr:102, avr:103, avr:104, avr:105, avr:106, avr:107,
bfin, cris, crisv32, cris:common_v10_v32, frv, tomcat, simple, fr550, fr500, fr450, fr400,
fr300, ft32, h8300, h8300h, h8300s, h8300hn, h8300sn, h8300sx, h8300sxn, hppa1.0, i386,
i386:x86-64, i386:x64-32, i8086, i386:intel, i386:x86-64:intel, i386:x64-32:intel,
i386:nacl, i386:x86-64:nacl, i386:x64-32:nacl, iq2000, iq10, lm32, m16c, m32c, m32r,
m32rx, m32r2, m68hc11, m68hc12, m68hc12, m68k, m68k:68000, m68k:68008, m68k:68010,
m68k:68020, m68k:68030, m68k:68040, m68k:68060, m68k:cpu32, m68k:fido, m68k:isa-a:nodiv,
m68k:isa-a, m68k:isa-a:mac, m68k:isa-a:emac, m68k:isa-aplus, m68k:isa-aplus:mac,
m68k:isa-aplus:emac, m68k:isa-b:nousp, m68k:isa-b:nousp:mac, m68k:isa-b:nousp:emac,
m68k:isa-b, m68k:isa-b:mac, m68k:isa-b:emac, m68k:isa-b:float, m68k:isa-b:float:mac,
m68k:isa-b:float:emac, m68k:isa-c, m68k:isa-c:mac, m68k:isa-c:emac, m68k:isa-c:nodiv,
m68k:isa-c:nodiv:mac, m68k:isa-c:nodiv:emac, m68k:5200, m68k:5206e, m68k:5307, m68k:5407,
m68k:528x, m68k:521x, m68k:5249, m68k:547x, m68k:548x, m68k:cfv4e, m88k:88100, mep, h1,
c5, MicroBlaze, mips, mips:3000, mips:3900, mips:4000, mips:4010, mips:4100, mips:4111,
mips:4120, mips:4300, mips:4400, mips:4600, mips:4650, mips:5000, mips:5400, mips:5500,
mips:5900, mips:6000, mips:7000, mips:8000, mips:9000, mips:10000, mips:12000, mips:14000,
mips:16000, mips:16, mips:mips5, mips:isa32, mips:isa32r2, mips:isa32r3, mips:isa32r5,
mips:isa32r6, mips:isa64, mips:isa64r2, mips:isa64r3, mips:isa64r5, mips:isa64r6, mips:sb1,
mips:loongson_2e, mips:loongson_2f, mips:loongson_3a, mips:octeon, mips:octeon+,
mips:octeon2, mips:octeon3, mips:xlr, mips:micromips, mn10300, am33, am33-2, moxie, msp:14,
MSP430, MSP430x11x1, MSP430x12, MSP430x13, MSP430x14, MSP430x15, MSP430x16, MSP430x20,
MSP430x21, MSP430x22, MSP430x23, MSP430x24, MSP430x26, MSP430x31, MSP430x32, MSP430x33,
MSP430x41, MSP430x42, MSP430x43, MSP430x44, MSP430x46, MSP430x47, MSP430x54, MSP430X, ms1,
ms1-003, ms2, n1h, n1h, n1h_v2, n1h_v3, n1h_v3m, nios2, nios2:r1, nios2:r2, rl78,
rs6000:6000, rs6000:rs1, rs6000:rsc, rs6000:rs2, powerpc:common64, powerpc:common,
powerpc:603, powerpc:EC603e, powerpc:604, powerpc:403, powerpc:601, powerpc:620,
powerpc:630, powerpc:a35, powerpc:rs64ii, powerpc:rs64iii, powerpc:7400, powerpc:e500,
powerpc:e500mc, powerpc:e500mc64, powerpc:MPC8XX, powerpc:750, powerpc:titan, powerpc:vle,
powerpc:e5500, powerpc:e6500, rx, rx, s390:64-bit, s390:31-bit, score7, score3, sh, sh2,
sh2e, sh-dsp, sh3, sh3-nommu, sh3-dsp, sh3e, sh4, sh4a, sh4al-dsp, sh4-nofpu,
sh4-nommu-nofpu, sh4a-nofpu, sh2a, sh2a-nofpu, sh2a-nofpu-or-sh4-nommu-nofpu,
sh2a-nofpu-or-sh3-nommu, sh2a-or-sh4, sh2a-or-sh3e, sh5, sparc, sparc:sparclet,
sparc:sparclite, sparc:v8plus, sparc:v8plusa, sparc:sparclite_le, sparc:v9, sparc:v9a,
sparc:v8plusb, sparc:v9b, sparc:v8plusc, sparc:v9c, sparc:v8plusd, sparc:v9d,
sparc:v8pluse, sparc:v9e, sparc:v8plusv, sparc:v9v, sparc:v8plusm, sparc:v9m, spu:256K,
tic6x, tilegx, tilegx32, v850:old-gcc-abi, v850e3v5:old-gcc-abi, v850e2v4:old-gcc-abi,
v850e2v3:old-gcc-abi, v850e2:old-gcc-abi, v850e1:old-gcc-abi, v850e:old-gcc-abi,
v850:rh850, v850e3v5, v850e2v4, v850e2v3, v850e2, v850e1, v850e, v850-rh850, vax,
xstormy16, xtensa, aarch64, aarch64:ilp32, alpha, alpha:ev4, alpha:ev5, alpha:ev6,
ia64-elf64, ia64-elf32, auto