Skip to main content

Remote debugging for ARM target board

Remote debugging for ARM target board

With GDB one can both trace and modify code and data flow, and otherwise analyze the behavior of code, without explicitly changing any of it.

Rather than run a full-blown instance of GDB on the target platform, you can use 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, and then waits for instructions from a remote instance of GDB running on a development workstation.

Remote target needs to have debugging stub (gdbserver),
The gdbserver is also referred to as the 'stub' and must be cross-compiled for
that target.
You also have to use a version of gdb on the host that was built
with the correct target in mind.  Executing your gdb with the -v flag will give
you information on how it was built.
before you begin, you need a communication interface between the PC running GDB
and the target platform: either a serial link or, preferably, an Ethernet network
connection. You also need a cross-target toolchain: a GNU C compiler (together with
a C run-time library and binary utilities, a.k.a. binutils) that runs on the
development workstation and generates executables for the target processor. You will
build two sets of binaries from the GDB source code:
cross-target -- where the host is the development workstation and the target is the
target processor
native -- where both host and target are the target processor
First download the GDB source code compressed archive, and unpack it
The GDB source package uses the GNU build system, where generating binaries is
usually just a few commands away (./configure ; make ; make install)

Configure gdbserver for ARM target board

 

To remote debug need a gdb built for the correct target. To do this, download the latest gdb release (6.8)

    $ tar –xvzf .gz 
    $ cd gdb-6.8 
    $ ./configure --host=i386 --target=arm-linux --build=i686 
--prefix=/home/bhagwat/arm-tools/bin/arm-linux-gdb
    $ make
    $ make install 
 

Cross target GDB ie arm-linux-gdb will be available in /home/bhagwat/arm-tools/bin/arm-linux-gdb/bin

 

Then, to build 'the stub' aka gdbserver for the arm-linux platform

 
    $ cd gdb-6.8/gdb/gdbserver 
    $ export CC=arm-linux-gcc   // if required
    $ export LD=arm-linux-ld    // if required 
    $ ./configure --build=i686 --host=arm-linux --target=arm-linux
    $ make
 

Copy gdbserver on target platform

gdbserver requires libthread_db.so.1 library, copy this from standard path to target boards /lib path.

Start with Remote Debugging

Start with simple hello.c example program

$ vi hello.c 
#include 
int main ( void)
{
   printf ( ”Hello , World ! \ n” ) ;
   return 0;
}
 

To build this program, you must use a cross compiler that is configured to generate binaries for the ARM Linux target (arm-linux-gcc).

Compile using arm-linux-gcc

$ arm-linux-gcc -g -Wall -o hello hello.c

Copy the program to board.

Telnet into the target and start gdbserver:

 $ gdbserver :4000 hello

The port number (4000) is arbitrary. Be sure to include the full path to your executable.

On the host, cd to the hello.c program directory and type:

 $ /home/bhagwat/arm-tools/bin/arm-linux-gdb/bin/arm-linux-gdb hello
 $ target remote ds:4000
 $ break main
 $ continue

Where "ds" is the name or IP address of your target board.

If you want to have some comfort, use ddd:

 $ ddd --gdb --debugger /home/bhagwat/arm-tools/bin/arm-linux-gdb/bin/arm-linux-gdb hello

Keep me updating.

Happy remote debugging.


Comments

nihilist hayvan said…
That was helpful. Thank you. But I guess one should set host as i686 not i386 whilst compiling gdb

omurhan
Bhagwat said…
Thanks Nihilist; I did not see much difference with i386 and i686 option it works well in both cases.
./configure --host=i686 --target=arm-linux --build=i686
Redjupiter said…
I tried the above but I get the following:

(gdb) target remote 192.168.1.100:4000
Remote debugging using 192.168.1.100:4000
[New Thread 1195]
Malformed packet(b) (missing colon): re:0;
Packet: 'T050b:00000000;0d:c03ecebe;0f:b0070040;thread:4ab;core:0;'


Any idea? been struggling with this for a bit.

thanks

Popular posts from this blog

Dotnet, .Net 3.5, 2.0, C# Interview Questions

Few questions on dotnet, C# 2.0, 3.5 On Object oriented concepts 1)What is inheritance with e.g 2)What is polymorphism -function overloading -Function overriding -virtual keyword use -Static keyword and use -Abstract classes -Interface -Object 3)What is threading and how do we use in realtime application(cognizant) 4)What is threadpooling, lock, monitor(write code sample) 5)Architecture of current project 6)Session state, diffrent types of state management. 7)What is Application_Start, how it works. 8)Type of authentication in asp.net 9)How to configure ASP.NET application. 10) What is Impersonation. 11) What is WebService, WSDL, UDDI, Discovery, asmx files. 12) How to implement WebService and use it. 13) When to use WebServices. 14) WPF, how to implement(BOA) 15) Testing concvepts. 16) Test attributes 17) Flow of Automation Test Method execution 18) Features of dotnet 3.5 19) CLR, garbage collection 20) Finally block 21) Manifest, Metadata, MSIL 22) Assemblies, Type of assemblies, str...

Linux SMB write performance With Simple Tips

SMB write performance can be increased by Tuning the buffer cache. The secret to good performance is to keep as much of the data in memory for as long as is possible. Writing to the disk is the slowest part of any filesystem. If you know that the filesystem will be heavily used, then you can tune this process for Linux Samba. writing out dirty blocks to the disk until the filesystem buffer cache is 80 percent full (80). default is 40%, source = http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap29sec287.html by writing echo 80 > /proc/sys/vm/dirty_ratio I am getting around 2MB increase while write operation, tested in Xp. I have tried with this single option, as the ref source is for linux 2.2 and we are using 2.6 kernel. we can try out Linux General Optimization suggested at http://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/gen-optim.html Tried with smb.conf, I am getting around 1MB gain while read and write. socket options = TCP_NODELAY I...

The Linux Foundation Free Training Program at linuxfoundation

The Linux Foundation Training Program is: * For the Community, by the Community. The Linux Foundation is building the program with its Technical Advisory Board to ensure the content, instructors and classes are the top quality available. * Technically the most advanced. Since the Linux Foundation works directly with community developers, it can cover features and advances in Linux before commercial companies. * Connected. The Linux Foundation has unfettered access to the leading developers and companies in the Linux ecosystem and will use these connections to best position attendees for success. For example, attendees can attend the exclusive, invite-only Collaboration Summit where they can forge connections beneficial to their career. * Real World. The Linux Foundation training courses all have hands on components and a highly rigorous curriculum of programming or administration exercises. Graduates will be well equipped to master Linux programming and system administr...