VC debugging collection

Source: Internet
Author: User

 

During debugging, you can modify eax to change the return value of the function.

 

Collect VC debugging skills-program art-51cto technical blog Login
Collect and organize VC debugging skills
Debugging is the most basic skill of a programmer. It is more important than learning a language. A programmer who does not debug means that, even if he can speak a language, he cannot compile any good software.
Here I will briefly list the skills that are commonly used in debugging based on my own experience and hope to be useful to you. This article stipulates that, when selecting a menu, the hierarchical menu is represented by/. For example, file/Open indicates that the sub-menu of the top menu file is open.


1. Settings
To debug a program, you must first include debugging information in the program. Generally, a project created from Appwizard contains the debug
Configuration automatically contains debugging information, but whether the debug version is not the deciding factor of the program containing debugging information, the program designer can add debugging information, including the release version, in any configuration.
To add debugging information, follow these steps:

A. Open the Project Settings dialog box (you can press the shortcut key Alt + F7 to open it, or open it through the IDE menu Project/settings)

B. Select the C/C ++ page, and select general in category. A debug info drop-down list box is displayed. The debugging information options include:
None:
No debugging information
Line numbers only:
The target file or executable file only contains the global and exported symbols and code line information, excluding the symbol debugging information.
C7 compatible:
The target file or executable file contains the line number and all symbol debugging information, including the variable name and type. Function and prototype.
Program database:
Create a library (PDB), including type information and symbol debugging information.
Program database for edit and continue:
In addition to the above functions, this option allows you to modify and continue the code during debugging.
This option also invalidates the optimization function set by # pragma.

C select the link page, and select the check box "Generate debug info". This option will allow the connector to write debugging information into the executable file and DLL
. If the options above program database are set on the C/C ++ page, Link
Incrementally can be selected. By selecting this option, the program can be compiled (that is, incremental compilation) on the basis of the previous compilation, rather than starting from the beginning each time.


2 breakpoint
Breakpoint is a code position set by the debugger. When the program runs to a breakpoint, the program is interrupted and returned to the debugger. Breakpoint is
The most common technique. During debugging, the program can be debugged online only when a breakpoint is set and the program is returned to the debugger.

Set a breakpoint: you can set a breakpoint in the following ways. First, move the cursor to the line of code that requires breakpoint settings, and then
Press the F9 shortcut key
In the breakpoints dialog box, press Ctrl + B or Alt + F9, or click Edit/breakpoints. Click break.
At, select the appropriate location information from the arrow on the right of the editing box. Generally, select line
XXX is enough. If you want to set a breakpoint that is not the current position, you can select Advanced and enter the function, row number, and executable file information.
Remove breakpoint: move the cursor to the row where the specified breakpoint is located, and press F9 again to cancel the breakpoint. As described above, after the breakpoints dialog box is opened, you can also remove the breakpoint as prompted.

Conditional breakpoint: you can set a condition for a breakpoint. Such a breakpoint is called a conditional breakpoint. For newly added breakpoints, you can click the conditions button to set an expression for the breakpoint. When this expression changes, the program
Interrupted. The following settings include "number of elements in the Observation Array or structure". It seems that the size of the memory zone pointed to by a pointer can be set, but I set a comparison value but changed it.
Memory areas out of the scope also seem to cause breakpoint to take effect. The last setting allows the program to be executed several times before the breakpoint is reached.

Data breakpoint: The data breakpoint can only be set in the breakpoints dialog box. Select the "data" page to display the dialog box for setting data breakpoints. Enter an expression in the edit box.
When the expression value changes, the data breakpoint is reached. Generally, this expression should consist of operators and global variables. For example, enter
G_bflag is the name of the global variable, so when the program has g_bflag =! G_bflag, the program stops at this statement.

Message breakpoint: VC also supports interception of Windows messages. There are two methods for interception: window message processing function and specific message interruption. In the breakpoints dialog box, select the message page to set the message breakpoint. If the name of the message processing function is written in the dialog box above
Each time a message is processed by this function, the breakpoint is reached (I think the effect should be the same if a normal breakpoint is used to intercept the message in this function ). If the drop-down
If a message is selected in the list box, the program is interrupted every time the message arrives.


