Compilation and debugging are often two important points in editing, so the choice of compiler and debugger becomes crucial, today, we will tell you how to use C ++ as the compiler and debugger selection element for Linux development tools, so that you can start the development more efficiently.
Compilation and debugging are often two important points in editing, so the choice of compiler and debugger becomes crucial, today, we will tell you how to use C ++ as the compiler and debugger selection elements for Linux development tools, so that you can develop them more efficiently.
Compiler
GCC (gnu compiler collection) is the preferred COMPILER for Linux development tools using C ++ ). There are two reasons: it is open-source by GNU, and it supports up to 96.15% of standard C ++. The support of VC ++ 6.0 is only 83.43%. GCC is not only a C or C ++ compiler in the general sense, but also can compile other languages such as java. Gcc is the gnu c Compiler, g ++ is the gnu c ++ Compiler, and EGCS (Enhanced GNU Compiler Suite) can be considered as the gcc Compiler version.
The compilation language goes through the following phases from the source program to the target code: Source Program> assembler> obj program> link to the final executable program. We can use a compilation Command to complete all the steps. It can also be executed step by step. Gcc has three important options:-E (preprocessing only),-S (generating assembly code), and-g (generating executable files with the original code debugging symbol, if you want to use gdb for debugging, you should enable this option during compilation ).
GCC, a Linux development tool using C ++, can be considered as a software package. in addition to the compilation tool, it also integrates the Debugger gdb, the performance analysis tool gcov, and gprof. As long as GCC is installed, these powerful tools can be used directly.
With gcov, we can view the number of times each line of code runs in the source code of a program. We can optimize the program by optimizing the code that runs the most frequently. When using gcov, you need to enable the fprofile-arcs and ftest-coverage options of GCC. Common options in gcov include-B branch statistics.
With the gprof tool, we can view the call sequence between functions and the running time of each function. We can understand gprof as an enhanced version of the linux/unix built-in tool time. When using gprof, you must enable the pg option of GCC.
What gcov and gprof have in common is to add some auxiliary information to compile the program for program diagnosis. In addition to these optimization methods, we can also use some memory leak tools to reduce wild pointers and unreleased memory space.
Debugger
Using C ++ as a Linux development tool, GDB is the GNU Debugger. it is a high-performance debugger attached to GCC. Through the combination of GDB and script, we can implement regression testing well.
GDB, a Linux development tool using C ++, can run in CLI and GUI modes. By default, GDB is in CLI mode. you can download and install GDB in GUI mode, such as xxgdb and ddd. A better way is to use GDB in EMACS. GDB includes all the debugging functions of the visual studio tool and functions that it does not have. In addition to support, we generally set breakpoints, single-step tracking, step in, step out, step over, and other powerful functions. In gdb, we can use the following pause methods: BreakPoint, WatchPoint, CatchPoint, Signals, and Thread Stops ).
The following lists some impressive features. 1) the watch command can suspend a program when the value of a variable changes. 2) run the print command to set the variable value and run a method supported by a program. 3) through the until command, we can pause the program when it runs to a program. 4) use the break .. if command to suspend a program when it meets a bool expression.