Skip to content
Permalink
Browse files

Merge branch 'xdebug_2_9'

  • Loading branch information
derickr committed Jan 12, 2020
2 parents 0c27eea + 0073c6c commit 4a2aa8985549d9a2fa2ff2ae29f02e9d6a3b06d0
@@ -50,8 +50,11 @@ static inline int object_or_ancestor_is_internal(zval dzval)

return 0;
}

#if PHP_VERSION_ID >= 70400
HashTable *xdebug_objdebug_pp(zval **zval_pp)
#else
HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp)
#endif
{
zval dzval = **zval_pp;
HashTable *tmp;
@@ -64,18 +67,26 @@ HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp)
XG_BASE(in_debug_info) = 1;
orig_exception = EG(exception);
EG(exception) = NULL;


#if PHP_VERSION_ID >= 70400
tmp = zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_DEBUG);
#else
tmp = Z_OBJ_HANDLER(dzval, get_debug_info)(&dzval, is_tmp);

#endif
XG_BASE(in_debug_info) = 0;
xdebug_tracing_restore_trace_context(original_trace_context);
EG(exception) = orig_exception;

return tmp;
} else {
#if PHP_VERSION_ID >= 70400
return zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_VAR_EXPORT);
#else
*is_tmp = 0;
if (Z_OBJ_HANDLER(dzval, get_properties)) {
return Z_OBJPROP(dzval);
}
#endif
}
return NULL;
}
@@ -257,43 +268,53 @@ static char* prepare_search_key(char *name, unsigned int *name_length, const cha
return element;
}

static zval *get_arrayobject_storage(zval *parent, HashTable **properties, int *is_temp)
{
#if PHP_VERSION_ID >= 70400
static zval *get_arrayobject_storage(zval *parent, HashTable **properties)
{
*properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG);
return zend_hash_str_find(*properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1);
}

static zval *get_splobjectstorage_storage(zval *parent, HashTable **properties)
{
*properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG);
return zend_hash_str_find(*properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1);
}

static zval *get_arrayiterator_storage(zval *parent, HashTable **properties)
{
*properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG);
return zend_hash_str_find(*properties, "\0ArrayIterator\0storage", sizeof("*ArrayIterator*storage") - 1);
}
#else
static zval *get_arrayobject_storage(zval *parent, HashTable **properties, int *is_temp)
{
*properties = Z_OBJDEBUG_P(parent, *is_temp);
#endif
return zend_hash_str_find(*properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1);
}

static zval *get_splobjectstorage_storage(zval *parent, HashTable **properties, int *is_temp)
{
#if PHP_VERSION_ID >= 70400
*properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG);
#else
*properties = Z_OBJDEBUG_P(parent, *is_temp);
#endif
return zend_hash_str_find(*properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1);
}

static zval *get_arrayiterator_storage(zval *parent, HashTable **properties, int *is_temp)
{
#if PHP_VERSION_ID >= 70400
*properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG);
#else
*properties = Z_OBJDEBUG_P(parent, *is_temp);
#endif
return zend_hash_str_find(*properties, "\0ArrayIterator\0storage", sizeof("*ArrayIterator*storage") - 1);
}
#endif

#if PHP_VERSION_ID < 70400
void xdebug_var_maybe_destroy_ht(HashTable *ht, int is_temp)
{
if (ht && is_temp) {
zend_hash_destroy(ht);
FREE_HASHTABLE(ht);
}
}
#endif

