2013年1月24日星期四

Setup remote debug gdb/gdbserver



cd /usr/local
mkdir arm-gdb

#download and build gdb for host "http://ftp.gnu.org/gnu/gdb/"
cd gdb-6.7
./configure --target=arm-linux-uclibc --prefix=/usr/local/arm-gdb --disable-werror
make
make install

#build gdbserver for target
cd ./gdb/gdbserver

#before building the gdbserver for target, the target toolchain should be ready first
./configure --target=arm-linux-uclibc --host=arm-linux-uclibc --prefix=/usr/local/arm-gdb/gdbserver
export PATH=$PATH:/root/workspace/skyhawk_trunk/build_arm/staging_dir/bin
make CC=arm-linux-uclibc-gcc
make install

#if using uclibc and need debug multi-thread program, make sure the PTHREADS_DEBUG_SUPPORT is enabled when building the library

Using Eclipse Juno Service Release 1 (Setting for debug with gdb/gdbserver)
Debug Configurations > C/C++ Application > change to GDB(DSF) Remote System Process Launcher>
Main (Tab):
  • input the execute file which run on target
Debugger (Tab):
  • select the custom build gdb debugger
  • Force thread list update on suspend (turn on for showing source when break inside thread)
  • .gdbinit (in project root)
    • set solib-absolute-prefix "paths of the .so that used in the project" (path1:path2)
    • set solib-search-path "paths of the .so that used in the project" (path1:path2)
    • handle SIG32 pass noprint nostop
    • set can-use-hw-watchpoints 0
  • Shared Libraries: input the paths of .so that used in the project (search from first line)
  • Connection: set the ip and port of the target which gdbserver is running at
Source(Tab):
  • input the path of the source file, gdb search from the first line

#Debugging steps
cross compile the program for target (disable strip if it exist in makefile)

copy all updated execute and .so file to target

$./gdbserver ip:port execute  (on target)

then start Debug from eclipse

problem not solved yet:
  • Cannot 'step into' the function inside a .so, but it can pause at the breakpoint preset in the .so function, if compiled the execute with .a , 'step into' is ok
  • if set breakpoint inside a function of .so, need to set again in every session of debug

Reference:
http://crasseux.com/books/ctutorial/Building-a-library.html

http://blog.csdn.net/hlchou/article/details/7425492
http://www.study-area.org/cyril/opentools/opentools/x1265.html


Some useful commands:
arm-linux-uclibc-ar -t libmylib.a      -list out the functions name inside the static library
nm --demangle libmylib.a/libmylib.so      -list out the functions name inside the static/shared library

沒有留言:

發佈留言