To debug a program on embedded devices with limited resources(memory, CPU) the gdbserver is used. The gdbserver is running on the embedded device, while the gdb is running on a regular PC and connect with gdbserver via network. The first step is to compile gdb for embedded device(platform). The following steps are for platform with ARM CPU.
Get the sources from official site: http://www.gnu.org/software/gdb/download/
Compile gdb
>tar -zxf gdb-7.4.tar.gz #extract the sources
>cd gdb-7.4
> ./configure --prefix=/home/programs/gdb/ --build=x86 --host=x86 --target=arm-linux
"--prefix" - where to install the program
"--build" - specify which platform is used for compilation.
"--host" - specify which platform is used for run gdb.
"--target" - specify which platform is used for run the debugging program.
>make
>make install
Compile gdbserver(the gcc compiler for arm-linux is necessary)
>tar -zxf gdb-7.4.tar.gz #extract the sources into new folder
>cd gdb/gdbserver
>./configure --host=arm-linux
>make
during the compilation linux-arm-low.c:642: error: `PTRACE_GETSIGINFO' undeclared (first use in this function) error occurs. Seems a include is missing, but by adding the following line before the error line, the problem will be solved.
#define PTRACE_GETSIGINFO 0x4202
>make
Copy the gdbserver executable from current directory to the target device and run:
>gdbserver :<port> <program>
From the PC run gdb and connect to gdbserver vi the network:
(gdb)>target remote ip:port
Now the program can be debuged with usual gdb commands.
No comments:
Post a Comment