Visual Studio Debugging Tips (1)-adding breakpoints based on string content

Source: Internet
Author: User
Tags strcmp

Original: Http://blog.csdn.net/cadcisdhht/archive/2010/06/05/5649681.aspx

When debugging programs with Visual Studio, we often need to add breakpoints based on values. For example, when i = = 2 o'clock interrupt run, we can add the following breakpoint:

Sometimes, we need to add a breakpoint based on the contents 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 when you run to trace (string), you can break the string if it is "two". If we were to add a breakpoint to a value, add the following breakpoint:

When we run the above code, we find that even if the contents of string "Two", the run is not interrupted. This is because the = = operator compares the address of the two string rather than the content, so the above breakpoint does not meet our needs.

Visual Studio takes into account that programmers often add breakpoints based on the contents of strings, so special support for strings is added to this feature of adding breakpoints. When we add breakpoints based on string content, we can use functions like strcmp to set breakpoints.

So in the example above, we can use the STRCMP function to add the following breakpoint:

The string functions supported in the Add Breakpoints feature in Visual Studio are: 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.