Use C ++ instead of C (3) to use tracking statements

xiaoxiao2021-03-06  15

Use tracking statements

31.outputDebugstring API function, MFC AFXOUTDEBUGSTRING Macro and MFC AFXDUMPSTACK Functions are compiled in all versions, but all other tracking statements can be compiled only when the _debug symbol is defined.

32. Tracking statements cannot contain program code or have indirect effects on program code. The purpose of tracking statements is to provide information to programmers, not users.

33. Differences with assertions:

(1) Tracking statements are unconditional. As an assertion is a conditional Boolean sentence, and the tracking statement can always be implemented.

(2) Tracking statements do not display bugs directly. As an assertion is used to display the bug, the tracking statement is used to display the program execution and variable values.

(3) Tracking statements can be ignored casually. By default, the assertion program is executed, and pops up a message box waits for a user or programmer's response; tracking statements Output to debug window or files, so it is easy to be ignored by programmers. This feature makes the tracking statement for warnings for the overall programs inspect and programs. A good class is: assertions to compiler errors, tracking statements warning for compiler.

34.void OutputDebugString (LPCTSTR TRACETEXT), this Windows API function is part of Windows, so it has always been valid, which makes this function to be tracked in the program startup and end. In contrast, the Visual C C runtime correspondence library and the MFC tracking statement does not apply to the trace program startup and end because they are only valid after loading its DLL. If you just want to use OutputDebugstring in the debug version, you can use the following macro to implement:

#ifdef _Debug

#define OutputTranceString (Text) Outputdebugstring (Text)

#ELSE

#define outputTranceString (TEX) (Void) (0))

35. There is no tracking statement in the runtraine library, but it has the output stream of standard character mode for tracking, specific: C speech StderR stream and C language CERR and CLOG streams. Stderr does not require a buffer, CERR uses unit buffers, and Clog uses full buffer.

36. Using the MFC Tracer tool to control the tracking statement output by the MFC itself

37. The valid use of the tracking statement requires a policy, too many tracking messages reduce their validity. The following is two basic tracking statement strategies:

(1) Debugger Supplementary Policy: Use the tracking statement to supplement the information provided by the interactive debugger

(2) Debugger instead of the policy: use the tracking statement instead of interactive debugger

38. Using the integrated diagnostic tracking statement allows you to view the most important incidents in the program; use special diagnostic tracking statements to solve a special problem; once the determined problem has been resolved, the tracking statement for special diagnosis is deleted.

39. In the case where the interactive debugger does not solve the problem, such as debugging servers, cross-machine debugging (such as DCOM), the exaggeration design language call encounters programming statements, cross-process debugging encounters process, debug thread, remote debugging, Extending procedures that are difficult to debug due to uncertain principles of Hessianburg. Use the tracking statement to solve the problem.

40. Tracking debugging skills

(1) Use the DebugView utility

(2) Consider providing a redirect output settings

(3) Treatment of long strings

(4) Handling a large number of tracking output

(5) Produce commissioning report

(6) Output independent lines, and don't forget the newLine characters

(7) Don't forget to check the tracking statement

Note: Whenever there is an error in your program and you want more information, you should check the tracking message.

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

New Post(0)