Practical Tips: specific implementation of Gdbserver remote debugging

Source: Internet
Author: User
Tags parse error

 

The nfs target board is used to mount the local directory. First of all, you must activate the local nfs sharing service. The specific steps are as follows:

1. Go to the/etc directory, and add/home 192.168.0. * (rw, sync) to the vim exports file. Save the file and exit.

Note:/home is the name of the folder to be shared, 192.168.0. * This is the ip address of the client that is allowed to access the NFS server. If nfs fails, the Operation permission on the folder is indicated by the rw ro parameter. sync: data is synchronized to the memory and hard disk. You can also use async, at this time, the data is saved in the memory, instead of immediately written to the hard disk. You can remove the sync in the brackets.

2. restart the nfs service. The command is/sbin/service nfs restart.

3. Enter the command route del default to close the gateway (accelerate the mount speed)

4. mount 192.168.0.47 (the ip address of the Local Machine):/home/mnt is used to test whether the local machine has activated the nfs service.

In the cd/mnt directory, check whether the content in mnt is consistent with that in home. If the content is consistent, the nfs service has been activated.

When the nfs service of the local machine is activated, you also need to configure the IP address of the Development Board. Because the IP address of each development board is configured differently, assume that the IP address of the Development Board is 192.168.2.100.

To build a cross-compilation environment:

1. Generally, the c compiling environment is automatically installed when linux is installed. Therefore, you do not need to reinstall the gcc compiler.

2. Install the Cross Compiler

Download the cross-compiler cross-3.2.tar.bz2 from ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/and store it in the/usr/local directory.

Switch to this directory:

# Cd/usr/local

# Mkdir arm

Then decompress cross-3.2.tar.bz2:

# Tar jxvf cross-3.2.tar.bz2-C/usr/local/arm

Decompress the package and copy the last arm in/usr/local/arm to/usr/local, that is, run the command cd/usr/local/arm/usr/local to copy the arm to/usr/local using cp-a arm/usr/local.

3. Add the PATH of the cross compiler to the PATH. (Two methods: a and B)

A, # export PATH = $ PATH:/usr/local/arm/bin

Note: (this is only valid under the current terminal ,)

B. Modify the/etc/profile file:

# Vim/etc/profile

Add the path settings as follows:

Export PATH = $ PATH:/usr/local/arm/bin

4. Make the new environment variable take effect.

# Source/etc/profile

5. Check whether the PATH is added to the PATH.

# Echo $ PATH

If/usr/local/arm/bin is displayed, the PATH of the cross compiler is added to PATH. Since then, the cross-compilation environment has been installed.

6. Test.

Let's test a simple example.

/* Hello. c */

# Include

Int main ()

{

Printf ("hello word !");

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

(-O can be understood as "Generate as the target") arm-linux-gcc is the first time, and someone may ask where to come from, open the installed cross-compilation tool directory/usr/local/arm-linux/bin/and you will find an arm-linux-gcc file in it, this is the gcc compiler for arm CPU. In the future, you can use other compilation tool chain to see what the compiler is. After compilation, you can download it to the target machine for testing. Of course, you can test the correctness on a PC first. You can use gcc hello. c-o hello to generate a program on the PC, and run./hello to find that the terminal displays hello! . A program compiled with arm-linux-gcc cannot run on a PC. After running the program, an error report is provided: the binary file cannot be executed. It indicates that the files compiled in the Cross-compilation environment are binary code files that can be executed by hardware.

7. The cross-compilation environment is successfully set up.

To perform remote gdbserver debugging, you must install the gdb remote debugging tool:

The source code package of gdb can be downloaded from http: // ftp.cs.pu.edu.tw/linux/sourceware/gdb/releases/, and the latest version is gdb-6.4. Download to a directory, and download to your own user directory:/home/vicky.

After the download, go to the/home/vicky directory and configure the compilation steps as follows:

# Tar jxvf gdb-6.4-tar-bz2

# Cd gdb-6.4

#./Configure -- target = arm-linux -- prefix =/usr/local/arm-gdb-v

# Make

(This step may cause a problem, prompting a function (the specific function name does not remember) parse error, that is, an "}" is added before the unsigned side "}", you can use vi to enter that line and delete it. Generally, no error occurs .)

# Make install

# Export PATH = $ PATH:/usr/local/arm-gdb

Go to the gdbserver directory:

#./Configure -- target = arm-linux-host = arm-linux

# Make CC =/usr/local/arm/bin/arm-linux-gcc

(This step specifies the location of arm-linux-gcc, which may be different from yours)

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.

Next we can use gdb + gdbserver to debug the program on our development board. Running gdbserver on the target board is actually running under the minicom of the host machine, and my red hat linux is installed under vmware. I did it after # mount 192.168.2.100: // tmp under minicom (here the-o nolock parameter can be left blank, but it is faster to execute this step without adding it ), hello and gdbserver are both located in the linux root directory, and the host root directory is mounted to the/tmp directory of the Development Board.

To debug gdb, start the gdbserver service on the target system. Enter the following command in the directory where gdbserver is located:

(Under minicom)

# Cd/tmp

#./Gdbserver 192.168.2.100: 2345 hello

192.168.2.100 is the host machine IP address, and a debugging process is enabled on port 2345 of the target system. hello is the program to be debugged.

Prompt:

Process/tmp/hello created: pid = "80"

Listening on port 2345

(Under another Terminal)

# 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 is the Development Board IP address)

Prompt:

Remote debugging using 192.168.2.223: 2345

[New thread 80]

[Switching to thread 80]

0x40002a90 in ?? ()

At the same time, the following message is displayed under minicom:

Remot

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.