/xdebug_var.c
C | 2912 lines | 2781 code | 90 blank | 41 comment | 193 complexity | 60df2dfa2e3b85949f700adcfd32b3f7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
Large files files are truncated, but you can click here to view the full file
- /*
- +----------------------------------------------------------------------+
- | Xdebug |
- +----------------------------------------------------------------------+
- | Copyright (c) 2002-2016 Derick Rethans |
- +----------------------------------------------------------------------+
- | This source file is subject to version 1.0 of the Xdebug license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://xdebug.derickrethans.nl/license.php |
- | If you did not receive a copy of the Xdebug license and are unable |
- | to obtain it through the world-wide-web, please send a note to |
- | xdebug@derickrethans.nl so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Derick Rethans <derick@xdebug.org> |
- +----------------------------------------------------------------------+
- */
- #include "php.h"
- #include "ext/standard/php_string.h"
- #include "ext/standard/url.h"
- #include "zend.h"
- #include "zend_extensions.h"
- #if PHP_VERSION_ID >= 70000
- # include "ext/standard/php_smart_string.h"
- # include "zend_smart_str.h"
- #else
- # include "ext/standard/php_smart_str.h"
- #endif
- #include "php_xdebug.h"
- #include "xdebug_compat.h"
- #include "xdebug_private.h"
- #include "xdebug_mm.h"
- #include "xdebug_var.h"
- #include "xdebug_xml.h"
- /* Set correct int format to use */
- #if PHP_VERSION_ID >= 70000
- # include "Zend/zend_long.h"
- # if SIZEOF_ZEND_LONG == 4
- # define XDEBUG_INT_FMT "%ld"
- # else
- # define XDEBUG_INT_FMT "%lld"
- # endif
- #else
- # define XDEBUG_INT_FMT "%ld"
- #endif
- ZEND_EXTERN_MODULE_GLOBALS(xdebug)
- HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp TSRMLS_DC)
- {
- zval dzval = **zval_pp;
- HashTable *tmp;
- if (!XG(in_debug_info) && Z_OBJ_HANDLER(dzval, get_debug_info)) {
- zend_bool old_trace = XG(do_trace);
- #if PHP_VERSION_ID >= 70000
- zend_object *orig_exception;
- #else
- zval *orig_exception;
- #endif
- XG(do_trace) = 0;
- XG(in_debug_info) = 1;
- orig_exception = EG(exception);
- EG(exception) = NULL;
- tmp = Z_OBJ_HANDLER(dzval, get_debug_info)(&dzval, is_tmp TSRMLS_CC);
- XG(in_debug_info) = 0;
- XG(do_trace) = old_trace;
- EG(exception) = orig_exception;
- return tmp;
- } else {
- *is_tmp = 0;
- if (Z_OBJ_HANDLER(dzval, get_properties)) {
- return Z_OBJPROP(dzval);
- }
- }
- return NULL;
- }
- char* xdebug_error_type_simple(int type)
- {
- switch (type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- return xdstrdup("fatal-error");
- break;
- case E_RECOVERABLE_ERROR:
- return xdstrdup("catchable-fatal-error");
- break;
- case E_WARNING:
- case E_CORE_WARNING:
- case E_COMPILE_WARNING:
- case E_USER_WARNING:
- return xdstrdup("warning");
- break;
- case E_PARSE:
- return xdstrdup("parse-error");
- break;
- case E_NOTICE:
- case E_USER_NOTICE:
- return xdstrdup("notice");
- break;
- case E_STRICT:
- return xdstrdup("strict-standards");
- break;
- case E_DEPRECATED:
- case E_USER_DEPRECATED:
- return xdstrdup("deprecated");
- break;
- case 0:
- return xdstrdup("xdebug");
- break;
- default:
- return xdstrdup("unknown-error");
- break;
- }
- }
- char* xdebug_error_type(int type)
- {
- switch (type) {
- case E_ERROR:
- case E_CORE_ERROR:
- case E_COMPILE_ERROR:
- case E_USER_ERROR:
- return xdstrdup("Fatal error");
- break;
- case E_RECOVERABLE_ERROR:
- return xdstrdup("Catchable fatal error");
- break;
- case E_WARNING:
- case E_CORE_WARNING:
- case E_COMPILE_WARNING:
- case E_USER_WARNING:
- return xdstrdup("Warning");
- break;
- case E_PARSE:
- return xdstrdup("Parse error");
- break;
- case E_NOTICE:
- case E_USER_NOTICE:
- return xdstrdup("Notice");
- break;
- case E_STRICT:
- return xdstrdup("Strict standards");
- break;
- case E_DEPRECATED:
- case E_USER_DEPRECATED:
- return xdstrdup("Deprecated");
- break;
- case 0:
- return xdstrdup("Xdebug");
- break;
- default:
- return xdstrdup("Unknown error");
- break;
- }
- }
- /*************************************************************************************************************************************/
- #if PHP_VERSION_ID >= 70000
- # define T(offset) (*(union _temp_variable *)((char*)zdata->current_execute_data->Ts + offset))
- #elif PHP_VERSION_ID >= 50500
- # define T(offset) (*EX_TMP_VAR(zdata, offset))
- #else
- # define T(offset) (*(temp_variable *)((char*)zdata->Ts + offset))
- #endif
- #if PHP_VERSION_ID >= 70000
- zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var)
- {
- zend_free_op should_free;
- return zend_get_zval_ptr(node_type, node, zdata, &should_free, BP_VAR_IS);
- }
- #else
- zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var)
- {
- switch (node_type) {
- case IS_CONST:
- #if PHP_VERSION_ID >= 50300
- return node->zv;
- #else
- return &node->u.constant;
- #endif
- break;
- case IS_TMP_VAR:
- *is_var = 1;
- return &T(node->var).tmp_var;
- break;
- case IS_VAR:
- *is_var = 1;
- if (T(node->var).var.ptr) {
- return T(node->var).var.ptr;
- }
- break;
- case IS_CV: {
- zval **tmp;
- tmp = zend_get_compiled_variable_value(zdata, node->constant);
- if (tmp) {
- return *tmp;
- }
- break;
- }
- case IS_UNUSED:
- fprintf(stderr, "\nIS_UNUSED\n");
- break;
- default:
- fprintf(stderr, "\ndefault %d\n", node_type);
- break;
- }
- *is_var = 1;
- return NULL;
- }
- #endif
- /*****************************************************************************
- ** PHP Variable related utility functions
- */
- /*****************************************************************************
- ** Data returning functions
- */
- #define XF_ST_ROOT 0
- #define XF_ST_ARRAY_INDEX_NUM 1
- #define XF_ST_ARRAY_INDEX_ASSOC 2
- #define XF_ST_OBJ_PROPERTY 3
- #define XF_ST_STATIC_ROOT 4
- #define XF_ST_STATIC_PROPERTY 5
- inline static HashTable *fetch_ht_from_zval(zval *z TSRMLS_DC)
- {
- #if PHP_VERSION_ID >= 70000
- if (Z_TYPE_P(z) == IS_REFERENCE) {
- z = &z->value.ref->val;
- }
- #endif
- switch (Z_TYPE_P(z)) {
- case IS_ARRAY:
- return Z_ARRVAL_P(z);
- break;
- case IS_OBJECT:
- return Z_OBJPROP_P(z);
- break;
- }
- return NULL;
- }
- #if PHP_VERSION_ID >= 70000
- inline static char *fetch_classname_from_zval(zval *z, int *length, zend_class_entry **ce TSRMLS_DC)
- {
- zend_string *class_name;
- if (Z_TYPE_P(z) != IS_OBJECT) {
- return NULL;
- }
- class_name = Z_OBJ_HANDLER_P(z, get_class_name)(Z_OBJ_P(z));
- *ce = Z_OBJCE_P(z);
- *length = class_name->len;
- return estrdup(class_name->val);
- }
- #else
- inline static char *fetch_classname_from_zval(zval *z, int *length, zend_class_entry **ce TSRMLS_DC)
- {
- char *name;
- SIZETorZUINT name_len;
- zend_class_entry *tmp_ce;
- if (Z_TYPE_P(z) != IS_OBJECT) {
- return NULL;
- }
- tmp_ce = zend_get_class_entry(z TSRMLS_CC);
- if (Z_OBJ_HT_P(z)->get_class_name == NULL ||
- Z_OBJ_HT_P(z)->get_class_name(z, (const char **) &name, &name_len, 0 TSRMLS_CC) != SUCCESS) {
- if (!tmp_ce) {
- return NULL;
- }
- *length = tmp_ce->name_length;
- *ce = tmp_ce;
- return estrdup(tmp_ce->name);
- } else {
- *ce = tmp_ce;
- }
- *length = name_len;
- return name;
- }
- #endif
- static char* prepare_search_key(char *name, unsigned int *name_length, char *prefix, int prefix_length)
- {
- char *element;
- int extra_length = 0;
- if (prefix_length) {
- if (prefix[0] == '*') {
- extra_length = 3;
- } else {
- extra_length = 2 + prefix_length;
- }
- }
- element = malloc(*name_length + 1 + extra_length);
- memset(element, 0, *name_length + 1 + extra_length);
- if (extra_length) {
- memcpy(element + 1, prefix, extra_length - 2);
- }
- memcpy(element + extra_length, name, *name_length);
- *name_length += extra_length;
- return element;
- }
- static zval *get_arrayobject_storage(zval *parent TSRMLS_DC)
- {
- int is_temp;
- HashTable *properties = Z_OBJDEBUG_P(parent, is_temp);
- #if PHP_VERSION_ID >= 70000
- zval *tmp = NULL;
- if ((tmp = zend_hash_str_find(properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1)) != NULL) {
- return tmp;
- #else
- zval **tmp = NULL;
- if (zend_hash_find(properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage"), (void **) &tmp) == SUCCESS) {
- return *tmp;
- #endif
- }
- return NULL;
- }
- static zval *get_splobjectstorage_storage(zval *parent TSRMLS_DC)
- {
- int is_temp;
- HashTable *properties = Z_OBJDEBUG_P(parent, is_temp);
- #if PHP_VERSION_ID >= 70000
- zval *tmp = NULL;
- if ((tmp = zend_hash_str_find(properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1)) != NULL) {
- return tmp;
- #else
- zval **tmp = NULL;
- if (zend_hash_find(properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage"), (void **) &tmp) == SUCCESS) {
- return *tmp;
- #endif
- }
- return NULL;
- }
- static zval *get_arrayiterator_storage(zval *parent TSRMLS_DC)
- {
- int is_temp;
- HashTable *properties = Z_OBJDEBUG_P(parent, is_temp);
- #if PHP_VERSION_ID >= 70000
- zval *tmp = NULL;
- if ((tmp = zend_hash_str_find(properties, "\0ArrayIterator\0storage", sizeof("*ArrayIterator*storage") - 1)) != NULL) {
- return tmp;
- #else
- zval **tmp = NULL;
- if (zend_hash_find(properties, "\0ArrayIterator\0storage", sizeof("*ArrayIterator*storage"), (void **) &tmp) == SUCCESS) {
- return *tmp;
- #endif
- }
- return NULL;
- }
- static zval* fetch_zval_from_symbol_table(zval *parent, char* name, unsigned int name_length, int type, char* ccn, int ccnl, zend_class_entry *cce TSRMLS_DC)
- {
- HashTable *ht = NULL;
- zval *retval_p = NULL;
- #if PHP_VERSION_ID < 70000
- zval **retval_pp = NULL;
- #endif
- char *element = NULL;
- unsigned int element_length = name_length;
- zend_property_info *zpp;
- if (parent) {
- ht = fetch_ht_from_zval(parent TSRMLS_CC);
- }
- switch (type) {
- case XF_ST_STATIC_ROOT:
- case XF_ST_STATIC_PROPERTY:
- /* First we try a public,private,protected property */
- element = prepare_search_key(name, &element_length, "", 0);
- #if PHP_VERSION_ID >= 70000
- if (cce && &cce->properties_info && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL) && cce->static_members_table) {
- retval_p = &cce->static_members_table[zpp->offset];
- #else
- if (cce && &cce->properties_info && zend_hash_find(&cce->properties_info, element, element_length + 1, (void **) &zpp) == SUCCESS) {
- retval_p = cce->static_members_table[zpp->offset];
- #endif
- goto cleanup;
- }
- element_length = name_length;
- /* Then we try to see whether the first char is * and use the part between * and * as class name for the private property */
- if (name[0] == '*') {
- char *secondStar;
- secondStar = strstr(name + 1, "*");
- if (secondStar) {
- free(element);
- element_length = name_length - (secondStar + 1 - name);
- element = prepare_search_key(secondStar + 1, &element_length, "", 0);
- #if PHP_VERSION_ID >= 70000
- if (cce && &cce->properties_info && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL)) {
- retval_p = &cce->static_members_table[zpp->offset];
- #else
- if (cce && &cce->properties_info && zend_hash_find(&cce->properties_info, element, element_length + 1, (void **) &zpp) == SUCCESS) {
- retval_p = cce->static_members_table[zpp->offset];
- #endif
- goto cleanup;
- }
- }
- }
- break;
- case XF_ST_ROOT:
- /* Check for compiled vars */
- element = prepare_search_key(name, &element_length, "", 0);
- #if PHP_VERSION_ID >= 70000
- if (XG(active_execute_data) && XG(active_execute_data)->func) {
- #else
- if (XG(active_execute_data) && XG(active_execute_data)->op_array) {
- #endif
- int i = 0;
- #if PHP_VERSION_ID >= 70000
- hashULONG hash_value = zend_inline_hash_func(element, element_length);
- zend_op_array *opa = &XG(active_execute_data)->func->op_array;
- #else
- hashULONG hash_value = zend_inline_hash_func(element, element_length + 1);
- zend_op_array *opa = XG(active_execute_data)->op_array;
- #endif
- zval **CV;
- while (i < opa->last_var) {
- #if PHP_VERSION_ID >= 70000
- if (ZSTR_H(opa->vars[i]) == hash_value &&
- ZSTR_LEN(opa->vars[i]) == element_length &&
- strncmp(STR_NAME_VAL(opa->vars[i]), element, element_length) == 0)
- #else
- if (opa->vars[i].hash_value == hash_value &&
- opa->vars[i].name_len == (int) element_length &&
- strcmp(STR_NAME_VAL(opa->vars[i].name), element) == 0)
- #endif
- {
- #if PHP_VERSION_ID >= 70000
- zval *CV_z = ZEND_CALL_VAR_NUM(XG(active_execute_data), i);
- CV = &CV_z;
- #elif PHP_VERSION_ID >= 50500
- CV = (*EX_CV_NUM(XG(active_execute_data), i));
- #else
- CV = XG(active_execute_data)->CVs[i];
- #endif
- if (CV) {
- retval_p = *CV;
- goto cleanup;
- }
- }
- i++;
- }
- }
- free(element);
- ht = XG(active_symbol_table);
- /* break intentionally missing */
- case XF_ST_ARRAY_INDEX_ASSOC:
- element = prepare_search_key(name, &name_length, "", 0);
- /* Handle "this" in a different way */
- if (type == XF_ST_ROOT && strcmp("this", element) == 0) {
- if (XG(This)) {
- retval_p = XG(This);
- } else {
- retval_p = NULL;
- }
- goto cleanup;
- }
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_hash_str_find(ht, element, name_length)) != NULL)) {
- #else
- if (ht && zend_hash_find(ht, element, name_length + 1, (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- break;
- case XF_ST_ARRAY_INDEX_NUM:
- element = prepare_search_key(name, &name_length, "", 0);
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_hash_index_find(ht, strtoull(element, NULL, 10))) != NULL)) {
- #else
- if (ht && zend_hash_index_find(ht, strtoul(element, NULL, 10), (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- break;
- case XF_ST_OBJ_PROPERTY:
- /* First we try an object handler */
- if (cce) {
- zval *tmp_val;
- #if PHP_VERSION_ID >= 70000
- zval dummy;
- tmp_val = zend_read_property(cce, parent, name, name_length, 0, &dummy);
- if (tmp_val && tmp_val != &EG(uninitialized_zval)) {
- #else
- tmp_val = zend_read_property(cce, parent, name, name_length, 0 TSRMLS_CC);
- if (tmp_val && tmp_val != EG(uninitialized_zval_ptr)) {
- #endif
- retval_p = tmp_val;
- goto cleanup;
- }
- if (EG(exception)) {
- zend_clear_exception(TSRMLS_C);
- }
- }
- /* Then we try a public property */
- element = prepare_search_key(name, &element_length, "", 0);
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_symtable_str_find(ht, element, element_length)) != NULL)) {
- #else
- if (ht && zend_symtable_find(ht, element, element_length + 1, (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- element_length = name_length;
- /* Then we try it again as protected property */
- free(element);
- element = prepare_search_key(name, &element_length, "*", 1);
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_hash_str_find(ht, element, element_length)) != NULL)) {
- #else
- if (ht && zend_hash_find(ht, element, element_length + 1, (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- element_length = name_length;
- /* Then we try it again as private property */
- free(element);
- element = prepare_search_key(name, &element_length, ccn, ccnl);
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_hash_str_find(ht, element, element_length)) != NULL)) {
- #else
- if (ht && zend_hash_find(ht, element, element_length + 1, (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- element_length = name_length;
-
- /* All right, time for a mega hack. It's SplObjectStorage access time! */
- if (strncmp(ccn, "SplObjectStorage", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) {
- element = NULL;
- if ((retval_p = get_splobjectstorage_storage(parent TSRMLS_CC)) != NULL) {
- if (retval_p) {
- goto cleanup;
- }
- }
- }
- /* Then we try to see whether the first char is * and use the part between * and * as class name for the private property */
- if (name[0] == '*') {
- char *secondStar;
- secondStar = strstr(name + 1, "*");
- if (secondStar) {
- free(element);
- element_length = name_length - (secondStar + 1 - name);
- /* All right, time for a mega hack. It's ArrayObject access time! */
- if (strncmp(name + 1, "ArrayObject", secondStar - name - 1) == 0 && strncmp(secondStar + 1, "storage", element_length) == 0) {
- element = NULL;
- if ((retval_p = get_arrayobject_storage(parent TSRMLS_CC)) != NULL) {
- if (retval_p) {
- goto cleanup;
- }
- }
- }
- /* All right, time for a mega hack. It's ArrayIterator access time! */
- if (strncmp(name + 1, "ArrayIterator", secondStar - name - 1) == 0 && strncmp(secondStar + 1, "storage", element_length) == 0) {
- element = NULL;
- if ((retval_p = get_arrayiterator_storage(parent TSRMLS_CC)) != NULL) {
- if (retval_p) {
- goto cleanup;
- }
- }
- }
- /* The normal one */
- element = prepare_search_key(secondStar + 1, &element_length, name + 1, secondStar - name - 1);
- #if PHP_VERSION_ID >= 70000
- if (ht && ((retval_p = zend_hash_str_find(ht, element, element_length)) != NULL)) {
- #else
- if (ht && zend_hash_find(ht, element, element_length + 1, (void **) &retval_pp) == SUCCESS) {
- retval_p = *retval_pp;
- #endif
- goto cleanup;
- }
- }
- }
- break;
- }
- cleanup:
- if (element) {
- free(element);
- }
- return retval_p;
- }
- zval* xdebug_get_php_symbol(char* name TSRMLS_DC)
- {
- int found = -1;
- int state = 0;
- char **p = &name;
- char *keyword = NULL, *keyword_end = NULL;
- int type = XF_ST_ROOT;
- zval *retval = NULL;
- char *current_classname = NULL;
- zend_class_entry *current_ce = NULL;
- int cc_length = 0;
- char quotechar = 0;
- do {
- if (*p[0] == '\0') {
- found = 0;
- } else {
- switch (state) {
- case 0:
- if (*p[0] == '$') {
- keyword = *p + 1;
- break;
- }
- if (*p[0] == ':') { /* special tricks */
- keyword = *p;
- state = 7;
- break;
- }
- keyword = *p;
- state = 1;
- /* break intentionally missing */
- case 1:
- if (*p[0] == '[') {
- keyword_end = *p;
- if (keyword) {
- retval = fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- if (current_classname) {
- efree(current_classname);
- }
- current_classname = NULL;
- cc_length = 0;
- current_ce = NULL;
- keyword = NULL;
- }
- state = 3;
- } else if (*p[0] == '-') {
- keyword_end = *p;
- if (keyword) {
- retval = fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- if (current_classname) {
- efree(current_classname);
- }
- current_classname = NULL;
- cc_length = 0;
- current_ce = NULL;
- if (retval) {
- current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce TSRMLS_CC);
- }
- keyword = NULL;
- }
- state = 2;
- type = XF_ST_OBJ_PROPERTY;
- } else if (*p[0] == ':') {
- keyword_end = *p;
- if (keyword) {
- retval = fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- if (current_classname) {
- efree(current_classname);
- }
- current_classname = NULL;
- cc_length = 0;
- if (retval) {
- current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce TSRMLS_CC);
- }
- keyword = NULL;
- }
- state = 8;
- type = XF_ST_STATIC_PROPERTY;
- }
- break;
- case 2:
- if (*p[0] != '>') {
- keyword = *p;
- state = 1;
- }
- break;
- case 8:
- if (*p[0] != ':') {
- keyword = *p;
- state = 1;
- }
- break;
- case 3: /* Parsing in [...] */
- /* Associative arrays */
- if (*p[0] == '\'' || *p[0] == '"') {
- state = 4;
- keyword = *p + 1;
- quotechar = *p[0];
- type = XF_ST_ARRAY_INDEX_ASSOC;
- }
- /* Numerical index */
- if (*p[0] >= '0' && *p[0] <= '9') {
- cc_length = 0;
- state = 6;
- keyword = *p;
- type = XF_ST_ARRAY_INDEX_NUM;
- }
- /* Numerical index starting with a - */
- if (*p[0] == '-') {
- state = 9;
- keyword = *p;
- }
- break;
- case 9:
- /* Numerical index starting with a - */
- if (*p[0] >= '0' && *p[0] <= '9') {
- state = 6;
- type = XF_ST_ARRAY_INDEX_NUM;
- }
- break;
- case 4:
- if (*p[0] == quotechar) {
- quotechar = 0;
- state = 5;
- keyword_end = *p;
- retval = fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- if (current_classname) {
- efree(current_classname);
- }
- current_classname = NULL;
- cc_length = 0;
- if (retval) {
- current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce TSRMLS_CC);
- }
- keyword = NULL;
- }
- break;
- case 5:
- if (*p[0] == ']') {
- state = 1;
- }
- break;
- case 6:
- if (*p[0] == ']') {
- state = 1;
- keyword_end = *p;
- retval = fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- if (current_classname) {
- efree(current_classname);
- }
- current_classname = NULL;
- cc_length = 0;
- if (retval) {
- current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce TSRMLS_CC);
- }
- keyword = NULL;
- }
- break;
- case 7: /* special cases, started with a ":" */
- if (*p[0] == ':') {
- state = 1;
- keyword_end = *p;
- if (strncmp(keyword, "::", 2) == 0 && XG(active_fse)->function.class) { /* static class properties */
- zend_class_entry *ce = xdebug_fetch_class(XG(active_fse)->function.class, strlen(XG(active_fse)->function.class), ZEND_FETCH_CLASS_SELF TSRMLS_CC);
- current_classname = estrdup(STR_NAME_VAL(ce->name));
- cc_length = strlen(STR_NAME_VAL(ce->name));
- current_ce = ce;
- keyword = *p + 1;
- type = XF_ST_STATIC_ROOT;
- } else {
- keyword = NULL;
- }
- }
- break;
- }
- (*p)++;
- }
- } while (found < 0);
- if (keyword != NULL) {
- retval = fetch_zval_from_symbol_table(retval, keyword, *p - keyword, type, current_classname, cc_length, current_ce TSRMLS_CC);
- }
- if (current_classname) {
- efree(current_classname);
- }
- return retval;
- }
- char* xdebug_get_property_info(char *mangled_property, int mangled_len, char **property_name, char **class_name)
- {
- const char *prop_name, *cls_name;
- #if PHP_VERSION_ID >= 70000
- zend_string *i_mangled = zend_string_init(mangled_property, mangled_len - 1, 0);
- zend_unmangle_property_name(i_mangled, &cls_name, &prop_name);
- #else
- zend_unmangle_property_name(mangled_property, mangled_len, &cls_name, &prop_name);
- #endif
- *property_name = (char *) xdstrdup(prop_name);
- *class_name = cls_name ? xdstrdup(cls_name) : NULL;
- #if PHP_VERSION_ID >= 70000
- zend_string_release(i_mangled);
- #endif
- if (*class_name) {
- if (*class_name[0] == '*') {
- return "protected";
- } else {
- return "private";
- }
- } else {
- return "public";
- }
- }
- #define XDEBUG_MAX_INT 2147483647
- xdebug_var_export_options* xdebug_var_export_options_from_ini(TSRMLS_D)
- {
- xdebug_var_export_options *options;
- options = xdmalloc(sizeof(xdebug_var_export_options));
- options->max_children = XG(display_max_children);
- options->max_data = XG(display_max_data);
- options->max_depth = XG(display_max_depth);
- options->show_hidden = 0;
- options->show_location = XG(overload_var_dump) > 1;
- if (options->max_children == -1 || options->max_children > XDEBUG_MAX_INT) {
- options->max_children = XDEBUG_MAX_INT;
- } else if (options->max_children < 1) {
- options->max_children = 0;
- }
- if (options->max_data == -1 || options->max_data > XDEBUG_MAX_INT) {
- options->max_data = XDEBUG_MAX_INT;
- } else if (options->max_data < 1) {
- options->max_data = 0;
- }
- if (options->max_depth == -1 || options->max_depth > 1023) {
- options->max_depth = 1023;
- } else if (options->max_depth < 1) {
- options->max_depth = 0;
- }
- options->runtime = (xdebug_var_runtime_page*) xdmalloc((options->max_depth + 1) * sizeof(xdebug_var_runtime_page));
- options->no_decoration = 0;
- return options;
- }
- xdebug_var_export_options xdebug_var_nolimit_options = { XDEBUG_MAX_INT, XDEBUG_MAX_INT, 1023, 1, 0, NULL, 0 };
- xdebug_var_export_options* xdebug_var_get_nolimit_options(TSRMLS_D)
- {
- return &xdebug_var_nolimit_options;
- }
- /*****************************************************************************
- ** Normal variable printing routines
- */
- #if PHP_VERSION_ID >= 70000
- static int xdebug_array_element_export(zval *zv_nptr, zend_ulong index, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options)
- {
- zval **zv = &zv_nptr;
- #else
- static int xdebug_array_element_export(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- int level = va_arg(args, int);
- xdebug_str *str = va_arg(args, struct xdebug_str*);
- int debug_zval = va_arg(args, int);
- xdebug_var_export_options *options = va_arg(args, xdebug_var_export_options*);
- #endif
- if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
- options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
- {
- if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */
- xdebug_str_add(str, xdebug_sprintf("%ld => ", HASH_APPLY_NUMERIC(hash_key)), 1);
- } else { /* string key */
- SIZETorINT newlen = 0;
- char *tmp, *tmp2;
-
- tmp = xdebug_str_to_str((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), "'", 1, "\\'", 2, &newlen);
- tmp2 = xdebug_str_to_str(tmp, newlen - 1, "\0", 1, "\\0", 2, &newlen);
- if (tmp) {
- efree(tmp);
- }
- xdebug_str_addl(str, "'", 1, 0);
- if (tmp2) {
- xdebug_str_addl(str, tmp2, newlen, 0);
- efree(tmp2);
- }
- xdebug_str_add(str, "' => ", 0);
- }
- xdebug_var_export(zv, str, level + 2, debug_zval, options TSRMLS_CC);
- xdebug_str_addl(str, ", ", 2, 0);
- }
- if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
- xdebug_str_addl(str, "..., ", 5, 0);
- }
- options->runtime[level].current_element_nr++;
- return 0;
- }
- #if PHP_VERSION_ID >= 70000
- static int xdebug_object_element_export(zval *zv_nptr, zend_ulong index, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options, char *class_name)
- {
- zval **zv = &zv_nptr;
- #else
- static int xdebug_object_element_export(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- int level = va_arg(args, int);
- xdebug_str *str = va_arg(args, struct xdebug_str*);
- int debug_zval = va_arg(args, int);
- xdebug_var_export_options *options = va_arg(args, xdebug_var_export_options*);
- char *class_name = va_arg(args, char*);
- #endif
- if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
- options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
- {
- if (!HASH_KEY_IS_NUMERIC(hash_key)) {
- char *prop_name, *modifier, *prop_class_name;
- modifier = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &prop_name, &prop_class_name);
- if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) {
- xdebug_str_add(str, xdebug_sprintf("%s $%s = ", modifier, prop_name), 1);
- } else {
- xdebug_str_add(str, xdebug_sprintf("%s ${%s}:%s = ", modifier, prop_class_name, prop_name), 1);
- }
- xdfree(prop_name);
- xdfree(prop_class_name);
- } else {
- xdebug_str_add(str, xdebug_sprintf("public $%d = ", HASH_APPLY_NUMERIC(hash_key)), 1);
- }
- xdebug_var_export(zv, str, level + 2, debug_zval, options TSRMLS_CC);
- xdebug_str_addl(str, "; ", 2, 0);
- }
- if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
- xdebug_str_addl(str, "...; ", 5, 0);
- }
- options->runtime[level].current_element_nr++;
- return 0;
- }
- void xdebug_var_export(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
- {
- HashTable *myht;
- char* tmp_str;
- int is_temp;
- #if PHP_VERSION_ID >= 70000
- zend_ulong num;
- zend_string *key;
- zval *val;
- zval *tmpz;
- #endif
- if (!struc || !(*struc)) {
- return;
- }
- #if PHP_VERSION_ID >= 70000
- if (debug_zval) {
- if (Z_TYPE_P(*struc) >= IS_STRING && Z_TYPE_P(*struc) != IS_INDIRECT) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->value.counted->gc.refcount, Z_TYPE_P(*struc) == IS_REFERENCE), 1);
- } else {
- xdebug_str_add(str, "(refcount=0, is_ref=0)=", 0);
- }
- }
- if (Z_TYPE_P(*struc) == IS_REFERENCE) {
- tmpz = &((*struc)->value.ref->val);
- struc = &tmpz;
- }
- #else
- if (debug_zval) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->refcount__gc, (*struc)->is_ref__gc), 1);
- }
- #endif
- switch (Z_TYPE_P(*struc)) {
- #if PHP_VERSION_ID >= 70000
- case IS_TRUE:
- case IS_FALSE:
- xdebug_str_add(str, xdebug_sprintf("%s", Z_TYPE_P(*struc) == IS_TRUE ? "TRUE" : "FALSE"), 1);
- break;
- #else
- case IS_BOOL:
- xdebug_str_add(str, xdebug_sprintf("%s", Z_LVAL_P(*struc) ? "TRUE" : "FALSE"), 1);
- break;
- #endif
- case IS_NULL:
- xdebug_str_addl(str, "NULL", 4, 0);
- break;
- case IS_LONG:
- xdebug_str_add(str, xdebug_sprintf(XDEBUG_INT_FMT, Z_LVAL_P(*struc)), 1);
- break;
- case IS_DOUBLE:
- xdebug_str_add(str, xdebug_sprintf("%.*G", (int) EG(precision), Z_DVAL_P(*struc)), 1);
- break;
- case IS_STRING: {
- #if PHP_VERSION_ID >= 70000
- zend_string *i_string = zend_string_init(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), 0);
- zend_string *tmp_zstr;
- tmp_zstr = php_addcslashes(i_string, 0, "'\\\0..\37", 7);
- tmp_str = estrndup(tmp_zstr->val, tmp_zstr->len);
- zend_string_release(tmp_zstr);
- zend_string_release(i_string);
- #else
- int tmp_len;
- tmp_str = php_addcslashes(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), &tmp_len, 0, "'\\\0..\37", 7 TSRMLS_CC);
- #endif
- if (options->no_decoration) {
- xdebug_str_add(str, tmp_str, 0);
- } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) {
- xdebug_str_add(str, xdebug_sprintf("'%s'", tmp_str), 1);
- } else {
- xdebug_str_addl(str, "'", 1, 0);
- xdebug_str_addl(str, xdebug_sprintf("%s", tmp_str), options->max_data, 1);
- xdebug_str_addl(str, "...'", 4, 0);
- }
- efree(tmp_str);
- } break;
- case IS_ARRAY:
- myht = Z_ARRVAL_P(*struc);
- if (XDEBUG_APPLY_COUNT(myht) < 1) {
- xdebug_str_addl(str, "array (", 7, 0);
- if (level <= options->max_depth) {
- options->runtime[level].current_element_nr = 0;
- options->runtime[level].start_element_nr = 0;
- options->runtime[level].end_element_nr = options->max_children;
- #if PHP_VERSION_ID >= 70000
- ZEND_HASH_INC_APPLY_COUNT(myht);
- ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
- xdebug_array_element_export(val, num, key, level, str, debug_zval, options);
- } ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(myht);
- #else
- zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) xdebug_array_element_export, 4, level, str, debug_zval, options);
- #endif
- /* Remove the ", " at the end of the string */
- if (myht->nNumOfElements > 0) {
- xdebug_str_chop(str, 2);
- }
- } else {
- xdebug_str_addl(str, "...", 3, 0);
- }
- xdebug_str_addl(str, ")", 1, 0);
- } else {
- xdebug_str_addl(str, "...", 3, 0);
- }
- break;
- case IS_OBJECT:
- myht = xdebug_objdebug_pp(struc, &is_temp TSRMLS_CC);
- if (XDEBUG_APPLY_COUNT(myht) < 1) {
- char *class_name = (char*) STR_NAME_VAL(Z_OBJCE_P(*struc)->name);
- xdebug_str_add(str, xdebug_sprintf("class %s { ", class_name), 1);
- if (level <= options->max_depth) {
- options->runtime[level].current_element_nr = 0;
- options->runtime[level].start_element_nr = 0;
- options->runtime[level].end_element_nr = options->max_children;
- #if PHP_VERSION_ID >= 70000
- ZEND_HASH_INC_APPLY_COUNT(myht);
- ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
- xdebug_object_element_export(val, num, key, level, str, debug_zval, options, class_name);
- } ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(myht);
- #else
- zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export, 5, level, str, debug_zval, options, class_name);
- #endif
- /* Remove the ", " at the end of the string */
- if (myht->nNumOfElements > 0) {
- xdebug_str_chop(str, 2);
- }
- } else {
- xdebug_str_addl(str, "...", 3, 0);
- }
- xdebug_str_addl(str, " }", 2, 0);
- } else {
- xdebug_str_addl(str, "...", 3, 0);
- }
- if (is_temp) {
- zend_hash_destroy(myht);
- efree(myht);
- }
- break;
- case IS_RESOURCE: {
- char *type_name;
- #if PHP_VERSION_ID >= 70000
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"), 1);
- #else
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_LVAL_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("resource(%ld) of type (%s)", Z_LVAL_P(*struc), type_name ? type_name : "Unknown"), 1);
- #endif
- break;
- }
- #if PHP_VERSION_ID >= 70000
- case IS_UNDEF:
- xdebug_str_addl(str, "*uninitialized*", sizeof("*uninitialized*") - 1, 0);
- break;
- #endif
- default:
- xdebug_str_addl(str, "NFC", 3, 0);
- break;
- }
- }
- char* xdebug_get_zval_value(zval *val, int debug_zval, xdebug_var_export_options *options)
- {
- xdebug_str str = XDEBUG_STR_INITIALIZER;
- int default_options = 0;
- TSRMLS_FETCH();
- if (!options) {
- options = xdebug_var_export_options_from_ini(TSRMLS_C);
- default_options = 1;
- }
- xdebug_var_export(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
- if (default_options) {
- xdfree(options->runtime);
- xdfree(options);
- }
- return str.d;
- }
- static void xdebug_var_synopsis(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
- {
- HashTable *myht;
- #if PHP_VERSION_ID >= 70000
- zval *tmpz;
- #endif
- if (!struc || !(*struc)) {
- return;
- }
- #if PHP_VERSION_ID >= 70000
- if (debug_zval) {
- if (Z_TYPE_P(*struc) >= IS_STRING && Z_TYPE_P(*struc) != IS_INDIRECT) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->value.counted->gc.refcount, Z_TYPE_P(*struc) == IS_REFERENCE), 1);
- } else {
- xdebug_str_add(str, "(refcount=0, is_ref=0)=", 0);
- }
- }
- if (Z_TYPE_P(*struc) == IS_REFERENCE) {
- tmpz = &((*struc)->value.ref->val);
- struc = &tmpz;
- }
- #else
- if (debug_zval) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->refcount__gc, (*struc)->is_ref__gc), 1);
- }
- #endif
- switch (Z_TYPE_P(*struc)) {
- #if PHP_VERSION_ID >= 70000
- case IS_TRUE:
- xdebug_str_addl(str, "true", 4, 0);
- break;
- case IS_FALSE:
- xdebug_str_addl(str, "false", 5, 0);
- break;
- #else
- case IS_BOOL:
- xdebug_str_addl(str, "bool", 4, 0);
- break;
- #endif
- case IS_NULL:
- xdebug_str_addl(str, "null", 4, 0);
- break;
- case IS_LONG:
- xdebug_str_addl(str, "long", 4, 0);
- break;
- case IS_DOUBLE:
- xdebug_str_addl(str, "double", 6, 0);
- break;
- case IS_STRING:
- xdebug_str_add(str, xdebug_sprintf("string(%d)", Z_STRLEN_P(*struc)), 1);
- break;
- case IS_ARRAY:
- myht = Z_ARRVAL_P(*struc);
- xdebug_str_add(str, xdebug_sprintf("array(%d)", myht->nNumOfElements), 1);
- break;
- case IS_OBJECT: {
- xdebug_str_add(str, xdebug_sprintf("class %s", STR_NAME_VAL(Z_OBJCE_P(*struc)->name)), 1);
- break;
- }
- case IS_RESOURCE: {
- char *type_name;
- #if PHP_VERSION_ID >= 70000
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"), 1);
- #else
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_LVAL_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("resource(%ld) of type (%s)", Z_LVAL_P(*struc), type_name ? type_name : "Unknown"), 1);
- #endif
- break;
- }
- #if PHP_VERSION_ID >= 70000
- case IS_UNDEF:
- xdebug_str_addl(str, "*uninitialized*", sizeof("*uninitialized*") - 1, 0);
- break;
- #endif
- default:
- xdebug_str_addl(str, "NFC", 3, 0);
- break;
- }
- }
- char* xdebug_get_zval_synopsis(zval *val, int debug_zval, xdebug_var_export_options *options)
- {
- xdebug_str str = XDEBUG_STR_INITIALIZER;
- int default_options = 0;
- TSRMLS_FETCH();
- if (!options) {
- options = xdebug_var_export_options_from_ini(TSRMLS_C);
- default_options = 1;
- }
- xdebug_var_synopsis(&val, (xdebug_str*) &str, 1, debug_zval, options TSRMLS_CC);
- if (default_options) {
- xdfree(options->runtime);
- xdfree(options);
- }
- return str.d;
- }
- /*****************************************************************************
- ** Plain text/ANSI coloured variable printing routines
- */
- #define ANSI_COLOR_POINTER (mode == 1 ? "[0m" : "")
- #define ANSI_COLOR_BOOL (mode == 1 ? "[35m" : "")
- #define ANSI_COLOR_LONG (mode == 1 ? "[32m" : "")
- #define ANSI_COLOR_NULL (mode == 1 ? "[34m" : "")
- #define ANSI_COLOR_DOUBLE (mode == 1 ? "[33m" : "")
- #define ANSI_COLOR_STRING (mode == 1 ? "[31m" : "")
- #define ANSI_COLOR_EMPTY (mode == 1 ? "[30m" : "")
- #define ANSI_COLOR_ARRAY (mode == 1 ? "[33m" : "")
- #define ANSI_COLOR_OBJECT (mode == 1 ? "[31m" : "")
- #define ANSI_COLOR_RESOURCE (mode == 1 ? "[36m" : "")
- #define ANSI_COLOR_MODIFIER (mode == 1 ? "[32m" : "")
- #define ANSI_COLOR_RESET (mode == 1 ? "[0m" : "")
- #define ANSI_COLOR_BOLD (mode == 1 ? "[1m" : "")
- #define ANSI_COLOR_BOLD_OFF (mode == 1 ? "[22m" : "")
- #if PHP_VERSION_ID >= 70000
- static int xdebug_array_element_export_text_ansi(zval *zv_nptr, zend_ulong index, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options)
- {
- zval **zv = &zv_nptr;
- #else
- static int xdebug_array_element_export_text_ansi(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- int level = va_arg(args, int);
- int mode = va_arg(args, int);
- xdebug_str *str = va_arg(args, struct xdebug_str*);
- int debug_zval = va_arg(args, int);
- xdebug_var_export_options *options = va_arg(args, xdebug_var_export_options*);
- #endif
- if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
- options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
- {
- xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2), ""), 1);
- if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */
- xdebug_str_add(str, xdebug_sprintf("[%ld] %s=>%s\n", HASH_APPLY_NUMERIC(hash_key), ANSI_COLOR_POINTER, ANSI_COLOR_RESET), 1);
- } else { /* string key */
- SIZETorINT newlen = 0;
- char *tmp, *tmp2;
-
- tmp = xdebug_str_to_str((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), "'", 1, "\\'", 2, &newlen);
- tmp2 = xdebug_str_to_str(tmp, newlen - 1, "\0", 1, "\\0", 2, &newlen);
- if (tmp) {
- efree(tmp);
- }
- xdebug_str_addl(str, "'", 1, 0);
- if (tmp2) {
- xdebug_str_addl(str, tmp2, newlen, 0);
- efree(tmp2);
- }
- xdebug_str_add(str, "' =>\n", 0);
- }
- xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options TSRMLS_CC);
- }
- if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
- xdebug_str_add(str, xdebug_sprintf("\n%*s(more elements)...\n", (level * 2), ""), 1);
- }
- options->runtime[level].current_element_nr++;
- return 0;
- }
- #if PHP_VERSION_ID >= 70000
- static int xdebug_object_element_export_text_ansi(zval *zv_nptr, zend_ulong index, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options)
- {
- zval **zv = &zv_nptr;
- #else
- static int xdebug_object_element_export_text_ansi(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
- {
- int level = va_arg(args, int);
- int mode = va_arg(args, int);
- xdebug_str *str = va_arg(args, struct xdebug_str*);
- int debug_zval = va_arg(args, int);
- xdebug_var_export_options *options = va_arg(args, xdebug_var_export_options*);
- #endif
- if (options->runtime[level].current_element_nr >= options->runtime[level].start_element_nr &&
- options->runtime[level].current_element_nr < options->runtime[level].end_element_nr)
- {
- xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2), ""), 1);
- if (!HASH_KEY_IS_NUMERIC(hash_key)) {
- char *prop_name, *class_name, *modifier;
- modifier = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &prop_name, &class_name);
- xdebug_str_add(str, xdebug_sprintf("%s%s%s%s%s $%s %s=>%s\n",
- ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, modifier, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_RESET,
- prop_name, ANSI_COLOR_POINTER, ANSI_COLOR_RESET), 1);
- xdfree(prop_name);
- xdfree(class_name);
- } else {
- xdebug_str_add(str, xdebug_sprintf("%s%spublic%s%s ${%d} %s=>%s\n",
- ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_RESET,
- HASH_APPLY_NUMERIC(hash_key), ANSI_COLOR_POINTER, ANSI_COLOR_RESET), 1);
- }
- xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options TSRMLS_CC);
- }
- if (options->runtime[level].current_element_nr == options->runtime[level].end_element_nr) {
- xdebug_str_add(str, xdebug_sprintf("\n%*s(more elements)...\n", (level * 2), ""), 1);
- }
- options->runtime[level].current_element_nr++;
- return 0;
- }
- void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
- {
- HashTable *myht;
- char* tmp_str;
- int tmp_len;
- int is_temp;
- #if PHP_VERSION_ID >= 70000
- zend_ulong num;
- zend_string *key;
- zval *val;
- zval *tmpz;
- #endif
- if (!struc || !(*struc)) {
- return;
- }
-
- xdebug_str_add(str, xdebug_sprintf("%*s", (level * 2) - 2, ""), 1);
- #if PHP_VERSION_ID >= 70000
- if (debug_zval) {
- if (Z_TYPE_P(*struc) >= IS_STRING && Z_TYPE_P(*struc) != IS_INDIRECT) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->value.counted->gc.refcount, Z_TYPE_P(*struc) == IS_REFERENCE), 1);
- } else {
- xdebug_str_add(str, "(refcount=0, is_ref=0)=", 0);
- }
- }
- if (Z_TYPE_P(*struc) == IS_REFERENCE) {
- tmpz = &((*struc)->value.ref->val);
- struc = &tmpz;
- }
- #else
- if (debug_zval) {
- xdebug_str_add(str, xdebug_sprintf("(refcount=%d, is_ref=%d)=", (*struc)->refcount__gc, (*struc)->is_ref__gc), 1);
- }
- #endif
- switch (Z_TYPE_P(*struc)) {
- #if PHP_VERSION_ID >= 70000
- case IS_TRUE:
- case IS_FALSE:
- xdebug_str_add(str, xdebug_sprintf("%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, Z_TYPE_P(*struc) == IS_TRUE ? "true" : "false", ANSI_COLOR_RESET), 1);
- break;
- #else
- case IS_BOOL:
- xdebug_str_add(str, xdebug_sprintf("%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, Z_LVAL_P(*struc) ? "true" : "false", ANSI_COLOR_RESET), 1);
- break;
- #endif
- case IS_NULL:
- xdebug_str_add(str, xdebug_sprintf("%s%sNULL%s%s", ANSI_COLOR_BOLD, ANSI_COLOR_NULL, ANSI_COLOR_RESET, ANSI_COLOR_BOLD_OFF), 1);
- break;
- case IS_LONG:
- xdebug_str_add(str, xdebug_sprintf("%sint%s(%s" XDEBUG_INT_FMT "%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_LVAL_P(*struc), ANSI_COLOR_RESET), 1);
- break;
- case IS_DOUBLE:
- xdebug_str_add(str, xdebug_sprintf("%sdouble%s(%s%.*G%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_DOUBLE, (int) EG(precision), Z_DVAL_P(*struc), ANSI_COLOR_RESET), 1);
- break;
- case IS_STRING: {
- char *pattern = (mode == 1) ? "'\\\0..\37" : "\0";
- size_t pattern_len = (mode == 1) ? 7 : 1;
- #if PHP_VERSION_ID >= 70000
- zend_string *i_string = zend_string_init(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), 0);
- zend_string *tmp_zstr;
- tmp_zstr = php_addcslashes(i_string, 0, pattern, pattern_len);
- tmp_str = estrndup(tmp_zstr->val, tmp_zstr->len);
- tmp_len = tmp_zstr->len;
- zend_string_release(tmp_zstr);
- zend_string_release(i_string);
- #else
- tmp_str = php_addcslashes(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), &tmp_len, 0, pattern, pattern_len TSRMLS_CC);
- #endif
- if (options->no_decoration) {
- xdebug_str_addl(str, tmp_str, tmp_len, 0);
- } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) {
- xdebug_str_add(str, xdebug_sprintf("%sstring%s(%s%ld%s) \"%s%s%s\"",
- ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF,
- ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET,
- ANSI_COLOR_STRING, tmp_str, ANSI_COLOR_RESET), 1);
- } else {
- xdebug_str_add(str, xdebug_sprintf("%sstring%s(%s%ld%s) \"%s",
- ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF,
- ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET, ANSI_COLOR_STRING), 1);
- xdebug_str_addl(str, tmp_str, options->max_data, 0);
- xdebug_str_add(str, xdebug_sprintf("%s\"...", ANSI_COLOR_RESET), 1);
- }
- efree(tmp_str);
- } break;
- case IS_ARRAY:
- myht = Z_ARRVAL_P(*struc);
- if (XDEBUG_APPLY_COUNT(myht) < 1) {
- xdebug_str_add(str, xdebug_sprintf("%sarray%s(%s%d%s) {\n", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET), 1);
- if (level <= options->max_depth) {
- options->runtime[level].current_element_nr = 0;
- options->runtime[level].start_element_nr = 0;
- options->runtime[level].end_element_nr = options->max_children;
- #if PHP_VERSION_ID >= 70000
- ZEND_HASH_INC_APPLY_COUNT(myht);
- ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
- xdebug_array_element_export_text_ansi(val, num, key, level, mode, str, debug_zval, options);
- } ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(myht);
- #else
- zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) xdebug_array_element_export_text_ansi, 5, level, mode, str, debug_zval, options);
- #endif
- } else {
- xdebug_str_add(str, xdebug_sprintf("%*s...\n", (level * 2), ""), 1);
- }
- xdebug_str_add(str, xdebug_sprintf("%*s}", (level * 2) - 2 , ""), 1);
- } else {
- xdebug_str_add(str, xdebug_sprintf("&%sarray%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF), 1);
- }
- break;
- case IS_OBJECT:
- myht = xdebug_objdebug_pp(struc, &is_temp TSRMLS_CC);
- if (myht && XDEBUG_APPLY_COUNT(myht) < 1) {
- xdebug_str_add(str, xdebug_sprintf("%sclass%s %s%s%s#%d (%s%d%s) {\n",
- ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF,
- ANSI_COLOR_OBJECT, STR_NAME_VAL(Z_OBJCE_P(*struc)->name), ANSI_COLOR_RESET,
- Z_OBJ_HANDLE_P(*struc),
- ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET), 1);
- if (level <= options->max_depth) {
- options->runtime[level].current_element_nr = 0;
- options->runtime[level].start_element_nr = 0;
- options->runtime[level].end_element_nr = options->max_children;
- #if PHP_VERSION_ID >= 70000
- ZEND_HASH_INC_APPLY_COUNT(myht);
- ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
- xdebug_object_element_export_text_ansi(val, num, key, level, mode, str, debug_zval, options);
- } ZEND_HASH_FOREACH_END();
- ZEND_HASH_DEC_APPLY_COUNT(myht);
- #else
- zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) xdebug_object_element_export_text_ansi, 5, level, mode, str, debug_zval, options);
- #endif
- } else {
- xdebug_str_add(str, xdebug_sprintf("%*s...\n", (level * 2), ""), 1);
- }
- xdebug_str_add(str, xdebug_sprintf("%*s}", (level * 2) - 2, ""), 1);
- } else {
- xdebug_str_add(str, xdebug_sprintf("%*s...\n", (level * 2), ""), 1);
- }
- if (is_temp) {
- zend_hash_destroy(myht);
- efree(myht);
- }
- break;
- case IS_RESOURCE: {
- char *type_name;
- #if PHP_VERSION_ID >= 70000
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("%sresource%s(%s%ld%s) of type (%s)",
- ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF,
- ANSI_COLOR_RESOURCE, Z_RES_P(*struc)->handle, ANSI_COLOR_RESET, type_name ? type_name : "Unknown"), 1);
- #else
- type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_LVAL_P(*struc) TSRMLS_CC);
- xdebug_str_add(str, xdebug_sprintf("%sresource%s(%s%ld%s) of type (%s)",
- ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF,
- ANSI_COLOR_RESOURCE, Z_LVAL_P(*struc), ANSI_COLOR_RESET, type_name ? type_name : "Unknown"), 1);
- #endif
- break;
- }
- #if PHP_VERSION_ID >= 70000
- case IS_UNDEF:
- xdebug_str_add(str, xdebug_sprintf("%s*uninitialized*%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET), 0);
- break;
- #endif
- default:
- xdebug_str_add(str, xdebug_sprintf("%sNFC%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET), 0);
- break;
- }
- xdebug_str_addl(str, "\n", 1, 0);
- }
- char* xdebug_get_zval_value_text_ansi(zval *val, int mode, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
- {
- xdebug_str str = XDEBUG_STR_INITIALIZER;
- int default_options = 0;
- if (!options) {
- options = xdebug_var_export_options_from_ini(TSRMLS_C);
- default_options = 1;
- }
- if (options->show_location && !debug_zval) {
- xdebug_str_add(&str, xdebug_sprintf("%s%s%s:%s%d%…
Large files files are truncated, but you can click here to view the full file