xref: /PHP-5.3/.gdbinit (revision 7ace6dd1)
1define ____executor_globals
2	if basic_functions_module.zts
3		set $tsrm_ls = ts_resource_ex(0, 0)
4		set $eg = ((zend_executor_globals*) (*((void ***) $tsrm_ls))[executor_globals_id-1])
5		set $cg = ((zend_compiler_globals*) (*((void ***) $tsrm_ls))[compiler_globals_id-1])
6	else
7		set $eg = executor_globals
8		set $cg = compiler_globals
9	end
10end
11
12document ____executor_globals
13	portable way of accessing executor_globals, set $eg
14	this also sets compiler_globals to $cg
15	ZTS detection is automatically based on ext/standard module struct
16end
17
18define print_cvs
19	____executor_globals
20	set $p = $eg.current_execute_data.CVs
21	set $c = $eg.current_execute_data.op_array.last_var
22	set $v = $eg.current_execute_data.op_array.vars
23	set $i = 0
24
25	printf "Compiled variables count: %d\n", $c
26	while $i < $c
27		printf "%d = %s\n", $i, $v[$i].name
28		if $p[$i] != 0
29			printzv *$p[$i]
30		else
31			printf "*uninitialized*\n"
32		end
33		set $i = $i + 1
34	end
35end
36
37define dump_bt
38	set $t = $arg0
39	while $t
40		printf "[0x%08x] ", $t
41		if $t->function_state.function->common.function_name
42			printf "%s() ", $t->function_state.function->common.function_name
43		else
44			printf "??? "
45		end
46		if $t->op_array != 0
47			printf "%s:%d ", $t->op_array->filename, $t->opline->lineno
48		end
49		set $t = $t->prev_execute_data
50		printf "\n"
51	end
52end
53
54document dump_bt
55	dumps the current execution stack. usage: dump_bt executor_globals.current_execute_data
56end
57
58define printzv
59	set $ind = 1
60	____printzv $arg0 0
61end
62
63document printzv
64	prints zval contents
65end
66
67define ____printzv_contents
68	set $zvalue = $arg0
69	set $type = $zvalue->type
70
71	printf "(refcount=%d", $zvalue->refcount__gc
72	if $zvalue->is_ref__gc
73		printf ",is_ref"
74	end
75	printf ") "
76	if $type == 0
77		printf "NULL"
78	end
79	if $type == 1
80		printf "long: %ld", $zvalue->value.lval
81	end
82	if $type == 2
83		printf "double: %lf", $zvalue->value.dval
84	end
85	if $type == 3
86		printf "bool: "
87		if $zvalue->value.lval
88			printf "true"
89		else
90			printf "false"
91		end
92	end
93	if $type == 4
94		printf "array(%d): ", $zvalue->value.ht->nNumOfElements
95		if ! $arg1
96			printf "{\n"
97			set $ind = $ind + 1
98			____print_ht $zvalue->value.ht 1
99			set $ind = $ind - 1
100			set $i = $ind
101			while $i > 0
102				printf "  "
103				set $i = $i - 1
104			end
105			printf "}"
106		end
107		set $type = 0
108	end
109	if $type == 5
110		printf "object"
111		____executor_globals
112		set $handle = $zvalue->value.obj.handle
113		set $handlers = $zvalue->value.obj.handlers
114		if basic_functions_module.zts
115			set $zobj = zend_objects_get_address($zvalue, $tsrm_ls)
116		else
117			set $zobj = zend_objects_get_address($zvalue)
118		end
119		if $handlers->get_class_entry == &zend_std_object_get_class
120			set $cname = $zobj->ce.name
121		else
122			set $cname = "Unknown"
123		end
124		printf "(%s) #%d", $cname, $handle
125		if ! $arg1
126			if $handlers->get_properties == &zend_std_get_properties
127				set $ht = $zobj->properties
128				if $ht
129					printf "(%d): ", $ht->nNumOfElements
130					printf "{\n"
131					set $ind = $ind + 1
132					____print_ht $ht 1
133					set $ind = $ind - 1
134					set $i = $ind
135					while $i > 0
136						printf "  "
137						set $i = $i - 1
138					end
139					printf "}"
140				else
141					echo "no properties found"
142				end
143			end
144		end
145		set $type = 0
146	end
147	if $type == 6
148		printf "string(%d): ", $zvalue->value.str.len
149		____print_str $zvalue->value.str.val $zvalue->value.str.len
150	end
151	if $type == 7
152		printf "resource: #%d", $zvalue->value.lval
153	end
154	if $type == 8
155		printf "constant"
156	end
157	if $type == 9
158		printf "const_array"
159	end
160	if $type > 9
161		printf "unknown type %d", $type
162	end
163	printf "\n"
164end
165
166define ____printzv
167	____executor_globals
168	set $zvalue = $arg0
169
170	printf "[0x%08x] ", $zvalue
171
172	if $zvalue == $eg.uninitialized_zval_ptr
173		printf "*uninitialized* "
174	end
175
176	set $zcontents = (zval*) $zvalue
177	if $arg1
178		____printzv_contents $zcontents $arg1
179	else
180		____printzv_contents $zcontents 0
181	end
182end
183
184define ____print_const_table
185	set $ht = $arg0
186	set $p = $ht->pListHead
187
188	while $p != 0
189		set $const = (zend_constant *) $p->pData
190
191		set $i = $ind
192		while $i > 0
193			printf "  "
194			set $i = $i - 1
195		end
196
197		if $p->nKeyLength > 0
198			____print_str $p->arKey $p->nKeyLength
199			printf " => "
200		else
201			printf "%d => ", $p->h
202		end
203
204		____printzv_contents &$const->value 0
205		set $p = $p->pListNext
206	end
207end
208
209define print_const_table
210	set $ind = 1
211	printf "[0x%08x] {\n", $arg0
212	____print_const_table $arg0
213	printf "}\n"
214end
215
216define ____print_ht
217	set $ht = (HashTable*)$arg0
218	set $p = $ht->pListHead
219
220	while $p != 0
221		set $i = $ind
222		while $i > 0
223			printf "  "
224			set $i = $i - 1
225		end
226
227		if $p->nKeyLength > 0
228			____print_str $p->arKey $p->nKeyLength
229			printf " => "
230		else
231			printf "%d => ", $p->h
232		end
233
234		if $arg1 == 0
235			printf "%p\n", (void*)$p->pData
236		end
237		if $arg1 == 1
238			set $zval = *(zval **)$p->pData
239			____printzv $zval 1
240		end
241		if $arg1 == 2
242			printf "%s\n", (char*)$p->pData
243		end
244
245		set $p = $p->pListNext
246	end
247end
248
249define print_ht
250	set $ind = 1
251	printf "[0x%08x] {\n", $arg0
252	____print_ht $arg0 1
253	printf "}\n"
254end
255
256document print_ht
257	dumps elements of HashTable made of zval
258end
259
260define print_htptr
261	set $ind = 1
262	printf "[0x%08x] {\n", $arg0
263	____print_ht $arg0 0
264	printf "}\n"
265end
266
267document print_htptr
268	dumps elements of HashTable made of pointers
269end
270
271define print_htstr
272	set $ind = 1
273	printf "[0x%08x] {\n", $arg0
274	____print_ht $arg0 2
275	printf "}\n"
276end
277
278document print_htstr
279	dumps elements of HashTable made of strings
280end
281
282define ____print_ft
283	set $ht = $arg0
284	set $p = $ht->pListHead
285
286	while $p != 0
287		set $func = (zend_function*)$p->pData
288
289		set $i = $ind
290		while $i > 0
291			printf "  "
292			set $i = $i - 1
293		end
294
295		if $p->nKeyLength > 0
296			____print_str $p->arKey $p->nKeyLength
297			printf " => "
298		else
299			printf "%d => ", $p->h
300		end
301
302		printf "\"%s\"\n", $func->common.function_name
303		set $p = $p->pListNext
304	end
305end
306
307define print_ft
308	set $ind = 1
309	printf "[0x%08x] {\n", $arg0
310	____print_ft $arg0
311	printf "}\n"
312end
313
314document print_ft
315	dumps a function table (HashTable)
316end
317
318define ____print_inh_class
319	set $ce = $arg0
320	if $ce->ce_flags & 0x10 || $ce->ce_flags & 0x20
321		printf "abstract "
322	else
323		if $ce->ce_flags & 0x40
324			printf "final "
325		end
326	end
327	printf "class %s", $ce->name
328	if $ce->parent != 0
329		printf " extends %s", $ce->parent->name
330	end
331	if $ce->num_interfaces != 0
332		printf " implements"
333		set $tmp = 0
334		while $tmp < $ce->num_interfaces
335			printf " %s", $ce->interfaces[$tmp]->name
336			set $tmp = $tmp + 1
337			if $tmp < $ce->num_interfaces
338				printf ","
339			end
340		end
341	end
342	set $ce = $ce->parent
343end
344
345define ____print_inh_iface
346	set $ce = $arg0
347	printf "interface %s", $ce->name
348	if $ce->num_interfaces != 0
349		set $ce = $ce->interfaces[0]
350		printf " extends %s", $ce->name
351	else
352		set $ce = 0
353	end
354end
355
356define print_inh
357	set $ce = $arg0
358	set $depth = 0
359	while $ce != 0
360		set $tmp = $depth
361		while $tmp != 0
362			printf " "
363			set $tmp = $tmp - 1
364		end
365		set $depth = $depth + 1
366		if $ce->ce_flags & 0x80
367			____print_inh_iface $ce
368		else
369			____print_inh_class $ce
370		end
371		printf " {\n"
372	end
373	while $depth != 0
374		set $tmp = $depth
375		while $tmp != 1
376			printf " "
377			set $tmp = $tmp - 1
378		end
379		printf "}\n"
380		set $depth = $depth - 1
381	end
382end
383
384define print_pi
385	set $pi = $arg0
386	printf "[0x%08x] {\n", $pi
387	printf "    h     = %lu\n", $pi->h
388	printf "    flags = %d (", $pi->flags
389	if $pi->flags & 0x100
390		printf "ZEND_ACC_PUBLIC"
391	else
392		if $pi->flags & 0x200
393			printf "ZEND_ACC_PROTECTED"
394		else
395			if $pi->flags & 0x400
396				printf "ZEND_ACC_PRIVATE"
397			else
398				if $pi->flags & 0x800
399					printf "ZEND_ACC_CHANGED"
400				end
401			end
402		end
403	end
404	printf ")\n"
405	printf "    name  = "
406	____print_str $pi->name $pi->name_length
407	printf "\n}\n"
408end
409
410define ____print_str
411	set $tmp = 0
412	set $str = $arg0
413	printf "\""
414	while $tmp < $arg1
415		if $str[$tmp] > 32 && $str[$tmp] < 127
416			printf "%c", $str[$tmp]
417		else
418			printf "\\%o", $str[$tmp]
419		end
420		set $tmp = $tmp + 1
421	end
422	printf "\""
423end
424
425define printzn
426	____executor_globals
427	set $ind = 0
428	set $znode = $arg0
429	if $znode->op_type == 1
430		set $optype = "IS_CONST"
431	end
432	if $znode->op_type == 2
433		set $optype = "IS_TMP_VAR"
434	end
435	if $znode->op_type == 4
436		set $optype = "IS_VAR"
437	end
438	if $znode->op_type == 8
439		set $optype = "IS_UNUSED"
440	end
441
442	printf "[0x%08x] %s", $znode, $optype
443
444	if $znode->op_type == 1
445		printf ": "
446		____printzv &$znode->u.constant 0
447	end
448	if $znode->op_type == 2
449		printf ": "
450		set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
451		____printzv ((union _temp_variable *)$tvar)->tmp_var 0
452	end
453	if $znode->op_type == 4
454		printf ": "
455		set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
456		____printzv *$tvar->var.ptr_ptr 0
457	end
458	if $znode->op_type == 8
459		printf "\n"
460	end
461end
462
463document printzn
464	print type and content of znode.
465	usage: printzn &opline->op1
466end
467
468define printzops
469	printf "op1 => "
470	printzn &execute_data->opline.op1
471	printf "op2 => "
472	printzn &execute_data->opline.op2
473	printf "result => "
474	printzn &execute_data->opline.result
475end
476
477document printzops
478	dump operands of the current opline
479end
480
481define zbacktrace
482	____executor_globals
483	dump_bt $eg.current_execute_data
484end
485
486document zbacktrace
487	prints backtrace.
488	This command is almost a short cut for
489	> (gdb) ____executor_globals
490	> (gdb) dump_bt $eg.current_execute_data
491end
492
493define zmemcheck
494	set $p = alloc_globals.head
495	set $stat = "?"
496	set $total_size = 0
497	if $arg0 != 0
498		set $not_found = 1
499	else
500		set $not_found = 0
501	end
502	printf " block      size      status file:line\n"
503	printf "-------------------------------------------------------------------------------\n"
504	while $p
505		set $aptr = $p + sizeof(struct _zend_mem_header) + sizeof(align_test)
506		if $arg0 == 0 || (void *)$aptr == (void *)$arg0
507			if $p->magic == 0x7312f8dc
508				set $stat = "OK"
509			end
510			if $p->magic == 0x99954317
511				set $stat = "FREED"
512			end
513			if $p->magic == 0xfb8277dc
514				set $stat = "CACHED"
515			end
516			set $filename = strrchr($p->filename, '/')
517			if !$filename
518				set $filename = $p->filename
519			else
520				set $filename = $filename + 1
521			end
522			printf " 0x%08x ", $aptr
523			if $p->size == sizeof(struct _zval_struct) && ((struct _zval_struct *)$aptr)->type >= 0 && ((struct _zval_struct *)$aptr)->type < 10
524				printf "ZVAL?(%-2d) ", $p->size
525			else
526				printf "%-9d ", $p->size
527			end
528			set $total_size = $total_size + $p->size
529			printf "%-06s %s:%d", $stat, $filename, $p->lineno
530			if $p->orig_filename
531				set $orig_filename = strrchr($p->orig_filename, '/')
532				if !$orig_filename
533					set $orig_filename = $p->orig_filename
534				else
535					set $orig_filename = $orig_filename + 1
536				end
537				printf " <= %s:%d\n", $orig_filename, $p->orig_lineno
538			else
539				printf "\n"
540			end
541			if $arg0 != 0
542				set $p = 0
543				set $not_found = 0
544			else
545				set $p = $p->pNext
546			end
547		else
548			set $p = $p->pNext
549		end
550	end
551	if $not_found
552		printf "no such block that begins at 0x%08x.\n", $aptr
553	end
554	if $arg0 == 0
555		printf "-------------------------------------------------------------------------------\n"
556		printf "     total: %d bytes\n", $total_size
557	end
558end
559
560document zmemcheck
561	show status of a memory block.
562	usage: zmemcheck [ptr].
563	if ptr is 0, all blocks will be listed.
564end
565