Gdbserver implementation of remote debugging (tested through)

Source: Internet
Author: User
Tags bz2 parse error
The concrete realization of Gdbserver remote debugging

Author: Nguin from: http://www.linuxdiyf.com
I am using the NFS target board to mount the local directory method, of course, first of all, you have to open the local NFS shared services, the following steps:
1, into the/etc directory, VIM exports this file, add/home 192.168.0.* (Rw,sync) after the Save exit
Note:/home is the name of the folder to be shared, 192.168.0.* is allowed to access the client IP for this NFS server, if NFS is unsuccessful, the following parameters RW ro and other flags on the folder operation permissions, Sync: Data synchronization write memory and hard drive, you can also use async, The data is temporarily stored in memory and not written to the hard disk immediately. You can remove the sync inside 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 (Speed mount speed)
4, Mount 192.168.0.47 (IP for this machine):/HOME/MNT is used to test whether this machine is open for NFS service.
Cd/mnt directory to see if the content of the MNT is consistent with the content of the home, if consistent, indicating that NFS services have been opened.
When the local NFS service is open, you also need to configure the Development Board IP address, because each Development Board IP address configuration method is not the same, so assume the Development Board IP address is 192.168.2.100.
Steps to build a cross-compilation environment:
1, the general installation of Linux, the automatic installation of C compilation environment, so no need to reinstall the GCC compiler.
2, the installation of cross-compiler
From
ftp://ftp.arm.linux.org.uk/pub/armlinux/toolchain/
Download the cross compiler cross-3.2.tar.bz2, stored in the/usr/local directory.
Switch to this directory:
# cd/usr/local
# mkdir Arm
Then unzip the cross-3.2.tar.bz2:
# tar JXVF cross-3.2.tar.bz2–c/usr/local/arm
After decompression, the last arm of the/usr/local/arm/usr/local/arm is copied to/usr/local, which is the command cd/usr/local/arm/usr/local, with Cp-a arm/usr/ Local to copy arm into the/usr/local.
3, the intersection of the compiler path to add to the path. (Two methods of A,b)
A, # export path= $PATH:/usr/local/arm/bin
Note: (This can only be valid under the current terminal)
b, modify the/etc/profile file:
# Vim/etc/profile
Add the path setting, adding the following at the end:
Export path= $PATH:/usr/local/arm/bin
4. Make the new environment variable effective.
# Source/etc/profile
5, check whether the path to join the method.
# echo $PATH
If there is a/usr/local/arm/bin in the display, the path of the cross compiler is added. Since then, the cross-compilation environment installation is complete.
6, testing.
Let's test a simple example below.
/*hello.c*/
#include
int main ()
{
printf ("Hello word!\n");
return 0;
}
After the program is lost, confirm correct, save. Enter the directory where the program files reside
# ARM-LINUX-GCC Hello.c–o Hello
(-O can be understood as "target generation") ARM-LINUX-GCC is the first time that someone might ask where it came from, and you might want to open the cross-compilation tool directory that you just installed/usr/local/arm-linux/arm-linux/bin/ You can see that there is a ARM-LINUX-GCC file, this is the CPU for the arm of the GCC compiler. You can also see what the compiler is by using other compiler tools later in the chain. After compiling, you can download to the target machine for testing. Of course, you can test the correctness of the PC first. With gcc hello.c–o Hello, you can build a PC program, running./hello can find the terminal display hello! words. A program compiled with ARM-LINUX-GCC cannot be run on a PC, and error reporting after running: Unable to execute binary files. Indicates that a file compiled by a cross compilation environment is a hardware executable binary code file.
7, cross-compilation environment to build success.
To gdbserver remote debugging by line, you must also install the GDB Remote Debugging tool:
GDB's source code package 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, the author downloads to their own user directory:/home/vicky.
After downloading, enter the/home/vicky directory, 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 have a problem, the hint of a function (specific function name do not remember) Parse error, is unsigned the front of more than one "}", you use VI to enter that line to delete it on the line. There is no error in general. )
#make Install
#export path= $PATH:/usr/local/arm-gdb
Enter Gdbserver directory:
#./configure--target=arm-linux–host=arm-linux
#make CC=/USR/LOCAL/ARM/BIN/ARM-LINUX-GCC
(This step is to specify the position of ARM-LINUX-GCC, may not be the same as yours)
Make the Gdbserver executable file in the Gdbserver directory without error, burn it to the root file system partition of Flash, or mount it via NFS. Just make sure Gdbserver can run on the Development Board.
The following can be used Gdb+gdbserver debug our Development Board program. Running Gdbserver on the target board is actually under the minicom of the host, and my Red Hat Linux is installed under VMware. I did it after minicom #mount 192.168.2.100://tmp (where parameter-o nolock can be done without this step, but faster), Hello and Gdbserver are all located in the Linux root directory, Hang the host root directory in the/TMP directory on the Development Board.
To perform GDB debugging, first start the Gdbserver service on the target system. Enter the command in the directory where the Gdbserver resides:
(Under Minicom)
#cd/tmp
#./gdbserver 192.168.2.100:2345 Hello
192.168.2.100 for host IP, a debug process is opened on the 2345 port of the target system, hello for the program to be debugged.
Prompt appears:
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 for Development Board IP)
Prompt appears:
Remote Debugging using 192.168.2.223:2345
[New Thread 80]
[Switching to Thread 80]
0x40002a90 in?? ()
At the same time under the minicom hint:
Remote Debugging from Host 192.168.2.100
(GDB)
Connection is successful, this time you can enter a variety of GDB commands such as list, run, Next, step, break, and so on program debugging.
Note: In these steps of Remote debugging NFS configures and installs the cross compilation tool, and there is no order to install the GDB tool, only to configure the IP address of the Development Board before gdbserver the remote connection.
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.