FastNetMon

Friday 9 November 2012

Расширенная отладка PHP по дампам памяти на Debian


Стандартная попытка отладить PHP по дампу памяти через dbg выглядит примерно так:
backtrace 20
#0  0x00000000006689fd in do_bind_function ()
#1  0x00000000006ab77c in ?? ()
#2  0x00000000006ab510 in execute ()
#3  0x00000000006b71cf in ?? ()
#4  0x00000000006ab510 in execute ()
#5  0x00000000006b1ead in ?? ()
#6  0x00000000006ab510 in execute ()
#7  0x00000000006d3f86 in ?? ()
#8  0x00000000006ab510 in execute ()
#9  0x00007fdc9c0acbd5 in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#10 0x00007fdc9c0ab53c in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#11 0x00007fdc9c0acbd5 in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#12 0x00007fdc9c0ab53c in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#13 0x0000000000682cdd in zend_execute_scripts ()
#14 0x000000000062e2a8 in php_execute_script ()
#15 0x000000000071123f in ?? ()
#16 0x00007fdca362cc8d in __libc_start_main () from /lib/libc.so.6
#17 0x000000000042d289 in _start ()

Чтобы сделать выдачу попонятнее, нужно поставить  debug symbols, содержащие информацию о том, что и где находится:

apt-get install -y php5-dbg
Теперь все на порядок понятнее и даже можно посмотреть, на какой строке возникает ошибка:
 backtrace 20
#0  0x00000000006689fd in do_bind_function (opline=0x7fdc948e2b40, function_table=0x11a8c80, compile_time=0 '\000')
    at /tmp/buildd/php5-5.3.3/Zend/zend_compile.c:2956
#1  0x00000000006ab77c in ZEND_DECLARE_FUNCTION_SPEC_HANDLER (execute_data=0x189f908) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:582
#2  0x00000000006ab510 in execute (op_array=0x1ccd620) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:107
#3  0x00000000006b71cf in ZEND_INCLUDE_OR_EVAL_SPEC_TMP_HANDLER (execute_data=0x189bb90)
    at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:5256
#4  0x00000000006ab510 in execute (op_array=0x1bf6cf8) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:107
#5  0x00000000006b1ead in ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER (execute_data=0x1898c80)
    at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:22511
#6  0x00000000006ab510 in execute (op_array=0x1b1f538) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:107
#7  0x00000000006d3f86 in zend_do_fcall_common_helper_SPEC (execute_data=0x1898b40) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:340
#8  0x00000000006ab510 in execute (op_array=0x1b1f3e8) at /tmp/buildd/php5-5.3.3/Zend/zend_vm_execute.h:107
#9  0x00007fdc9c0acbd5 in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#10 0x00007fdc9c0ab53c in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#11 0x00007fdc9c0acbd5 in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#12 0x00007fdc9c0ab53c in ?? () from /opt/ioncube/ioncube_loader_lin_5.3.so
#13 0x0000000000682cdd in zend_execute_scripts (type=0, retval=0x7fff4ea76820, file_count=3) at /tmp/buildd/php5-5.3.3/Zend/zend.c:1266
#14 0x000000000062e2a8 in php_execute_script (primary_file=0x630f6a) at /tmp/buildd/php5-5.3.3/main/main.c:2289
#15 0x000000000071123f in main (argc=1319612504, argv=0x0) at /tmp/buildd/php5-5.3.3/sapi/cgi/cgi_main.c:2139

А вот так можно тоже самое сделать одной единственной командой:
gdb /usr/bin/php5-cgi -c /var/log//dumps/core.php5-fastcgi-pr.1114  -x "bt"  -batch -x 'bt'

No comments :

Post a Comment

Note: only a member of this blog may post a comment.