C ++ Builder debugging technology

xiaoxiao2021-03-06  97

C Builder debugging technology

During the software development process, debugging is an important link, and debugging skills are also important skills that developers must master. Now developing tools, such as C Builder, usually provide a powerful debugger. A good debugger, plus an experienced developer, so that the software quickly develops from the original state to the code with the publish quality. The debugger provides some tools to check the status of running software, and developers should have insights to explain this information. The following is some of my questions and answers I am using the C Builder process about debugging technology, welcome to supplement and correct.

N q: In VC, you can compile parameter debug or ndebug, which can compile DEBUG and non-DEBUG version with different parameters. I don't know how to do it in C Builder?

A: It can also be done in C Builder, the method is to click on the menu Project | Options ..., open the engineering properties:

In Conditional Defines, you can define compilation parameters, the following code, if the condition is defined as NDebug, the output result is "The Actual Messages", if the above condition is defined as debug, the output is "The debugging message".

#ifdef debug

ShowMessage ("THE Debugging Messages);

#ELSE

ShowMessage ("THE Actual Messages");

#ENDIF

Note that the above conditions are compilation parameters, and the project is set to Full Debug or Release has no relationship. That is

It is said that debugging information is also output if the project is set to debug, even if Conditional Defines is set to Debug.

N Q: Why do you need to compile parameter debug or ndebug to compile different versions.

A: In addition to using a software debugger, we can also insert some statements in the debug phase to record log information, then write this information into a console, file, or other output device. The advantage of doing this is that there are many bugs related to time. It is also important to remove debug statements from published products because some sensitive information about product implementation may leak out by debug messages. If you are mastered by the competitors, this information may derive a lot of information. One way is to insert a number of SHOWMessage statements in the development phase, remove these statements one by one after the product is released. However, manual will remove these statements, not only time, and it is easy to miss. After the product is released, if you find a bug, you should restore these debug statements to track problems, what should I do? The solution is to bring the compilation parameter debug or ndebug, generate a suitable version according to your own needs, without modifying the code.

n q: In multi-threaded program, because the order of execution of a code is uncertain, it is not possible to use the breakpoint track of C Builder. What debugging method should I use?

A: It should be pointed out that even the multi-threaded program, you can use C Builder's breakpoint tracking technology, just need more patience and skills. Because regardless of the multi-threaded operation timing, for one of the threads, it must be done according to the timing, we can firmly focus on the code to be executed by this thread, eliminate the interference of other code execution, you can track our result. The extreme case is not using a single step, and each statement is plus a breakpoint. Another possible situation is that although a thread is an execution sequence, other threads may also be such a code, which may appear to perform a fifth statement, suddenly jump to the first statement execution. For this situation, we are giving threads to identify threads when you create a thread, so you know that the thread that we want to track is running when tracing. n q: Some problems can only be found on the scene. Is there a technology that sets a switch variable, if it is opened, then output debugging information, otherwise, do not perform output debugging information, improve efficiency?

A: Indeed, it is now found that there are only some questions that appear on the spot, which cannot be reproduced in the test environment, or if you need a lot of strength, you can reproduce the problem, which also brings us additional maintenance. Specifically, this is not a technical problem, because only one switch variable is needed, you can choose between output and no output, this is just a program habit:

1) Use of useful information in a critical location (or location, such as connection data, etc.).

2) Whether a unified output class is used, which can output this information to the same location, or determine whether to output (otherwise, output to a different location, some output, some do not output, easy to cause confusion).

转载请注明原文地址:https://www.9cbs.com/read-104292.html

New Post(0)