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 ()
{
Char * string;
For (INT I = 0; I <5; ++ I ){
String = getstring (I );
Trace (string );
}
}
Char * cvsdebugtricksdlg: getstring (INT number)
{
Switch (number ){
Case 0:
Return "zero ";
Case 1:
Return "one ";
Case 2:
Return "two ";
Default:
Return "other ";
}
}
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.