From bd72fdca98d093f5a905d86cbe1ab5f89b36d62d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 10 Jul 2015 11:22:34 +0200 Subject: Better opcode dump for finally * Move opcode decode into opline decode, so we can adjust it for extended_value. * Show extended_value and secondary jump ops for FAST_CALL and FAST_RET. --- sapi/phpdbg/phpdbg_print.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'sapi/phpdbg/phpdbg_print.c') diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 95e0caf784..eff9a406e1 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -83,10 +83,9 @@ static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */ do { char *decode = phpdbg_decode_opline(op_array, opline); if (decode != NULL) { - phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" opcode=\"%s\" op=\"%s\"", " L%-4u #%-5u %-23s %s", + phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s", opline->lineno, opcode, - phpdbg_decode_opcode(opline->opcode) + 5, /* remove ZEND_ prefix */ decode); free(decode); } else { -- cgit v1.2.1 From 762c6dd6662d0269bdb6161706d2f40fb6802e43 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Tue, 14 Jul 2015 06:28:15 +0200 Subject: Show also runtime-bound functions/classes/methods with phpdbg -p --- sapi/phpdbg/phpdbg_print.c | 74 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 19 deletions(-) (limited to 'sapi/phpdbg/phpdbg_print.c') diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index eff9a406e1..b7bb9e688a 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -270,23 +270,27 @@ void phpdbg_print_opcodes_function(const char *function, size_t len) { zend_function *func = zend_hash_str_find_ptr(EG(function_table), function, len); if (!func) { + zend_string *rt_name; + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, func) { + if (func->type == ZEND_USER_FUNCTION && *rt_name->val == '\0') { + if (func->op_array.function_name->len == len && !zend_binary_strcasecmp(function, len, func->op_array.function_name->val, func->op_array.function_name->len)) { + phpdbg_print_opcodes_function(rt_name->val, rt_name->len); + } + } + } ZEND_HASH_FOREACH_END(); + return; } - phpdbg_out("function name: %.*s\n", (int) len, function); + phpdbg_out("function name: %.*s\n", ZSTR_LEN(func->op_array.function_name), ZSTR_VAL(func->op_array.function_name)); phpdbg_print_function_helper(func); } -void phpdbg_print_opcodes_method(const char *class, const char *function) { - zend_class_entry *ce; +static void phpdbg_print_opcodes_method_ce(zend_class_entry *ce, const char *function) { zend_function *func; - if (phpdbg_safe_class_lookup(class, strlen(class), &ce) != SUCCESS) { - return; - } - if (ce->type != ZEND_USER_CLASS) { - phpdbg_out("function name: %s::%s (internal)\n", class, function); + phpdbg_out("function name: %s::%s (internal)\n", ce->name->val, function); return; } @@ -294,20 +298,34 @@ void phpdbg_print_opcodes_method(const char *class, const char *function) { return; } - phpdbg_out("function name: %s::%s\n", class, function); + phpdbg_out("function name: %s::%s\n", ce->name->val, function); phpdbg_print_function_helper(func); } -void phpdbg_print_opcodes_class(const char *class) { +void phpdbg_print_opcodes_method(const char *class, const char *function) { zend_class_entry *ce; - zend_function *method; - zend_string *method_name; - zend_bool first = 1; if (phpdbg_safe_class_lookup(class, strlen(class), &ce) != SUCCESS) { + zend_string *rt_name; + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, ce) { + if (ce->type == ZEND_USER_CLASS && *rt_name->val == '\0') { + if (ce->name->len == strlen(class) && !zend_binary_strcasecmp(class, strlen(class), ce->name->val, ce->name->len)) { + phpdbg_print_opcodes_method_ce(ce, function); + } + } + } ZEND_HASH_FOREACH_END(); + return; } + phpdbg_print_opcodes_method_ce(ce, function); +} + +static void phpdbg_print_opcodes_ce(zend_class_entry *ce) { + zend_function *method; + zend_string *method_name; + zend_bool first = 1; + phpdbg_out("%s %s: %s\n", (ce->type == ZEND_USER_CLASS) ? "user" : "internal", @@ -342,10 +360,28 @@ void phpdbg_print_opcodes_class(const char *class) { } ZEND_HASH_FOREACH_END(); } +void phpdbg_print_opcodes_class(const char *class) { + zend_class_entry *ce; + + if (phpdbg_safe_class_lookup(class, strlen(class), &ce) != SUCCESS) { + zend_string *rt_name; + ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, ce) { + if (ce->type == ZEND_USER_CLASS && *rt_name->val == '\0') { + if (ce->name->len == strlen(class) && !zend_binary_strcasecmp(class, strlen(class), ce->name->val, ce->name->len)) { + phpdbg_print_opcodes_ce(ce); + } + } + } ZEND_HASH_FOREACH_END(); + + return; + } + + phpdbg_print_opcodes_ce(ce); +} + PHPDBG_API void phpdbg_print_opcodes(char *function) { - char *method_name; - strtok(function, ":"); + char *method_name = strtok(function, ":"); if (function == NULL) { phpdbg_print_opcodes_main(); @@ -364,15 +400,15 @@ PHPDBG_API void phpdbg_print_opcodes(char *function) } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), name, ce) { + ZEND_HASH_FOREACH_PTR(EG(class_table), ce) { if (ce->type == ZEND_USER_CLASS) { phpdbg_out("\n\n"); - phpdbg_print_opcodes_class(ZSTR_VAL(name)); + phpdbg_print_opcodes_ce(ce); } } ZEND_HASH_FOREACH_END(); - } else if ((method_name = strtok(NULL, ":")) == NULL) { + } else if (method_name == NULL) { phpdbg_print_opcodes_function(function, strlen(function)); - } else if ((method_name + 1) == NULL) { + } else if ((method_name = strtok(NULL, ":")) == NULL) { phpdbg_print_opcodes_class(function); } else { phpdbg_print_opcodes_method(function, method_name); -- cgit v1.2.1 From 20e5027293bf8711bc4f6cabd8f304ca5b127690 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 17 Jul 2015 16:49:34 +0200 Subject: Switch asprintf to spprintf in phpdbg opcode dump Also use %td where appropriate, a lot of the values are ptrdiff based. Fix a leak in phpdbg_frame.c. --- sapi/phpdbg/phpdbg_print.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'sapi/phpdbg/phpdbg_print.c') diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index b7bb9e688a..4a00189b46 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -82,15 +82,11 @@ static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */ do { char *decode = phpdbg_decode_opline(op_array, opline); - if (decode != NULL) { - phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s", - opline->lineno, - opcode, - decode); - free(decode); - } else { - phpdbg_error("print", "type=\"decodefailure\" opline=\"%16p\"", "Failed to decode opline %16p", opline); - } + phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s", + opline->lineno, + opcode, + decode); + efree(decode); opline++; } while (opcode++ < end); } -- cgit v1.2.1