Debugging a Linux Application with MontaVista 5.0

From Texas Instruments Embedded Processors Wiki

Jump to: navigation, search
Translate this page to   

DVSDK provided filesystem with MontaVista 5.0 (MVL 5.0) does not contain GDB and gdbserver for debugging ARM application. This page will guide you through the steps for cross compiling gdb/gdbserver and finally a example commands that can used for debugging a simple application.

Contents

What is GDB

GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it executes -- or what another program was doing at the moment it crashed. GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:

The program being debugged can be written in Ada, C, C++, Objective-C, Pascal (and many other languages). Those programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on most popular UNIX and Microsoft Windows variants.


What is gdbserver

GDBserver, a program that lets you run GDB on a different machine than the one on which your program is running. The advantage of using GDBserver is that it needs just a fraction of the target resources that GDB consumes, because it implements only the low-level functionality of the debugger -- namely setting breakpoints and accessing the target processor registers and read/write application memory. GDBserver takes control of the application being debugged, then waits for instructions from a remote instance of GDB running on a development workstation.

Cross compiling gdb and gdbserver

 host# cd /home/user/workdir/filesys
 host# tar zxvf gdb-6.6.tar.gz 
 host# cd gdb-6.6
 host# ./configure --host=i686-pc-linux-gnu --target=armv5tl-montavista-linux-gnueabi --prefix=/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le

Note that the install command is expecting to be able to write to your MontaVista installation directory, you may have to change permissions on the install directory if you are building this as a user that cannot write to /opt.

 host# make && make install
 host# cd gdb/gdbserver
 host# CC=/opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin/arm_v5t_le-gcc ./configure  --host=armv5tl-montavista-linux-gnueabi --prefix=/home/user/workdir/filesys

Note that the install command is expecting to be able to write to your NFS mounted filesystem, you may have to change the permissions of your filesystem to allow your user rights to write to the filesystem directories (namely /home/user/workdir/filesys/bin).

 host# make && make install

Assumption

Debugging application using gdb and gdbserver

Compile and build application

Compile and build application using "-g" option.

host# mkdir -p /home/user/targetfs/opt/sample
host# cd /home/user/targetfs/opt/sample
host# cat sample.c 
#include <stdio.h>
int main (int argc, char **argv) {
  int x, y;
  x = 20, y = 10;
  printf("%d+%d=%d\n", x, y, x+y);
  /* Set the break point here and change value of x from gdb */
  printf("%d*%d=%d\n", x, y, x*y);
   /* Set the break point here and change value of y from gdb */
  printf("%d/%d=%d\n", x, y, x/y);
  return 0;
}
host# arm_v5t_le-gcc -g sample.c -o sample

Debugging

host IP address: 192.168.100.1 target IP address: 192.168.100.2

target# cd /opt/sample
target# gdbserver 192.168.100.1:1000 ./sample
 Process ./sample created; pid = 733
 Listening on port 1000

At this point of time target is waiting for connection from the host

 host# /home/user/targetfs/opt/sample
 host# /opt/mv_pro_5.0/montavista/pro/devkit/arm/v5t_le/bin/armv5tl-montavista-linux-gnueabi-gdb ./sample
 GNU gdb 6.6
 Copyright (C) 2006 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you are
 welcome to change it and/or distribute copies of it under certain conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for details.
 This GDB was configured as "--host=i686-pc-linux-gnu --target=armv5tl-montavista-linux-gnueabi"...
 (gdb) set solib-search-path /home/user/workdir/filesys/lib
 (gdb) target remote 192.168.100.2:1000
 Remote debugging using 192.68.100.1:1000
 0x400007e0 in _start ()
 from /home/user/targetfs/lib/ld-linux.so.3
 (gdb)

At this point host is successfully connected to target gdbserver and now you can use gdb command to run the application.

For more information on gdb commands refer GNU GDB Debugger Command

Also see Debugging remotely on DaVinci using gdb for another example.

E2e.jpg For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Debugging a Linux Application with MontaVista 5.0 here.
Hyperlink blue.png Links
ARM Microcontroller MCU ARM Processor Digital Media Processor Digital Signal Processing Microcontroller MCU Multi Core Processor
Ultra Low Power DSP 8 bit Microcontroller MCU 16 bit Microcontroller MCU 32 bit Microcontroller MCU

Leave a Comment

Comments

Comments on Debugging a Linux Application with MontaVista 5.0


Fullofsquirrels said ...

I was unable to get gdb to compile due to warnings being treated as errors, so I added this onto the end of the config step: "--disable-werror". Now everything builds OK.

--Fullofsquirrels 23:54, 22 February 2010 (CST)

Ckw089 said ...

It will be great to extend this to include the remote multithreaded application debugging. Especially how to avoid the problem caused by different version of shared libraries on target file system and host.

--Ckw089 01:44, 11 September 2010 (CDT)

Scraimer said ...

"different version of shared libraries on the target system" - the example above addresses this by doing "set solib-search-path /home/user/workdir/filesys/lib" to set the search path for relatively-pathed libraries. You may also need to set the search path for absolutely-pathed libraries, by setting solib-absolute-prefix

--Scraimer 06:16, 27 December 2011 (CST)

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox