2013-11-17 15:42:34 +00:00
/*
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2015-03-13 09:09:42 +00:00
| PHP Version 7 |
2013-11-17 15:42:34 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
2017-01-04 17:23:42 +00:00
| Copyright ( c ) 1997 - 2017 The PHP Group |
2013-11-17 15:42:34 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| This source file is subject to version 3.01 of the PHP license , |
| that is bundled with this package in the file LICENSE , and is |
| available through the world - wide - web at the following url : |
| http : //www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world - wide - web , please send a note to |
| license @ php . net so we can mail you a copy immediately . |
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
| Authors : Felipe Pena < felipe @ php . net > |
| Authors : Joe Watkins < joe . watkins @ live . co . uk > |
2013-12-18 10:02:50 +00:00
| Authors : Bob Weinand < bwoebi @ php . net > |
2013-11-17 15:42:34 +00:00
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
*/
# include "php.h"
2013-11-22 09:56:17 +00:00
# include "phpdbg.h"
2013-11-17 15:42:34 +00:00
# include "phpdbg_utils.h"
# include "phpdbg_info.h"
2013-11-24 13:36:29 +00:00
# include "phpdbg_bp.h"
2014-02-19 20:18:49 +00:00
# include "phpdbg_prompt.h"
2013-11-17 15:42:34 +00:00
2016-02-16 22:47:37 +00:00
ZEND_EXTERN_MODULE_GLOBALS ( phpdbg )
2013-11-22 09:56:17 +00:00
2014-10-02 23:29:41 +00:00
# define PHPDBG_INFO_COMMAND_D(f, h, a, m, l, s, flags) \
2015-03-21 22:19:12 +00:00
PHPDBG_COMMAND_D_EXP ( f , h , a , m , l , s , & phpdbg_prompt_commands [ 13 ] , flags )
2014-02-19 20:18:49 +00:00
2014-02-02 16:35:28 +00:00
const phpdbg_command_t phpdbg_info_commands [ ] = {
2014-10-20 19:14:13 +00:00
PHPDBG_INFO_COMMAND_D ( break , " show breakpoints " , ' b ' , info_break , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( files , " show included files " , ' F ' , info_files , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( classes , " show loaded classes " , ' c ' , info_classes , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( funcs , " show loaded classes " , ' f ' , info_funcs , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( error , " show last error " , ' e ' , info_error , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( constants , " show user defined constants " , ' d ' , info_constants , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( vars , " show active variables " , ' v ' , info_vars , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( globals , " show superglobals " , ' g ' , info_globals , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( literal , " show active literal constants " , ' l ' , info_literal , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
PHPDBG_INFO_COMMAND_D ( memory , " show memory manager stats " , ' m ' , info_memory , NULL , 0 , PHPDBG_ASYNC_SAFE ) ,
2014-02-02 16:35:28 +00:00
PHPDBG_END_COMMAND
} ;
2013-11-24 13:36:29 +00:00
PHPDBG_INFO ( break ) /* {{{ */
{
2014-12-13 22:06:14 +00:00
phpdbg_print_breakpoints ( PHPDBG_BREAK_FILE ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_SYM ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_METHOD ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_OPLINE ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_FILE_OPLINE ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_FUNCTION_OPLINE ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_METHOD_OPLINE ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_COND ) ;
phpdbg_print_breakpoints ( PHPDBG_BREAK_OPCODE ) ;
2013-11-24 13:36:29 +00:00
return SUCCESS ;
} /* }}} */
2013-11-17 15:42:34 +00:00
PHPDBG_INFO ( files ) /* {{{ */
{
2014-10-24 17:29:50 +00:00
zend_string * fname ;
2013-11-17 15:42:34 +00:00
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2014-10-07 11:08:30 +00:00
phpdbg_notice ( " includedfilecount " , " num= \" %d \" " , " Included files: %d " , zend_hash_num_elements ( & EG ( included_files ) ) ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_error ( " signalsegv " , " " , " Could not fetch included file count, invalid data source " ) ;
2014-10-24 17:29:50 +00:00
return SUCCESS ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-17 15:42:34 +00:00
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_STR_KEY ( & EG ( included_files ) , fname ) {
2015-08-27 03:34:52 +00:00
phpdbg_writeln ( " includedfile " , " name= \" %s \" " , " File: %s " , ZSTR_VAL ( fname ) ) ;
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_error ( " signalsegv " , " " , " Could not fetch file name, invalid data source, aborting included file listing " ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-17 15:42:34 +00:00
return SUCCESS ;
} /* }}} */
2013-11-17 18:43:37 +00:00
PHPDBG_INFO ( error ) /* {{{ */
{
2013-11-17 19:00:59 +00:00
if ( PG ( last_error_message ) ) {
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2014-10-07 11:08:30 +00:00
phpdbg_writeln ( " lasterror " , " error= \" %s \" file= \" %s \" line= \" %d \" " , " Last error: %s at %s line %d " , PG ( last_error_message ) , PG ( last_error_file ) , PG ( last_error_lineno ) ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_notice ( " lasterror " , " error= \" \" " , " No error found! " ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-17 19:00:59 +00:00
} else {
2014-09-21 02:17:19 +00:00
phpdbg_notice ( " lasterror " , " error= \" \" " , " No error found! " ) ;
2013-11-17 19:00:59 +00:00
}
2013-11-17 18:43:37 +00:00
return SUCCESS ;
} /* }}} */
2014-10-20 19:14:13 +00:00
PHPDBG_INFO ( constants ) /* {{{ */
2013-11-17 18:43:37 +00:00
{
2014-10-20 19:14:13 +00:00
HashTable consts ;
zend_constant * data ;
2013-11-17 18:43:37 +00:00
2014-10-20 19:14:13 +00:00
zend_hash_init ( & consts , 8 , NULL , NULL , 0 ) ;
if ( EG ( zend_constants ) ) {
phpdbg_try_access {
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( EG ( zend_constants ) , data ) {
2014-10-20 19:14:13 +00:00
if ( data - > module_number = = PHP_USER_CONSTANT ) {
2014-10-24 17:29:50 +00:00
zend_hash_update_ptr ( & consts , data - > name , data ) ;
2014-10-20 19:14:13 +00:00
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-20 19:14:13 +00:00
} phpdbg_catch_access {
phpdbg_error ( " signalsegv " , " " , " Cannot fetch all the constants, invalid data source " ) ;
} phpdbg_end_try_access ( ) ;
2013-11-26 22:20:52 +00:00
}
2014-10-20 19:14:13 +00:00
phpdbg_notice ( " constantinfo " , " num= \" %d \" " , " User-defined constants (%d) " , zend_hash_num_elements ( & consts ) ) ;
if ( zend_hash_num_elements ( & consts ) ) {
phpdbg_out ( " Address Refs Type Constant \n " ) ;
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( & consts , data ) {
2014-10-20 19:14:13 +00:00
2016-02-14 13:02:19 +00:00
# define VARIABLEINFO(attrs, msg, ...) \
phpdbg_writeln ( " constant " , \
" address= \" %p \" refcount= \" %d \" type= \" %s \" name= \" %.*s \" " attrs , \
" %-18p %-7d %-9s %.*s " msg , & data - > value , \
Z_REFCOUNTED ( data - > value ) ? Z_REFCOUNT ( data - > value ) : 1 , \
zend_zval_type_name ( & data - > value ) , \
( int ) ZSTR_LEN ( data - > name ) , ZSTR_VAL ( data - > name ) , # # __VA_ARGS__ )
2014-10-20 19:14:13 +00:00
switch ( Z_TYPE ( data - > value ) ) {
case IS_STRING :
phpdbg_try_access {
2016-02-14 13:02:19 +00:00
VARIABLEINFO ( " length= \" %zd \" value= \" %.*s \" " , " \n string (%zd) \" %.*s%s \" " , Z_STRLEN ( data - > value ) , Z_STRLEN ( data - > value ) < 255 ? ( int ) Z_STRLEN ( data - > value ) : 255 , Z_STRVAL ( data - > value ) , Z_STRLEN ( data - > value ) > 255 ? " ... " : " " ) ;
2014-10-20 19:14:13 +00:00
} phpdbg_catch_access {
VARIABLEINFO ( " " , " " ) ;
} phpdbg_end_try_access ( ) ;
break ;
2014-10-24 17:29:50 +00:00
case IS_TRUE :
VARIABLEINFO ( " value= \" true \" " , " \n bool (true) " ) ;
break ;
case IS_FALSE :
VARIABLEINFO ( " value= \" false \" " , " \n bool (false) " ) ;
2014-10-20 19:14:13 +00:00
break ;
case IS_LONG :
VARIABLEINFO ( " value= \" %ld \" " , " \n int (%ld) " , Z_LVAL ( data - > value ) ) ;
break ;
case IS_DOUBLE :
VARIABLEINFO ( " value= \" %lf \" " , " \n double (%lf) " , Z_DVAL ( data - > value ) ) ;
break ;
default :
VARIABLEINFO ( " " , " " ) ;
# undef VARIABLEINFO
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-20 19:14:13 +00:00
}
2013-11-17 18:43:37 +00:00
2014-10-20 19:14:13 +00:00
return SUCCESS ;
} /* }}} */
2015-07-20 00:18:50 +00:00
static int phpdbg_arm_auto_global ( zval * ptrzv ) {
zend_auto_global * auto_global = Z_PTR_P ( ptrzv ) ;
2014-09-23 14:48:37 +00:00
if ( auto_global - > armed ) {
2014-10-02 23:29:41 +00:00
if ( PHPDBG_G ( flags ) & PHPDBG_IN_SIGNAL_HANDLER ) {
2016-02-14 13:02:19 +00:00
phpdbg_notice ( " variableinfo " , " unreachable= \" %.*s \" " , " Cannot show information about superglobal variable %.*s " , ( int ) ZSTR_LEN ( auto_global - > name ) , ZSTR_VAL ( auto_global - > name ) ) ;
2014-10-02 23:29:41 +00:00
} else {
2014-12-13 22:06:14 +00:00
auto_global - > armed = auto_global - > auto_global_callback ( auto_global - > name ) ;
2013-11-17 18:43:37 +00:00
}
}
2014-09-23 14:48:37 +00:00
return 0 ;
}
2013-11-17 18:43:37 +00:00
2014-12-13 22:06:14 +00:00
static int phpdbg_print_symbols ( zend_bool show_globals ) {
2014-10-24 17:29:50 +00:00
HashTable vars ;
zend_array * symtable ;
zend_string * var ;
zval * data ;
2013-11-17 18:43:37 +00:00
2014-10-24 17:29:50 +00:00
if ( ! EG ( current_execute_data ) | | ! EG ( current_execute_data ) - > func ) {
2014-09-21 02:17:19 +00:00
phpdbg_error ( " inactive " , " type= \" op_array \" " , " No active op array! " ) ;
2013-11-26 22:20:52 +00:00
return SUCCESS ;
}
2014-09-23 14:48:37 +00:00
if ( show_globals ) {
2014-10-02 23:29:41 +00:00
/* that array should only be manipulated during init, so safe for async access during execution */
2014-12-13 22:06:14 +00:00
zend_hash_apply ( CG ( auto_globals ) , ( apply_func_t ) phpdbg_arm_auto_global ) ;
2014-09-23 14:48:37 +00:00
symtable = & EG ( symbol_table ) ;
2014-12-13 22:06:14 +00:00
} else if ( ! ( symtable = zend_rebuild_symbol_table ( ) ) ) {
2014-10-24 17:29:50 +00:00
phpdbg_error ( " inactive " , " type= \" symbol_table \" " , " No active symbol table! " ) ;
return SUCCESS ;
2013-11-17 18:43:37 +00:00
}
2013-11-18 22:12:27 +00:00
2013-11-18 21:59:42 +00:00
zend_hash_init ( & vars , 8 , NULL , NULL , 0 ) ;
2013-11-17 18:43:37 +00:00
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2015-02-13 19:20:39 +00:00
ZEND_HASH_FOREACH_STR_KEY_VAL ( symtable , var , data ) {
2014-12-13 22:06:14 +00:00
if ( zend_is_auto_global ( var ) ^ ! show_globals ) {
2014-10-24 17:29:50 +00:00
zend_hash_update ( & vars , var , data ) ;
2014-10-02 23:29:41 +00:00
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_error ( " signalsegv " , " " , " Cannot fetch all data from the symbol table, invalid data source " ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-18 22:12:27 +00:00
2014-09-23 14:48:37 +00:00
if ( show_globals ) {
2014-09-24 22:21:27 +00:00
phpdbg_notice ( " variableinfo " , " num= \" %d \" " , " Superglobal variables (%d) " , zend_hash_num_elements ( & vars ) ) ;
2014-09-23 14:48:37 +00:00
} else {
2014-10-24 17:29:50 +00:00
zend_op_array * ops = & EG ( current_execute_data ) - > func - > op_array ;
2014-09-21 02:17:19 +00:00
2013-11-25 10:17:57 +00:00
if ( ops - > function_name ) {
if ( ops - > scope ) {
2015-07-20 00:18:50 +00:00
phpdbg_notice ( " variableinfo " , " method= \" %s::%s \" num= \" %d \" " , " Variables in %s::%s() (%d) " , ops - > scope - > name - > val , ops - > function_name - > val , zend_hash_num_elements ( & vars ) ) ;
2013-11-25 10:17:57 +00:00
} else {
2015-07-20 00:18:50 +00:00
phpdbg_notice ( " variableinfo " , " function= \" %s \" num= \" %d \" " , " Variables in %s() (%d) " , ZSTR_VAL ( ops - > function_name ) , zend_hash_num_elements ( & vars ) ) ;
2013-11-25 10:17:57 +00:00
}
} else {
if ( ops - > filename ) {
2015-06-30 10:59:27 +00:00
phpdbg_notice ( " variableinfo " , " file= \" %s \" num= \" %d \" " , " Variables in %s (%d) " , ZSTR_VAL ( ops - > filename ) , zend_hash_num_elements ( & vars ) ) ;
2013-11-25 10:17:57 +00:00
} else {
2014-09-24 22:21:27 +00:00
phpdbg_notice ( " variableinfo " , " opline= \" %p \" num= \" %d \" " , " Variables @ %p (%d) " , ops , zend_hash_num_elements ( & vars ) ) ;
2013-11-25 10:17:57 +00:00
}
}
}
2013-11-20 18:52:34 +00:00
2013-11-18 23:04:20 +00:00
if ( zend_hash_num_elements ( & vars ) ) {
2014-10-20 14:05:37 +00:00
phpdbg_out ( " Address Refs Type Variable \n " ) ;
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_STR_KEY_VAL ( & vars , var , data ) {
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2015-07-20 00:18:50 +00:00
const char * isref = " " ;
2016-02-14 13:02:19 +00:00
# define VARIABLEINFO(attrs, msg, ...) \
phpdbg_writeln ( " variable " , \
" address= \" %p \" refcount= \" %d \" type= \" %s \" refstatus= \" %s \" name= \" %.*s \" " attrs , \
" %-18p %-7d %-9s %s$%.*s " msg , data , Z_REFCOUNTED_P ( data ) ? Z_REFCOUNT_P ( data ) : 1 , zend_zval_type_name ( data ) , isref , ( int ) ZSTR_LEN ( var ) , ZSTR_VAL ( var ) , # # __VA_ARGS__ )
2015-07-20 00:18:50 +00:00
retry_switch :
2014-10-24 17:29:50 +00:00
switch ( Z_TYPE_P ( data ) ) {
case IS_RESOURCE :
phpdbg_try_access {
2014-12-13 22:06:14 +00:00
const char * type = zend_rsrc_list_get_rsrc_type ( Z_RES_P ( data ) ) ;
2014-10-24 17:29:50 +00:00
VARIABLEINFO ( " type= \" %s \" " , " \n |-------(typeof)------> (%s) \n " , type ? type : " unknown " ) ;
} phpdbg_catch_access {
VARIABLEINFO ( " type= \" unknown \" " , " \n |-------(typeof)------> (unknown) \n " ) ;
} phpdbg_end_try_access ( ) ;
break ;
case IS_OBJECT :
phpdbg_try_access {
2016-02-14 13:02:19 +00:00
VARIABLEINFO ( " instanceof= \" %s \" " , " \n |-----(instanceof)----> (%s) \n " , ZSTR_VAL ( Z_OBJCE_P ( data ) - > name ) ) ;
2014-10-24 17:29:50 +00:00
} phpdbg_catch_access {
VARIABLEINFO ( " instanceof= \" %s \" " , " \n |-----(instanceof)----> (unknown) \n " ) ;
} phpdbg_end_try_access ( ) ;
break ;
case IS_STRING :
phpdbg_try_access {
2016-02-14 13:02:19 +00:00
VARIABLEINFO ( " length= \" %zd \" value= \" %.*s \" " , " \n string (%zd) \" %.*s%s \" " , Z_STRLEN_P ( data ) , Z_STRLEN_P ( data ) < 255 ? ( int ) Z_STRLEN_P ( data ) : 255 , Z_STRVAL_P ( data ) , Z_STRLEN_P ( data ) > 255 ? " ... " : " " ) ;
2014-10-24 17:29:50 +00:00
} phpdbg_catch_access {
2014-10-20 14:05:37 +00:00
VARIABLEINFO ( " " , " " ) ;
2014-10-24 17:29:50 +00:00
} phpdbg_end_try_access ( ) ;
break ;
case IS_TRUE :
VARIABLEINFO ( " value= \" true \" " , " \n bool (true) " ) ;
break ;
case IS_FALSE :
VARIABLEINFO ( " value= \" false \" " , " \n bool (false) " ) ;
break ;
case IS_LONG :
VARIABLEINFO ( " value= \" %ld \" " , " \n int (%ld) " , Z_LVAL_P ( data ) ) ;
break ;
case IS_DOUBLE :
VARIABLEINFO ( " value= \" %lf \" " , " \n double (%lf) " , Z_DVAL_P ( data ) ) ;
break ;
2015-07-20 00:18:50 +00:00
case IS_REFERENCE :
isref = " & " ;
data = Z_REFVAL_P ( data ) ;
goto retry_switch ;
case IS_INDIRECT :
data = Z_INDIRECT_P ( data ) ;
goto retry_switch ;
2014-10-24 17:29:50 +00:00
default :
VARIABLEINFO ( " " , " " ) ;
2013-11-18 23:04:20 +00:00
}
2013-11-20 18:52:34 +00:00
2014-10-20 19:14:13 +00:00
# undef VARIABLEINFO
2014-10-24 17:29:50 +00:00
} phpdbg_catch_access {
2015-08-27 03:34:52 +00:00
phpdbg_writeln ( " variable " , " address= \" %p \" name= \" %s \" " , " %p \t n/a \t n/a \t $%s " , data , ZSTR_VAL ( var ) ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2013-11-18 21:59:42 +00:00
}
2013-11-18 22:12:27 +00:00
2013-11-18 21:59:42 +00:00
zend_hash_destroy ( & vars ) ;
2013-11-18 22:12:27 +00:00
2013-11-17 18:43:37 +00:00
return SUCCESS ;
} /* }}} */
2013-11-17 18:45:08 +00:00
2014-09-23 14:48:37 +00:00
PHPDBG_INFO ( vars ) /* {{{ */
{
2014-12-13 22:06:14 +00:00
return phpdbg_print_symbols ( 0 ) ;
2014-09-23 14:48:37 +00:00
}
PHPDBG_INFO ( globals ) /* {{{ */
{
2014-12-13 22:06:14 +00:00
return phpdbg_print_symbols ( 1 ) ;
2014-09-23 14:48:37 +00:00
}
2013-11-22 09:09:54 +00:00
PHPDBG_INFO ( literal ) /* {{{ */
{
2014-10-02 23:29:41 +00:00
/* literals are assumed to not be manipulated during executing of their op_array and as such async safe */
2014-10-24 17:29:50 +00:00
zend_bool in_executor = PHPDBG_G ( in_execution ) & & EG ( current_execute_data ) & & EG ( current_execute_data ) - > func ;
if ( in_executor | | PHPDBG_G ( ops ) ) {
zend_op_array * ops = in_executor ? & EG ( current_execute_data ) - > func - > op_array : PHPDBG_G ( ops ) ;
2015-07-20 00:18:50 +00:00
int literal = 0 , count = ops - > last_literal - 1 ;
2013-11-24 01:49:48 +00:00
2013-11-22 09:56:17 +00:00
if ( ops - > function_name ) {
if ( ops - > scope ) {
2015-07-20 00:18:50 +00:00
phpdbg_notice ( " literalinfo " , " method= \" %s::%s \" num= \" %d \" " , " Literal Constants in %s::%s() (%d) " , ops - > scope - > name - > val , ops - > function_name - > val , count ) ;
2013-11-22 09:56:17 +00:00
} else {
2015-07-20 00:18:50 +00:00
phpdbg_notice ( " literalinfo " , " function= \" %s \" num= \" %d \" " , " Literal Constants in %s() (%d) " , ops - > function_name - > val , count ) ;
2013-11-22 09:56:17 +00:00
}
} else {
if ( ops - > filename ) {
2015-06-30 10:59:27 +00:00
phpdbg_notice ( " literalinfo " , " file= \" %s \" num= \" %d \" " , " Literal Constants in %s (%d) " , ZSTR_VAL ( ops - > filename ) , count ) ;
2013-11-22 09:56:17 +00:00
} else {
2014-09-24 22:21:27 +00:00
phpdbg_notice ( " literalinfo " , " opline= \" %p \" num= \" %d \" " , " Literal Constants @ %p (%d) " , ops , count ) ;
2013-11-22 09:56:17 +00:00
}
}
2013-11-24 01:49:48 +00:00
2013-11-22 09:56:17 +00:00
while ( literal < ops - > last_literal ) {
2014-10-24 17:29:50 +00:00
if ( Z_TYPE ( ops - > literals [ literal ] ) ! = IS_NULL ) {
2014-09-21 02:17:19 +00:00
phpdbg_write ( " literal " , " id= \" %u \" " , " |-------- C%u -------> [ " , literal ) ;
2014-12-13 22:06:14 +00:00
zend_print_zval ( & ops - > literals [ literal ] , 0 ) ;
2014-09-21 02:17:19 +00:00
phpdbg_out ( " ] \n " ) ;
2013-11-23 17:36:33 +00:00
}
2013-11-22 09:09:54 +00:00
literal + + ;
}
} else {
2014-09-21 02:17:19 +00:00
phpdbg_error ( " inactive " , " type= \" execution \" " , " Not executing! " ) ;
2013-11-22 09:09:54 +00:00
}
2013-11-24 01:49:48 +00:00
2013-11-22 09:09:54 +00:00
return SUCCESS ;
} /* }}} */
2013-12-01 08:34:17 +00:00
PHPDBG_INFO ( memory ) /* {{{ */
{
2014-10-02 23:29:41 +00:00
size_t used , real , peak_used , peak_real ;
zend_mm_heap * heap ;
zend_bool is_mm ;
if ( PHPDBG_G ( flags ) & PHPDBG_IN_SIGNAL_HANDLER ) {
2014-12-13 22:06:14 +00:00
heap = zend_mm_set_heap ( phpdbg_original_heap_sigsafe_mem ( ) ) ;
2014-10-02 23:29:41 +00:00
}
2014-12-13 22:06:14 +00:00
if ( ( is_mm = is_zend_mm ( ) ) ) {
used = zend_memory_usage ( 0 ) ;
real = zend_memory_usage ( 1 ) ;
peak_used = zend_memory_peak_usage ( 0 ) ;
peak_real = zend_memory_peak_usage ( 1 ) ;
2014-10-02 23:29:41 +00:00
}
if ( PHPDBG_G ( flags ) & PHPDBG_IN_SIGNAL_HANDLER ) {
2014-12-13 22:06:14 +00:00
zend_mm_set_heap ( heap ) ;
2014-10-02 23:29:41 +00:00
}
if ( is_mm ) {
2014-09-21 02:17:19 +00:00
phpdbg_notice ( " meminfo " , " " , " Memory Manager Information " ) ;
phpdbg_notice ( " current " , " " , " Current " ) ;
2014-10-07 11:08:30 +00:00
phpdbg_writeln ( " used " , " mem= \" %.3f \" " , " |-------> Used: \t %.3f kB " , ( float ) ( used / 1024 ) ) ;
phpdbg_writeln ( " real " , " mem= \" %.3f \" " , " |-------> Real: \t %.3f kB " , ( float ) ( real / 1024 ) ) ;
2014-09-21 02:17:19 +00:00
phpdbg_notice ( " peak " , " " , " Peak " ) ;
2014-10-07 11:08:30 +00:00
phpdbg_writeln ( " used " , " mem= \" %.3f \" " , " |-------> Used: \t %.3f kB " , ( float ) ( peak_used / 1024 ) ) ;
phpdbg_writeln ( " real " , " mem= \" %.3f \" " , " |-------> Real: \t %.3f kB " , ( float ) ( peak_real / 1024 ) ) ;
2013-12-01 08:34:17 +00:00
} else {
2014-09-21 02:17:19 +00:00
phpdbg_error ( " inactive " , " type= \" memory_manager \" " , " Memory Manager Disabled! " ) ;
2013-12-01 08:34:17 +00:00
}
return SUCCESS ;
} /* }}} */
2014-12-13 22:06:14 +00:00
static inline void phpdbg_print_class_name ( zend_class_entry * ce ) /* { { { */
2013-11-20 18:52:34 +00:00
{
2014-10-24 17:29:50 +00:00
const char * visibility = ce - > type = = ZEND_USER_CLASS ? " User " : " Internal " ;
const char * type = ( ce - > ce_flags & ZEND_ACC_INTERFACE ) ? " Interface " : ( ce - > ce_flags & ZEND_ACC_ABSTRACT ) ? " Abstract Class " : " Class " ;
2016-02-14 13:02:19 +00:00
phpdbg_writeln ( " class " , " type= \" %s \" flags= \" %s \" name= \" %.*s \" methodcount= \" %d \" " , " %s %s %.*s (%d) " , visibility , type , ( int ) ZSTR_LEN ( ce - > name ) , ZSTR_VAL ( ce - > name ) , zend_hash_num_elements ( & ce - > function_table ) ) ;
2013-11-17 18:26:56 +00:00
} /* }}} */
PHPDBG_INFO ( classes ) /* {{{ */
{
2014-10-24 17:29:50 +00:00
zend_class_entry * ce ;
2013-11-17 18:26:56 +00:00
HashTable classes ;
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
zend_hash_init ( & classes , 8 , NULL , NULL , 0 ) ;
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( EG ( class_table ) , ce ) {
if ( ce - > type = = ZEND_USER_CLASS ) {
zend_hash_next_index_insert_ptr ( & classes , ce ) ;
2014-10-02 23:29:41 +00:00
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_notice ( " signalsegv " , " " , " Not all classes could be fetched, possibly invalid data source " ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-17 18:26:56 +00:00
2014-09-24 22:21:27 +00:00
phpdbg_notice ( " classinfo " , " num= \" %d \" " , " User Classes (%d) " , zend_hash_num_elements ( & classes ) ) ;
2013-11-17 18:26:56 +00:00
2014-10-02 23:29:41 +00:00
/* once added, assume that classes are stable... until shutdown. */
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( & classes , ce ) {
2014-12-13 22:06:14 +00:00
phpdbg_print_class_name ( ce ) ;
2013-11-17 18:45:08 +00:00
2014-10-24 17:29:50 +00:00
if ( ce - > parent ) {
2014-12-16 11:20:29 +00:00
zend_class_entry * pce ;
2014-10-09 10:24:52 +00:00
phpdbg_xml ( " <parents %r> " ) ;
2014-12-16 11:20:29 +00:00
pce = ce - > parent ;
2013-11-17 18:26:56 +00:00
do {
2014-09-21 02:17:19 +00:00
phpdbg_out ( " |-------- " ) ;
2014-12-13 22:06:14 +00:00
phpdbg_print_class_name ( pce ) ;
2013-11-17 21:01:41 +00:00
} while ( ( pce = pce - > parent ) ) ;
2014-09-21 02:17:19 +00:00
phpdbg_xml ( " </parents> " ) ;
2013-11-17 18:26:56 +00:00
}
2013-11-17 18:45:08 +00:00
2014-10-24 17:29:50 +00:00
if ( ce - > info . user . filename ) {
2015-06-30 10:59:27 +00:00
phpdbg_writeln ( " classsource " , " file= \" %s \" line= \" %u \" " , " |---- in %s on line %u " , ZSTR_VAL ( ce - > info . user . filename ) , ce - > info . user . line_start ) ;
2013-11-26 10:02:58 +00:00
} else {
2014-09-21 02:17:19 +00:00
phpdbg_writeln ( " classsource " , " " , " |---- no source code " ) ;
2013-11-26 10:02:58 +00:00
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2013-11-17 18:26:56 +00:00
zend_hash_destroy ( & classes ) ;
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
return SUCCESS ;
} /* }}} */
2013-11-17 18:55:06 +00:00
PHPDBG_INFO ( funcs ) /* {{{ */
{
2014-10-24 17:29:50 +00:00
zend_function * zf ;
2013-11-17 18:55:06 +00:00
HashTable functions ;
2013-11-17 19:40:49 +00:00
2013-11-17 18:55:06 +00:00
zend_hash_init ( & functions , 8 , NULL , NULL , 0 ) ;
2014-10-02 23:29:41 +00:00
phpdbg_try_access {
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( EG ( function_table ) , zf ) {
2014-10-02 23:29:41 +00:00
if ( zf - > type = = ZEND_USER_FUNCTION ) {
2014-10-24 17:29:50 +00:00
zend_hash_next_index_insert_ptr ( & functions , zf ) ;
2014-10-02 23:29:41 +00:00
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_catch_access {
2014-10-07 11:08:30 +00:00
phpdbg_notice ( " signalsegv " , " " , " Not all functions could be fetched, possibly invalid data source " ) ;
2014-10-02 23:29:41 +00:00
} phpdbg_end_try_access ( ) ;
2013-11-17 18:55:06 +00:00
2014-09-24 22:21:27 +00:00
phpdbg_notice ( " functioninfo " , " num= \" %d \" " , " User Functions (%d) " , zend_hash_num_elements ( & functions ) ) ;
2013-11-17 19:40:49 +00:00
2014-10-24 17:29:50 +00:00
ZEND_HASH_FOREACH_PTR ( & functions , zf ) {
zend_op_array * op_array = & zf - > op_array ;
2013-11-17 18:55:06 +00:00
2015-06-30 10:59:27 +00:00
phpdbg_write ( " function " , " name= \" %s \" " , " |-------- %s " , op_array - > function_name ? ZSTR_VAL ( op_array - > function_name ) : " {main} " ) ;
2013-11-17 19:40:49 +00:00
2014-09-24 22:21:27 +00:00
if ( op_array - > filename ) {
2015-06-30 10:59:27 +00:00
phpdbg_writeln ( " functionsource " , " file= \" %s \" line= \" %d \" " , " in %s on line %d " , ZSTR_VAL ( op_array - > filename ) , op_array - > line_start ) ;
2014-09-24 22:21:27 +00:00
} else {
phpdbg_writeln ( " functionsource " , " " , " (no source code) " ) ;
}
2014-10-24 17:29:50 +00:00
} ZEND_HASH_FOREACH_END ( ) ;
2013-11-17 18:55:06 +00:00
zend_hash_destroy ( & functions ) ;
2013-11-17 19:40:49 +00:00
2013-11-17 18:55:06 +00:00
return SUCCESS ;
} /* }}} */