5.2 Embedded Linux program compilation and debugging

Source: Internet
Author: User

    1. Experiment two embedded Linux program compiling and debugging
    • Experimental Purpose:
    1. Learn to use and configure Vim
    2. Mastering the GCC compiler's use
    3. Learn how to use GDB to step through the program
    • Experimental requirements:
    1. Be familiar with using Vim described in this section to create, edit, and save files.
    2. The four processes of preprocessing, compiling, compiling and linking are implemented by GCC respectively.
    3. Compile a multi-file project with GCC and make a compilation script.
    4. Using GDB single-step debugging to fix the wrong program
    • Experimental steps:
    1. Use GCC to preprocess, compile, assemble, link four processes, compile multi-file projects with GCC, and make compilation scripts.

      1. GCC process compilation four processes

      1. Source

?

(2), pretreatment

Generate main.i preprocessing files to implement header files, macros, precompiled deployment

?

(3), compiling

Generate Main. S assembly file

(4), compilation

Finally call the as assembler to generate the MAIN.O binary target file from the assembly file

?

(5), link

Finally, the LD Linker is called to link the target file into an executable file.

2. Multi-File Project compilation

(1), File directory structure

The custom header file is placed in the INC directory, and the auxiliary module source files are placed in the SRC directory

(2), compile script

?

Compiling an executable with debug information

(3), perform compilation

????

(4), compile results

After running the debugging, you can strip out the extra symbol information and publish it.

Second, the use of GDB single-Step Debugging correction Results Error Program

1, the wrong program source code,

2. Compile the program

3. Running the program

Inverse string printing results are not displayed properly!

4, using GDB debugging positioning problems

(1), Start GDB load Debug Program

???? (2), breakpoint to problematic function

?

???? (3), execute the program, run to the breakpoint

?

???? (4), Display problem function code

?

(5), breakpoint to problem-generating point

?

(6), continue to execute, stop at the problem-generating point

?

(7), display problem variables

?

The array position is shifted back a bit backwards when the string is reversed:

should read:

?

(7), modify code, program compile and run validation

Experiment Experience:

???? This experiment is to realize the simple compiling and debugging of the embedded Linux program, mainly let us learn how to debug, deeply realize every step of program execution, understand the actual process of program running.

5.2 Embedded Linux program compilation and debugging

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.