php-src/phpdbg_info.c

248 lines
7.4 KiB
C
Raw Normal View History

2013-11-17 15:42:34 +00:00
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2013 The PHP Group |
+----------------------------------------------------------------------+
| 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> |
+----------------------------------------------------------------------+
*/
#include "php.h"
#include "phpdbg_utils.h"
#include "phpdbg_info.h"
PHPDBG_INFO(files) /* {{{ */
{
HashPosition pos;
char *fname;
phpdbg_notice("Included files: %d",
zend_hash_num_elements(&EG(included_files)));
zend_hash_internal_pointer_reset_ex(&EG(included_files), &pos);
while (zend_hash_get_current_key_ex(&EG(included_files), &fname,
NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
phpdbg_writeln("File: %s", fname);
zend_hash_move_forward_ex(&EG(included_files), &pos);
}
return SUCCESS;
} /* }}} */
PHPDBG_INFO(error) /* {{{ */
{
2013-11-17 19:00:59 +00:00
if (PG(last_error_message)) {
phpdbg_writeln("Last error: %s at %s line %d",
PG(last_error_message), PG(last_error_file), PG(last_error_lineno));
} else {
phpdbg_notice("No error found!");
}
return SUCCESS;
} /* }}} */
PHPDBG_INFO(vars) /* {{{ */
{
2013-11-18 21:59:42 +00:00
HashTable vars;
HashPosition pos;
char *var;
2013-11-18 22:12:27 +00:00
zval **data;
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
if (!EG(active_symbol_table)) {
phpdbg_error("No active symbol table!");
return SUCCESS;
}
}
2013-11-18 21:59:42 +00:00
zend_hash_init(&vars, 8, NULL, NULL, 0);
zend_hash_internal_pointer_reset_ex(EG(active_symbol_table), &pos);
while (zend_hash_get_current_key_ex(EG(active_symbol_table), &var,
NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
zend_hash_get_current_data_ex(EG(active_symbol_table), (void **)&data, &pos);
if (*var != '_') {
2013-11-18 21:59:42 +00:00
zend_hash_update(
&vars, var, strlen(var)+1, (void**)data, sizeof(zval*), NULL);
}
zend_hash_move_forward_ex(EG(active_symbol_table), &pos);
}
2013-11-18 22:12:27 +00:00
2013-11-18 21:59:42 +00:00
phpdbg_notice("Variables: %d",
zend_hash_num_elements(&vars));
2013-11-18 23:04:20 +00:00
if (zend_hash_num_elements(&vars)) {
phpdbg_writeln("Address\t\tRefs\tType\t\tVariable");
for (zend_hash_internal_pointer_reset_ex(&vars, &pos);
zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS;
zend_hash_move_forward_ex(&vars, &pos)) {
char *var;
2013-11-18 21:59:42 +00:00
2013-11-18 23:04:20 +00:00
zend_hash_get_current_key_ex(&vars, &var, NULL, NULL, 0, &pos);
2013-11-18 22:12:27 +00:00
2013-11-18 23:04:20 +00:00
if (*data) {
phpdbg_write(
2013-11-18 23:04:20 +00:00
"%p\t%d\t",
*data,
Z_REFCOUNT_PP(data));
switch (Z_TYPE_PP(data)) {
case IS_STRING: phpdbg_write("(string)\t"); break;
case IS_LONG: phpdbg_write("(integer)\t"); break;
case IS_DOUBLE: phpdbg_write("(float)\t"); break;
case IS_RESOURCE: phpdbg_write("(resource)\t"); break;
case IS_ARRAY: phpdbg_write("(array)\t"); break;
case IS_OBJECT: phpdbg_write("(object)\t"); break;
case IS_NULL: phpdbg_write("(null)\t"); break;
}
2013-11-18 23:18:22 +00:00
if (Z_TYPE_PP(data) == IS_RESOURCE) {
int type;
phpdbg_writeln(
"%s$%s", Z_ISREF_PP(data) ? "&": "", var);
if (zend_list_find(Z_RESVAL_PP(data), &type)) {
phpdbg_write(
"|-------(typeof)------> (%s)",
zend_rsrc_list_get_rsrc_type(type TSRMLS_CC));
} else {
phpdbg_write(
"|-------(typeof)------> (unknown)");
}
phpdbg_writeln(EMPTY);
} else if (Z_TYPE_PP(data) == IS_OBJECT) {
2013-11-18 23:04:20 +00:00
phpdbg_writeln(
"%s$%s", Z_ISREF_PP(data) ? "&": "", var);
phpdbg_write(
"|-----(instanceof)----> (%s)", Z_OBJCE_PP(data)->name);
phpdbg_writeln(EMPTY);
} else {
phpdbg_write(
"%s$%s", Z_ISREF_PP(data) ? "&": "", var);
}
} else {
phpdbg_write(
2013-11-18 23:04:20 +00:00
"n/a\tn/a\tn/a\t$%s", var);
}
2013-11-18 23:04:20 +00:00
phpdbg_writeln(EMPTY);
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
return SUCCESS;
} /* }}} */
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) { /* {{{ */
phpdbg_write(
"%s %s %s (%d)",
2013-11-17 18:45:08 +00:00
((*ce)->type == ZEND_USER_CLASS) ?
2013-11-17 18:26:56 +00:00
"User" : "Internal",
2013-11-17 18:45:08 +00:00
((*ce)->ce_flags & ZEND_ACC_INTERFACE) ?
2013-11-17 18:26:56 +00:00
"Interface" :
((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ?
"Abstract Class" :
2013-11-17 18:45:08 +00:00
"Class",
2013-11-17 18:26:56 +00:00
(*ce)->name, zend_hash_num_elements(&(*ce)->function_table));
} /* }}} */
PHPDBG_INFO(classes) /* {{{ */
{
HashPosition position;
zend_class_entry **ce;
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);
2013-11-17 18:45:08 +00:00
for (zend_hash_internal_pointer_reset_ex(EG(class_table), &position);
2013-11-17 18:26:56 +00:00
zend_hash_get_current_data_ex(EG(class_table), (void**)&ce, &position) == SUCCESS;
zend_hash_move_forward_ex(EG(class_table), &position)) {
if ((*ce)->type == ZEND_USER_CLASS) {
zend_hash_next_index_insert(
&classes, ce, sizeof(ce), NULL);
}
}
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
phpdbg_notice("User Classes (%d)",
zend_hash_num_elements(&classes));
2013-11-17 18:45:08 +00:00
for (zend_hash_internal_pointer_reset_ex(&classes, &position);
2013-11-17 18:26:56 +00:00
zend_hash_get_current_data_ex(&classes, (void**)&ce, &position) == SUCCESS;
zend_hash_move_forward_ex(&classes, &position)) {
phpdbg_print_class_name(ce TSRMLS_CC);
phpdbg_writeln(EMPTY);
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
if ((*ce)->parent) {
zend_class_entry *pce = (*ce)->parent;
do {
phpdbg_write("|-------- ");
phpdbg_print_class_name(&pce TSRMLS_CC);
phpdbg_writeln(EMPTY);
} while ((pce = pce->parent));
2013-11-17 18:26:56 +00:00
}
2013-11-17 18:45:08 +00:00
2013-11-17 18:26:56 +00:00
if ((*ce)->info.user.filename) {
phpdbg_writeln(
2013-11-17 18:45:08 +00:00
"|---- in %s on line %lu",
2013-11-17 18:26:56 +00:00
(*ce)->info.user.filename,
(*ce)->info.user.line_start);
} else phpdbg_writeln("|---- no source code");
2013-11-17 18:33:34 +00:00
phpdbg_writeln(EMPTY);
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) /* {{{ */
{
HashPosition position;
zend_function *zf, **pzf;
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);
2013-11-17 19:40:49 +00:00
for (zend_hash_internal_pointer_reset_ex(EG(function_table), &position);
2013-11-17 18:55:06 +00:00
zend_hash_get_current_data_ex(EG(function_table), (void**)&zf, &position) == SUCCESS;
zend_hash_move_forward_ex(EG(function_table), &position)) {
if (zf->type == ZEND_USER_FUNCTION) {
zend_hash_next_index_insert(
&functions, (void**) &zf, sizeof(zend_function), NULL);
}
}
2013-11-17 19:40:49 +00:00
2013-11-17 18:55:06 +00:00
phpdbg_notice("User Functions (%d)",
zend_hash_num_elements(&functions));
2013-11-17 19:40:49 +00:00
for (zend_hash_internal_pointer_reset_ex(&functions, &position);
2013-11-17 18:55:06 +00:00
zend_hash_get_current_data_ex(&functions, (void**)&pzf, &position) == SUCCESS;
zend_hash_move_forward_ex(&functions, &position)) {
zend_op_array *op_array = &((*pzf)->op_array);
2013-11-17 19:40:49 +00:00
2013-11-17 18:55:06 +00:00
phpdbg_writeln(
"|-------- %s in %s on line %d",
op_array->function_name ? op_array->function_name : "{main}",
op_array->filename ? op_array->filename : "(no source code)",
op_array->line_start);
}
zend_hash_destroy(&functions);
2013-11-17 19:40:49 +00:00
2013-11-17 18:55:06 +00:00
return SUCCESS;
} /* }}} */