3 Watch
VC supports viewing the values of variables, expressions, and memory. All these observations must be performed when the breakpoint is interrupted.
The viewing variable value is the simplest. When the breakpoint arrives, move the cursor over the variable and you will be able to see the value of the variable after a while.
VC provides a watch mechanism to watch the values of variables and expressions. In the breakpoint status, right-click the variable and choose quick watch,
A dialog box is displayed, showing the value of this variable.
Click the watch button on the debug toolbar to display a watch view (wattings, watch2, watch3, and watmethane). Enter a variable or expression in the view to observe it.
Variable or expression value. Note: This expression does not have any side effects. For example, the ++ operator is definitely forbidden to be used in this expression, because this operator will modify the value of the variable, resulting in the destruction of the software logic.


4 Memory
Because the pointer points to an array, watch can only display the value of the first element. You can use the memory function to display the subsequent content of an array or a piece of memory. In
Click the memory button on the debug toolbar to bring up a dialog box where you can enter an address to display the memory content pointed to by this address.


5 varibles
The varibles button on the debug toolbar displays the values of all variables visible in the current execution context. In particular, the variables involved in the current command are displayed in red.


6 registers
The reigsters button on the debug toolbar pops up to display the values of all current registers.


7. Process Control
VC allows the interrupted program to continue running, run in a single step, and run at the specified cursor, corresponding to the shortcut keys F5, F10/F11, and CTRL + F10 respectively. Each shortcut key has the following functions:
Shortcut Key description
F5 Continues Running
F10 in a single step. If a subfunction is involved, it is not included in the subfunction.
F11: in a single step, if a sub-function is involved, enter the sub-function.
CTRL + F10 run to the current cursor.


8 call stack
The call stack reflects the sequence in which the current breakpoint function is called. Click call stack on the debug toolbar to display the call
Stack dialog box. The callstack dialog box displays a call series. The top part is the current function, and the top part is the upper-level function that calls the function in sequence. Click these function names to jump to the corresponding function.


9 Other debugging methods
The system provides a series of special functions or macros to process information related to the debug version, as follows:

10 macro name/Function Name Description
The trace usage is exactly the same as that of printf. It outputs debugging information in the output box.
Assert receives an expression. If the expression is true, no action is taken; otherwise, the current program is interrupted. This macro appears in the system.
The interruption caused should be deemed that your function call does not meet the system's prerequisites for calling this function. For example, setwindowtext is called for a window that has not yet been created.
The Verify and assert functions are similar. The difference is that in the release version, assert does not calculate the value of the input expression, but verify calculates the value of the expression.

Follow:
A good programmer should not give all the judgment to the compiler and debugger, and should implement program protection and error locating in the program. Specific measures include:

For all functions with returned values, you should check the returned values unless you are sure that this function call will never go wrong, or you do not care if it is wrong.
Some functions return errors. You need to use other functions to obtain the error details. For example, if accept returns invalid_socket, the accept fails.
For specific failure causes, you should immediately use wsagetlasterror to obtain the error code and solve the problem accordingly.
Some functions throw an error through the exception mechanism and use the try-catch statement to check the error.
Programmers should handle the errors they can handle at the underlying level. If they cannot handle the errors, they should report the errors to users so that they can decide how to handle them. If an exception occurs in the program,
However, the error information returned by the return value and other mechanisms is not judged, which only increases the difficulty of searching for errors.
In addition, to compile programs in VC, you should not write CPP/H files at the beginning, but create a suitable project first. Because only in this way can VC select the appropriate compilation and Connection
. For CPP files added to the project, check whether the stdafx. h header file is explicitly included in the first line. This is Microsoft Visual
The precompiled header file that studio sets to accelerate compilation. In this # include
All the code before the "stdafx. H" line will be ignored, so other header files should be included after this line.
Because the. c file cannot contain stdafx. H, you can use project settings to set its pre-compilation header to "not used":
The Project Settings dialog box is displayed.
Select C/C ++
Select precompilation header for category
Select not to use the pre-compiled header.
[Url] http://www.yzcc.com/yzcc/vv/08475592434.html#/url]

Other tips:

1. How can I view the error message (getlasterror () in the debugging status ())?
Generally, you can use getlasterror () to get the error number and then use formatmessage (...) to get the error description.
Here is a more direct method: Add @ err, HR in the watch window

2. How do I know if the program has a memory leak (Memory Leak )?
Press in the VC development environment
[F5]: run the program in the debugging status. The test may result in memory leakage. Close the program and view the running information in the output window. If there is a leak, there will be a record in the output. Of course, you cannot rely solely on this method to find that the program has a memory leak.

