Windows应用程序调试必备的--符号文件(Symbols)(vc设置符号表)

来源:互联网 发布:tw域名注册 编辑:程序博客网 时间:2024/06/07 09:45

Windows Symbol Files

from:http://www.7880.com/info/Article-56f07840.html

1.什么是Symbol File?     

              Symbol files hold a variety of data which are not actually needed when running the binaries(Dll,EXE...), but which could be very useful in the debugging process(It's a good partner for VC6++ and WinDbg).
             通俗的说,Symbol File是包含了相关二进制文件(EXE,DLL)调试信息的一种文件,它以.pdb为扩展名,比如WinXP下有一个GDI32.dll,那么微软在编译该DLL的时候会产生一个GDI32.pdb文件,程序员有了这个PDB文件愿意的话就可以用它来调试,跟踪到GDI32.dll的内部去!
             该文件和二进制文件的编译版本密切相关,比如你修改了DLL的输出函数等,再编译该DLL那么原先的PDB文件就过时了,不能再胜任调试的重担了,这时候你需要的是修改后编译产生的PDB文件.
             大家在用VC6编译的时候会发现PDB文件会存在于Debug/Release目录下(关于如何产生Release版本的PDB请参看4.如何在VC6++中编译产生Release版本的二进制文件的PDB文件?).

Typically, symbol files might contain: 
    1.全局变量(Global variables)
    2.局部变量(Local variables)
    3.函数名和它们的入口地址(Function names and the addresses of their entry points)
    4.FPO data(frame pointer omission),frame pointer是一种用来在调用堆栈(Call stack)中找到下一 个将要被调用的函数的数据结构源代码的行序号(Source-line numbers)

2.如何得到Symbol Files?

       要安装Symbol Files请先确定你的OS版本再到微软的网站上去下载相应的Symbol Files安装,安装没有什么特殊的要求,只需要随便安装到一个目录,然后在Windows的环境变量中中设定这个Path(也可以在VC6,WinDbg中设置,这样的话只有Vc6或者是WinDbg自己能看到了…)然后WinDbg,Ntsd,

DrWatson之类的调试软件就可以找到了. 
   安装Symbol Files就一个原则,请大家注意:

    "If you plan to install symbols manually, it is crucial that you remember this basic rule: the symbol files on the host computer are required to match the version of Windows installed on the target computer"

   host computer     The host computer is the machine that runs the debugging session. In a typical two-system debugging  session, the host can be any computer which can be connected to the target computer

   target computer  The target computer is the machine that has experienced the failure of a software component, system service, an application, or of the operating system. This is the computer that needs to be debugged and is the focus of the debugging session. This can be a computer located within a few feet of the computer on which you run the debugging session, or it can be in a completely different location. Sometimes referred to as the debuggee

3.如何在VC6中集成Symbol Files??   

     1.Open your workspace in VC6++;
     2.Open the Options dialog box (Tools->Options);
     3.Click the Directoties tab;
     4.Click Executable files from the Show directories for drop-down list;
     5.Add the path of symbol-files  to path-list;
     6.Click OK to finish.

4.如何在VC6++中编译产生Release版本的二进制文件的PDB文件?

 

 这是Microsoft的方法,实战中为了使得我们的代码被别人Copy到其他地方也可以编译通过我一般用#pragma预编译开关来帮助我产生我需要的文件:

 

 

5.Free Build(retail build) and Checked Build(debug build)

   Two different builds of each NT-based operating system exist: 
   The free build (or retail build) of Windows is the end-user version of the operating system. The system and drivers are built with full optimization, debugging asserts are disabled, and debugging information is stripped from the binaries. A free system and driver are smaller and faster, and it uses less memory. 
The checked build (or debug build) of Windows serves as a testing and debugging aid in the developing of the operating system and kernel-mode drivers. The checked build contains extra error checking, argument verification, and debugging information that is not available in the free build. A checked system or driver can help isolate and track down driver problems that can cause unpredictable behavior, result in memory leaks, or result in improper device configuration. 
    Although the checked build provides extra protection, it consumes more memory and disk space than the free build. System and driver performance is slower for the following reasons: 
    The executables contain symbolic debugging information. 
    Additional code paths are executed due to parameter checking and output of diagnostic messages for debugging purposes.

 

6.如何更新Symbols

          如果大家用上了WinDbg会发现符号文件(PDB)有多么的重要,可是这些文件都是和本地的OS相关的比如说你的WinXP打了SP补丁的话可能原来的符号文件就会出现不匹配的想象怎么办?网上更新!请在你们的WinDbg的Symbols Path里面输入下面一行:

        SRV*D:\Symbols\websymbols*http://msdl.microsoft.com/download/symbols

       (红色部分写上你们想保存的本地路径)

如果你不是通过代理上网,那么在你用WinDbg打开一个被调试程序后,输入symchk回车,windbg就会自动的连到微软的网站根据你的机器的情况更新新的PDB文件并保存在上面红色部分的本地路径里面,这样你就可以确保你的符号文件版本和你机器上的文件的版本一致(我指的是系统文件:DLL,SYS...).

 

如果你是通过代理上网那么你需要配置一下:

注意:http://home.lenovo/proxy.pac是我假设的代理配置脚本地址;10.99.20.26:8080是我假设的代理服务器地址和端口,实战中请根据你自己的情况设置.

1.配置好IE;


2.设置一个环境变量;
   

该环境变量为:_NT_SYMBOL_PATH;像我这样填写就可以了 


3.告诉WinDbg:以后可以去微软网站下载PDB文件了 

有任何问题欢迎邮件交流:yangminga@lenovo.com或perdubug@hotmail.com

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 被安装了尿道锁怎么办 狼青小狗腿罗圈怎么办 备孕期间有霉菌怎么办 虫子进皮肤里了怎么办 生完孩子肚子越来越大怎么办 怀孕8个月肚子小怎么办 孕晚期胎儿不长怎么办 肚子上肉特别多怎么办 奶堵了有硬块怎么办 便秘5天肚子胀怎么办 上火大便拉不出来怎么办 大便拉不出来肚子痛怎么办 戒奶奶涨有硬块怎么办 忌奶的时候涨奶怎么办 娃儿隔奶,,奶涨怎么办 狗肚子很大很鼓怎么办 注册不了的二建怎么办 专升本没考过怎么办 警察乱拘留人该怎么办 玩英雄联盟太卡怎么办 一方离婚证丢了怎么办 遭遇呼死你软件怎么办 开车遇见碰瓷的怎么办 遇到碰瓷老人的怎么办 睿强遥控锁坏了怎么办 地暖分水器坏了怎么办 京东赠品无货怎么办 图书馆的书丢了怎么办 三次临牌用完了怎么办 m3u8文件只有10k怎么办 寿县到淮南高铁怎么办 冰箱停电肉臭了怎么办 新买冰箱有异味怎么办 海康用户被锁定怎么办 大华dss录像没了怎么办 燃气软管超过2米怎么办 中央空调进了水怎么办 车门被划了一道怎么办 镜前灯没有留线怎么办 永大电梯故障44怎么办 物业把电梯停了怎么办