《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)
--------------------+++++-------------------------
@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
- 《windows 程序调试》读书笔记之跟踪篇
- 《windows 程序调试》读书笔记之断言篇
- 《windows 程序调试》读书笔记之编译器篇
- windows 程序调试 读书笔记
- 关于程序跟踪调试
- 《Windows程序调试(Debugging Windows Programs)》读书笔记(一)
- vc++学习之调试器逐步跟踪程序
- Linux下gdb调试程序之堆栈跟踪
- Windows程序调试----第一部分 调试策略----第4章 使用跟踪语句
- Windows程序调试之格式化输出
- gdb调试之堆栈跟踪
- gdb调试之堆栈跟踪
- 重载new,delete跟踪调试程序
- 利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
- 利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
- 利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
- 关于java程序的跟踪调试
- 利用__FILE__, __LINE__, __FUNCTION__跟踪调试程序
- 从零开始,纯手写,创建一个自己的网站
- ~这些年,我们一起学过的java~06~我的五子棋学习之旅~
- 程序员,你需要大量地阅读
- 线性表----链接栈的基本操作
- View的生命周期
- 《windows 程序调试》读书笔记之跟踪篇
- 网络流的EK算法模板
- Java中的String与常量池
- Remember the Word,LA3942(Trie树+DP)
- fedora14下编译qtopia问题. uuid, X11
- PDF在线解决方案(1)
- windows与linux 汇编差异
- 《windows 程序调试》读书笔记之编译器篇
- VS2010编译调试STL源代码