Monday, November 29, 2010

Playing with GDB: Installing GDB and debugging remote application on PPC target

Building Application for PPC Target:

I used MPC8377 as target and built my application using Application Development Kit (ADK) for MPC 8377 that comes with Mentor Embedded Linux (MEL). 
You can use any other cross toolchain to build your application. Another easily available is the one provided by CodeSourcery.


On Host Machine:

If you have Linux(Ubuntu) machine then you might already  GDB for native (x86) application debugging. But for cross debugging for any non-x86 architecture, you need to get GDB source, configure it for that particular architecture and install it by following below instructions:

  • Download latest source of GDB "gdb-7.2.tar.gz" from "http://ftp.gnu.org/gnu/gdb/".
  • Untar "gdb-7.2.tar.gz" file.
  • Open terminal and change directory to location where you extracted the "gdb-7.2.tar.gz" file.
  • Run "./configure --target=powerpc-linux".
  • Run "make".
  • Run "make install".
Now you have got GDB configured for PPC on your host machine.

On Target Side:

GDB is a remote serial protocol in which you need some application on target side that understands GDB protocol. In terms of GDB, this application is called Debugging stub. For PPC with embedded linux, we have gdbserver that provides a replacement of GDB stub.

  • Boot kernel on your PPC target
  • Note ip address assigned to target by dhcp (In case you did not assigned static ip using bootargs).
  • Copy your out file (elf file build with debug info) to target system. You can transfer files easily by mounting any local folder. You can also use scp for remote copy.
  • Run gdbserver on target by giving command "gdbserver:12345 outfilename". Here 12345 is port number used for communication and outfilename is name of .elf file.
Below are output messages
root@mpc8377e-rdb:~# gdbserver :12345 HelloWorld
Process HelloWorld created; pid = 1623
Listening on port 12345



To learn more about gdbserver read http://davis.lbl.gov/Manuals/GDB/gdb_17.html#SEC138

Now you have gdbserver running on your target platform. This gdbserver understands GDB protocol via TCP/IP.

Now come back to host machine and give following command:
powerpc-linux-gdb outfilename

In my case it was
taimoor@taimoor-ubuntu:~$ powerpc-linux-gdb /home/taimoor/TestApps8377/HelloWorld_8377/Debug/HelloWorld_8377
GNU gdb (GDB) 7.2
Copyright (C) 2010 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=powerpc-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/taimoor/HelloWorld_8377/Debug/HelloWorld_8377...done.
(gdb)

Now you have debugger running on your host machine.Now give the following command to connect to gdbserver running on target.

(gdb) target remote [target ip]:12345

Here targetip is IP of target platform. you can check targetip using ifconfig command on target's terminal. If you have given some static IP then use that one.

Now you can use gdb commands like "b main" to break in main function and then 'c' to continue.

No comments:

Post a Comment