GDB for i.MX Linux userspace and Eclipse integration

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GDB for i.MX Linux userspace and Eclipse integration

9,285 Views
AdrianGancev
NXP Employee
NXP Employee
  1. General Debug Models and Mapping on GDB
  2. General Requirements
  3. Building latest GDB
  4. Using GDB - first steps
  5. Other Runtime Analysis Tools for Linux
  6. Using the ECLIPSE Front End


General Debug Models and Mapping on GDB

  • CROSS: ELF on host, agent on target
       - native agent runs on target for run control functions
       - cross debugger runs on host for elf parsing and user interface
       - communication over serial or ethernet

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

 

  • NATIVE: ELF on target
        - both native debugger and agent run on target
        - elf parsing, user interface and run control are all performed on target

Pros: doesn’t need additional connection with a host

doesn’t require a host debugger aware of target architecture

 

General Requirements

  • debugger/agent awareness of target architecture and OS
  • The application must be built with debug information

           gcc: -g / -ggdb / -gdwarf-2

           as:   -g / -gdwarf-2  or -gdwarf2

  •  As little optimizations as possible

            gcc -O0

  • Availability of sources
  • The application must not interfere with debugger mechanisms
  •  Un-stripped target libraries (Linux: ld.so, libthread-db.so, libpthread.so)

(uncheck strip options on LTIB Target Image Generation menu)

    

Building latest GDB

  • Have cross gcc in PATH
  • Build cross version

- 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

  • Clean the build folder

           $ make distclean

           $ find . –name config.cache|xargs rm

… or better remove the entire source folder and uncompress the tarball again

  • Build native version (including gdbserver)

- 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

  • CROSS

         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


  • NATIVE

         Run debugger on target

        $ gdb <myapp>

        Use "set substitute-path <build-path> <actual-path>" for path mapping

  • Use gdb commands like the following and learn the highlighted shortcuts:

 

        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:

        strace, strace-graph
        ltrace
        duma (Detect Unintended Memory Access)
        dmalloc
 
Using the ECLIPSE Front End

 

  • Run ECLIPSE and

 

              o Create a project:
 
                - Create a Makefile Project with Existing Code
                - Choose Cross GCC
                - Optional: Configure paths to build tool in Project Properties

              o Configure a debugger (and remote system):
 
                - Create a Debug Configuration of type C/C++ Remote Application
                - Use GDB/DSF Manual Remote Debugger Launcher
                - Specify cross gdb in Debugger/Main tab
                - Specify a gdbinit file in Debugger/Main tab that contains:

               set sysroot <rootfs>

                - Configure target IP and gdbserver port in Debugger/Connection tab
 
              o Prepare the target for debugging and start debugging
 
                - Run gdbserver on host
                - Try start from entrypoint mode
                - Try attach to process mode
 
-- End --
7 Replies

2,175 Views
fatalfeel
Contributor V
0 Kudos
Reply

2,175 Views
fishzheng
Contributor I

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




0 Kudos
Reply

2,175 Views
fishzheng
Contributor I

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


0 Kudos
Reply

2,176 Views
AdrianGancev
NXP Employee
NXP Employee

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

0 Kudos
Reply

2,176 Views
fishzheng
Contributor I

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

0 Kudos
Reply

2,176 Views
OtavioSalvador
Senior Contributor II

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,

0 Kudos
Reply

2,176 Views
PeterChan
NXP Employee
NXP Employee

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

0 Kudos
Reply