现在的位置: 首页 > 综合 > 正文

windows 调试若干知识

2013年02月05日 ⁄ 综合 ⁄ 共 4792字 ⁄ 字号 评论关闭

 

1、 创建map文件

<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:21.0pt;
mso-char-indent-count:2.0;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:2075465320;
mso-list-type:hybrid;
mso-list-template-ids:473879982 2027220046 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:18.0pt;
text-indent:-18.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
-->

为你的程序创建映射文件,你必须对
VC++
工程中的相应选项进行适当的设置。第一步是打开映射文件生成功能。你可以在工程设置对话框里进行设置。在
link
标签里的
debug
类里打开
generate mapfile
选项。由于一些奇怪的原因,
VC++
没有把输出程序代码地址和源代码行号的映射作为默认设置。要得到这些信息,还需要在
Project Option
对话框里嵌入
”/MAPINFO: LINES”.
得到导出序号也许很有用
,
所以你还需要在
project option
里输入
”/MAPINFO: EXPORTS”.

 

2. release和debug编译选项。

Debug Build
Options:

/Od

/D  
"WIN32"  
## define macros.

/D  
"_WINDOWS"

/D  
"_DEBUG"

/D  
"_AFXDLL"

/D  
"_UNICODE"

/D "UNICODE"

/Gm 
## minimal build

 
/EHsc  
## enable c++ exception

/RTC1 
## basic runtime checks

 
/MDd  
##
use multithreaded debug dll

/Yu"stdafx.h"
 
## use precompiled headers

/Fp"Debug/TestDatabase.pch"  
## precompiled header file

 
/Fo "Debug//"   
## object file name

/Fd "Debug/vc90.pdb"
 
## program database filename

/W3  
## warning level

/nologo

 
/c   
##
keep comments

/ZI 
## do not include default library names in
obj files.

 
/TP  
##
compile as c++ source files.

/errorReport:prompt 
## error report.

 

Release Build
Options:

/O2 
## maximize speed optimization.

/Oi 
## enables intrinsic functions,.this could
generate faster but possiblely larger codes.

/GL  
## enable cross module optimizations by
delaying code generation to link time. Called whole program optimization.

/D
"WIN32" ## define WIN32

/D
"_WINDOWS"

/D
"NDEBUG"

/D
"_AFXDLL"

/D
"_UNICODE"

/D
"UNICODE"

/FD   
##

/EHsc  
## enable c++ exception

/MD   
## use multi threaded dll

/Gy   
## enable function-level linking, for edit
and continue.

/Yu"stdafx.h"
## precomiled headers

/Fp"Release/TestDatabase.pch"
 
## pch files

/Fo"Release//"
  
## object files

/Fd"Release/vc90.pdb"
 
## program database files.

/W3  
## warning level

/nologo

/c ## keep
comments

/Zi 
##

 
/TP 
##
compiled as c++ source files.

 
/errorReport:prompt

 

3. 同调试版的c/c++运行时库

使用调试版本的函数库:

除了有调试符号外,
debug

c runtime lib
使用了调试堆。下面是调试库一些特点的总结:

1.    



对内存分配进行了跟踪,使得用户能够检查内存泄漏。

2.    



在刚分配的内存里写上
0xcd
的字节,这有助于发现未初始化数据的错误。

3.    



在被释放的内存里写上
0xcd
的字节。有助于发现被释放的内存

4.    



在缓冲区的两边各分配了
4
个字节的保护数据,并写入值
0xfd
,用来检查内存的上溢出和下溢出

5.    



在每个内存分配的地方对源文件和行号进行了记录,这有助于用户在源代码中对内存分配进行定位。

6.    



在调试版本中更能容易发现内存错误。而且调试版本允许对内存的写操作有四个字节的上溢出和下溢出,对程序不会有任何影响。同样的错误在发布版中就会导致内存破坏。

 

4关于优化。


关闭优化开关:

因为未被优化的汇编代码直接对应于源代码,所以比优化后的代码更容易读懂,所以当你调试代码时,调试器会以

你预想的方式工作,而优化后的代码却可能会四处跳转。和你预想的很不一样。而且一些变量也因为优化去掉了。此外,为被优化的代码编译与链接会更快,从而会有更短的调试周期。

理论上讲,调试版本不会比发布版本更完善,所以一旦你的调试版本通过,基本可以确信你的发布版本可以运行。不幸的是,这个完美的理论因为优化而被打破了。优化代码要求编译器做一些假设,并去除了一些冗余,但有时这些假设不一定正确,并且去掉的冗余有可能隐藏错误。

抱歉!评论已关闭.