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

Source: Internet
Author: User

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.

 

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.