3. When a variable meets certain conditions, it stops at the breakpoint.
See the following program snippet:
2 int ilocation;
...
30 ilocation ++
...
Requirement: Set a breakpoint on line30 and want to go to ilocation> 100.
Source: [url] http://blog.tianya.cn/blogger/post_show.asp? Blogid = 237133 & postid = 3587659 [/url]

Code style for debugging:
  
No global variables
All variables must be initialized. member variables must be initialized in the constructor.
Try to use const
Detailed notes
  
  
VC ++ compilation options:
  
Always use/W4 Warning Level
The/GZ compilation option is always used in the debugging version, and it is used to send errors only in the release version.
Compilation without warning: ensure that no warning is generated after compilation, but check carefully before removing the warning.
  
  
Debugging method:
  
1. Use assert (Principle: as simple as possible)
Assert takes effect only under debug, but not under release.
  
Example:
Char * strcpy (char * DEST, char * Source)
{
Assert (source! = 0 );
Assert (DEST! = 0 );
Char * returnstring = DEST;
While (* DEST ++ = * Source ++ )! = '/0 ')
{
;
}
Return returnstring;
}
2. Defensive Programming
  
Example:
Char * strcpy (char * DEST, char * Source)
{
If (Source = 0)
{
Assert (false );
Reutrn 0;
}
If (DEST = 0)
{
Assert (false );
Return 0;
}
Char * returnstring = DEST;
While (* DEST ++ = * Source ++ )! = '/0 ')
{
;
}
Return returnstring;
}
3. Use trace
  
The following example can only be displayed in debug,
  
Example:
  
A) tracecstring cstest = "test ";
Trace ("cstring is % s/n", cstest );
B) atltrace
  
C), afxdump
Ctime time = ctime: getcurrenttime ();
# Ifdef _ debug
Afxdump <time <"/N ";
# Endif
4. Use getlasterror to check the returned value and get the error code to analyze the cause of the error.
  
5. Record the error information to the file.
  
Exception Handling
  
When designing a program, you must consider how to handle exceptions. When an error occurs, you should not simply report the error and exit the program, you should try your best to restore the status before an error or let the program run from the beginning. In addition, you should be able to tolerate certain errors, that is, allow the existence of errors, however, the program can still complete the task normally.
  
Debugging skills
  
1. debug and run F5 in VC ++
  
A) you can see the information printed with trace in the output debug window.
B) The call stack of the program can be seen in the call Stack window.
  
2. When the debug version is running, a crash occurs. Select retry for debugging. Analyze the error location and cause by checking the call stack.
3. Use the ing file for debugging
  
A) create a ing file: select the link item in Project Settings, and select generate mapfile. The output Code address is/MapInfo:
Lines to obtain the serial number:/MapInfo: exports.
B) when the program is released, the ing files of all modules should be archived.
C) view the ing file: see the file "identify error lines of source code through the crash address.
  
4. Release versions that can be debugged
  
In Project Settings, select debug info for item C ++ as program database and debug for item link.
Info and Microsoft format.
  
5. view the API error code. In the Watch window, enter @ err to view the error code or @ err, HR. ", HR" indicates the description of the error code.
6. set next statement: this function can be directly redirected to the specified code line for execution. It is generally used to test the code for exception handling.
7. debug memory variable changes: Stop when Memory changes.
  
Common Errors
  
1. Cause of program crash when the function returns
  
A) Write automatic variable out of bounds
B) The function prototype does not match.
  
2. MFC
  
A) use the wrong function prototype to process user-defined messages
  
The correct function prototype is:
Afx_msg lresult onmymessage (wparam, lparam );
3. Use terminatethread with caution: Using terminatethread may cause resource leakage.
  
4. Use _ beginthreadex. Do not use create thread as a common thread.

Windows debugging

1. Windows tracking statement:

(1) trace (_ T ("WARNING (functionname): Object % s not found./N"), objectname );

The output result is displayed in the output debugging window. The trace information is output to the output window. [Used in debugging]

(2) c ++ Runtime Library Function tracking statement
Ansi c Runtime library functions do not have trace statements, but Vc ++ C Runtime library functions are available. You can use _ rptn or _ rptfn to debug the report macro, but you must reference crtdbg. h In the program and use the C Runtime function library link:
_ Rpt0 (reporttype, format );
_ Rpt1 (reporttype, format, arg1 );
_ Rpt2 (reporttype, format, arg1, arg2 );

