分类: C/C++
2008-04-23 22:04:57
关于调试时输出的字符串信息
作者:
使用工具:VC6.0,IDA
当我们要在程序中输出调试信息时,常常以字符串的形式来输出,例如:
printf("Some debug information here!\n");
这段代码在Debug和Release版下都输出调试信息,这不是我们所要的,一般地大家都会添加
#if _DEBUG
printf("Some debug information here!\n");
#endif
这样就达到了在Debug版里程序输出调试信息,在Release版下不输出调试信息的目的。(在Release版里
void printInfo(char *strInfo)
{
#if _DEBUG
printf(strInfo);
#endif
}
注:该函数只是演示用的,很简单,没有其他检查字符串功能。
printInfo("Some debug information here!\n");
确实,在Debug模式下运行该程序,则输出如下信息:
Some debug information here!
在Release模式下,则没输出什么信息;
#if _DEBUG
#define _D(str) str
#else
#define _D(str) NULL
#endif
此时输出语句变为:
printInfo(_D("Some debug information here!\n"));
在Debug模式下运行程序,依然输出调试信息:“Some debug information here!”;在Release下,则什么都不输出,此时我们用IDA看一下Release版的二进制文件,则没有发现该调试信息字符串。
#if _DEBUG
void printInfo(char *strInfo)
{
printf(strInfo);
}
#else
#define printInfo(str)
#endif
注意:该宏把函数printInfo的定义也放进去了;
“Some debug information here!”;在Release下,也什么都不输出,此时我们用IDA看一下Release版的二进制文件,也没有发现该调试信息字符串。