Preface:
Beginners after learning the makefile knowledge, full of confidence, the inner feel that should be good to learn not only to master the language of the writing, but also to learn the corresponding tools to adjust the development efficiency. Sometimes we write the code after the execution of the results and we do not expect the same, what to do, this time will have to debug. When it comes to debugging experienced development children's shoes know in Windows downstream of the well-known VS integration Platform, then under Linux, especially C, C + + have what tools to facilitate our debugging, here I recommend to everyone is GDB, it is also GNU debugger, specifically for debugging.
Knowledge Points:
GDB is broadly divided into the following functions:
1. Start the program;
2. Can be debugged through breakpoints;
3. Stop at the breakpoint to see the status of the operation;
4. Can dynamically change the execution of the environment, including the system environment, system variables, local variables and so on;
Principle:
At the time of compiling debugging information (such as breakpoints, output debugging information, etc.), execute GDB debugging, the program will be executed in accordance with the debugging information in the order of the breakpoint, the output of debugging information and so on to facilitate the programmer debugging program, one time to observe the program in the running of everything. This is done by creating a simple example of GCC compilation, GDB startup, and debugging steps.
Practice:
1. First create a simple gdbtest.c file with the following content:
#include <stdio.h>int main (void) { int a = 1; int b = 2; int C = a + B; printf ("Result:%d", c); return 0; }
2. Compile as follows:
Gcc-wall-g gdbtest.c-o gdbtest #-g parameters
3. Start gdb and load the gdbtest executable file:
GDB #直接在当前gdbtest. C directory, type GDB command into the debugger
File Gdbtest #在gdb命令下输入此命令加载文件, output reading symbols from gdbtest ... done means load complete
4. Use the command l to view the file the code is listed and the tag is OK, remember the line number or function name so as to break the point;
5. Use format: b function (line number) break point, enter command: b Main or: B 3 effect is the same!
6. Using the R command to run the program will pause at the breakpoint, you can use the S command to perform the next step, you can use the P print variable information to view the related variables:
7. You can also use the command: disassemble main to see the assembly code of the main function, this application is more advanced tricks!
This class will be the first to understand the next gdb and simple motion gdb to do simple debugging. Continue tomorrow!! 1