- Experiment two embedded Linux program compiling and debugging
- Learn to use and configure Vim
- Mastering the GCC compiler's use
- Learn how to use GDB to step through the program
- Experimental requirements:
- Be familiar with using Vim described in this section to create, edit, and save files.
- The four processes of preprocessing, compiling, compiling and linking are implemented by GCC respectively.
- Compile a multi-file project with GCC and make a compilation script.
- Using GDB single-step debugging to fix the wrong program
- 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
- 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