AdrianGancev

GDB for i.MX Linux userspace and Eclipse integration

Discussion created by AdrianGancev Employee on Apr 30, 2012
Latest reply on Jan 14, 2016 by jesse stone
  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 --

Outcomes