Original article: http://blog.csdn.net/cadcisdhht/archive/2010/06/05/5649681.aspx
When using Visual Studio to debug programs, we often need to add breakpoints Based on numerical values. For example, to interrupt the running when I = 2, we can add the following breakpoint:
In some cases, we need to add breakpoints based on the content of the string. For example, we are debugging the following code:
Void cvsdebugtricksdlg: onbnclickedbutton1 () <br/>{< br/> char * string; <br/> for (INT I = 0; I <5; ++ I) <br/>{< br/> string = getstring (I); <br/> trace (string ); <br/>}</P> <p> char * cvsdebugtricksdlg: getstring (INT number) <br/>{< br/> switch (number) <br/>{< br/> case 0: <br/> return "zero"; <br/> case 1: <br/> return "one "; <br/> case 2: <br/> return "two"; <br/> default: <br/> return "other "; <br/>}< br/>}
We hope that the running will be interrupted if the string is "two" when it is run to trace (string. If we add a breakpoint in the same way as adding a breakpoint based on a numeric value, add the following breakpoint:
When we run the above Code, we will find that even if the string content is "two", the operation is not interrupted. This is because the = Operator compares the addresses of two strings rather than the content, so the above breakpoint cannot meet our needs.
Visual Studio allows programmers to add breakpoints based on the content of a string. Therefore, it provides special support for adding breakpoints. When adding breakpoints Based on the string content, you can use strcmp and other functions to set breakpoints.
In the above example, we can use the strcmp function to add the following breakpoint:
The string functions supported by the breakpoint adding function in Visual Studio include strlen, wcslen, strnlen, wcsnlen, strcmp, wcscmp, _ stricmp, _ wcsicmp, strncmp, wcsncmp, _ strnicmp, _ wcsnicmp, strchr, wcschr, strstr, wcsstr.