xref: /PHP-7.4/.gdbinit (revision 50f47659)
18e9805bbSXinchen Huidefine set_ts
28e9805bbSXinchen Hui	set $tsrm_ls = $arg0
38e9805bbSXinchen Huiend
48e9805bbSXinchen Hui
58e9805bbSXinchen Huidocument set_ts
68e9805bbSXinchen Hui	set the ts resource, it is impossible for gdb to
78e9805bbSXinchen Hui	call ts_resource_ex while no process is running,
837c329d7SPeter Kokot	but we could get the resource from the argument
98e9805bbSXinchen Hui	of frame info.
108e9805bbSXinchen Huiend
118e9805bbSXinchen Hui
12cfbf35a5SMarcus Boergerdefine ____executor_globals
136dcb27d3SMarcus Boerger	if basic_functions_module.zts
14*50f47659SDylan K. Taylor		set $tsrm_ls = _tsrm_ls_cache
1549e9d8f3SXinchen Hui		set $eg = ((zend_executor_globals*) (*((void ***) $tsrm_ls))[executor_globals_id-1])
1649e9d8f3SXinchen Hui		set $cg = ((zend_compiler_globals*) (*((void ***) $tsrm_ls))[compiler_globals_id-1])
1734fb4297SMitch Hagstrand		set $eg_ptr = $eg
18cfbf35a5SMarcus Boerger	else
19cfbf35a5SMarcus Boerger		set $eg = executor_globals
20edc7e305SMarcus Boerger		set $cg = compiler_globals
2134fb4297SMitch Hagstrand		set $eg_ptr = (zend_executor_globals*) &executor_globals
22cfbf35a5SMarcus Boerger	end
23cfbf35a5SMarcus Boergerend
24cfbf35a5SMarcus Boerger
25cfbf35a5SMarcus Boergerdocument ____executor_globals
26a4e3f297SMarcus Boerger	portable way of accessing executor_globals, set $eg
27edc7e305SMarcus Boerger	this also sets compiler_globals to $cg
286dcb27d3SMarcus Boerger	ZTS detection is automatically based on ext/standard module struct
29cfbf35a5SMarcus Boergerend
30cfbf35a5SMarcus Boerger
31e4e7e2b8SDerick Rethansdefine print_cvs
321ee1f79eSMitch Hagstrand	if $argc == 0
331ee1f79eSMitch Hagstrand		____executor_globals
341ee1f79eSMitch Hagstrand		set $cv_ex_ptr = $eg.current_execute_data
351ee1f79eSMitch Hagstrand	else
361ee1f79eSMitch Hagstrand		set $cv_ex_ptr = (zend_execute_data *)$arg0
371ee1f79eSMitch Hagstrand	end
381ee1f79eSMitch Hagstrand	set $cv_count = $cv_ex_ptr.func.op_array.last_var
391ee1f79eSMitch Hagstrand	set $cv = $cv_ex_ptr.func.op_array.vars
401ee1f79eSMitch Hagstrand	set $cv_idx = 0
411ee1f79eSMitch Hagstrand	set $callFrameSize = (sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)
42e4e7e2b8SDerick Rethans
431ee1f79eSMitch Hagstrand	printf "Compiled variables count: %d\n\n", $cv_count
441ee1f79eSMitch Hagstrand	while $cv_idx < $cv_count
451ee1f79eSMitch Hagstrand		printf "[%d] '%s'\n", $cv_idx, $cv[$cv_idx].val
461ee1f79eSMitch Hagstrand		set $zvalue = ((zval *) $cv_ex_ptr) + $callFrameSize + $cv_idx
471ee1f79eSMitch Hagstrand		printzv $zvalue
481ee1f79eSMitch Hagstrand		set $cv_idx = $cv_idx + 1
49e4e7e2b8SDerick Rethans	end
50e4e7e2b8SDerick Rethansend
51e4e7e2b8SDerick Rethans
521ee1f79eSMitch Hagstranddocument print_cvs
531ee1f79eSMitch Hagstrand	Prints the compiled variables and their values.
541ee1f79eSMitch Hagstrand	If a zend_execute_data pointer is set this will print the compiled
551ee1f79eSMitch Hagstrand	variables of that scope. If no parameter is used it will use
561ee1f79eSMitch Hagstrand	current_execute_data for scope.
571ee1f79eSMitch Hagstrand
581ee1f79eSMitch Hagstrand	usage: print_cvs [zend_execute_data *]
591ee1f79eSMitch Hagstrandend
601ee1f79eSMitch Hagstrand
61c1706b50SThies C. Arntzendefine dump_bt
6253734416SXinchen Hui	set $ex = $arg0
63b5e36ec2SNikita Popov	while $ex
64b5e36ec2SNikita Popov		printf "[%p] ", $ex
65b5e36ec2SNikita Popov		set $func = $ex->func
66b5e36ec2SNikita Popov		if $func
67b7e139a5SNikita Popov			if $ex->This->value.obj
68b5e36ec2SNikita Popov				if $func->common.scope
69b5e36ec2SNikita Popov					printf "%s->", $func->common.scope->name->val
70613674c7SReeze Xia				else
71b7e139a5SNikita Popov					printf "%s->", $ex->This->value.obj->ce.name->val
72613674c7SReeze Xia				end
73b5e36ec2SNikita Popov			else
74b5e36ec2SNikita Popov				if $func->common.scope
75b5e36ec2SNikita Popov					printf "%s::", $func->common.scope->name->val
76b5e36ec2SNikita Popov				end
77b5e36ec2SNikita Popov			end
78b5e36ec2SNikita Popov
7953734416SXinchen Hui			if $func->common.function_name
8053734416SXinchen Hui				printf "%s(", $func->common.function_name->val
8153734416SXinchen Hui			else
8253734416SXinchen Hui				printf "(main"
8353734416SXinchen Hui			end
84b5e36ec2SNikita Popov
85b5e36ec2SNikita Popov			set $callFrameSize = (sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)
86613674c7SReeze Xia
87f0d9d182SDmitry Stogov			set $count = $ex->This.u2.num_args
88b5e36ec2SNikita Popov			set $arg = 0
89b5e36ec2SNikita Popov			while $arg < $count
90b5e36ec2SNikita Popov				if $arg > 0
91b5e36ec2SNikita Popov					printf ", "
9217f5bf2eSXinchen Hui				end
93b5e36ec2SNikita Popov
94b5e36ec2SNikita Popov				set $zvalue = (zval *) $ex + $callFrameSize + $arg
95b5e36ec2SNikita Popov				set $type = $zvalue->u1.v.type
96b5e36ec2SNikita Popov				if $type == 1
97b5e36ec2SNikita Popov					printf "NULL"
98b5e36ec2SNikita Popov				end
99b5e36ec2SNikita Popov				if $type == 2
100b5e36ec2SNikita Popov					printf "false"
101b5e36ec2SNikita Popov				end
102b5e36ec2SNikita Popov				if $type == 3
103b5e36ec2SNikita Popov					printf "true"
104b5e36ec2SNikita Popov				end
105b5e36ec2SNikita Popov				if $type == 4
106b5e36ec2SNikita Popov					printf "%ld", $zvalue->value.lval
107b5e36ec2SNikita Popov				end
108b5e36ec2SNikita Popov				if $type == 5
109b5e36ec2SNikita Popov					printf "%f", $zvalue->value.dval
110b5e36ec2SNikita Popov				end
111b5e36ec2SNikita Popov				if $type == 6
112b5e36ec2SNikita Popov					____print_str $zvalue->value.str->val $zvalue->value.str->len
113b5e36ec2SNikita Popov				end
114b5e36ec2SNikita Popov				if $type == 7
11597433d8fSXinchen Hui					printf "array(%d)[%p]", $zvalue->value.arr->nNumOfElements, $zvalue
116b5e36ec2SNikita Popov				end
117b5e36ec2SNikita Popov				if $type == 8
118b5e36ec2SNikita Popov					printf "object[%p]", $zvalue
119b5e36ec2SNikita Popov				end
120b5e36ec2SNikita Popov				if $type == 9
121b5e36ec2SNikita Popov					printf "resource(#%d)", $zvalue->value.lval
122b5e36ec2SNikita Popov				end
123b5e36ec2SNikita Popov				if $type == 10
124b5e36ec2SNikita Popov					printf "reference"
125b5e36ec2SNikita Popov				end
126b5e36ec2SNikita Popov				if $type > 10
127b5e36ec2SNikita Popov					printf "unknown type %d", $type
128b5e36ec2SNikita Popov				end
129b5e36ec2SNikita Popov				set $arg = $arg + 1
13017f5bf2eSXinchen Hui			end
131b5e36ec2SNikita Popov
132b5e36ec2SNikita Popov			printf ") "
133c1706b50SThies C. Arntzen		else
134c1706b50SThies C. Arntzen			printf "??? "
135c1706b50SThies C. Arntzen		end
136b5e36ec2SNikita Popov		if $func != 0
13753734416SXinchen Hui			if $func->type == 2
13853734416SXinchen Hui				printf "%s:%d ", $func->op_array.filename->val, $ex->opline->lineno
13953734416SXinchen Hui			else
14053734416SXinchen Hui				printf "[internal function]"
14153734416SXinchen Hui			end
142c1706b50SThies C. Arntzen		end
143b5e36ec2SNikita Popov		set $ex = $ex->prev_execute_data
144c1706b50SThies C. Arntzen		printf "\n"
145cfbf35a5SMarcus Boerger	end
146c1706b50SThies C. Arntzenend
1476e3faef2SMoriyoshi Koizumi
148c1706b50SThies C. Arntzendocument dump_bt
149c1706b50SThies C. Arntzen	dumps the current execution stack. usage: dump_bt executor_globals.current_execute_data
150c1706b50SThies C. Arntzenend
1516e3faef2SMoriyoshi Koizumi
1526e3faef2SMoriyoshi Koizumidefine printzv
1537177ada1SSterling Hughes	set $ind = 1
15437c329d7SPeter Kokot	____printzv $arg0 0
1556e3faef2SMoriyoshi Koizumiend
1566e3faef2SMoriyoshi Koizumi
1576e3faef2SMoriyoshi Koizumidocument printzv
158a4e3f297SMarcus Boerger	prints zval contents
1596e3faef2SMoriyoshi Koizumiend
1606e3faef2SMoriyoshi Koizumi
1617177ada1SSterling Hughesdefine ____printzv_contents
1626e3faef2SMoriyoshi Koizumi	set $zvalue = $arg0
163bdeeddbbSNikita Popov	set $type = $zvalue->u1.v.type
1646e3faef2SMoriyoshi Koizumi
165d1ae74a1SNikita Popov	# 15 == IS_INDIRECT
166d73789efSNikita Popov	if $type > 5 && $type < 12
167e6e5defbSMichael Wallner		printf "(refcount=%d) ", $zvalue->value.counted->gc.refcount
168d1ae74a1SNikita Popov	end
169d1ae74a1SNikita Popov
1706dcb27d3SMarcus Boerger	if $type == 0
17115e9bfa0SXinchen Hui		printf "UNDEF"
1726e3faef2SMoriyoshi Koizumi	end
1736dcb27d3SMarcus Boerger	if $type == 1
174da5db1c9SMitch Hagstrand		printf "NULL"
1756e3faef2SMoriyoshi Koizumi	end
1766dcb27d3SMarcus Boerger	if $type == 2
177bdeeddbbSNikita Popov		printf "bool: false"
1786e3faef2SMoriyoshi Koizumi	end
1796dcb27d3SMarcus Boerger	if $type == 3
180bdeeddbbSNikita Popov		printf "bool: true"
1816e3faef2SMoriyoshi Koizumi	end
182da5db1c9SMitch Hagstrand	if $type == 4
18315e9bfa0SXinchen Hui		printf "long: %ld", $zvalue->value.lval
184da5db1c9SMitch Hagstrand	end
185da5db1c9SMitch Hagstrand	if $type == 5
186da5db1c9SMitch Hagstrand		printf "double: %f", $zvalue->value.dval
187da5db1c9SMitch Hagstrand	end
188da5db1c9SMitch Hagstrand	if $type == 6
189da5db1c9SMitch Hagstrand		printf "string: %s", $zvalue->value.str->val
190da5db1c9SMitch Hagstrand	end
19137c329d7SPeter Kokot	if $type == 7
192d1ae74a1SNikita Popov		printf "array: "
1936e3faef2SMoriyoshi Koizumi		if ! $arg1
1946e3faef2SMoriyoshi Koizumi			set $ind = $ind + 1
195d27a8a7dSAdam Saponara			____print_ht $zvalue->value.arr 1
1966e3faef2SMoriyoshi Koizumi			set $ind = $ind - 1
1976e3faef2SMoriyoshi Koizumi			set $i = $ind
1986e3faef2SMoriyoshi Koizumi			while $i > 0
1996e3faef2SMoriyoshi Koizumi				printf "  "
2006e3faef2SMoriyoshi Koizumi				set $i = $i - 1
2016e3faef2SMoriyoshi Koizumi			end
2026e3faef2SMoriyoshi Koizumi		end
2036dcb27d3SMarcus Boerger		set $type = 0
2046e3faef2SMoriyoshi Koizumi	end
205bdeeddbbSNikita Popov	if $type == 8
2066dcb27d3SMarcus Boerger		printf "object"
2076dcb27d3SMarcus Boerger		____executor_globals
2086dcb27d3SMarcus Boerger		set $handle = $zvalue->value.obj.handle
2096dcb27d3SMarcus Boerger		set $handlers = $zvalue->value.obj.handlers
210db894fa6SMitch Hagstrand		set $zobj = $zvalue->value.obj
211db894fa6SMitch Hagstrand		set $cname = $zobj->ce->name->val
2126dcb27d3SMarcus Boerger		printf "(%s) #%d", $cname, $handle
2136e3faef2SMoriyoshi Koizumi		if ! $arg1
2146dcb27d3SMarcus Boerger			if $handlers->get_properties == &zend_std_get_properties
215db894fa6SMitch Hagstrand				if $zobj->properties
216d73789efSNikita Popov					printf "\nProperties "
217db894fa6SMitch Hagstrand					set $ht = $zobj->properties
2186dcb27d3SMarcus Boerger					set $ind = $ind + 1
219a4e3f297SMarcus Boerger					____print_ht $ht 1
2206dcb27d3SMarcus Boerger					set $ind = $ind - 1
2216dcb27d3SMarcus Boerger					set $i = $ind
2226dcb27d3SMarcus Boerger					while $i > 0
2236dcb27d3SMarcus Boerger						printf "  "
2246dcb27d3SMarcus Boerger						set $i = $i - 1
2256dcb27d3SMarcus Boerger					end
2266dcb27d3SMarcus Boerger				else
227d73789efSNikita Popov					printf " {\n"
228d73789efSNikita Popov					set $ht = &$zobj->ce->properties_info
229d73789efSNikita Popov					set $k = 0
230d73789efSNikita Popov					set $num = $ht->nNumUsed
231d73789efSNikita Popov					while $k < $num
232d73789efSNikita Popov						set $p = (Bucket*)($ht->arData + $k)
233d73789efSNikita Popov						set $name = $p->key
234d73789efSNikita Popov						set $prop = (zend_property_info*)$p->val.value.ptr
235d73789efSNikita Popov						set $val = (zval*)((char*)$zobj + $prop->offset)
236d73789efSNikita Popov						printf "%s => ", $name->val
237d73789efSNikita Popov						printzv $val
238d73789efSNikita Popov						set $k = $k + 1
239d73789efSNikita Popov					end
2406dcb27d3SMarcus Boerger				end
241cfbf35a5SMarcus Boerger			end
2426e3faef2SMoriyoshi Koizumi		end
2436dcb27d3SMarcus Boerger		set $type = 0
2446e3faef2SMoriyoshi Koizumi	end
245bdeeddbbSNikita Popov	if $type == 9
24615e9bfa0SXinchen Hui		printf "resource: #%d", $zvalue->value.res->handle
2476dcb27d3SMarcus Boerger	end
248bdeeddbbSNikita Popov	if $type == 10
249afd8a021SNikita Popov		printf "reference: "
250afd8a021SNikita Popov		____printzv &$zvalue->value.ref->val $arg1
2516dcb27d3SMarcus Boerger	end
252bdeeddbbSNikita Popov	if $type == 11
25315e9bfa0SXinchen Hui		printf "const: %s", $zvalue->value.str->val
2546dcb27d3SMarcus Boerger	end
255bdeeddbbSNikita Popov	if $type == 12
256da5db1c9SMitch Hagstrand		printf "CONSTANT_AST"
257bdeeddbbSNikita Popov	end
25815e9bfa0SXinchen Hui	if $type == 13
259d73789efSNikita Popov		printf "indirect: "
260d73789efSNikita Popov		____printzv $zvalue->value.zv $arg1
2616e3faef2SMoriyoshi Koizumi	end
26215e9bfa0SXinchen Hui	if $type == 14
263d73789efSNikita Popov		printf "pointer: %p", $zvalue->value.ptr
26415e9bfa0SXinchen Hui	end
26515e9bfa0SXinchen Hui	if $type == 15
266d73789efSNikita Popov		printf "_ERROR"
267d73789efSNikita Popov	end
268d73789efSNikita Popov	if $type == 16
269d73789efSNikita Popov		printf "_BOOL"
27015e9bfa0SXinchen Hui	end
27115e9bfa0SXinchen Hui	if $type == 17
272d73789efSNikita Popov		printf "CALLABLE"
27315e9bfa0SXinchen Hui	end
274da5db1c9SMitch Hagstrand	if $type == 18
275da5db1c9SMitch Hagstrand		printf "ITERABLE"
276da5db1c9SMitch Hagstrand	end
277da5db1c9SMitch Hagstrand	if $type == 19
278da5db1c9SMitch Hagstrand		printf "VOID"
279da5db1c9SMitch Hagstrand	end
280da5db1c9SMitch Hagstrand	if $type == 20
281d73789efSNikita Popov		printf "_NUMBER"
282da5db1c9SMitch Hagstrand	end
283d73789efSNikita Popov	if $type > 20
2846dcb27d3SMarcus Boerger		printf "unknown type %d", $type
2856e3faef2SMoriyoshi Koizumi	end
2866e3faef2SMoriyoshi Koizumi	printf "\n"
2876e3faef2SMoriyoshi Koizumiend
2886e3faef2SMoriyoshi Koizumi
2897177ada1SSterling Hughesdefine ____printzv
2907177ada1SSterling Hughes	____executor_globals
2917177ada1SSterling Hughes	set $zvalue = $arg0
2927177ada1SSterling Hughes
293ded11f42SXinchen Hui	printf "[%p] ", $zvalue
2947177ada1SSterling Hughes
2956dcb27d3SMarcus Boerger	set $zcontents = (zval*) $zvalue
2967177ada1SSterling Hughes	if $arg1
2977177ada1SSterling Hughes		____printzv_contents $zcontents $arg1
2987177ada1SSterling Hughes	else
29937c329d7SPeter Kokot		____printzv_contents $zcontents 0
3007177ada1SSterling Hughes	end
3017177ada1SSterling Hughesend
3027177ada1SSterling Hughes
30334fb4297SMitch Hagstranddefine print_global_vars
30434fb4297SMitch Hagstrand	____executor_globals
30534fb4297SMitch Hagstrand	set $symtable = ((HashTable *)&($eg_ptr->symbol_table))
30634fb4297SMitch Hagstrand	print_ht $symtable
30734fb4297SMitch Hagstrandend
30834fb4297SMitch Hagstrand
30934fb4297SMitch Hagstranddocument print_global_vars
31034fb4297SMitch Hagstrand	Prints the global variables
31134fb4297SMitch Hagstrandend
31234fb4297SMitch Hagstrand
3137177ada1SSterling Hughesdefine print_const_table
3147177ada1SSterling Hughes	set $ind = 1
315ded11f42SXinchen Hui	printf "[%p] {\n", $arg0
316da5db1c9SMitch Hagstrand	____print_ht $arg0 4
3177177ada1SSterling Hughes	printf "}\n"
3187177ada1SSterling Hughesend
3197177ada1SSterling Hughes
320da5db1c9SMitch Hagstranddocument print_const_table
321da5db1c9SMitch Hagstrand	Dumps elements of Constants HashTable
322da5db1c9SMitch Hagstrand	Example: print_const_table executor_globals.zend_constants
323da5db1c9SMitch Hagstrandend
324da5db1c9SMitch Hagstrand
3256e3faef2SMoriyoshi Koizumidefine ____print_ht
326a4e3f297SMarcus Boerger	set $ht = (HashTable*)$arg0
32715e9bfa0SXinchen Hui	set $n = $ind
32815e9bfa0SXinchen Hui	while $n > 0
32915e9bfa0SXinchen Hui		printf "  "
33015e9bfa0SXinchen Hui		set $n = $n - 1
33115e9bfa0SXinchen Hui	end
332d1ae74a1SNikita Popov
333d1ae74a1SNikita Popov	if $ht->u.v.flags & 4
334d1ae74a1SNikita Popov		printf "Packed"
335d1ae74a1SNikita Popov	else
336d1ae74a1SNikita Popov		printf "Hash"
337d1ae74a1SNikita Popov	end
338d1ae74a1SNikita Popov	printf "(%d)[%p]: {\n", $ht->nNumOfElements, $ht
339d1ae74a1SNikita Popov
340d1ae74a1SNikita Popov	set $num = $ht->nNumUsed
341d1ae74a1SNikita Popov	set $i = 0
342d1ae74a1SNikita Popov	set $ind = $ind + 1
343d1ae74a1SNikita Popov	while $i < $num
344d1ae74a1SNikita Popov		set $p = (Bucket*)($ht->arData + $i)
345d1ae74a1SNikita Popov		set $n = $ind
346d1ae74a1SNikita Popov		if $p->val.u1.v.type > 0
347d1ae74a1SNikita Popov			while $n > 0
348d1ae74a1SNikita Popov				printf "  "
349d1ae74a1SNikita Popov				set $n = $n - 1
350d1ae74a1SNikita Popov			end
351d1ae74a1SNikita Popov			printf "[%d] ", $i
35237c329d7SPeter Kokot			if $p->key
3536b631f07SDylan K. Taylor				____print_str $p->key->val $p->key->len
3546b631f07SDylan K. Taylor				printf " => "
355d1ae74a1SNikita Popov			else
35615e9bfa0SXinchen Hui				printf "%d => ", $p->h
35715e9bfa0SXinchen Hui			end
358d1ae74a1SNikita Popov			if $arg1 == 0
359d1ae74a1SNikita Popov				printf "%p\n", (zval *)&$p->val
36015e9bfa0SXinchen Hui			end
361d1ae74a1SNikita Popov			if $arg1 == 1
362d1ae74a1SNikita Popov				set $zval = (zval *)&$p->val
363d1ae74a1SNikita Popov				____printzv $zval 1
364d1ae74a1SNikita Popov			end
365d1ae74a1SNikita Popov			if $arg1 == 2
366d1ae74a1SNikita Popov				printf "%s\n", (char*)$p->val.value.ptr
367d1ae74a1SNikita Popov			end
368d1ae74a1SNikita Popov			if $arg1 == 3
369d1ae74a1SNikita Popov				set $func = (zend_function*)$p->val.value.ptr
370d1ae74a1SNikita Popov				printf "\"%s\"\n", $func->common.function_name->val
371d1ae74a1SNikita Popov			end
372da5db1c9SMitch Hagstrand			if $arg1 == 4
373da5db1c9SMitch Hagstrand				set $const = (zend_constant *)$p->val.value.ptr
374da5db1c9SMitch Hagstrand				____printzv $const 1
375da5db1c9SMitch Hagstrand			end
376d1ae74a1SNikita Popov		end
377d1ae74a1SNikita Popov		set $i = $i + 1
378d1ae74a1SNikita Popov	end
379d1ae74a1SNikita Popov	set $ind = $ind - 1
380d1ae74a1SNikita Popov	printf "}\n"
3816e3faef2SMoriyoshi Koizumiend
3826e3faef2SMoriyoshi Koizumi
3836e3faef2SMoriyoshi Koizumidefine print_ht
38415e9bfa0SXinchen Hui	set $ind = 0
385a4e3f297SMarcus Boerger	____print_ht $arg0 1
3866e3faef2SMoriyoshi Koizumiend
3876e3faef2SMoriyoshi Koizumi
3886e3faef2SMoriyoshi Koizumidocument print_ht
3896e3faef2SMoriyoshi Koizumi	dumps elements of HashTable made of zval
3906e3faef2SMoriyoshi Koizumiend
3916e3faef2SMoriyoshi Koizumi
392a4e3f297SMarcus Boergerdefine print_htptr
39315e9bfa0SXinchen Hui	set $ind = 0
394a4e3f297SMarcus Boerger	____print_ht $arg0 0
395a4e3f297SMarcus Boergerend
396a4e3f297SMarcus Boerger
397a4e3f297SMarcus Boergerdocument print_htptr
398a4e3f297SMarcus Boerger	dumps elements of HashTable made of pointers
399a4e3f297SMarcus Boergerend
400a4e3f297SMarcus Boerger
401a4e3f297SMarcus Boergerdefine print_htstr
40237c329d7SPeter Kokot	set $ind = 0
403a4e3f297SMarcus Boerger	____print_ht $arg0 2
404a4e3f297SMarcus Boergerend
405a4e3f297SMarcus Boerger
406a4e3f297SMarcus Boergerdocument print_htstr
407a4e3f297SMarcus Boerger	dumps elements of HashTable made of strings
408a4e3f297SMarcus Boergerend
409a4e3f297SMarcus Boerger
4106dcb27d3SMarcus Boergerdefine print_ft
41115e9bfa0SXinchen Hui	set $ind = 0
41215e9bfa0SXinchen Hui	____print_ht $arg0 3
4136dcb27d3SMarcus Boergerend
4146dcb27d3SMarcus Boerger
4156dcb27d3SMarcus Boergerdocument print_ft
4166dcb27d3SMarcus Boerger	dumps a function table (HashTable)
4176dcb27d3SMarcus Boergerend
4186dcb27d3SMarcus Boerger
41955f0daf6SMichael Wallnerdefine ____print_inh_class
42055f0daf6SMichael Wallner	set $ce = $arg0
42155f0daf6SMichael Wallner	if $ce->ce_flags & 0x10 || $ce->ce_flags & 0x20
42255f0daf6SMichael Wallner		printf "abstract "
42355f0daf6SMichael Wallner	else
42455f0daf6SMichael Wallner		if $ce->ce_flags & 0x40
42555f0daf6SMichael Wallner			printf "final "
42655f0daf6SMichael Wallner		end
42755f0daf6SMichael Wallner	end
42815e9bfa0SXinchen Hui	printf "class %s", $ce->name->val
42955f0daf6SMichael Wallner	if $ce->parent != 0
43015e9bfa0SXinchen Hui		printf " extends %s", $ce->parent->name->val
43155f0daf6SMichael Wallner	end
43255f0daf6SMichael Wallner	if $ce->num_interfaces != 0
43355f0daf6SMichael Wallner		printf " implements"
43455f0daf6SMichael Wallner		set $tmp = 0
43555f0daf6SMichael Wallner		while $tmp < $ce->num_interfaces
43615e9bfa0SXinchen Hui			printf " %s", $ce->interfaces[$tmp]->name->val
43755f0daf6SMichael Wallner			set $tmp = $tmp + 1
43855f0daf6SMichael Wallner			if $tmp < $ce->num_interfaces
43955f0daf6SMichael Wallner				printf ","
44055f0daf6SMichael Wallner			end
44155f0daf6SMichael Wallner		end
44255f0daf6SMichael Wallner	end
44355f0daf6SMichael Wallner	set $ce = $ce->parent
44455f0daf6SMichael Wallnerend
44555f0daf6SMichael Wallner
44655f0daf6SMichael Wallnerdefine ____print_inh_iface
44755f0daf6SMichael Wallner	set $ce = $arg0
44815e9bfa0SXinchen Hui	printf "interface %s", $ce->name->val
44955f0daf6SMichael Wallner	if $ce->num_interfaces != 0
45055f0daf6SMichael Wallner		set $ce = $ce->interfaces[0]
45115e9bfa0SXinchen Hui		printf " extends %s", $ce->name->val
45255f0daf6SMichael Wallner	else
45355f0daf6SMichael Wallner		set $ce = 0
45455f0daf6SMichael Wallner	end
45555f0daf6SMichael Wallnerend
45655f0daf6SMichael Wallner
45778d11cbcSMichael Wallnerdefine print_inh
45878d11cbcSMichael Wallner	set $ce = $arg0
45978d11cbcSMichael Wallner	set $depth = 0
46078d11cbcSMichael Wallner	while $ce != 0
46178d11cbcSMichael Wallner		set $tmp = $depth
46278d11cbcSMichael Wallner		while $tmp != 0
46378d11cbcSMichael Wallner			printf " "
46478d11cbcSMichael Wallner			set $tmp = $tmp - 1
46578d11cbcSMichael Wallner		end
46655f0daf6SMichael Wallner		set $depth = $depth + 1
46755f0daf6SMichael Wallner		if $ce->ce_flags & 0x80
46855f0daf6SMichael Wallner			____print_inh_iface $ce
46955f0daf6SMichael Wallner		else
47055f0daf6SMichael Wallner			____print_inh_class $ce
47178d11cbcSMichael Wallner		end
47278d11cbcSMichael Wallner		printf " {\n"
47378d11cbcSMichael Wallner	end
47478d11cbcSMichael Wallner	while $depth != 0
47578d11cbcSMichael Wallner		set $tmp = $depth
47678d11cbcSMichael Wallner		while $tmp != 1
47778d11cbcSMichael Wallner			printf " "
47878d11cbcSMichael Wallner			set $tmp = $tmp - 1
47978d11cbcSMichael Wallner		end
48078d11cbcSMichael Wallner		printf "}\n"
48178d11cbcSMichael Wallner		set $depth = $depth - 1
48278d11cbcSMichael Wallner	end
48378d11cbcSMichael Wallnerend
48478d11cbcSMichael Wallner
48578d11cbcSMichael Wallnerdefine print_pi
486db894fa6SMitch Hagstrand	set $pi = (zend_property_info *)$arg0
48701f7998dSMitch Hagstrand	set $initial_offset = ((uint32_t)(zend_uintptr_t)(&((zend_object*)0)->properties_table[(0)]))
48801f7998dSMitch Hagstrand	set $ptr_to_val = (zval*)((char*)$pi->ce->default_properties_table + $pi->offset - $initial_offset)
489ded11f42SXinchen Hui	printf "[%p] {\n", $pi
49001f7998dSMitch Hagstrand	printf "    offset = %p\n", $pi->offset
491db894fa6SMitch Hagstrand	printf "    ce = [%p] %s\n", $pi->ce, $pi->ce->name->val
49201f7998dSMitch Hagstrand	printf "    flags = 0x%x (", $pi->flags
49378d11cbcSMichael Wallner	if $pi->flags & 0x100
49478d11cbcSMichael Wallner		printf "ZEND_ACC_PUBLIC"
49578d11cbcSMichael Wallner	else
49678d11cbcSMichael Wallner		if $pi->flags & 0x200
49778d11cbcSMichael Wallner			printf "ZEND_ACC_PROTECTED"
49878d11cbcSMichael Wallner		else
49978d11cbcSMichael Wallner			if $pi->flags & 0x400
50078d11cbcSMichael Wallner				printf "ZEND_ACC_PRIVATE"
50178d11cbcSMichael Wallner			else
50278d11cbcSMichael Wallner				if $pi->flags & 0x800
50301f7998dSMitch Hagstrand					printf "ZEND_ACC_EARLY_BINDING"
50401f7998dSMitch Hagstrand				else
50501f7998dSMitch Hagstrand					if $pi->flags & 0x20000
50601f7998dSMitch Hagstrand						printf "ZEND_ACC_SHADOW"
50701f7998dSMitch Hagstrand					end
50878d11cbcSMichael Wallner				end
50978d11cbcSMichael Wallner			end
51078d11cbcSMichael Wallner		end
51178d11cbcSMichael Wallner	end
51278d11cbcSMichael Wallner	printf ")\n"
51378d11cbcSMichael Wallner	printf "    name  = "
514db894fa6SMitch Hagstrand	print_zstr $pi->name
51501f7998dSMitch Hagstrand	printf "    default value: "
51601f7998dSMitch Hagstrand	printzv $ptr_to_val
517db894fa6SMitch Hagstrand	printf "}\n"
518db894fa6SMitch Hagstrandend
519db894fa6SMitch Hagstrand
520db894fa6SMitch Hagstranddocument print_pi
521db894fa6SMitch Hagstrand	Takes a pointer to an object's property and prints the property information
522db894fa6SMitch Hagstrand	usage: print_pi <ptr>
52378d11cbcSMichael Wallnerend
52478d11cbcSMichael Wallner
52578d11cbcSMichael Wallnerdefine ____print_str
52678d11cbcSMichael Wallner	set $tmp = 0
52778d11cbcSMichael Wallner	set $str = $arg0
528db894fa6SMitch Hagstrand	if $argc > 2
529db894fa6SMitch Hagstrand		set $maxlen = $arg2
530db894fa6SMitch Hagstrand	else
531db894fa6SMitch Hagstrand		set $maxlen = 256
532db894fa6SMitch Hagstrand	end
533db894fa6SMitch Hagstrand
53478d11cbcSMichael Wallner	printf "\""
535db894fa6SMitch Hagstrand	while $tmp < $arg1 && $tmp < $maxlen
536db894fa6SMitch Hagstrand		if $str[$tmp] > 31 && $str[$tmp] < 127
53778d11cbcSMichael Wallner			printf "%c", $str[$tmp]
53878d11cbcSMichael Wallner		else
53978d11cbcSMichael Wallner			printf "\\%o", $str[$tmp]
54078d11cbcSMichael Wallner		end
54178d11cbcSMichael Wallner		set $tmp = $tmp + 1
54278d11cbcSMichael Wallner	end
543a6d33eb6SNikita Popov	if $tmp != $arg1
544a6d33eb6SNikita Popov		printf "..."
545a6d33eb6SNikita Popov	end
54678d11cbcSMichael Wallner	printf "\""
54778d11cbcSMichael Wallnerend
54878d11cbcSMichael Wallner
5496e3faef2SMoriyoshi Koizumidefine printzn
550cfbf35a5SMarcus Boerger	____executor_globals
5516e3faef2SMoriyoshi Koizumi	set $ind = 0
5526e3faef2SMoriyoshi Koizumi	set $znode = $arg0
5536e3faef2SMoriyoshi Koizumi	if $znode->op_type == 1
5546e3faef2SMoriyoshi Koizumi		set $optype = "IS_CONST"
5556e3faef2SMoriyoshi Koizumi	end
55637c329d7SPeter Kokot	if $znode->op_type == 2
5576e3faef2SMoriyoshi Koizumi		set $optype = "IS_TMP_VAR"
5586e3faef2SMoriyoshi Koizumi	end
55937c329d7SPeter Kokot	if $znode->op_type == 4
5606e3faef2SMoriyoshi Koizumi		set $optype = "IS_VAR"
5616e3faef2SMoriyoshi Koizumi	end
5626e3faef2SMoriyoshi Koizumi	if $znode->op_type == 8
5636e3faef2SMoriyoshi Koizumi		set $optype = "IS_UNUSED"
5646e3faef2SMoriyoshi Koizumi	end
5656e3faef2SMoriyoshi Koizumi
566ded11f42SXinchen Hui	printf "[%p] %s", $znode, $optype
5676e3faef2SMoriyoshi Koizumi
5686e3faef2SMoriyoshi Koizumi	if $znode->op_type == 1
5696e3faef2SMoriyoshi Koizumi		printf ": "
57039742252SMoriyoshi Koizumi		____printzv &$znode->u.constant 0
5716e3faef2SMoriyoshi Koizumi	end
5726e3faef2SMoriyoshi Koizumi	if $znode->op_type == 2
5736e3faef2SMoriyoshi Koizumi		printf ": "
574cfbf35a5SMarcus Boerger		set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
57539742252SMoriyoshi Koizumi		____printzv ((union _temp_variable *)$tvar)->tmp_var 0
5766e3faef2SMoriyoshi Koizumi	end
5776e3faef2SMoriyoshi Koizumi	if $znode->op_type == 4
5786e3faef2SMoriyoshi Koizumi		printf ": "
579cfbf35a5SMarcus Boerger		set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
58039742252SMoriyoshi Koizumi		____printzv *$tvar->var.ptr_ptr 0
5816e3faef2SMoriyoshi Koizumi	end
5826e3faef2SMoriyoshi Koizumi	if $znode->op_type == 8
5836e3faef2SMoriyoshi Koizumi		printf "\n"
5846e3faef2SMoriyoshi Koizumi	end
5856e3faef2SMoriyoshi Koizumiend
5866e3faef2SMoriyoshi Koizumi
5876e3faef2SMoriyoshi Koizumidocument printzn
588e184a55bSMoriyoshi Koizumi	print type and content of znode.
58937c329d7SPeter Kokot	usage: printzn &opline->op1
59080bfd184SMoriyoshi Koizumiend
59180bfd184SMoriyoshi Koizumi
59280bfd184SMoriyoshi Koizumidefine printzops
59337c329d7SPeter Kokot	printf "op1 => "
59480bfd184SMoriyoshi Koizumi	printzn &execute_data->opline.op1
59580bfd184SMoriyoshi Koizumi	printf "op2 => "
59680bfd184SMoriyoshi Koizumi	printzn &execute_data->opline.op2
59780bfd184SMoriyoshi Koizumi	printf "result => "
59880bfd184SMoriyoshi Koizumi	printzn &execute_data->opline.result
59980bfd184SMoriyoshi Koizumiend
60080bfd184SMoriyoshi Koizumi
60180bfd184SMoriyoshi Koizumidocument printzops
60280bfd184SMoriyoshi Koizumi	dump operands of the current opline
60380bfd184SMoriyoshi Koizumiend
60480bfd184SMoriyoshi Koizumi
6059ad34131SMitch Hagstranddefine print_zstr
6069ad34131SMitch Hagstrand	set $zstr = (zend_string *)$arg0
607db894fa6SMitch Hagstrand	if $argc == 2
608db894fa6SMitch Hagstrand		set $maxlen = $arg1
609db894fa6SMitch Hagstrand	else
610db894fa6SMitch Hagstrand		set $maxlen = $zstr->len
611db894fa6SMitch Hagstrand	end
6129ad34131SMitch Hagstrand	printf "string(%d) ", $zstr->len
613db894fa6SMitch Hagstrand	____print_str $zstr->val $zstr->len $maxlen
6149ad34131SMitch Hagstrand	printf "\n"
6159ad34131SMitch Hagstrandend
6169ad34131SMitch Hagstrand
6179ad34131SMitch Hagstranddocument print_zstr
6189ad34131SMitch Hagstrand	print the length and contents of a zend string
619db894fa6SMitch Hagstrand	usage: print_zstr <ptr> [max length]
6209ad34131SMitch Hagstrandend
6219ad34131SMitch Hagstrand
622097bfda3SMoriyoshi Koizumidefine zbacktrace
623097bfda3SMoriyoshi Koizumi	____executor_globals
624097bfda3SMoriyoshi Koizumi	dump_bt $eg.current_execute_data
625097bfda3SMoriyoshi Koizumiend
626097bfda3SMoriyoshi Koizumi
627097bfda3SMoriyoshi Koizumidocument zbacktrace
628097bfda3SMoriyoshi Koizumi	prints backtrace.
629097bfda3SMoriyoshi Koizumi	This command is almost a short cut for
630097bfda3SMoriyoshi Koizumi	> (gdb) ____executor_globals
631097bfda3SMoriyoshi Koizumi	> (gdb) dump_bt $eg.current_execute_data
632097bfda3SMoriyoshi Koizumiend
633097bfda3SMoriyoshi Koizumi
6346d2ca4b5SXinchen Huidefine lookup_root
6356d2ca4b5SXinchen Hui	set $found = 0
6366d2ca4b5SXinchen Hui	if gc_globals->roots
6376d2ca4b5SXinchen Hui		set $current = gc_globals->roots->next
6386d2ca4b5SXinchen Hui		printf "looking ref %p in roots\n", $arg0
6396d2ca4b5SXinchen Hui		while $current != &gc_globals->roots
6406d2ca4b5SXinchen Hui			if $current->ref == $arg0
6416d2ca4b5SXinchen Hui				set $found = $current
6426d2ca4b5SXinchen Hui				break
6436d2ca4b5SXinchen Hui			end
6446d2ca4b5SXinchen Hui			set $current = $current->next
6456d2ca4b5SXinchen Hui		end
6466d2ca4b5SXinchen Hui		if $found != 0
6476d2ca4b5SXinchen Hui			printf "found root %p\n", $found
6486d2ca4b5SXinchen Hui		else
6496d2ca4b5SXinchen Hui			printf "not found\n"
6506d2ca4b5SXinchen Hui		end
6516d2ca4b5SXinchen Hui	end
6526d2ca4b5SXinchen Huiend
6536d2ca4b5SXinchen Hui
6546d2ca4b5SXinchen Huidocument lookup_root
6556d2ca4b5SXinchen Hui	lookup a refcounted in root
6566d2ca4b5SXinchen Hui	usage: lookup_root [ptr].
6576d2ca4b5SXinchen Huiend