forked from openswoole/ext-openswoole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdbinit
277 lines (255 loc) · 6.95 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
define co_list
call swoole_coro_iterator_reset()
set $running = 1
while $running
set $co = swoole_coro_iterator_each()
if $co
printf "coroutine %d ", $co->get_cid()
if $co->state == 0
printf "%s\n", "SW_CORO_INIT"
end
if $co->state == 1
color $RED
printf "%s\n", "SW_CORO_WAITING"
color_reset
end
if $co->state == 2
color $GREEN
printf "%s\n", "SW_CORO_RUNNING"
color_reset
end
if $co->state == 3
printf "%s\n", "SW_CORO_END"
end
end
set $running = 0
end
end
define co_bt
if swoole_coro_count() == 0
printf "no coroutines running\n"
end
____executor_globals
if $argc > 0
set $cid = (int)$arg0
else
set $cid = 'swoole::Coroutine::get_current_cid'()
end
printf "coroutine cid:[%d]\n",$cid
__co_bt $cid
end
document co_bt
dump current coroutine or the cid backtrace.
useage: co_bt [cid]
end
define __co_bt
set $cid = (int)$arg0
set $co = swoole_coro_get($cid)
if $co
set $task = (php_coro_task *)$co->task
if $task
set $backup = $eg.current_execute_data
dump_bt $task->execute_data
set $eg.current_execute_data = $backup
end
else
printf "coroutines %d not found\n", $cid
end
end
define co_status
printf "\t c_stack_size: %d\n", Coroutine::stack_size
printf "\t call_stack_size: %d\n", Coroutine::call_stack_size
printf "\t active: %d\n", swoole::PHPCoroutine::active
printf "\t coro_num: %d\n", swoole::PHPCoroutine::coro_num
printf "\t max_coro_num: %d\n", swoole::PHPCoroutine::max_coro_num
printf "\t peak_coro_num: %d\n", swoole::PHPCoroutine::peak_coro_num
end
define ____executor_globals
if basic_functions_module.zts
if !$tsrm_ls
set $tsrm_ls = ts_resource_ex(0, 0)
end
set $eg = ((zend_executor_globals*) (*((void ***) $tsrm_ls))[executor_globals_id-1])
else
set $eg = executor_globals
end
end
define ____print_str
set $tmp = 0
set $str = $arg0
if $argc > 2
set $maxlen = $arg2
else
set $maxlen = 256
end
printf "\""
while $tmp < $arg1 && $tmp < $maxlen
if $str[$tmp] > 31 && $str[$tmp] < 127
printf "%c", $str[$tmp]
else
printf "\\%o", $str[$tmp]
end
set $tmp = $tmp + 1
end
if $tmp != $arg1
printf "..."
end
printf "\""
end
define dump_bt
set $ex = $arg0
while $ex
printf "[%p] ", $ex
set $func = $ex->func
if $func
if $ex->This->value.obj
if $func->common.scope
printf "%s->", $func->common.scope->name->val
else
printf "%s->", $ex->This->value.obj->ce.name->val
end
else
if $func->common.scope
printf "%s::", $func->common.scope->name->val
end
end
if $func->common.function_name
printf "%s(", $func->common.function_name->val
else
printf "(main"
end
set $callFrameSize = (sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)
set $count = $ex->This.u2.num_args
set $arg = 0
while $arg < $count
if $arg > 0
printf ", "
end
set $zvalue = (zval *) $ex + $callFrameSize + $arg
set $type = $zvalue->u1.v.type
if $type == 1
printf "NULL"
end
if $type == 2
printf "false"
end
if $type == 3
printf "true"
end
if $type == 4
printf "%ld", $zvalue->value.lval
end
if $type == 5
printf "%f", $zvalue->value.dval
end
if $type == 6
____print_str $zvalue->value.str->val $zvalue->value.str->len
end
if $type == 7
printf "array(%d)[%p]", $zvalue->value.arr->nNumOfElements, $zvalue
end
if $type == 8
printf "object[%p]", $zvalue
end
if $type == 9
printf "resource(#%d)", $zvalue->value.lval
end
if $type == 10
printf "reference"
end
if $type > 10
printf "unknown type %d", $type
end
set $arg = $arg + 1
end
printf ") "
else
printf "??? "
end
if $func != 0
if $func->type == 2
printf "%s:%d ", $func->op_array.filename->val, $ex->opline->lineno
else
printf "[internal function]"
end
end
set $ex = $ex->prev_execute_data
printf "\n"
end
end
# __________________color functions_________________
#
set $USECOLOR = 1
# color codes
set $BLACK = 0
set $RED = 1
set $GREEN = 2
set $YELLOW = 3
set $BLUE = 4
set $MAGENTA = 5
set $CYAN = 6
set $WHITE = 7
set $COLOR_REGNAME = $GREEN
set $COLOR_REGVAL = $BLACK
set $COLOR_REGVAL_MODIFIED = $RED
set $COLOR_SEPARATOR = $BLUE
set $COLOR_CPUFLAGS = $RED
# this is ugly but there's no else if available :-(
define color
if $USECOLOR == 1
# BLACK
if $arg0 == 0
echo \033[30m
else
# RED
if $arg0 == 1
echo \033[31m
else
# GREEN
if $arg0 == 2
echo \033[32m
else
# YELLOW
if $arg0 == 3
echo \033[33m
else
# BLUE
if $arg0 == 4
echo \033[34m
else
# MAGENTA
if $arg0 == 5
echo \033[35m
else
# CYAN
if $arg0 == 6
echo \033[36m
else
# WHITE
if $arg0 == 7
echo \033[37m
end
end
end
end
end
end
end
end
end
end
define color_reset
if $USECOLOR == 1
echo \033[0m
end
end
define color_bold
if $USECOLOR == 1
echo \033[1m
end
end
define color_underline
if $USECOLOR == 1
echo \033[4m
end
end