forked from mongodb/mongo-c-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gdbinit
242 lines (211 loc) · 4.41 KB
/
.gdbinit
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
define printbson
set $bson = $arg0
if $bson->flags & BSON_FLAG_INLINE
print ((bson_impl_inline_t*) $bson)->data
set $data = &(((bson_impl_inline_t*) $bson)->data)
printf "INLINE"
__printbson $data
else
set $impl = (bson_impl_alloc_t*) $bson
printf "ALLOC [%p + %d]", $impl->buf, $impl->offset
__printbson (*$impl->buf) + $impl->data
end
end
define __printbson
set $bson = ((uint32_t*)$arg0)
printf " (len=%d)\n", $bson[0]
printf "{\n"
__printelements ($bson+1) 0 1
printf "\n}\n"
end
define __printelements
set $data = ((uint8_t*)$arg0)
set $isDocument = $arg1
set $depth = $arg2
set $addComma = 0
while $data != 0
set $type = (uint8_t)($data[0])
if $type == 0
loop_break
end
if $addComma == 1
printf ",\n"
end
set $addComma = 1
__printSpaces $depth
printf "'%s' : ", (char*) ($data+1)
# skip through C String
while $data[0] != '\0'
set $data = $data + 1
end
set $data = $data + 1
if $type == 0x01
__printDouble $data
end
if $type == 0x02
__printString $data
end
if $type == 0x03
__printDocument $data $depth
end
if $type == 0x04
__printArray $data $depth
end
if $type == 0x05
__printBinary $data
end
if $type == 0x07
__printObjectID $data
end
if $type == 0x08
__printBool $data
end
if $type == 0x09
__printUtcDateTime $data
end
if $type == 0x0a
__printNull
end
if $type == 0x0b
__printRegex $data
end
if $type == 0x0d
__printJavascript $data
end
if $type == 0x0e
__printSymbol $data
end
if $type == 0x0f
__printJavascriptWScope $data
end
if $type == 0x10
__printInt32 $data
end
if $type == 0x11
__printTimestamp $data
end
if $type == 0x12
__printInt64 $data
end
end
end
define __printSpaces
set $i = 0
while $i < (4 * $arg0)
printf " "
set $i = $i + 1
end
end
define __printDocument
set $value = ((uint8_t*) $arg0)
set $depth = $arg1
printf "{\n"
__printElements ($value+4) 1 ($depth+1)
printf "\n"
__printSpaces ($depth-1)
printf "}"
set $depth = $depth-1
set $data = $data + 1
end
define __printArray
set $value = ((uint8_t*) $arg0)
set $depth = $arg1
printf "[\n"
__printElements ($value+4) (0) ($depth+1)
printf "\n"
__printSpaces ($depth-1)
printf "]"
set $depth = $depth-1
set $data = $data + 1
end
define __printDouble
set $value = ((double*) $arg0)
printf "%f", $value[0]
set $data = $data + 8
end
define __printString
set $value = ((char*) $arg0) + 4
printf "\"%s\"", $value
set $data = $data + 4 + ((uint32_t*)$data)[0]
end
define __printBinary
set $value = ((uint8_t*) $arg0)
set $length = ((int32_t*) $arg0)[0]
printf "Binary(\"%02X\", \"", $value[4]
set $i = 4
while $i < $length
printf "%02X", $value[$i+5]
set $i = $i + 1
end
printf "\")"
set $data = $data + 5 + ((uint32_t*)$data)[0]
end
define __printObjectID
set $value = ((uint8_t*) $arg0)
set $i = 0
printf "ObjectID(\""
while $i < 12
printf "%02X", $value[$i]
set $i = $i + 1
end
printf "\")"
set $data = $data + 12
end
define __printBool
set $value = ((uint8_t*) $arg0)
printf "%s", $value[0] ? "true" : "false"
set $data = $data + 1
end
define __printUtcDateTime
set $value = ((uint64_t*) $arg0)
printf "UTCDateTime(%ld)", $value[0]
set $data = $data + 8
end
define __printNull
printf "null"
end
define __printRegex
printf "Regex(\"%s\", \"", (char*) $data
# skip through C String
while $data[0] != '\0'
set $data = $data + 1
end
set $data = $data + 1
printf "%s\")", (char*) $data
# skip through C String
while $data[0] != '\0'
set $data = $data + 1
end
set $data = $data + 1
end
define __printJavascript
set $value = ((char*) $arg0) + 4
printf "JavaScript(\"%s\")", $value
set $data = $data + 4 + ((uint32_t*)$data)[0]
end
define __printSymbol
set $value = ((char*) $arg0) + 4
printf "Symbol(\"%s\")", $value
set $data = $data + 4 + ((uint32_t*)$data)[0]
end
define __printJavascriptWScope
set $value = ((char*) $arg0) + 8
printf "JavaScript(\"%s\") with scope: ", $value
set $data = $data + 8 + ((uint32_t*)$data)[1]
__printDocument $data $depth
end
define __printInt32
set $value = ((uint32_t*) $arg0)
printf "NumberInt(\"%d\")", $value[0]
set $data = $data + 4
end
define __printTimestamp
set $value = ((uint32_t*) $arg0)
printf "Timestamp(%u, %u)", $value[0], $value[1]
set $data = $data + 8
end
define __printInt64
set $value = ((uint64_t*) $arg0)
printf "NumberLong(\"%ld\")", $value[0]
set $data = $data + 8
end