General Debug Models and Mapping on GDB
Pros: sources are not required on target
the agent adds minimal overhead on target
can be integrated with a visual front end
Suitable for intensive debugging of large amount of code.
Can be used without an OS on target.
Terminology: native agent = gdbserver, cross debugger = gdb
Pros: doesn’t need additional connection with a host
doesn’t require a host debugger aware of target architecture
General Requirements
gcc: -g / -ggdb / -gdwarf-2
as: -g / -gdwarf-2 or -gdwarf2
gcc -O0
(uncheck strip options on LTIB Target Image Generation menu)
Building latest GDB
- Configure --target=$TARGET --prefix=<install destination>
- Build
- Install
Example- full commands listing for i.MX6:
$ export PATH=$PATH:/opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/bin/
$ export TARGET=arm-fsl-linux-gnueabi
$ ./configure --target=$TARGET --prefix=/usr/local/gdb-7.4-arm-fsl-linux-gnueabi
$ make
$ sudo make install
$ make distclean
$ find . –name config.cache|xargs rm
… or better remove the entire source folder and uncompress the tarball again
- Select target architecture and runtime (CFLAGS)
- Copy libtermcap in cross gcc runtime folder (one time operation per runtime)
- Configure --build=$MACHTYPE --host=$TARGET --prefix=<install destination>
- Build
- Install
Example- Full commands listing for i.MX6:
$ export CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp"
$ sudo cp <rootfs>/usr/lib/libtermcap.* /opt/freescale/usr/local/gcc-4.4.4-glibc-2.11.1-multilib-1.0/arm-fsl-linux-gnueabi/arm-fsl-linux-gnueabi/multi-libs/armv7-a/neon/lib
$ ./configure --build=$MACHTYPE --host=$TARGET --prefix=<rootfs>/usr/local/gdb7.4
$ make
$ sudo chmod a+w <rootfs>/usr/local/
$ make install
Using GDB - first steps
Run agent on target
$ gdbserver :port <myapp>
Run debugger on host
$ my_built_cross_gdb
In GDB, use commands like:
file <myapp> - specify the debugged file
set sysroot <target_root_fs> - for library discovery
(set solib-search-path and solib-absolute-prefix <target_root_fs>/lib – for gdb-6.6)
target remote <target-IP>:<port> - connect with agent
Run debugger on target
$ gdb <myapp>
Use "set substitute-path <build-path> <actual-path>" for path mapping
break <symbol>
break <file>:<line>
continue/run (note the differences!)
next
list
info thread
thread <id>
backtrace
frame
Other Runtime Analysis Tools for Linux
Check <fsl-arm-toolchain>/…/debug-root/usr/binfolder for pre-built target tools:
set sysroot <rootfs>
kgdb + eclipse + arm gdb
Programming Guide: KGDB + Eclipse debug Kernel on i.mx6 Android
openocd + eclipse + arm gdb
Programming Guide: OpenOCD with Eclipse debug u-boot & kernel on i.mx6
I compiled one native gdb for iMX6, but it will crash as following:
(I tried version gdb-7.4, gdb-7.4.1, and gdb-.76, I got the same result.)
usr/local/gdb-7.6/bin$ ./gdb --version
Segmentation fault
Then I check the coredump by this segmentation fault, it show:
sudo /usr/local/gdb-7.6-arm-fsl-linux-gnueabi/bin/arm-fsl-linux-gnueabi-gdb ./gdb ./core
GNU gdb (GDB) 7.6
Copyright (C) 2013 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=i686-pc-linux-gnu --target=arm-fsl-linux-gnueabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/nfs/usr/local/gdb-7.4/bin/gdb...done.
[New LWP 670]
Core was generated by `./gdb --version'.
Program terminated with signal 11, Segmentation fault.
#0 0x2ab0fc94 in ?? () from /home/nfs/lib/libtermcap.so.2
(gdb) bt
#0 0x2ab0fc94 in ?? () from /home/nfs/lib/libtermcap.so.2
#1 0x2ab1003c in tgetnum () from /home/nfs/lib/libtermcap.so.2
#2 0x003b4aa4 in ?? ()
#3 0x003b4aa4 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) quit
More details. Only gdb will crash, and others gdbserver and run will work normally.
root@Target /mnt/nfs/usr/local/gdb-7.6/bin$ ./gdb --version
Segmentation fault
root@Target /mnt/nfs/usr/local/gdb-7.6/bin$ ./gdbserver --version
GNU gdbserver (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "arm-fsl-linux-gnueabi"
root@Target /mnt/nfs/usr/local/gdb-7.6/bin$ ./run --version
GNU simulator (GDB) 7.6
Run strace ./gdb and you'll see the reason of the crash. It's usually a missing file, /etc/termcap, so you can fix the problem as it follows:
$ touch /etc/termcap
Cool, it works.
Thanks.
root@TARGET /mnt/nfs/usr/local/gdb-7.6/bin$ ./gdbserver --version
GNU gdbserver (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public
License.
This gdbserver was configured as "arm-fsl-linux-gnueabi"
root@TARGET /mnt/nfs/usr/local/gdb-7.6/bin$ ./gdb --version
Segmentation fault
root@TARGET /mnt/nfs/usr/local/gdb-7.6/bin$ mount -o remount,rw /
root@TARGET /mnt/nfs/usr/local/gdb-7.6/bin$ touch /etc/termcap
root@TARGET /mnt/nfs/usr/local/gdb-7.6/bin$ ./gdb --version
GNU gdb (GDB) 7.6
Copyright (C) 2013 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 "arm-fsl-linux-gnueabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
On Wed, Jun 19, 2013 at 4:02 PM, AdrianGancev <admin@community.freescale.com
To avoid all this manual steps you can take a look in Yocto; it is capable of build the development sysroot and toolchain as you wish.
This is how we've doing for customers.
I sent a video here today at https://community.freescale.com/message/304134#304134
Regards,
Very helpful information!
I follow the steps for i.MX233 and they also work. Here is the my command list to build the i.MX233 GDB cross debugger.
$ export PATH=$PATH:/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin
$ export TARGET=arm-none-linux-gnueabi
$ ./configure --target=$TARGET --prefix=/usr/local/gdb-7.5-arm-none-linux-gnueabi
$ make
$ sudo make install
Thanks,
Peter