.gdbinit 13 KB

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