How to remotely debug embedded linux applications using gdbserver

Source: Internet
Author: User

Personal environment: ubuntu10.04, xp, 8.0.1 virtual machine, Master/Slave machine, and s3c2410


The remote debugging method based on gdb and gdbsever is described here. Environment: PC: win7, virtual machine: 10.04, lower computer: Flying embedded TE2440 Development Board.


Embedded linux applications are generally developed by compiling code in linux, and compiled with the cross compiler arm-linux-gcc before being downloaded to the board for running. If remote debugging is established (you can debug the linux application on the ubuntu server), it is extremely convenient for the development program.
Here are some methods taken from the network. Some problems encountered by myself are added, and solutions are proposed.
1. First, establish an nfs file system. Let the file system on ubuntu on the PC assume that the path is/home/xxx/work/, which can be mounted to the board. For the method, see another article in this blog. In the IP environment, the IP address of PC win7 is (this is not important, as long as it is in the same network segment ). The IP address in the VM is The IP address in the lower computer is
2. Install tools such as the cross-compilation environment arm-linux-gcc. Methods can be found online. Assume that the version has been installed and is 3.4.1. Path:/usr/local/arm/3.4.1/bin. And create environment variables.
3. Let's test a simple example.

/* Hello. c */
# Include
Int main ()
Printf ("hello word! \ N ");
Return 0;
After the program is lost, confirm it is correct and save it. Enter the directory where the program file is located
# Arm-linux-gcc hello. c-o hello

Put the hello file in the nfs shared directory/home/xxx/work/, and execute hello program./hello on the serial port terminal.
4. To install gdb and gdbserver remotely debug gdbserver, you must also install the gdb remote debugging tool:
The source code package of gdb can be downloaded from http: // what I download is gdb-6.6. Download to a directory, the author downloads to his own user directory
After the download, go to the directory and configure the compilation steps as follows:
# Tar jxvf gdb-6.6-tar-bz2
# Cd gdb-6.6
#./Configure -- target = arm-linux -- prefix =/usr/local/arm-gdb-v
# After executing make in this step, I will see the following error: Maid: 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_result: the compilation is interrupted because the returned value is not received. This is because-Werror is added to the makefile, and the warning is treated as an error. Delete the-Werror option in the following files and save it to re-compile. successful
Bfd/Makefile: 185: WARN_CFLAGS =-W-Wall-Wstrict-prototypes-Wmissing-prototypes-Werror
Opcodes/Makefile: 175: WARN_CFLAGS =-W-Wall-Wstrict-prototypes-Wmissing-prototypes-Werror: # make install
# Export PATH = $ PATH:/usr/local/arm-gdb
Go to the gdbserver directory (under 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 arm-Linux-GCC, which may be different from yours.) at this time, another error may occur: /usr/local/ARM/3.4.1/bin/ARM-Linux-gcc-C-wall-g-O2-I. -I. -I. /.. /regformats-I. /.. /.. /include-I .. /.. /BFD-I. /.. /.. linux-arm-low.c/BFD

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 of ubuntu, you can add-I/usr/include

Run:/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, and burn it to the root file system partition of flash, or use nfs mount. You only need to ensure that gdbserver can run on the Development Board.

5. install necessary library

If your embedded linux does not have the library installed, running gdbserver on the board will prompt an error. The solution is as follows:

Copy the files under/usr/local/arm/3.4.1/arm-linux/lib in your arm-linux-gcc cross-compiling environment to the root directory of the TE2440 Development Board /lib (you can first put it in the nfs shared folder and then enter the Copy command in the serial port terminal ). And create a soft link to the in the/lib directory.

Command: # ln-s

After running gdbserver./gdbserver again, the system does not prompt that the database cannot be found.

6. debug the hello program

To debug gdb, start the gdbserver service on the target system. Enter the command in the directory where gdbserver is located: (Serial Port Terminal)
# Cd/tmp
#./Gdbserver 2345 hello is the host machine IP address, and a debugging process is enabled on port 2345 of the target system (avoid using the port number below 1024). hello is the program to be debugged.
Process/tmp/hello created: pid = "80"
Listening on port 2345


# Cd/

# Export Path = $ path:/usr/local/ARM-GDB/bin
# Arm-Linux-GDB hello
(GDB) target remote 2345
( is the Development Board IP address)
Remote debugging using 2345
[New thread 80]
[Switching to thread 80]
0x40002a90 in ?? ()
At the same time, the terminal prompts in the serial port:
Remote debugging from host
After successful connection, you can enter various gdb commands such as list, run, next, step, and break to debug the program. As for 0x40002a90 in ?? () The problem is that the shared library path of arm-linux-gdb is not set. The library file cannot be found. You can solve the problem by entering the following statements. Set solib-absolute-prefix/usr/local/arm/4.4.3/arm-none-linux-gnueabi/sys-root/is the reprinted content. But after my practice: found that the bfd/elf32-arm.c/Makefile opcodes/Makefile change, there is also a return value for no errors. Is/gdb/cli/cli-cmds.c of a file does not return the value of getcwd processing is also reported, so the previous/gdb directory Makefile to change, change WERROR_CFLAGS =-Werror to WRROR_CFLAGS =. After the-Werror is deleted, run make. It should be noted that the Makefile in the entire gdb package does not exist after being decompressed and is executed. according to Makefile. in, Makefile. am and so on. /configure is used to generate the Makefile file. If an error occurs when you execute make, do not execute Makefile after you change the Makefile. /configure. Execute make directly. Otherwise, the modified Makefile is restored after./configure is executed.
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: 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.