Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions extension/meminfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ PHP_FUNCTION(meminfo_dump)
*/
void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, int *first_element)
{
zend_execute_data *exec_frame, *prev_frame;
zend_execute_data *exec_frame;
zend_execute_data *original_execute_data;
zend_array *p_symbol_table;

original_execute_data = EG(current_execute_data);
exec_frame = EG(current_execute_data);

char frame_label[500];
Expand Down Expand Up @@ -122,6 +124,8 @@ void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, i
}
exec_frame = exec_frame->prev_execute_data;
}

EG(current_execute_data) = original_execute_data;
}

/**
Expand Down Expand Up @@ -192,7 +196,7 @@ void meminfo_browse_zvals_from_symbol_table(php_stream *stream, char* frame_labe
HashPosition pos;

zend_string *key;
zend_long index;
zend_ulong index;

zend_hash_internal_pointer_reset_ex(p_symbol_table, &pos);

Expand Down Expand Up @@ -246,6 +250,11 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H
zval = Z_INDIRECT_P(zval);
}

if (Z_TYPE_P(zval) == IS_UNDEF) {
zend_hash_move_forward_ex(ht, &pos);
continue;
}

if (Z_ISREF_P(zval)) {
ZVAL_DEREF(zval);
}
Expand Down Expand Up @@ -288,7 +297,9 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H

break;
case HASH_KEY_IS_LONG:
php_stream_printf(stream, " \"%ld\":\"%s\"", num_key, zval_id);
php_stream_printf(stream, " \"" ZEND_ULONG_FMT "\":\"%s\"", num_key, zval_id);
break;
default:
break;
}

Expand All @@ -311,6 +322,10 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy
zv = Z_INDIRECT_P(zv);
}

if (Z_TYPE_P(zv) == IS_UNDEF) {
return;
}

if (Z_ISREF_P(zv)) {
ZVAL_DEREF(zv);
}
Expand All @@ -333,7 +348,7 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy

php_stream_printf(stream, " \"%s\" : {\n", zval_identifier);
php_stream_printf(stream, " \"type\" : \"%s\",\n", zend_get_type_by_const(Z_TYPE_P(zv)));
php_stream_printf(stream, " \"size\" : \"%ld\",\n", meminfo_get_element_size(zv));
php_stream_printf(stream, " \"size\" : \"" ZEND_ULONG_FMT "\",\n", meminfo_get_element_size(zv));

if (frame_label) {
zend_string * escaped_frame_label;
Expand Down Expand Up @@ -447,7 +462,11 @@ void meminfo_build_frame_label(char* frame_label, int frame_label_len, zend_exec
zend_object *object;
zend_execute_data *ptr;

object = Z_OBJ(frame->This);
if (Z_TYPE(frame->This) == IS_OBJECT) {
object = Z_OBJ(frame->This);
} else {
object = NULL;
}
ptr = frame->prev_execute_data;

if (frame->func) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Check that all children items are properly linked through their identifiers
<?php
$dump = fopen('php://memory', 'rw');

#[AllowDynamicProperties]
class MyClass {
public $myDeclaredVar;
}
Expand Down