debugging - How to dump PHP backtrace on live running script in lldb? -


i'm playing around lldb (debugger) , did following experiment.

  1. run php script as:

    php -r "sleep(1000);" 

    or:

    php -r "function r(){sleep(1000);}r();" 
  2. on console, i've called directly zif_debug_backtrace() lldb:

    echo 'call (void)zif_debug_backtrace()' | lldb -p $(pgrep -fn php) 

above worked, process stopped following warning:

warning: sleep() expects @ 2 parameters, 1606408648 given in command line code on line 1 call stack:     0.0016     235152   1. {main}() command line code:0     0.0021     235248   2. sleep(1000) command line code:1 

i'm not quite sure why script had stop , need achieve transparency (without affecting script)?

p.s. same happening when calling zif_debug_print_backtrace() , when calling custom_backtrace() showing: backtrace null function called. i'm using xdebug if change anything.

maybe need call different function zend_fetch_debug_backtrace (see: image dump symtab)? or use right arguments, if so, one?

i'm interested in lldb/gdb solutions in order print backtrace.


similar approach works in ruby, e.g.:

  1. run: ruby -e 'sleep 1000'.
  2. in terminal: echo 'call (void)rb_backtrace()' | lldb -p $(pgrep -nf ruby).

you can't call internal functions that, internal functions expect things frame, return value , on ... don't' it.

there .gdbinit distributed php, in there function named zbacktrace, port lldb.

another thing do, easier, call api function generates trace, call properly.

here gdb (php7):

define ztrace     set $var = malloc(sizeof(zval))     call zend_fetch_debug_backtrace($var, 0, 0, 0)     call php_var_dump($var, 0)     call _zval_ptr_dtor($var, 0, 0)     call free($var) end  document ztrace     show debug backtrace end  

and lldb (php7):

(lldb) expr zval $var; (lldb) expr zend_fetch_debug_backtrace(&$var, 0, 0, 0) (lldb) expr php_var_dump(&$var, 0) (lldb) expr _zval_ptr_dtor(&$var, 0, 0) 

since asked, lldb php5.6 (no-zts):

(lldb) expr zval *$zp = (zval*) malloc(sizeof(zval)) (lldb) expr zend_fetch_debug_backtrace($zp, 0, 0, 0) (lldb) expr php_var_dump(&$zp, 0) (lldb) expr _zval_ptr_dtor(&$zp, 0, 0) (lldb) expr free($zp) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -