arm linux port gdb/gdbserver

The use of the debugging tool gdb is an indispensable skill for embedded Linux developers.

At present, in the embedded Linux system, there are mainly three remote debugging methods, which are suitable for debugging in different occasions: using ROM Monitor to debug the target machine program, using KGDB to debug the system kernel, and using gdbserver to debug user space programs .

The difference between these three debugging methods mainly lies in the existence form of the remote debugging stub of the target machine, but the design ideas and implementation methods are roughly the same.

We use it most often to debug applications. It is to use gdb+gdbserver to debug. In many cases, users need to repeatedly debug an application, especially complex programs. Debugging with GDB method, due to the limited resources of the embedded system, it is generally not possible to debug directly on the target system, and usually use gdb+gdbserver to debug. Gdbserver runs on the target system, and gdb runs on the host machine.

To perform GDB debugging, the target system must include the gdbserver program, and the host must also install the gdb program (at present, it seems that ARM's DS-5 tool can be used to replace the host's GDB to achieve visual debugging). Generally, there is a gdb that can run in the linux distribution, but developers cannot directly use the gdb in this distribution for remote debugging, but to obtain the source code package of gdb, make a simple configuration for the arm platform, and recompile to get Corresponding gdb.

gdb : v7.81

compile

One script does it all.

##
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#    File Name:  make.sh
#    Created  :  Tue 24 Dec 2019 04:20:51 PM CST
##
#!/bin/sh
BASE=`pwd`
BUILD_HOST=arm-linux
OUTPUT=${BASE}/install/
make_dirs() {
    cd ${BASE}
    mkdir  compressed  install  source -p
    sudo ls
}
tget () { #try wget
    filename=`basename $1`
    echo "Downloading [${filename}]..."
    if [ ! -f ${filename} ];then
        wget $1
    fi
    echo "[OK] Downloaded [${filename}] "
}
download_package () {
    cd ${BASE}/compressed
    #下载包
    tget http://ftp.gnu.org/gnu/gdb/gdb-7.8.1.tar.xz
}
tar_package () {
    cd ${BASE}/compressed
    ls * > /tmp/list.txt
    for TAR in `cat /tmp/list.txt`
    do
        tar -xf $TAR -C  ../source
    done
    rm -rf /tmp/list.txt
}
make_gdb_host () {
    cd ${BASE}/source/gdb*
    ./configure --target=${BUILD_HOST} --prefix=${OUTPUT}/gdb_host
    make && make install
}
make_gdb_target () {
    cd ${BASE}/source/gdb*/gdb/gdbserver
    ./configure --host=${BUILD_HOST} --prefix=${OUTPUT}/gdbserver
    make && make install
}
make_dirs
#download_package
tar_package
# arm gdb 分为2个部分
make_gdb_host
make_gdb_target
exit $?

test

Copy the compiled gdbserver to the target board /usr/sbin, modify the execution permission, and test a simple helloworld program:

on the board

  1. gdbserver <host ip : 端口> <程序名>
  2. 例如:
  3. $ gdbserver 192.168.1.100:5000 helloworld # 启动调试,等待主机连接
  4. Process helloworld created; pid = 698
  5. Listening on port 5000

the host

Run the following command to enter the gdb debugging interface (take the arm-linux-gcc toolchain as an example)

  1. arm-linux-gdb <程序名>

Enter the interactive command:

  1. (gdb)target remote <target-board-ip:端口>

After that, use the gdb command to start debugging

 

Guess you like

Origin blog.csdn.net/u010258235/article/details/130128929