_ Rptf0 (reporttype, format );
_ Rptf1 (reporttype, format, arg1 );
_ Rptf2 (reporttype, format, arg1, arg2 );
Example:
Int A = 1000, B = 2000;
Int * P = &;
Int * q = & B;
_ Rptf2 (_ crt_warn, "% x, % x", p, q); // output directly in outputwindow
_ Rptf2 (_ crt_error, "% x, % x", p, q); // The error dialog box is displayed.
_ Rptf2 (_ crt_assert, "% x, % x", p, q); // The aeesrt dialog box is displayed.
Reporttype: _ crt_warn _ crt_error _ crt_assert
Here, _ crt_warn is used for tracking statements, and _ rptfn macro reports the source code file name and the row number that calls these macros. [Used in debugging]
You can use the _ crtsetreportmode function to change the default output settings (for example, output to the debugger output window, file, or message box) and the _ crtsetreportfile function to specify the file to which the report is output.

(3) Tracking statements in MFC
Difference: when using a trace macro, you need to use the _ t macro to format the parameters to correct Unicode correction. Otherwise, you do not need to use the _ t macro in a tracen macro.
Trace (_ T ("ssss/N "));
Trace2 ("% d r % d l/N", 1, 2 );

(4) exceptions and returned values

In the C ++ program, exceptions and return values can be used to return status information. The best way to return the status of a function in C is to return the value.
Try
{
// Code may fail
}
Catch
{
// Handle the failure
}
There will only be overhead when an exception is thrown! Catch blocks have some overhead, but try blocks have very little overhead! You can only handle exceptions in the debug version, and the MessageBox is displayed. The release version does not handle exceptions, so it is optimized.
Try
{
Int * pint = 0;
* Pint = 42;
}
Catch (...)
{
MessageBox (_ T ("exception was caught! "), _ T (" exception test "), mb_ OK );
}
(5) ansi c ++ runtime function library tracking
Specifically: stderr in C language and clog stream in C ++ language, no effect in Windows programs!

(6) outputdebugstring (_ T ("trace debug info! /N "); [used in debugging]
If you only want to use outputdebugstring In the debugging version, you can use the following macro:
# Ifdef _ debug
# Define outputtracestring (text) outputdebugstring (text)
# Else
# Define outputtracestring (text) (void) (0 ))
# Endif

Use afxoutputdebugstring
The afxoutputdebugstring macro uses the same syntax as outputdebugstring.

7. Use cobiect: Dump
The cobject class has a dump virtual function that can be reloaded by all its subclass functions and output their values.
Example 1-2: Use the following statement to output the pobject value of the cobject derived class. Afxdump is a predefined global variable cdumpcontext. Note that cdumpcontext supports the insert operator (<) for the most common built-in data types and pointer and reference of cobject ). Several Classes derived from cobject also have predefined insertion operators, cpoint, csize, crect, cstring, ctime, and ctimespan.
# If _ debug
Afxdump (pobiect );
Pobject-> dump (afxdump );
Afxdump <pobject;
# Endif

Example 1-3:
Afxdump <_ T ("WARNING: This object doesn't seem right:/N") <pobject;
8. Use afxdump
Afxdump is a tracing statement equivalent to the cerr stream in MFC, so you can directly output tracing messages to it.
The trace macro is implemented by afxdump and afxdump is implemented by afxoutputdebugstring. Afxoutputdebugstring is implemented by _ rpt0 In the debugging version. You can use the following method to redirect afxdump.
# Ifdef _ debug
Cfile dumpfile; // must be a global variable
Dumpfile. Open (_ T ("dump. log"), cfile: modewrite | cfile: modecreate );
Afxdump. m_pfile = & dumpfile;
# Endif
9. Use afxdumpstack
You can use the afxdumpstack function to output a call Stack:
Void afxapi afxdumpstack (DWORD dwtarget = afx_stack_dump_target_default );
Parameter number: dwtarget determines the output location in debugging and release versions. It can be output to the trace macro, outputdebugstring, or to the clipboard. If afx_stack_dump_target_trace is used, it indicates that the trace macro is output in the debug version, but not in the release version! If you want to output data in the released version, you can use the afx_stack_dump_target_ods option and the imagehlp. dll file must be included in the path. In Project & #61664; settings & #61664; link & #61664; category & #61664; debug both formats.
10. The most basic type of the ATL trace statement is the atltrace function:
Inline void_cdecl atltrace (lpctstr format ......);
Atltrace (format ......);

