Cross-Compiling of GDB and gdbserver in Linux

Source: Internet
Author: User
Tags gdb debugger

 

As the saying goes: to do good deeds, first put it on your machine.
A debugger must be generated before debugging embedded systems. Generally, the debugger in Linux is GDB.
This article only describes how to generate a debugger. It does not involve reasoning. You need to find a theory, a teacher, or a textbook.

1. Download GDB:
Is:

Http://ftp.gnu.org/gnu/gdb/

Generally, the latest version is better. Therefore, download the version 7.2. Of course, nothing is absolute.
Take the file gdb-7.2.tar.bz2 as an example.
2. decompress:

$ Tar jxvf gdb-7.2.tar.bz2

Note: Tips: The general compressed files under linuxare suffixed with .tar.bz2and .tar.gz. The decompressing commands have two or three options:

XF (V), the former with the J option, and the latter with the Z option.

3. Enter the Directory

$ CD gdb-7.2/

4. Configuration

$./Configure -- target = arm-Linux -- Program-Prefix = arm-Linux--- prefix =/usr/local/ARM-GDB

Note: -- Target = arm-LinuxThe target platform is the Linux kernel running on the ARM architecture.; -- Program-Prefix = arm-Linux-Indicates the prefix of the generated executable file, such as arm-Linux-GDB., -- PrefixIt refers to the directory in which the generated executable file is installed. This directory needs to be selected based on the actual situation. If the directory does not exist, it is automatically created. Of course, the permission is sufficient.

5. Compile and install

$ Make

$ Make install

Fortunately, three subdirectories are generated under the directory specified by -- prefix: Bin, Lib, and share. The arm-Linux-GDB we need is in the bin directory.
If you accidentally check its size, you will find it is as large as 14 MB! Oh, my God! How does one occupy so much space? It doesn't matter. We can slim it down. That's right! The strip command is used!

$ Strip arm-Linux-GDB-O arm-Linux-GDB-stripped
$ LS-lH
Total 33 m

-Rwxr-XR-x 1 latelee root 14 m 12-14 16:16 arm-Linux-GDB

-Rwxr-XR-x 1 latelee root 3.1 m 12-14 arm-Linux-GDB-stripped

 

As you can see, the strip file size is only 3.1 MB, and the slimming effect is obvious! It is absolutely convincing to advertise.
This file is the cross-debugger that we will run on the host during remote debugging: it is executed on the host, but the code for debugging is another architecture. However, the host-only debugger is not enough. You also need to run a gdbserver on the target board. How did this stuff come from?

1. In the directory of the gdb decompressed just now: gdb-7.2, enter the./GDB/gdbserver subdirectory

$ Cd gdb/gdbserver

$ Pwd

/Home/gotohell/soft/gdb-7.2/GDB/gdbserver

2. Configuration

$./Configure -- target = arm-Linux -- Host = arm-Linux

Here-- HostPlatform and system for generating executable files: Linux system running on ARM platform
3. Compile

$ Make

If everything is okay, gdbserver will be generated in the current directory, which only runs under arm.

Note: most of the information on the Internet shows that the make statement is incorrect, indicating that a header file does not exist. I personally became handsome and did not find that problem in GDB 7.2. If the version is earlier than 7.2, you must pay attention to it. The solution is also simple. After the configuration (execute./configure ),

# Define have_sys_reg_h 1

Comment out the statement.
In addition, it is also suggested that the cross-compiler (execute make cc = arm-Linux-GCC) must be specified to compile gdbserver. However, it is okay to make it directly here. Of course, the cross compiler must be installed and environment variables configured. Let's take a look at this guy:

$ File gdbserver

Gdbserver: Elf 32-bit LSB executable, arm, Version 1 (sysv), dynamically linked (uses

Shared libs), for GNU/Linux 2.6.14, not stripped

32-bit, ARM platform, dynamic link, not strip.
Similarly, we also reduce its volume:

$ Arm-Linux-strip gdbserver-O gdbserver-stripped

$ LS-lH | grep gdbserver

-Rwxr-XR-x 1 latelee root 534 K 12-14 gdbserver

-Rwxr-XR-x 1 latelee root 173 K 12-14 gdbserver-stripped

The slimming effect is equally obvious!
Note that the cross-version of Strip must be used here, that isArm-Linux-strip.

At this point, we have generated two heavyweight files:Arm-Linux-GDBAndGdbserver. Their versions are consistent, which is very important. We need to download the gdbserver to the development board. We can use a variety of methods, including but not limited to NFS. You need to run this program on the Development Board during debugging. Execute the arm-Linux-gdb debugger on the host.

(The HTML syntax coloring tool is provided by Li Chi, the studio of latelee. "latelee" is the reserved term in the system and appears in a bold red font)

As for the debugging technology and debugging steps, it is not within the scope of this article. In subsequent articles, the relevant content may probably appear. You don't have to wait.

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.