Guide to debug (debug) when programming C/C++ with Dev C++
- 24-07-2022
- trienkhaiweb
- 0 Comments
In programming, a lot of problems can happen that we don't anticipate causing the program to crash without notice. error, or run not according to our will, maybe due to the wrong algorithm, missing declaration, incorrect memory allocation …. Then we need the power of the IDE.
Debugging Concepts
Debugging is the process of finding errors that prevent a computer program or system from working properly. First we need to determine whether your DevC++ is 32bit or 64bit, after determining we choose 64bit-Debug or 32bit-Debug Check the Compiler option and add the -static-libgcc parameter as shown below: Then we look at the line index of the editor, and select the red point that represents that when running debug, will start running debugging at that line of code (breakpoint), example below: The next step is to look down and select debug (or press F5) to open the Debug management window Description of Dev C++ debugging features:
- Debug : click to start the debug process
- Add watch : add variables or expressions that we want to monitor during the debug run and how they change.
- There are 2 ways to add add watch:
- Method 1: pressing add watch will display a line for us to enter variables and expressions
- Method 2: you can highlight the variable or expression and then click add watch
- After adding you choose the debug window as follows to track the value of the added variable
- There are 2 ways to add add watch:
- Next line (F7) : Jump to the next line, but we have to pay attention, if you abbreviate the code to shorten the program, the code will be skipped and jump to the next line, if you are sure your code is correct, it's okay, otherwise, it should be written explicitly so that the program can debug correctly.
- Stop execution : stop the debugging process
- Into function : has the function to access the function.
- Skip function : Exit the running function. (The opposite of into function)
Debugging is an important step that programmers must know, especially when learning any programming language, they should learn the debugging features that the IDE provides for easy access. more programming when we don't know the algorithm or the program crashes unexpectedly and we don't know where the error is located inside the program. Most IDEs provide debugging features, for experienced programmers, they rarely use debug or debug by printing variables to the screen to diagnose errors, however, for newbies, the Thanks to the computer to help us debug clearly better, right?