Dump stl的vector,list,map的三个windbg脚本

用Windbg查看stl的容器实在是已经让人悲伤的事情,为了方便,所以写了这么3个脚本
vector:

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
r? $t0 = ${$arg1}

.if (${/d:$VectorType}) {
r? $t0 = @@C++(*((${$VectorType} *)@$t0))
}

.if (${/d:$arg2}) {
.if ($sicmp("${$arg2}", "-c") == 0) {
r $t2 = 0
aS ${/v:command} "${$arg3}"
}
}
.else {
r $t2 = 1
aS ${/v:command} " "
}


r? $t1 = @@C++(@$t0._Mylast)
r? $t0 = @@C++(@$t0._Myfirst)

.printf "size = %d\n", @@C++((@$t1 - @$t0))

.while (@$t0 != @$t1) {
.if ($t2 == 1) {
?? @@c++(@$t0->_Bx)
}
.else {
r? $t9 = @$t0->_Bx
command
}

r? [email protected]$t0+1
}

ad command

list:

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
r? $t0 = ${$arg1}

.if (${/d:$ListType}) {
r? $t0 = @@C++(*((${$ListType} *)@$t0))
}

.if (${/d:$arg2}) {
.if ($sicmp("${$arg2}", "-c") == 0) {
r $t2 = 0
aS ${/v:command} "${$arg3}"
}
}
.else {
r $t2 = 1
aS ${/v:command} " "
}

.printf "size = %d\n", @@C++(@$t0._Mysize)

r? $t1 = @@C++(@$t0._Myhead)
r? $t0 = @@C++(@$t0._Myhead)
r? $t0 = @@C++(@$t0->_Next)

.while (@$t0 != @$t1) {
.if ($t2 == 1) {
?? @@c++(@$t0->_Myval._Bx)
}
.else {
r? $t9 = @$t0->_Myval._Bx
command
}

r? $t0 = @@C++(@$t0->_Next)
}

ad command

map:

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
.if ($sicmp("${$arg1}", "-n") == 0) { 

.if (@@C++(@$t0->_Left) != @@C++(@$t1)) {
.push /r /q
r? $t0 = @$t0->_Left
$$>a< ${$arg0} -n
.pop /r /q
}

.if (@@C++(@$t0->_Isnil) == 0) {
.if (@$t2 == 1) {
.printf /D "%p\n", @$t0, @$t0
.printf "key = "
?? @$t0->_Myval.first
.printf "value = "
?? @$t0->_Myval.second
}
.else {
r? $t9 = @$t0->_Myval
command
}
}

.if (@@C++(@$t0->_Right) != @@C++(@$t1)) {
.push /r /q
r? $t0 = @$t0->_Right
$$>a< ${$arg0} -n
.pop /r /q
}

}
.else {

r? $t0 = ${$arg1}

.if (${/d:$MapType}) {
r? $t0 = @@C++(*((${$MapType} *)@$t0))
}

.if (${/d:$arg2}) {
.if ($sicmp("${$arg2}", "-c") == 0) {
r $t2 = 0
aS ${/v:command} "${$arg3}"
}
}
.else {
r $t2 = 1
aS ${/v:command} " "
}



.printf "size = %d\n", @@C++(@$t0._Mysize)

r? $t0 = @$t0._Myhead->_Parent
r? $t1 = @$t0->_Parent

$$>a< ${$arg0} -n

ad command
}

Debugging