Similar to the MFC trace macro, it uses a 512-byte fixed-size buffer. If its parameters require a text buffer greater than 512 bytes, it will lead to an erroneous asserted. In fact, it is implemented using the outputdebugstring API function, so its output cannot be changed to other targets.
The atltrace2 function is another option for the ATL trace statement:
Inline void _ cedecl atltrace2 (DWORD category, uint level, lpctstr format ,...);
Atltrace (category, level, format );
This function adds a parameter tracing category (such as atltracecom, atltracewing wing, and atltracecontrol) and a parameter strict level. The category value is a bit mask. ATL uses a value between 0 and 2. Level 0 indicates the strictest level. Similar to the atltrace function, the atltrace2 function can only be used in the debug version!
11. VC ++ message Pragma
Pagama is a compilation tracking statement that can be used to warn of potential build problems found during preprocessing.
12. process long strings: [For example, process SQL statements]
(1) [debugging only]
Trace (longstring); // assert if _ tcslen (longstring)> 511, Max. 512
# Ifdef _ debug
Afxdump <longstring; // dosen't assert for long strings
# Endif
(2) ATL [debugging only]
Atltrace (longstring); // assert if _ tcslen (longstring)> 511, Max. 512
# Ifdef _ debug
Outputdebugstring (longstring); // dosen't assert for long strings
# Endif
13. process a large number of trace outputs.
If the tracing message data is generated more quickly than the output window processing speed, the message will fill the buffer zone and the data will be lost.
Simple Method: Call the sleep API function when outputting a code segment with a large amount of data, such as an object dump function. Example: Sleep (100 ).

Debugging
1. When an error occurs, call getlasterror () to obtain the corresponding error code.
The error code bit field has a fixed format, which is detailed in C:/program files/Microsoft Visual Studio/vc98/include/winerror. h:
//
// Values are 32 bit values layed out as follows:
//
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
// + --- +-+ ----------------------- + ------------------------------- +
// | Sev | c | r | facility | code |
// + --- +-+ ----------------------- + ------------------------------- +
//
// Sev-is the severity code security code
//
// 00-success 0-Security
// 01-Informational 1-Information
// 10-warning 2-warning
// 11-error 3-Error
// C-is the customer code flag
Customer Code: 0-defined by Microsoft, 1-defined by customer
// R-is a reserved bit the Reserved Bit must be 0
// Facility-is the Facility Code tool-defined by Microsoft
// Code-is the facility's status code of the code-Microsoft or customer defined
Tools: better ways to view error code, tools-> error lookup; In the Watch window of VC ++ debugger, enter @ err to monitor the returned value of getlasterror, err is a virtual storage device used by the debugger to display the latest error codes. You can also use @ err to convert the error code to the text format

Tip: during debugging, press F11 and ALT + 8 to display the Disassembly window. in the edit menu, select the go to command and select the address option in the go to what dialog box, enter the address that causes the crash in enter address expression.

Create a ing file: Project & #61664; settings & #61664; link & #61664; generate mapfile. You can see it in the debug file of the project. All the common symbols in the ing file use mixed names. You can use the name resolution tool (undname) of VC ++ to convert the mixed name to the original name. You can run "& #61664;" & #61664; "cmd" & #61664; Input
C:/Documents and Settings/zhangzhongping> Cd C:/program files/Microsoft Visual Studio/common/tools
Input:
C:/ProgramFiles/microsoftvisualstudio/common/tools> undname? Randexception @ ygxhhhh @ Z
Microsoft (r) Windows NT (r) Operating System
Undname version 5.00.1768.1copyright (c) Microsoft Corp. 1981-1998
Output:
>>? Randexception @ ygxhhhh @ z = randexception

When-F is input, the prototype of the entire function is displayed! When you view the ing file, the name parsing tool is very useful if there is an overload function!
Input:
C:/ProgramFiles/microsoftvisualstudio/common/tools> undname-F? Randexception @ ygxhhhh @ Z
Microsoft (r) Windows NT (r) Operating System
Undname version 5.00.1768.1copyright (c) Microsoft Corp. 1981-1998
Output:
>>? Randexception @ ygxhhhh @ z = void _ stdcall randexception (INT, Int, Int, INT)

Use the def files of MFC and ATL:

