About string information for output when debugging

Source: Internet
Author: User
Tags printf

Using tools: Vc6.0,ida

When we want to output debug information in a program, we often output it as a string, for example:

printf("Some debug information here!\n");

This code outputs debug information under Debug and release, which is not what we want, and generally everyone adds a precompiled instruction as follows:

#if _DEBUG 
   printf("Some debug information here!\n");
   #endif

This is achieved in the debug version of the program output debugging information, in the release version does not output debugging information purposes. (in release version even the printf function is not invoked) if you want to output debugging information in many places in the program, if the way above will be very troublesome;

(As for why trouble, may be unwilling to knock a few more times keyboard, hehe ...) )

So everyone thought of writing an output function, the code is as follows:

void printInfo(char *strInfo)
   {
   #if _DEBUG
     printf(strInfo);
   #endif
   }

Note: This function is only demo, very simple, no other check string functionality.

Where you want to output debugging information, call the following statement on the line:

printInfo("Some debug information here!\n");

Indeed, when you run the program in debug mode, the following information is exported:

Some debug information here!

In release mode, there is no information output;

We tend to think everything is OK at this time; If you think it is, there is no need to look down;

Although in release version run the program does not output debugging information, but these debugging information is left in the binary executable file;

We can use Ida to open the release version of the executable file and see the information shown in Figure one:

Figure I: The main function after Ida disassembly

Note: This function is the main function

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.