首页
社区
课程
招聘
[原创]搭建自己的符号服务器(二)——SVN篇
2020-10-10 16:02 6322

[原创]搭建自己的符号服务器(二)——SVN篇

2020-10-10 16:02
6322

目录

参考:
1、支持源文件索引符号服务器的构建和使用:http://blog.sina.com.cn/s/blog_715342050100oxdx.html
2、pdb 源码索引符号服务器创建过程:https://www.cnblogs.com/txk1452/p/3574632.html
3、https://docs.microsoft.com/en-us/archive/msdn-magazine/2006/august/source-server-helps-you-kill-bugs-dead-in-visual-studio-2005
4、https://www.codeproject.com/Articles/115125/Source-Indexing-and-Symbol-Servers-A-Guide-to-Easi
5、翻译版本:https://www.cnblogs.com/yilang/p/11996452.html

 

前篇大致说了dump分析时符号文件的原理,以及符号服务器的方便之处,本篇实操一把,以版本控制系统svn为例。
其实,windbg目录下已经为我们准备好了处理开发过程中符号的各种工具,支持多种版本控制工具,svn只是其中的一种,可以到安装目录C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\srcsrv中查看。Debugger内置支持的版本控制系统包括:

  • svn:Subversion
  • cvs:Concurrent Versions System
  • tfs:Visual Studio Team Foundation System
  • vss:Microsoft Visual SourceSafe
  • p4:Perforce

但不支持git!

0x00、准备

1、环境

系统:Windows 7 x64
软件:

  • Perl环境:ActivePerl
  • SVN客户端和服务端:VisualSVNVisualSVN Server
  • Windbg环境:安装VS或SDK

2、前提

0、环境变量添加:

  • Perl环境:C:\Perl64\bin;
  • svn.exe:C:\Program Files (x86)\VisualSVN\bin
  • svnindex, srctool(自己找):C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64\srcsrv
  • symstore(自己找):C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64

1、搭建SVN服务器或使用现有SVN服务器;
2、将工程添加到svn并提交、编译工程,注意按顺序来,(以Win32 Release为例)

0x01、源文件索引

源文件索引是为了向pdb文件中添加svn信息,包括svn仓库地址、版本等。索引之前,记得提交代码。编译成功后,就可以对生成的pdb文件进行索引添加了。

1、svnindex

索引使用svnindex.cmd批处理,调用了perl脚本。命令格式如下
svnindex /debug /source=源码路径 /symbols=符号文件路径
其中/debug是显示详细信息。不知道什么原因,开始时,这条命令没有起作用:zero file indexed?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
C:\Users\Nemo>svnindex /debug /source="D:\Work\DumpDemo\DumpDemo" /symbols="D:\Work\DumpDemo\Release"
--------------------------------------------------------------------------------
 
ssindex.cmd [STATUS] : Server ini file: C:\Program Files (x86)\Windows Kits\8.1\
Debuggers\x64\srcsrv\srcsrv.ini
ssindex.cmd [STATUS] : Source root    : D:\Work\DumpDemo\DumpDemo
ssindex.cmd [STATUS] : Symbols root   : D:\Work\DumpDemo\Release
ssindex.cmd [STATUS] : Control system : SVN
ssindex.cmd [STATUS] : SVN Executable : svn.exe
ssindex.cmd [STATUS] : SVN Revision   : <N/A>
ssindex.cmd [STATUS] : SVN Username   : <N/A>
ssindex.cmd [STATUS] : SVN Password   : <N/A>
--------------------------------------------------------------------------------
 
ssindex.cmd [STATUS] : Running... this will take some time...
ssindex.cmd [STATUS] : Processing svn.exe properties output ...
ssindex.cmd [INFO  ] : ... indexing D:\Work\DumpDemo\Release\DumpDemo.pdb
ssindex.cmd [INFO  ] : ... wrote C:\Users\Nemo\AppData\Local\Temp\index109B5.stream to D:\Work\DumpDemo\Release\DumpDemo.pdb ...

可以看到,对一个pdb文件进行了索引。如果目录中有多个pdb,将会对所有的pdb文件进行索引;如果指定了某一个pdb文件,将只索引指定的。

2、查看索引后的pdb

那么,在pdb中添加了哪些信息呢?使用文本工具打开pdb,可以看到下面一段

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SRCSRV: ini ------------------------------------------------
VERSION=1
INDEXVERSION=2
VERCTRL=Subversion
DATETIME=Tue Sep  8 15:32:07 2020
SRCSRV: variables ------------------------------------------
SVN_EXTRACT_TARGET=%targ%\%fnbksl%(%var3%)\%var4%\%fnfile%(%var1%)
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 ---------------------------------------
d:\work\dumpdemo\dumpdemo\stdafx.h*https://nemo-pc/*svn/Work/DumpDemo/DumpDemo/stdafx.h*38
d:\work\dumpdemo\dumpdemo\dump.h*https://nemo-pc/*svn/Work/DumpDemo/DumpDemo/dump.h*38
d:\work\dumpdemo\dumpdemo\dumpdemo.cpp*https://nemo-pc/*svn/Work/DumpDemo/DumpDemo/DumpDemo.cpp*38
d:\work\dumpdemo\dumpdemo\targetver.h*https://nemo-pc/*svn/Work/DumpDemo/DumpDemo/targetver.h*38
d:\work\dumpdemo\dumpdemo\stdafx.cpp*https://nemo-pc/*svn/Work/DumpDemo/DumpDemo/stdafx.cpp*38
SRCSRV: end ------------------------------------------------

也可以使用srctool工具查看索引后的pdb文件