The def file of MFC is
C:/ProgramFiles/microsoftvisual studio/vc98/mfc/src/Intel directory.
The def file of ATL is stored in
C:/program files/Microsoft Visual Studio/vc98/ATL/src directory.
If the user runs his program, the information about the ordinal 6880 cocould not be located in the dynamic link library mfc42.dll appears. You can view function 6880 in mfc42.def :? Screentoclient @ cwnd @ qbexpautagrect @ z @ 6880 noname. Then you can use the name resolution tool to parse the mixed names as follows:
Input:
C:/program files/Microsoft Visual Studio/common/tools> undname-F? Screentoclient @ cwnd @ qbexpautagrect @ z @ 6880 noname
Microsoft (r) Windows NT (r) Operating System
Undname version 5.00.1768.1copyright (c) Microsoft Corp. 1981-1998
Output:
>>? Screentoclient @ cwnd @ qbexpautagrect @ z = public: void _ thiscall cwnd: screentoclient (struct tagrect *) const
>>= @
> 6880 = 6880
> Noname = noname
Use the dependency browsing tool:
VC ++ dependency browsing tool (Common/tools/depends.exe)

Debugging of Memory leakage
In VC, we use _ crtdumpmemoryleaks () to detect memory leakage.
Example:
Void ctracedlg: onbutton1 ()
{
Int * pleak = new int; // intentionally causes memory leakage
_ Crtsetdbgflag (_ crtdbg_alloc_mem_df | _ crtdbg_leak_check_df );
// Delete pleak;
// Pleak = NULL;
_ Crtdumpmemoryleaks (); // call this function to display data of Memory leakage addresses in the debug window of the output window.

}
The debug window displays:
Detected memory leaks!
Dumping objects->
C:/ProgramFiles/microsoftvisualstudio/myprojects/Trace/tracedlg. cpp (181): {89} normal block at 0x004213b0, 4 bytes long.
Data: <> CD
Object dump complete.

Note: 0xcd indicates the allocated data.
0xdd indicates released data
0xfd indicates protected data

Assertions
1. assertion features:
(1) An error occurred while running (user input error, resource allocation error, file system error, hardware error, or other type error)
(2) The Boolean expression in the assertion shows the validity of an object or state, rather than correctness.
(3) Assertions exist only in the debugging version after Conditional compilation. In particular, assertions can be compiled only after _ debug symbol definition!
(4) assertions cannot contain program code, nor have side effects. They cannot modify program variables or call functions that can modify program variables.
(5) Assertions only provide useful information to programmers.
2. Type of assertion
(1) ansi c assertions
Void assert (expression) is included in the assert. h header file (it is best not to use assert)
Cause: * When the file name is too long, the path displayed in the dialog box will be ended!
* The function is driven by the ANSI ndebug function. If ndebug is defined, the assertions are canceled!

To enable JIT debugging (just-in-time), go to tools & #61664; Options & #61664; debug
Select just-in-time debugging. By default, Ole RPC debugging is selected.
Click "retry (r)" to display the marked row where the error is located.

(2) C Runtime function library assertions
_ Assert (Boolean expression) (crtdbg. h) [no]

_ Asserte (Boolean expression) (crtdbg. h) [This is often used]

_ Asserte macros provide more concise and useful information and display assertions!
(3) assertions in the MFC Library
The message boxes displayed by the assert (Boolean expression) assert macro and the _ assert macro are the same. The bool expression in Verify (Boolean expression) Verify is retained in the released version. It simplifies the determination of return values!
Cstring STR;
Verify (Str. loadstring (ids_string); // do not use the verify macro
Assert_valid macro is used to determine whether a pointer to an object of the cobject derived class is valid. Assert (pobjectderivedfromcobject); it is called before using the cobject derived class object to check the object's validity.
Assert_kindof (classname, pobjectderivedfromcobject );
Assert_pointer (pointer, pointertype );
Assert_null_or_pointer (pointer, pointertype );
Afxlsvalidaddress (const void * memoryaddress, uint memorybytes, bool iswriteable = true );
Bool afxlsvalidstring (lpcstr string, int stringlength =-1 );
(4) ATL assertions
If you use ATL, crtdbg. H is included in atlbase. h. In any ATL code, atlassert is your choice. In atldef. H, you will find that atlassert is an alias of _ assert.
Advantage: Using atlassert in ATL allows you to use your own assertions.
(5) Consider using _ asserte (false) to simplify the combination of Defensive Programming and assertions. To get descriptive asserted messages, consider using _ asserte ("Problem description. "= 0 ).
_ Asserte ("this is the object requires the mm_text Mapping mode" = 0 );
If (! Expression)
{
// Handle error
_ Assert (false );
...
}
If (failed (somefunction ()))
{
// Handle error
_ Assert (false)
}
(6) Consider using _ crtsetreportmode and _ crtsetreportfile

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.