Gdbserver remote debugging of embedded Linux application methods

Source: Internet
Author: User

here is a remote debugging method based on GDB and Gdbsever. Environment: PC: Win7, virtual machine: 10.04, the next machine: Flying embedded TE2440 Development Board.  the development of embedded Linux applications is generally written in Linux code, and the cross-compiler ARM-LINUX-GCC compiled and then downloaded to the board to run. If you set up remote debugging (the ability to debug Linux applications in the board in PC Ubuntu), this is extremely handy for developing programs.  The following are some of the methods that are excerpted from the network. Some of the problems that have been encountered are added, and solutions are proposed.  1, first set up NFS file system, so that the file system on the PC Ubuntu on the assumption that the path is:/home/xxx/work/can be mounted to the board up. Method can be seen in another article of this blog. Where the IP environment is the PC Win7 IP for 192.168.0.11 (this is not important, as long as the same network segment can be guaranteed). The IP in the virtual machine is: 192.168.0.57. The IP in the lower machine is 192.168.0.16.  2, install the cross-compilation environment ARM-LINUX-GCC and other tools. Method can be found online. Here the assumption is already installed, and the version is 3.4.1. The path is:/usr/local/arm/3.4.1/bin. and build environment variables.  3. Let's test a simple example below. /*hello.c*/
#include
int main ()
{
printf ("Hello word!\n");
return 0;
}
After the program is good to confirm the correct, save. Enter the directory where the program files are located
# ARM-LINUX-GCC Hello.c–o Helloput the hello file in the NFS shared directory/home/xxx/work/, and execute the Hello program in the serial terminal./hello.  4. Installing GDB and GdbserverTo debug remotely by line Gdbserver, you must also install the GDB Remote Debugging tool:
GDB source code package can be downloaded from http://ftp.cs.pu.edu.tw/linux/sourceware/gdb/releases/, I download is gdb-6.6. Download to a directory, the author download to their own user directory
After downloading, go to the directory and configure the compile steps as follows:
#tar JXVF gdb-6.6-tar-bz2
#cd gdb-6.6
#./configure--target=arm-linux--prefix=/usr/local/arm-gdb-v
#makeafter performing this step, I get the following errorcc1:warnings being treated as errors
/root/tools/gdb-6.6/bfd/elf32-arm.c:in function ' Find_thumb_glue ':
/root/tools/gdb-6.6/bfd/elf32-arm.c:2452:error:ignoring return value of ' asprintf ', declared with attribute Warn_ Unused_result
/root/tools/gdb-6.6/bfd/elf32-arm.c:in function ' Find_arm_glue ':
/root/tools/gdb-6.6/bfd/elf32-arm.c:2485:error:ignoring return value of ' asprintf ', declared with attribute Warn_ Unused_resultthis is because the return value has not been received resulting in a compile interrupt because makefile added-werror causes the warning to be treated as an errorRemove the-werror option from the following file and save to recompile successfully
Bfd/makefile:185:warn_cflags =-w-wall-wstrict-prototypes-wmissing-prototypes-werror
Opcodes/makefile:175:warn_cflags =-w-wall-wstrict-prototypes-wmissing-prototypes-werrorNext Execute:#make Install
#export path= $PATH:/usr/local/arm-gdb
Enter the Gdbserver directory (in the GDB directory):
#./configure--target=arm-linux–host=arm-linux
#make CC=/USR/LOCAL/ARM/3.4.1/BIN/ARM-LINUX-GCC
(This step specifies the location of the ARM-LINUX-GCC, which may not be the same as yours.)at this point, you may encounter an error : /usr/local/arm/3.4.1/bin/arm-linux-gcc-c-wall-g-o2-i.-I.-i./. /regformats-i./. /.. /include-i. /.. /bfd-i./. /.. /BFD linux-arm-low.c

Linux-arm-low.c:35:21:sys/reg.h:no such file or directory

Because Sys/reg.h is in the/usr/include/sys/reg.h directory in Ubuntu, you can add-i/usr/include

Then run separately:/usr/local/arm/3.4.1/bin/arm-linux-gcc-c-wall-g-o2-i.-I.-i./. /regformats-i./. /.. /include-i. /.. /bfd-i./. /.. /bfd-i/usr/include linux-arm-low.c

Ok!!!!!

Run it again.

#make CC=/USR/LOCAL/ARM/3.4.1/BIN/ARM-LINUX-GCC

If there is no error, generate the Gdbserver executable file in the Gdbserver directory, burn it to the root filesystem partition of the Flash, or via NFS mount. Just make sure that the gdbserver can be run on the Development Board.

5, install the necessary library libthread_db-1.0.so

If your embedded Linux is not installed libthread_db-1.0.so This library, running Gdbserver in the board will prompt the error. Here's how to fix it:

Copy the libthread_db-1.0.so file under/usr/local/arm/3.4.1/arm-linux/lib in your ARM-LINUX-GCC cross-compilation environment to the root of the TE2440 Development Board of the lower machine Lib (you can put it into the NFS shared folder before entering the copy command in the serial terminal). and set up a soft link libthread_db.so.1 in the/lib directory that points to libthread_db-1.0.so.

The command is as follows: #ln-S libthread_db-1.0.so libthread_db.so.1

After execution, run Gdbserver again./gdbserver will no longer be prompted to find the library.

6. Debug Hello Program

To debug GDB, start the Gdbserver service on the target system first. Enter the command in the directory where the Gdbserver is located: (Serial terminal)
#cd/tmp
#./gdbserver 192.168.2.57:2345 Hello
192.168.2.57 is the host IP, which opens a debug process on port 2345 of the target system (avoid using the port number below 1024), and Hello is the program to debug.
The prompt appears:
Process/tmp/hello created:pid= "80"
Listening on Port 2345

In the virtual machine Ubuntu in the terminal inside the input

#cd/

#export path= $PATH:/usr/local/arm-gdb/bin
#arm-linux-gdb Hello
(GDB) Target remote 192.168.2.223:2345
(192.168.2.223 for Development Board IP)
The prompt appears:
Remote Debugging using 192.168.2.223:2345
[New Thread 80]
[Switching to Thread 80]
0x40002a90 in?? ()
At the same time at the end of the port prompt:
Remote Debugging from Host 192.168.2.100
(GDB)
When the connection is successful, you can enter various GDB commands such as list, run, Next, step, break and so on to debug the program. As for the appearance of 0x40002a90 in?? () The problem is because the shared library path to Arm-linux-gdb is not set. The library file could not be found. You can resolve the issue by entering the following statement. Set solib-absolute-prefix/usr/local/arm/4.4.3/arm-none-linux-gnueabi/sys-root/

Gdbserver remote debugging of embedded Linux application methods

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.