Use trace statements
31. The outputdebugstring API function, the MFC afxoutputdebugstring macro, And the MFC afxdumpstack function are compiled in all versions, but all other trace statements can be compiled only when the _ debug symbol is defined.
32. Trace statements cannot contain program code or indirectly affect program code. The purpose of a tracing statement is to provide information to the programmer, not the user.
33. Differences from assertions:
(1) The tracing statement is unconditional. Assertion is a conditional Boolean statement, but the trace statement can always be executed.
(2) The tracing statement does not directly display bugs. Assertions are used to display bugs, while trace statements are used to display program execution and variable values.
(3) trace statements can be ignored at will. By default, assertions interrupt the execution of the program and a message box pops up waiting for the response from the user or programmer. The tracing statement outputs the information to the debugging window or file, so it is easy to be ignored by programmers. This feature makes the tracing statement ideal for the overall program inspection and program warning. A good analogy is that assertion is false to the compiler, And the tracing statement is used to warn the compiler.
34. Void outputdebugstring (lpctstr tracetext). This Windows API function is a part of windows, so it is always valid, which makes this function suitable for tracking during program startup and termination. In contrast, the C Runtime function libraries and MFC trace statements of Visual C ++ do not apply to the start and end of tracing programs, because they are only valid after their DLL is loaded. If you only want to use outputdebugstring In the debugging version, you can use the following macro:
# Ifdef _ debug
# Define outputtrancestring (text) outputdebugstring (text)
# Else
# Define outputtrancestring (text) (void) (0 ))
35. there are no trace statements in the ansi c ++ runtime function library, but it has an output stream for the standard character mode used for tracking, specifically: the stderr stream of C speech and the cerr and clog stream of C ++ language. Stderr does not require a buffer. cerr uses a unit buffer and clog uses a full buffer.
36. Use the MFC tracer tool to control the tracking statements output by the MFC itself
37. A policy is required for the effective use of Trace statements. Too many trace messages will reduce their validity. The following are two basic trace statement policies:
(1) supplemental policy of the debugger: Use a trace statement to supplement the information provided by the interactive debugger.
(2) debugger substitution policy: Use a trace statement instead of the interactive Debugger
38. the Integrated Diagnosis and tracking statement allows you to view the most important events in the program. The Special Diagnosis and tracking statement is used to solve a special problem. Once the problem has been fixed, delete the trace statement used for special diagnosis.
39. when the interactive debugger cannot solve the problem, such as debugging servers and cross-machine debugging (such as DCOM) programming Language debugging encounters programming statements, cross-process debugging encounters processes, debugging threads, remote debugging, and other program actions that are difficult to debug due to the uncertainty of the concept of heesburg. Use the tracking statement to solve the problem.
40. Tracking debugging skills
(1) Use the debugview Utility
(2) provide a redirection output setting.
(3) process long strings
(4) handling a large number of trace outputs
(5) generate the debugging report
(6) Output independent lines, and do not forget the newline character.
(7) Don't forget to check the tracing statement.
Note: whenever there is an error in your program and you want more information, you should check the tracing message.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.