《windows 程序调试》读书笔记之跟踪篇

来源:互联网 发布:软件发明专利怎么写 编辑:程序博客网 时间:2024/06/06 09:19
--------------------+++++-------------------------
@note:跟踪语句
windows:void OutputDebugString(LPCTSTR traceText);
#ifdef _DEBUG
#define OutputTraceString(text) OutputDebugString(text)
#esle
#define OutputTraceString(text) ((void) 0)
#endif
asci c++:在windows 界面环境中,无效;基于控制台的window程序
stderr:无缓冲区
cerr:单字节缓冲


clog:完全缓冲=>程序崩溃,log丢失
vc++ 运行库中:#include<crtdbg.h>
_RPTN:支持ascii,unicode
_RPT0(reportType,format)
_RPT1(reportType,format,param1)
_RPT2(reportType,format,param1,param2)
_RPT3(reportType,format,param1,,param2,param3)
_RPT4(reportType,format,param1,param2,param3,param4)
_RPTFN:不支持unicode
_RPTF0(reportType,format)
_RPTF1(reportType,format,param1)
_RPTF2(reportType,format,param1,param2)
_RPTF3(reportType,format,param1,,param2,param3)
_RPTF4(reportType,format,param1,param2,param3,param4)


reportTpyt:
_CRT_WARN/_CRT_ERROR/_CRT_ASSERT
默认输出至debug调试窗口,可用_CrtReportMode重定向输出


vc++ pragma:编译时跟踪语句,跟踪在预编译过程中,可能出现的潜在的编译链接问题
#pragma message("XXXX")
#error:打断编译


跟踪源代码:
#ifndef _DEBUG
#define _RPT4(Type,format,param1,param2,param3,param4)
#define _RPTF4(Type,format,param1,param2,param3,param4)
#else
#define _RPT4(Type,format,param1,param2,param3,param4)\
do{\
if(1 == _CrtDbgReport(Type,NULL,0,NULL,msg,\
param1,param2,param3,param4)){\
_CrtDbgBreak();\
}\
}while(0)
#define _RPTF4(Type,format,param1,param2,param3,param4)
do{\
if(1 == _CrtDbgReport(Type,__FILE__,__LINE__,NULL,msg,\
param1,param2,param3,param4)){\
_CrtDbgBreak();\
}\
}while(0)
#endif


自定义跟踪:
int CategoryFilter = 0xFFFFFFFF;
int DetailLevelFilter = 0xFFFFFFFF;
#ifdef _DEBUG
#define OutTraceString(category,DetailLevel,text)\
do{\
if(((category) & CategoryFilter)\
&& ((DetailLevel) & DetailLevelFilter))\
_RPT0(_CTR_WARN,text);\
}while(0)
#else
#define OutTraceString(category,DetailLevel,text) ((void) 0)
#endif


针对超过512字符的,使用outputdebugstring
针对大量输出的(输出速度>输出窗口的处理速度的),Sleep(100)
--------------------+++++-------------------------
0 0
原创粉丝点击