You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
13 KiB

23 years ago
20 years ago
23 years ago
23 years ago
20 years ago
23 years ago
11 years ago
11 years ago
10 years ago
11 years ago
23 years ago
20 years ago
12 years ago
20 years ago
20 years ago
20 years ago
12 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
23 years ago
20 years ago
12 years ago
20 years ago
20 years ago
20 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
20 years ago
20 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
20 years ago
12 years ago
20 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
23 years ago
23 years ago
23 years ago
  1. define set_ts
  2. set $tsrm_ls = $arg0
  3. end
  4. document set_ts
  5. set the ts resource, it is impossible for gdb to
  6. call ts_resource_ex while no process is running,
  7. but we could get the resource from the argument
  8. of frame info.
  9. end
  10. define ____executor_globals
  11. if basic_functions_module.zts
  12. if !$tsrm_ls
  13. set $tsrm_ls = ts_resource_ex(0, 0)
  14. end
  15. set $eg = ((zend_executor_globals*) (*((void ***) $tsrm_ls))[executor_globals_id-1])
  16. set $cg = ((zend_compiler_globals*) (*((void ***) $tsrm_ls))[compiler_globals_id-1])
  17. set $eg_ptr = $eg
  18. else
  19. set $eg = executor_globals
  20. set $cg = compiler_globals
  21. set $eg_ptr = (zend_executor_globals*) &executor_globals
  22. end
  23. end
  24. document ____executor_globals
  25. portable way of accessing executor_globals, set $eg
  26. this also sets compiler_globals to $cg
  27. ZTS detection is automatically based on ext/standard module struct
  28. end
  29. define print_cvs
  30. if $argc == 0
  31. ____executor_globals
  32. set $cv_ex_ptr = $eg.current_execute_data
  33. else
  34. set $cv_ex_ptr = (zend_execute_data *)$arg0
  35. end
  36. set $cv_count = $cv_ex_ptr.func.op_array.last_var
  37. set $cv = $cv_ex_ptr.func.op_array.vars
  38. set $cv_idx = 0
  39. set $callFrameSize = (sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)
  40. printf "Compiled variables count: %d\n\n", $cv_count
  41. while $cv_idx < $cv_count
  42. printf "[%d] '%s'\n", $cv_idx, $cv[$cv_idx].val
  43. set $zvalue = ((zval *) $cv_ex_ptr) + $callFrameSize + $cv_idx
  44. printzv $zvalue
  45. set $cv_idx = $cv_idx + 1
  46. end
  47. end
  48. document print_cvs
  49. Prints the compiled variables and their values.
  50. If a zend_execute_data pointer is set this will print the compiled
  51. variables of that scope. If no parameter is used it will use
  52. current_execute_data for scope.
  53. usage: print_cvs [zend_execute_data *]
  54. end
  55. define dump_bt
  56. set $ex = $arg0
  57. while $ex
  58. printf "[%p] ", $ex
  59. set $func = $ex->func
  60. if $func
  61. if $ex->This->value.obj
  62. if $func->common.scope
  63. printf "%s->", $func->common.scope->name->val
  64. else
  65. printf "%s->", $ex->This->value.obj->ce.name->val
  66. end
  67. else
  68. if $func->common.scope
  69. printf "%s::", $func->common.scope->name->val
  70. end
  71. end
  72. if $func->common.function_name
  73. printf "%s(", $func->common.function_name->val
  74. else
  75. printf "(main"
  76. end
  77. set $callFrameSize = (sizeof(zend_execute_data) + sizeof(zval) - 1) / sizeof(zval)
  78. set $count = $ex->This.u2.num_args
  79. set $arg = 0
  80. while $arg < $count
  81. if $arg > 0
  82. printf ", "
  83. end
  84. set $zvalue = (zval *) $ex + $callFrameSize + $arg
  85. set $type = $zvalue->u1.v.type
  86. if $type == 1
  87. printf "NULL"
  88. end
  89. if $type == 2
  90. printf "false"
  91. end
  92. if $type == 3
  93. printf "true"
  94. end
  95. if $type == 4
  96. printf "%ld", $zvalue->value.lval
  97. end
  98. if $type == 5
  99. printf "%f", $zvalue->value.dval
  100. end
  101. if $type == 6
  102. ____print_str $zvalue->value.str->val $zvalue->value.str->len
  103. end
  104. if $type == 7
  105. printf "array(%d)[%p]", $zvalue->value.arr->nNumOfElements, $zvalue
  106. end
  107. if $type == 8
  108. printf "object[%p]", $zvalue
  109. end
  110. if $type == 9
  111. printf "resource(#%d)", $zvalue->value.lval
  112. end
  113. if $type == 10
  114. printf "reference"
  115. end
  116. if $type > 10
  117. printf "unknown type %d", $type
  118. end
  119. set $arg = $arg + 1
  120. end
  121. printf ") "
  122. else
  123. printf "??? "
  124. end
  125. if $func != 0
  126. if $func->type == 2
  127. printf "%s:%d ", $func->op_array.filename->val, $ex->opline->lineno
  128. else
  129. printf "[internal function]"
  130. end
  131. end
  132. set $ex = $ex->prev_execute_data
  133. printf "\n"
  134. end
  135. end
  136. document dump_bt
  137. dumps the current execution stack. usage: dump_bt executor_globals.current_execute_data
  138. end
  139. define printzv
  140. set $ind = 1
  141. ____printzv $arg0 0
  142. end
  143. document printzv
  144. prints zval contents
  145. end
  146. define ____printzv_contents
  147. set $zvalue = $arg0
  148. set $type = $zvalue->u1.v.type
  149. # 15 == IS_INDIRECT
  150. if $type > 5 && $type < 12
  151. printf "(refcount=%d) ", $zvalue->value.counted->gc.refcount
  152. end
  153. if $type == 0
  154. printf "UNDEF"
  155. end
  156. if $type == 1
  157. printf "NULL"
  158. end
  159. if $type == 2
  160. printf "bool: false"
  161. end
  162. if $type == 3
  163. printf "bool: true"
  164. end
  165. if $type == 4
  166. printf "long: %ld", $zvalue->value.lval
  167. end
  168. if $type == 5
  169. printf "double: %f", $zvalue->value.dval
  170. end
  171. if $type == 6
  172. printf "string: %s", $zvalue->value.str->val
  173. end
  174. if $type == 7
  175. printf "array: "
  176. if ! $arg1
  177. set $ind = $ind + 1
  178. ____print_ht $zvalue->value.arr 1
  179. set $ind = $ind - 1
  180. set $i = $ind
  181. while $i > 0
  182. printf " "
  183. set $i = $i - 1
  184. end
  185. end
  186. set $type = 0
  187. end
  188. if $type == 8
  189. printf "object"
  190. ____executor_globals
  191. set $handle = $zvalue->value.obj.handle
  192. set $handlers = $zvalue->value.obj.handlers
  193. set $zobj = $zvalue->value.obj
  194. set $cname = $zobj->ce->name->val
  195. printf "(%s) #%d", $cname, $handle
  196. if ! $arg1
  197. if $handlers->get_properties == &zend_std_get_properties
  198. if $zobj->properties
  199. printf "\nProperties "
  200. set $ht = $zobj->properties
  201. set $ind = $ind + 1
  202. ____print_ht $ht 1
  203. set $ind = $ind - 1
  204. set $i = $ind
  205. while $i > 0
  206. printf " "
  207. set $i = $i - 1
  208. end
  209. else
  210. printf " {\n"
  211. set $ht = &$zobj->ce->properties_info
  212. set $k = 0
  213. set $num = $ht->nNumUsed
  214. while $k < $num
  215. set $p = (Bucket*)($ht->arData + $k)
  216. set $name = $p->key
  217. set $prop = (zend_property_info*)$p->val.value.ptr
  218. set $val = (zval*)((char*)$zobj + $prop->offset)
  219. printf "%s => ", $name->val
  220. printzv $val
  221. set $k = $k + 1
  222. end
  223. end
  224. end
  225. end
  226. set $type = 0
  227. end
  228. if $type == 9
  229. printf "resource: #%d", $zvalue->value.res->handle
  230. end
  231. if $type == 10
  232. printf "reference: "
  233. ____printzv &$zvalue->value.ref->val $arg1
  234. end
  235. if $type == 11
  236. printf "CONSTANT_AST"
  237. end
  238. if $type == 12
  239. printf "CALLABLE"
  240. end
  241. if $type == 13
  242. printf "ITERABLE"
  243. end
  244. if $type == 14
  245. printf "VOID"
  246. end
  247. if $type == 15
  248. printf "indirect: "
  249. ____printzv $zvalue->value.zv $arg1
  250. end
  251. if $type == 16
  252. printf "pointer: %p", $zvalue->value.ptr
  253. end
  254. if $type == 17
  255. printf "_ERROR"
  256. end
  257. if $type == 18
  258. printf "_BOOL"
  259. end
  260. if $type == 19
  261. printf "_NUMBER"
  262. end
  263. if $type > 19
  264. printf "unknown type %d", $type
  265. end
  266. printf "\n"
  267. end
  268. define ____printzv
  269. ____executor_globals
  270. set $zvalue = $arg0
  271. printf "[%p] ", $zvalue
  272. set $zcontents = (zval*) $zvalue
  273. if $arg1
  274. ____printzv_contents $zcontents $arg1
  275. else
  276. ____printzv_contents $zcontents 0
  277. end
  278. end
  279. define print_global_vars
  280. ____executor_globals
  281. set $symtable = ((HashTable *)&($eg_ptr->symbol_table))
  282. print_ht $symtable
  283. end
  284. document print_global_vars
  285. Prints the global variables
  286. end
  287. define print_const_table
  288. set $ind = 1
  289. printf "[%p] {\n", $arg0
  290. ____print_ht $arg0 4
  291. printf "}\n"
  292. end
  293. document print_const_table
  294. Dumps elements of Constants HashTable
  295. Example: print_const_table executor_globals.zend_constants
  296. end
  297. define ____print_ht
  298. set $ht = (HashTable*)$arg0
  299. set $n = $ind
  300. while $n > 0
  301. printf " "
  302. set $n = $n - 1
  303. end
  304. if $ht->u.v.flags & 4
  305. printf "Packed"
  306. else
  307. printf "Hash"
  308. end
  309. printf "(%d)[%p]: {\n", $ht->nNumOfElements, $ht
  310. set $num = $ht->nNumUsed
  311. set $i = 0
  312. set $ind = $ind + 1
  313. while $i < $num
  314. set $p = (Bucket*)($ht->arData + $i)
  315. set $n = $ind
  316. if $p->val.u1.v.type > 0
  317. while $n > 0
  318. printf " "
  319. set $n = $n - 1
  320. end
  321. printf "[%d] ", $i
  322. if $p->key
  323. printf "%s => ", $p->key->val
  324. else
  325. printf "%d => ", $p->h
  326. end
  327. if $arg1 == 0
  328. printf "%p\n", (zval *)&$p->val
  329. end
  330. if $arg1 == 1
  331. set $zval = (zval *)&$p->val
  332. ____printzv $zval 1
  333. end
  334. if $arg1 == 2
  335. printf "%s\n", (char*)$p->val.value.ptr
  336. end
  337. if $arg1 == 3
  338. set $func = (zend_function*)$p->val.value.ptr
  339. printf "\"%s\"\n", $func->common.function_name->val
  340. end
  341. if $arg1 == 4
  342. set $const = (zend_constant *)$p->val.value.ptr
  343. ____printzv $const 1
  344. end
  345. end
  346. set $i = $i + 1
  347. end
  348. set $ind = $ind - 1
  349. printf "}\n"
  350. end
  351. define print_ht
  352. set $ind = 0
  353. ____print_ht $arg0 1
  354. end
  355. document print_ht
  356. dumps elements of HashTable made of zval
  357. end
  358. define print_htptr
  359. set $ind = 0
  360. ____print_ht $arg0 0
  361. end
  362. document print_htptr
  363. dumps elements of HashTable made of pointers
  364. end
  365. define print_htstr
  366. set $ind = 0
  367. ____print_ht $arg0 2
  368. end
  369. document print_htstr
  370. dumps elements of HashTable made of strings
  371. end
  372. define print_ft
  373. set $ind = 0
  374. ____print_ht $arg0 3
  375. end
  376. document print_ft
  377. dumps a function table (HashTable)
  378. end
  379. define ____print_inh_class
  380. set $ce = $arg0
  381. if $ce->ce_flags & 0x10 || $ce->ce_flags & 0x20
  382. printf "abstract "
  383. else
  384. if $ce->ce_flags & 0x40
  385. printf "final "
  386. end
  387. end
  388. printf "class %s", $ce->name->val
  389. if $ce->parent != 0
  390. printf " extends %s", $ce->parent->name->val
  391. end
  392. if $ce->num_interfaces != 0
  393. printf " implements"
  394. set $tmp = 0
  395. while $tmp < $ce->num_interfaces
  396. printf " %s", $ce->interfaces[$tmp]->name->val
  397. set $tmp = $tmp + 1
  398. if $tmp < $ce->num_interfaces
  399. printf ","
  400. end
  401. end
  402. end
  403. set $ce = $ce->parent
  404. end
  405. define ____print_inh_iface
  406. set $ce = $arg0
  407. printf "interface %s", $ce->name->val
  408. if $ce->num_interfaces != 0
  409. set $ce = $ce->interfaces[0]
  410. printf " extends %s", $ce->name->val
  411. else
  412. set $ce = 0
  413. end
  414. end
  415. define print_inh
  416. set $ce = $arg0
  417. set $depth = 0
  418. while $ce != 0
  419. set $tmp = $depth
  420. while $tmp != 0
  421. printf " "
  422. set $tmp = $tmp - 1
  423. end
  424. set $depth = $depth + 1
  425. if $ce->ce_flags & 0x80
  426. ____print_inh_iface $ce
  427. else
  428. ____print_inh_class $ce
  429. end
  430. printf " {\n"
  431. end
  432. while $depth != 0
  433. set $tmp = $depth
  434. while $tmp != 1
  435. printf " "
  436. set $tmp = $tmp - 1
  437. end
  438. printf "}\n"
  439. set $depth = $depth - 1
  440. end
  441. end
  442. define print_pi
  443. set $pi = (zend_property_info *)$arg0
  444. set $initial_offset = ((uint32_t)(zend_uintptr_t)(&((zend_object*)0)->properties_table[(0)]))
  445. set $ptr_to_val = (zval*)((char*)$pi->ce->default_properties_table + $pi->offset - $initial_offset)
  446. printf "[%p] {\n", $pi
  447. printf " offset = %p\n", $pi->offset
  448. printf " ce = [%p] %s\n", $pi->ce, $pi->ce->name->val
  449. printf " flags = 0x%x (", $pi->flags
  450. if $pi->flags & 0x100
  451. printf "ZEND_ACC_PUBLIC"
  452. else
  453. if $pi->flags & 0x200
  454. printf "ZEND_ACC_PROTECTED"
  455. else
  456. if $pi->flags & 0x400
  457. printf "ZEND_ACC_PRIVATE"
  458. else
  459. if $pi->flags & 0x800
  460. printf "ZEND_ACC_EARLY_BINDING"
  461. else
  462. if $pi->flags & 0x20000
  463. printf "ZEND_ACC_SHADOW"
  464. end
  465. end
  466. end
  467. end
  468. end
  469. printf ")\n"
  470. printf " name = "
  471. print_zstr $pi->name
  472. printf " default value: "
  473. printzv $ptr_to_val
  474. printf "}\n"
  475. end
  476. document print_pi
  477. Takes a pointer to an object's property and prints the property information
  478. usage: print_pi <ptr>
  479. end
  480. define ____print_str
  481. set $tmp = 0
  482. set $str = $arg0
  483. if $argc > 2
  484. set $maxlen = $arg2
  485. else
  486. set $maxlen = 256
  487. end
  488. printf "\""
  489. while $tmp < $arg1 && $tmp < $maxlen
  490. if $str[$tmp] > 31 && $str[$tmp] < 127
  491. printf "%c", $str[$tmp]
  492. else
  493. printf "\\%o", $str[$tmp]
  494. end
  495. set $tmp = $tmp + 1
  496. end
  497. if $tmp != $arg1
  498. printf "..."
  499. end
  500. printf "\""
  501. end
  502. define printzn
  503. ____executor_globals
  504. set $ind = 0
  505. set $znode = $arg0
  506. if $znode->op_type == 1
  507. set $optype = "IS_CONST"
  508. end
  509. if $znode->op_type == 2
  510. set $optype = "IS_TMP_VAR"
  511. end
  512. if $znode->op_type == 4
  513. set $optype = "IS_VAR"
  514. end
  515. if $znode->op_type == 8
  516. set $optype = "IS_UNUSED"
  517. end
  518. printf "[%p] %s", $znode, $optype
  519. if $znode->op_type == 1
  520. printf ": "
  521. ____printzv &$znode->u.constant 0
  522. end
  523. if $znode->op_type == 2
  524. printf ": "
  525. set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
  526. ____printzv ((union _temp_variable *)$tvar)->tmp_var 0
  527. end
  528. if $znode->op_type == 4
  529. printf ": "
  530. set $tvar = (union _temp_variable *)((char *)$eg.current_execute_data->Ts + $znode->u.var)
  531. ____printzv *$tvar->var.ptr_ptr 0
  532. end
  533. if $znode->op_type == 8
  534. printf "\n"
  535. end
  536. end
  537. document printzn
  538. print type and content of znode.
  539. usage: printzn &opline->op1
  540. end
  541. define printzops
  542. printf "op1 => "
  543. printzn &execute_data->opline.op1
  544. printf "op2 => "
  545. printzn &execute_data->opline.op2
  546. printf "result => "
  547. printzn &execute_data->opline.result
  548. end
  549. document printzops
  550. dump operands of the current opline
  551. end
  552. define print_zstr
  553. set $zstr = (zend_string *)$arg0
  554. if $argc == 2
  555. set $maxlen = $arg1
  556. else
  557. set $maxlen = $zstr->len
  558. end
  559. printf "string(%d) ", $zstr->len
  560. ____print_str $zstr->val $zstr->len $maxlen
  561. printf "\n"
  562. end
  563. document print_zstr
  564. print the length and contents of a zend string
  565. usage: print_zstr <ptr> [max length]
  566. end
  567. define zbacktrace
  568. ____executor_globals
  569. dump_bt $eg.current_execute_data
  570. end
  571. document zbacktrace
  572. prints backtrace.
  573. This command is almost a short cut for
  574. > (gdb) ____executor_globals
  575. > (gdb) dump_bt $eg.current_execute_data
  576. end
  577. define lookup_root
  578. set $found = 0
  579. if gc_globals->roots
  580. set $current = gc_globals->roots->next
  581. printf "looking ref %p in roots\n", $arg0
  582. while $current != &gc_globals->roots
  583. if $current->ref == $arg0
  584. set $found = $current
  585. break
  586. end
  587. set $current = $current->next
  588. end
  589. if $found != 0
  590. printf "found root %p\n", $found
  591. else
  592. printf "not found\n"
  593. end
  594. end
  595. end
  596. document lookup_root
  597. lookup a refcounted in root
  598. usage: lookup_root [ptr].
  599. end