如何搭建一个符号服务器?
2021-12-14 / Hell

在上一篇文章Windbg如何在众多pdb中找到那个它?中介绍了Windbg快速查找可执行文件对应pdb的方法。那么我们是否可以将该能力运用到实际开发中呢?毕竟版本控制是一件复杂的事情。我们会交付给客户许许多多个版本。某一天客户丢给你一个dump,如何让才能让Windbg快速找到指定的pdb?而不是把每个版本的pdb路径都交给.sympath指令,相信你不会这么干对么?🤣

其实要构建一个类似的符号服务器并不难。只需要一个名为SymStore.exe的程序即可😉
这个程序可以在安装SDK时,选择Debugging Tools for Windows包获得。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
C:\Program Files (x86)\Windows Kits\10\Debuggers\x64>symstore.exe /?
Usage:
symstore add [/r] [/p] [/l] /f File /s Store /t Product [/v Version]
[/c Comment] [/d LogFile] [/compress]
symstore add [/r] [/p] [/l] [/q] /g Share /f File /x IndexFile [/a] [/d LogFile]
symstore add /y IndexFile /g Share /s Store [/p] /t Product [/v Version]
[/c Comment] [/d LogFile] [/compress]
symstore del /i ID /s Store [/d LogFile]
symstore query [/r] [/o] /f File /s Store

add Add files to server or create an index file.
del Delete a transaction from the server.
query Check if file(s) are indexed on the server.

/3 Create index2.txt when populating a new symbol server.
/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.
/g Share This is the server and share where the symbol files were
originally stored. When used with /f, Share should be
identical to the beginning of the File specifier. When
used with the /y, Share should be the location of the
original symbol files, not the index file. This allows
you to later change this portion of the file path in case
you move the symbol files to a different server and share.
/i ID Transaction ID string.
/l Allows the file to be in a local directory rather than a
network path.(This option is only used with the /p option.)
/p Causes SymStore to store a pointer to the file, rather than
the file itself.
/q Don't quote fields in the index file.
/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.
/c Comment Comment for the transaction.
/d LogFile Send output to LogFile instead of standard output.
/x IndexFile Causes SymStore not to store the actual symbol files in the
symbol store. Instead, information is stored which will
allow the files to be added later.
/y IndexFile This reads the data from a file created with /x.
/yi IndexFile Append a comment with the transaction ID to the end of the
index file.
/z pub | pri Pub option will only index symbols that have had the full
source information stripped. Pri will only index symbols
that contain the full source information. Both options
will index binaries.
/m <prefix> Give preference to files which have <prefix> at the beginning
of their path when storing/updating pointers.
/h pub | pri Give priority to pub or pri.
/a Causes SymStore to append new indexing information
to an existing index file. (This option is only used with
/x option.)
/o Give verbose output.
-:MSG [msg] When storing pointers, also add the provided message to the
file.ptr
-:REL Allow file.ptr paths to be relative. Implies '/l' also.
-:NOREFS Only valid during intial store creation or when used on a
store previously created with the -:NOREFS option. Omits the
creation of refs.ptr files for files and pointers stored.
Use of a store without refs.ptr precludes the ability to do
prioritization and the ability to delete transactions from the
store.
-:NOFORCECOPY
/compress When storing files, store compressed files on the server. Ignored
when storing pointers.

symstore.exe是一个支持事务的符号管理模块,它会在指定位置创建一些文件,用来记录操作。注意不要同时运行多个就好。

现在让我们来看看如何利用它快速搭建我们的符号服务器!
首先展示一下现在我负责项目的目录结构:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Folder PATH listing for volume Windows
Volume serial number is BCE9-D3D2
C:.
| .gitattributes
| README.md
|
+---abaabaaba
| \---1636093206
| +---Win32
| | askljdnhf.cat
| | askljdnhf.inf
| | askljdnhf.pdb
| | askljdnhf.sys
| |
| \---x64
| askljdnhf.cat
| askljdnhf.inf
| askljdnhf.pdb
| askljdnhf.sys
|
\---balalabalala
+---1636462090
| +---Win32
| | kmbvnjamfnbd.cat
| | kmbvnjamfnbd.inf
| | kmbvnjamfnbd.pdb
| | kmbvnjamfnbd.sys
| |
| \---x64
| kmbvnjamfnbd.cat
| kmbvnjamfnbd.inf
| kmbvnjamfnbd.pdb
| kmbvnjamfnbd.sys
|
+---1637652381
| +---Win32
| | kmbvnjamfnbd.cat
| | kmbvnjamfnbd.inf
| | kmbvnjamfnbd.pdb
| | kmbvnjamfnbd.sys
| |
| \---x64
| kmbvnjamfnbd.cat
| kmbvnjamfnbd.inf
| kmbvnjamfnbd.pdb
| kmbvnjamfnbd.sys
|
\---1637738935
+---Win32
| kmbvnjamfnbd.cat
| kmbvnjamfnbd.inf
| kmbvnjamfnbd.pdb
| kmbvnjamfnbd.sys
|
\---x64
kmbvnjamfnbd.cat
kmbvnjamfnbd.inf
kmbvnjamfnbd.pdb
kmbvnjamfnbd.sys

结构很简单,根据项目类型不同,分了两个目录abaabaababalalabalala;然后根据编译时间,进行分类;再下一层是目标平台的体系结构,目前是x86x64。如果没有有效的方法来快速帮我识别windbg需要的pdb在哪个路径,这真的是一场灾难😅
执行以下命令:

1
symstore add /r /f C:\WorkCode\dsgsdgercb\BuildHistory\*.pdb /s C:\WorkCode\sym /t kajhsksa

add: 表示添加动作
/r: 表示递归子文件夹
/f: 表示要进行寻找的路径
/s: 符号服务器的根路径

命令执行完成后,看一下C:\WorkCode\sym路径的结构:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
C:.
| pingme.txt
|
+---000Admin
| 0000000001
| history.txt
| lastid.txt
| server.txt
|
+---askljdnhf.pdb
| +---4A5CC674685E46FF8D5AF111DB48BAB61
| | askljdnhf.pdb
| | refs.ptr
| |
| \---58F360DACD0A4136895161C3643779471
| askljdnhf.pdb
| refs.ptr
|
\---kmbvnjamfnbd.pdb
+---0C53AFE2E0304FF082E3507CDE6772F81
| refs.ptr
| kmbvnjamfnbd.pdb
|
+---3F9093DB5F1549F198016027433697B71
| refs.ptr
| kmbvnjamfnbd.pdb
|
+---51B8D55C81884D9DA9C0CD36DC0A11DE1
| refs.ptr
| kmbvnjamfnbd.pdb
|
+---5D3B474FC22C454C9B3CC51C853A5A541
| refs.ptr
| kmbvnjamfnbd.pdb
|
+---C82E44AA3CF749249C253421E3BB94191
| refs.ptr
| kmbvnjamfnbd.pdb
|
\---FB3ACF80435D4FC9ABF42057BC3F623F1
refs.ptr
kmbvnjamfnbd.pdb

这个结构就和微软符号服务器结构一致了✅

PermaLink:
https://lazywang.life/2021/12/14/How-to-set-up-symbol-server/