Tips for Visual Studio debugging (1)-add breakpoints Based on string content

Source: Internet
Author: User

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.

Related Article

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.