pdb 源码索引符号服务器创建过程

pdb是调试程序必不可少的东西,它保存着一个exe或dll的调试信息,对pdb进行源码索引可以快速找到软件对应该版本的代码,本文以subversion版本控制服务器进行介绍

一、需要安装的软件

  1. windbg,在ddk安装包中可找到
  2. TortoiseSVN,安装时要选上命令行工具
  3. ActivePerl

  三个工具安装完成后要把windbg;windbg\srcsrv;TortoiseSVN\bin;Prel\bin加入到环境变量中

 

二、编译工程,索引PDB文件

  以KFileRecovery工程为例,编译后生成exe和PDB

  

  执行svnindex命令进行源码索引,执行命令前切保所的修改的代码已提交到svn

  svnindex /source="E:\work\c++\tu\KFileRecovery" /symbols="E:\work\c++\tu\KFileRecovery\bin" /debug

  source:表示源工程路径(必须是绝对路径),可以有多个,用分号分隔

  symbols:表示pdb文件所在的路径(必须是绝对路径),可以有多个,用分号分隔。svnindex会查找子目录下的pdb

  debug:表示输出调试信息

  注:svnindex对空格支持的不好,源代码路径中不能存在空格

  

  svnindex.cmd调用ssindex.cmd完成操作,ssindex.cmd使用Perl脚本,脚本中调用了windbg的srctool和pdbstr完成pdb文件索引,流程如下:

  调用srctool -r $pdbfile,获取pdb文件中的把有源文件,处理每个文件,获取svn路径和修订版本号,写入.stream临时文件中,最后调用pdbstr把.stream写入pdb文件中

  

  如:pdbstr -w -p:KFileRecovery -s:srcsrv -i:"C:\Users\tuxingkai\AppData\Local\Temp\index11780.stream"

    注:-s选项一定要是srcsrv,不然调试器不认

  下面来看一下ssindex.cmd生成的.stream文件格式

  

SRCSRV: ini ------------------------------------------------
VERSION=1
INDEXVERSION=2
VERCTRL=Subversion
DATETIME=Sat Mar  1 00:49:12 2014
SRCSRV: variables ------------------------------------------
SVN_EXTRACT_TARGET=%targ%\%fnbksl%(%var3%)\%var4%\%fnfile%(%var1%)   //%targ%:索引时pdb文件路径,%fnbksl%表示转换'/'为'\',%fnfile%表示取路径中的文件名,%varn%表示下面souce files的各个字段,以*分隔
SVN_EXTRACT_CMD=cmd /c svn.exe cat "%var2%%var3%@%var4%" --non-interactive > "%svn_extract_target%"
SRCSRVTRG=%SVN_extract_target%
SRCSRVCMD=%SVN_extract_cmd%
SRCSRV: source files ---------------------------------------
e:\work\c++\tu\kfilerecovery\disklib\pubfun.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/PubFun.cpp*3
e:\work\c++\tu\kfilerecovery\disklib\pubfun.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/PubFun.h*3
e:\work\c++\tu\kfilerecovery\stdafx.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/stdafx.h*3
e:\work\c++\tu\kfilerecovery\disklib\kdiskenum.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/KDiskEnum.cpp*3
e:\work\c++\tu\kfilerecovery\disklib\kdiskenum.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/KDiskEnum.h*3
e:\work\c++\tu\kfilerecovery\disklib\kdisk.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/KDisk.h*3
e:\work\c++\tu\kfilerecovery\disklib\kdisk.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/KDisk.cpp*3
e:\work\c++\tu\kfilerecovery\disklib\kdiskdef.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/DiskLib/KDiskDef.h*3
e:\work\c++\tu\kfilerecovery\stdafx.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/stdafx.cpp*3
e:\work\c++\tu\kfilerecovery\selectpartitiondlg.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/SelectPartitionDlg.cpp*3
e:\work\c++\tu\kfilerecovery\resource.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/resource.h*3
e:\work\c++\tu\kfilerecovery\selectpartitiondlg.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/SelectPartitionDlg.h*3
e:\work\c++\tu\kfilerecovery\kfilerecoveryview.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/KFileRecoveryView.h*3
e:\work\c++\tu\kfilerecovery\mainfrm.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/MainFrm.cpp*3
e:\work\c++\tu\kfilerecovery\aboutdlg.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/AboutDlg.h*3
e:\work\c++\tu\kfilerecovery\mainfrm.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/MainFrm.h*3
e:\work\c++\tu\kfilerecovery\childfrm.h*https://tuxingkai-pc/*svn/tu/KFileRecovery/ChildFrm.h*3
e:\work\c++\tu\kfilerecovery\kfilerecoveryview.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/KFileRecoveryView.cpp*3
e:\work\c++\tu\kfilerecovery\kfilerecovery.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/KFileRecovery.cpp*3
e:\work\c++\tu\kfilerecovery\childfrm.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/ChildFrm.cpp*3
e:\work\c++\tu\kfilerecovery\aboutdlg.cpp*https://tuxingkai-pc/*svn/tu/KFileRecovery/AboutDlg.cpp*3
SRCSRV: end ------------------------------------------------

  SVN_EXTRACT_TARGET和SVN_EXTRACT_CMD是环境变量,供下面的SRCSRVTRG、SRCSRVCMD选项使用

  SRCSRVTRG: 执行srctool -x从pdb源码服务器下载文件时,下载到这个目录下

  SRCSRVCMD: 执行srctool -x从pdb源码服务器下载文件时,对于每个源码文件要执行的命令及命令行参数

三、查看索引后的pdb文件信息

  srctool KFileRecovery.pdb

  

  看到上面信息,表示索引成功

四、将pdb文件加入到符号服务器

  

  执行sysmstore add /f *.* /s "E:\symserver" /t "KFileRecovery" /v "Build 1023" 把bin目录下的KFileRecovery.exe和KFileRecovery.pdb存储到符号服务器

五、配置HTTP符号服务器

  符号服务器可以是UNC路径,也可以是Http路径,对于UNC路径设置共享目录,加入权限就可以访问了。下面重点说一下HTTP方式的符号服务器配置

  需要软件:tomcat 6及以上版本

  将符号服务器目录设置为tomcat的虚拟目录,这样就可以通过http的方式访问符号服务器

  创建Symbols.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?> 
<Context 
    docBase="E:\symserver" 
    reloadable="true"> 
</Context> 

  将Symbols.xml复制到tomcat\conf\Catalina\localhost目录下,Catalina\localhost不存在就新建。然后启动tomcat即可。

六、VS2005 配置

  Tools->Option中选择Debugging->Symbols,配置如下:

  

  

  到这里源码索引符号服务器搭建过程就完成了。

 

posted @ 2014-03-01 01:34  小皮球  阅读(1467)  评论(0编辑  收藏  举报