Skip to content

Commit

Permalink
Merge branch 'master' of github.com:krakjoe/inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Jun 7, 2018
2 parents c7c10ff + b00a102 commit 2eab5e4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/break.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ static int php_inspector_break_handler(zend_execute_data *execute_data) {
BRK(state) = INSPECTOR_BREAK_RUNTIME;

if (EG(exception)) {
#if PHP_VERSION_ID >= 70200 && PHP_VERSION_ID < 70300
#if PHP_VERSION_ID >= 70200
const zend_op *throw = EG(opline_before_exception);

if (throw->result_type & (IS_VAR|IS_TMP_VAR)) {
Expand Down
55 changes: 43 additions & 12 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,40 @@ static zend_always_inline zend_string** php_inspector_map_dup_strings(zend_strin

static zend_always_inline void php_inspector_map_free(void *ptr, size_t num, size_t size, php_inspector_map_callback_t destructor) {
if (destructor) {
char *begin = (char*) ptr,
*end = ((char*) begin) + (num * size);

while (begin < end) {
destructor(
(void*) begin);
begin += size;
}
php_inspector_map_apply(ptr, num, size, destructor);
}

efree(ptr);
}
static zend_always_inline void php_inspector_map_reindex_const_op(zend_op_array *op_array, zend_op *orig_opcodes, zval *orig_literals) {
zend_op *opline = op_array->opcodes, *end = opline + op_array->last;

for (; opline < end; opline++) {
#if ZEND_USE_ABS_CONST_ADDR
if (opline->op1_type == IS_CONST) {
opline->op1.zv = (zval*)((char*)opline->op1.zv + ((char*)op_array->literals - (char*)orig_literals));
}
if (opline->op2_type == IS_CONST) {
opline->op2.zv = (zval*)((char*)opline->op2.zv + ((char*)op_array->literals - (char*)orig_literals));
}
#else
if (opline->op1_type == IS_CONST) {
opline->op1.constant =
(char*)(op_array->literals +
((zval*)((char*)(orig_opcodes + (opline - op_array->opcodes)) +
(int32_t)opline->op1.constant) - orig_literals)) -
(char*)opline;
}
if (opline->op2_type == IS_CONST) {
opline->op2.constant =
(char*)(op_array->literals +
((zval*)((char*)(orig_opcodes + (opline - op_array->opcodes)) +
(int32_t)opline->op2.constant) - orig_literals)) -
(char*)opline;
}
#endif
}
}

static zend_always_inline void php_inspector_map_opcode(zend_op *opline) {
zend_op *old =
Expand Down Expand Up @@ -251,13 +273,13 @@ static void php_inspector_map_destruct(zend_op_array *mapped) {

if (mapped->vars) {
php_inspector_map_free(mapped->vars,
mapped->last_var, sizeof(zend_string*),
mapped->last_var, sizeof(zend_string*),
(php_inspector_map_callback_t) php_inspector_map_string_delref);
}

if (mapped->literals) {
php_inspector_map_free(mapped->literals,
mapped->last_literal, sizeof(zval),
php_inspector_map_free(mapped->literals,
mapped->last_literal, sizeof(zval),
(php_inspector_map_callback_t) php_inspector_map_zval_delref);
}

Expand Down Expand Up @@ -291,6 +313,11 @@ static void php_inspector_map_destruct(zend_op_array *mapped) {
}

static zend_always_inline void php_inspector_map_construct(zend_op_array *mapped) {
#if PHP_VERSION_ID >= 70300
zval *old_literals = mapped->literals;
zend_op *old_opcodes = mapped->opcodes;
#endif

IMG(map) = mapped;

mapped->fn_flags &= ~ZEND_ACC_ARENA_ALLOCATED;
Expand Down Expand Up @@ -320,10 +347,14 @@ static zend_always_inline void php_inspector_map_construct(zend_op_array *mapped
mapped->literals, mapped->last_literal, sizeof(zval),
(php_inspector_map_callback_t) php_inspector_map_zval_addref);

mapped->opcodes = (zend_op*) php_inspector_map_dup(
mapped->opcodes = (zend_op *) php_inspector_map_dup(
mapped->opcodes, mapped->last, sizeof(zend_op),
NULL);

#if PHP_VERSION_ID >= 70300
php_inspector_map_reindex_const_op(mapped, old_opcodes, old_literals);
#endif

php_inspector_map_apply(
mapped->opcodes, mapped->last, sizeof(zend_op),
(php_inspector_map_callback_t) php_inspector_map_opcode);
Expand Down
4 changes: 4 additions & 0 deletions src/operand.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ static PHP_METHOD(InspectorOperand, getNumber) {

switch (zend_op_type(operand->type)) {
case IS_CONST:
#if PHP_VERSION_ID >= 70300
RETURN_LONG(function->literals - RT_CONSTANT(instruction->opline, *operand->op));
#else
RETURN_LONG(function->literals - RT_CONSTANT(function, *operand->op));
#endif
case IS_VAR:
case IS_TMP_VAR:
RETURN_LONG(EX_VAR_TO_NUM(operand->op->num - function->last_var));
Expand Down

0 comments on commit 2eab5e4

Please sign in to comment.