1
2
3
4
5
6
7
C:\Windows\system32>srctool D:\Work\DumpDemo\Release\DumpDemo.pdb
[d:\work\dumpdemo\dumpdemo\stdafx.h] cmd: cmd /c svn.exe cat "https://nemo-pc/svn/Work/DumpDemo/DumpDemo/stdafx.h@38" --non-interactive > "C:\Windows\system32\svn\Work\DumpDemo\DumpDemo\stdafx.h\38\stdafx.h"
[d:\work\dumpdemo\dumpdemo\dump.h] cmd: cmd /c svn.exe cat "https://nemo-pc/svn/Work/DumpDemo/DumpDemo/dump.h@38" --non-interactive > "C:\Windows\system32\svn\Work\DumpDemo\DumpDemo\dump.h\38\dump.h"
[d:\work\dumpdemo\dumpdemo\dumpdemo.cpp] cmd: cmd /c svn.exe cat "https://nemo-pc/svn/Work/DumpDemo/DumpDemo/DumpDemo.cpp@38" --non-interactive > "C:\Windows\system32\svn\Work\DumpDemo\DumpDemo\DumpDemo.cpp\38\dumpdemo.cpp"
[d:\work\dumpdemo\dumpdemo\targetver.h] cmd: cmd /c svn.exe cat "https://nemo-pc/svn/Work/DumpDemo/DumpDemo/targetver.h@38" --non-interactive > "C:\Windows\system32\svn\Work\DumpDemo\DumpDemo\targetver.h\38\targetver.h"
[d:\work\dumpdemo\dumpdemo\stdafx.cpp] cmd: cmd /c svn.exe cat "https://nemo-pc/svn/Work/DumpDemo/DumpDemo/stdafx.cpp@38" --non-interactive > "C:\Windows\system32\svn\Work\DumpDemo\DumpDemo\stdafx.cpp\38\stdafx.cpp"
D:\Work\DumpDemo\Release\DumpDemo.pdb: 5 source files are indexed - 302 are not.

可以看出,svnindex将svn仓库地址和当前版本号,以及如何组合这些信息存储到了pdb中,寻找源码时的操作已经在srctool的输出中显示了。
svn.exe cat "仓库文件地址@版本" --non-interactive > "本地路径"
可以复制svn.exe cat "仓库文件地址@版本"到命令行执行测试。

0x02、保存至符号服务器

保存pdb到符号服务器并不是简单的拷贝过去便可以了,必须遵循Debugger的保存格式,这样windbg才能自动在符号服务器中准确查找pdb文件。简单一点,必须使用symstore工具来上传pdb文件。

1、symstore

使用symstore命令将pdb文件保存到自己的“符号服务器”中,可以是本地的一个文件夹,也可以是远端的网络路径。命令示例

1
2
symstore add /f "符号路径\*.pdb" /s "符号服务器路径" /t "产品名称" /v "版本号" /o
symstore add /f "D:\Work\DumpDemo\Release\*.pdb" /s "D:\Symbols" /t "DempDemo" /v "1.0.0.0" /o

2、symstore格式

一些格式:

1
2
3
4
5
6
7
8
9
10
add             Add files to server or create an index file.
/f File         Network path of files or directories to add.
                If the named file begins with an '@' symbol, it is treated
                as a response file which is expected to contain a list of
                files (path and filename, 1 entry per line) to be stored.
/r              Add files or directories recursively.
/s Store        Root directory for the symbol store.
/t Product      Name of the product.
/v Version      Version of the product.
/o              Give verbose output.

执行示例

1
2
3
4
5
6
7
8
9
C:\Windows\system32>symstore add /f "D:\Work\DumpDemo\Release\*.pdb" /s "D:\Symbols" /t "DempDemo" /v "1.0.0.0" /o
SYMSTORE MESSAGE: 0 alternate indexers registered
SYMSTORE MESSAGE: LastId.txt reported id 3
SYMSTORE MESSAGE: Final id is 0000000003
SYMSTORE MESSAGE: Copying D:\Work\DumpDemo\Release\DumpDemo.pdb to D:\Symbols\DumpDemo.pdb\A3CC46D4F10E4703A393DA7288A713C14\DumpDemo.pdb [Force: T, Compress: F]
 
SYMSTORE: Number of files stored = 1
SYMSTORE: Number of errors = 0
SYMSTORE: Number of files ignored = 0

至此,源码之前已经提交到了版本服务器,符号文件经过处理也已经保存到了符号服务器(本地文件夹),接下来看使用。

0x03、dump分析示例

打开Windbg,由于另一台电脑连不上本地的svn服务器和符号服务器路径,这里直接在本机打开windbg,为了避免直接在原来的路径查找源码,将源码工程文件夹名字做了重命名。
设置windbg符号和源码路径,这里符号路径即“符号服务器”。

新建D:\Src文件夹,设置源码路径

打开dump文件(运行一下《篇一》生成的exe便有了),输入!analyze -v,便。。。。弹出了一个对话框,说明成功了

点“Yes”,对话框具体内容自行研究。。继续。。等一会儿(源码下载中)

分析完毕。打开设置的源码路径,会发现

确实自动下载源码了。
总结:通过源码索引及符号服务器,在只简单设置windbg的情况下,不用拉源码,不用看版本,自动准确完成了dump分析。

 

git篇。。。等一下


阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

最后于 2020-10-10 16:07 被comor编辑 ,原因: 修改超链接
收藏
点赞4
打赏
分享
最新回复 (2)
雪    币: 1779
活跃值: (1262)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lniwn 1 2020-10-10 16:11
2
0
很实用
雪    币: 218
活跃值: (169)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
djzbxxz 2020-10-17 10:36
3
0
好文
游客
登录 | 注册 方可回帖
返回