static void fetch_zval_from_symbol_table(
zval *value_in, char *name, unsigned int name_length,
@@ -303,7 +324,9 @@ static void fetch_zval_from_symbol_table(
char *element = NULL;
unsigned int element_length = name_length;
zend_property_info *zpp;
#if PHP_VERSION_ID < 70400
int is_temp = 0;
#endif
int free_duplicated_name = 0;
HashTable *myht = NULL;
zval *orig_value_in = value_in;
@@ -425,15 +448,27 @@ static void fetch_zval_from_symbol_table(
case XF_ST_OBJ_PROPERTY:
/* Let's see if there is a debug handler */
if (value_in && Z_TYPE_P(value_in) == IS_OBJECT) {
#if PHP_VERSION_ID >= 70400
myht = xdebug_objdebug_pp(&value_in);
#else
myht = xdebug_objdebug_pp(&value_in, &is_temp);
#endif
if (myht) {
zval *tmp = zend_symtable_str_find(myht, name, name_length);
if (tmp != NULL) {
ZVAL_COPY(&tmp_retval, tmp);
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
goto cleanup;
}
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
}
}
/* First we try an object handler */
@@ -487,7 +522,11 @@ static void fetch_zval_from_symbol_table(

/* All right, time for a mega hack. It's SplObjectStorage access time! */
if (strncmp(ccn, "SplObjectStorage", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) {
#if PHP_VERSION_ID >= 70400
zval *tmp = get_splobjectstorage_storage(value_in, &myht);
#else
zval *tmp = get_splobjectstorage_storage(value_in, &myht, &is_temp);
#endif
element = NULL;
if (tmp != NULL) {
ZVAL_COPY(&tmp_retval, tmp);
@@ -516,25 +555,50 @@ static void fetch_zval_from_symbol_table(

/* 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) {
#if PHP_VERSION_ID >= 70400
zval *tmp = get_arrayobject_storage(value_in, &myht);
#else
zval *tmp = get_arrayobject_storage(value_in, &myht, &is_temp);
#endif
element = NULL;
if (tmp != NULL) {
ZVAL_COPY(&tmp_retval, tmp);
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
goto cleanup;
}
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
}
/* 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) {
#if PHP_VERSION_ID >= 70400
zval *tmp = get_arrayiterator_storage(value_in, &myht);
#else
zval *tmp = get_arrayiterator_storage(value_in, &myht, &is_temp);
#endif
element = NULL;
if (tmp != NULL) {
ZVAL_COPY(&tmp_retval, tmp);
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
goto cleanup;
}
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif

}

/* The normal one */
@@ -69,8 +69,13 @@ xdebug_var_export_options* xdebug_var_get_nolimit_options(void);
xdebug_str* xdebug_get_property_type(zval* object, zval *val);
#endif
xdebug_str* xdebug_get_property_info(char *mangled_property, int mangled_len, const char **modifier, char **class_name);
#if PHP_VERSION_ID >= 70400
HashTable *xdebug_objdebug_pp(zval **zval_pp);
#else
HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp);
void xdebug_var_maybe_destroy_ht(HashTable *ht, int is_temp);
#endif


#define XDEBUG_VAR_ATTR_TEXT 0
#define XDEBUG_VAR_ATTR_HTML 1
@@ -120,7 +120,9 @@ void xdebug_var_export_html(zval **struc, xdebug_str *str, int level, int debug_
HashTable *myht;
char* tmp_str;
size_t newlen;
#if PHP_VERSION_ID < 70400
int is_temp;
#endif
zend_ulong num;
zend_string *key;
zval *val;
@@ -204,7 +206,11 @@ void xdebug_var_export_html(zval **struc, xdebug_str *str, int level, int debug_
break;

case IS_OBJECT:
#if PHP_VERSION_ID >= 70400
myht = xdebug_objdebug_pp(struc);
#else
myht = xdebug_objdebug_pp(struc, &is_temp);
#endif
xdebug_str_add(str, xdebug_sprintf("\n%*s", (level - 1) * 4, ""), 1);

if (!xdebug_zend_hash_is_recursive(myht)) {
@@ -231,11 +237,11 @@ void xdebug_var_export_html(zval **struc, xdebug_str *str, int level, int debug_
xdebug_str_add(str, xdebug_sprintf("<i>&amp;</i><b>object</b>(<i>%s</i>)", STR_NAME_VAL(Z_OBJCE_P(*struc)->name)), 1);
xdebug_str_add(str, xdebug_sprintf("[<i>%d</i>]\n", Z_OBJ_HANDLE_P(*struc)), 1);
}
if (is_temp) {
zend_hash_destroy(myht);
efree(myht);
}

#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
break;

case IS_RESOURCE: {
@@ -114,7 +114,9 @@ void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_
{
HashTable *myht;
char* tmp_str;
#if PHP_VERSION_ID < 70400
int is_temp;
#endif
zend_ulong num;
zend_string *key;
zval *val;
@@ -212,7 +214,11 @@ void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_
break;

case IS_OBJECT:
#if PHP_VERSION_ID >= 70400
myht = xdebug_objdebug_pp(struc);
#else
myht = xdebug_objdebug_pp(struc, &is_temp);
#endif

if (!xdebug_zend_hash_is_recursive(myht)) {
char *class_name = (char*) STR_NAME_VAL(Z_OBJCE_P(*struc)->name);
@@ -242,10 +248,11 @@ void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_
} else {
xdebug_str_addl(str, "...", 3, 0);
}
if (is_temp) {
zend_hash_destroy(myht);
efree(myht);
}
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
break;

case IS_RESOURCE: {
@@ -135,7 +135,9 @@ static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode,
HashTable *myht;
char* tmp_str;
int tmp_len;
#if PHP_VERSION_ID < 70400
int is_temp;
#endif
zend_ulong num;
zend_string *key;
zval *val;
@@ -239,7 +241,11 @@ static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode,
break;

case IS_OBJECT:
#if PHP_VERSION_ID >= 70400
myht = xdebug_objdebug_pp(struc);
#else
myht = xdebug_objdebug_pp(struc, &is_temp);
#endif

if (!xdebug_zend_hash_is_recursive(myht)) {
xdebug_str_add(str, xdebug_sprintf("%sclass%s %s%s%s#%d (%s%d%s) {\n",
@@ -267,10 +273,11 @@ static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode,
} else {
xdebug_str_add(str, xdebug_sprintf("%*s...\n", (level * 2), ""), 1);
}
if (is_temp) {
zend_hash_destroy(myht);
efree(myht);
}
#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
break;

case IS_RESOURCE: {
@@ -567,7 +567,9 @@ void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node
HashTable *merged_hash;
xdebug_str *class_name;
zend_class_entry *ce;
#if PHP_VERSION_ID < 70400
int is_temp;
#endif
zend_property_info *zpi_val;

ALLOC_HASHTABLE(merged_hash);
@@ -592,7 +594,11 @@ void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node
xdebug_zend_hash_apply_protection_end(&ce->properties_info);

/* Adding normal properties */
#if PHP_VERSION_ID >= 70400
myht = xdebug_objdebug_pp(struc);
#else
myht = xdebug_objdebug_pp(struc, &is_temp);
#endif
if (myht) {
zval *tmp_val;

@@ -637,8 +643,11 @@ void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node
zend_hash_destroy(merged_hash);
FREE_HASHTABLE(merged_hash);
xdebug_str_free(class_name);

#if PHP_VERSION_ID >= 70400
zend_release_properties(myht);
#else
xdebug_var_maybe_destroy_ht(myht, is_temp);
#endif
break;
}

@@ -19,7 +19,7 @@ xdebug_debug_zval('e->b[1]->@attributes["attb"]');
attb-1
attb-2
e: (refcount=1, is_ref=0)=class SimpleXMLElement { public $@attributes = (refcount=1, is_ref=0)=array ('att1' => (refcount=1, is_ref=0)='att-a'); public $b = (refcount=1, is_ref=0)=array (0 => (refcount=1, is_ref=0)=class SimpleXMLElement { ... }, 1 => (refcount=1, is_ref=0)=class SimpleXMLElement { ... }) }
e->@attributes: (refcount=0, is_ref=0)=array ('att1' => (refcount=1, is_ref=0)='att-a')
e->@attributes["att1"]: (refcount=0, is_ref=0)='att-a'
e->b[0]->@attributes: (refcount=0, is_ref=0)=array ('attb' => (refcount=1, is_ref=0)='attb-1')
e->b[1]->@attributes["attb"]: (refcount=0, is_ref=0)='attb-2'
e->@attributes: (refcount=%d, is_ref=0)=array ('att1' => (refcount=1, is_ref=0)='att-a')
e->@attributes["att1"]: (refcount=%d, is_ref=0)='att-a'
e->b[0]->@attributes: (refcount=%d, is_ref=0)=array ('attb' => (refcount=1, is_ref=0)='attb-1')
e->b[1]->@attributes["attb"]: (refcount=%d, is_ref=0)='attb-2'

0 comments on commit 4a2aa89

Please sign in to comment.
You can’t perform that action at this time.