From 088f589f7d5aa24a8c42fea582dc53b8cb7232c2 Mon Sep 17 00:00:00 2001 From: Bob Weinand Date: Mon, 29 Jun 2015 02:51:10 +0200 Subject: [PATCH] Make backtraces *much* more readable --- sapi/phpdbg/phpdbg_frame.c | 2 +- sapi/phpdbg/phpdbg_opcode.c | 54 +-------------------------------- sapi/phpdbg/phpdbg_utils.c | 60 +++++++++++++++++++++++++++++++++++++ sapi/phpdbg/phpdbg_utils.h | 2 ++ 4 files changed, 64 insertions(+), 54 deletions(-) diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c index 584052ee0b..c2a995dd4a 100644 --- a/sapi/phpdbg/phpdbg_frame.c +++ b/sapi/phpdbg/phpdbg_frame.c @@ -164,7 +164,7 @@ static void phpdbg_dump_prototype(zval *tmp) /* {{{ */ } ++j; - zend_print_flat_zval_r(argstmp); + php_printf("%s", phpdbg_short_zval_print(argstmp, 40)); phpdbg_xml(""); } ZEND_HASH_FOREACH_END(); diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index ffc5db04d4..75009108a2 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -53,60 +53,8 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t case IS_CONST: { zval *literal = RT_CONSTANT(ops, *op); - switch (Z_TYPE_P(literal)) { - case IS_UNDEF: - decode = zend_strndup("", 0); - break; - case IS_NULL: - decode = zend_strndup(ZEND_STRL("null")); - break; - case IS_FALSE: - decode = zend_strndup(ZEND_STRL("false")); - break; - case IS_TRUE: - decode = zend_strndup(ZEND_STRL("true")); - break; - case IS_LONG: - asprintf(&decode, ZEND_ULONG_FMT, Z_LVAL_P(literal)); - break; - case IS_DOUBLE: - asprintf(&decode, "%.*G", 14, Z_DVAL_P(literal)); - break; - case IS_STRING: { - int i; - zend_string *str = php_addcslashes(Z_STR_P(literal), 0, "\\\"", 2); - for (i = 0; i < str->len; i++) { - if (str->val[i] < 32) { - str->val[i] = ' '; - } - } - asprintf(&decode, "\"%.*s\"%c", str->len <= 18 ? (int) str->len : 17, str->val, str->len <= 18 ? 0 : '+'); - zend_string_release(str); - } break; - case IS_RESOURCE: - asprintf(&decode, "Rsrc #%d", Z_RES_HANDLE_P(literal)); - break; - case IS_ARRAY: - asprintf(&decode, "array(%d)", zend_hash_num_elements(Z_ARR_P(literal))); - break; - case IS_OBJECT: { - zend_string *str = Z_OBJCE_P(literal)->name; - asprintf(&decode, "%.*s%c", str->len <= 18 ? (int) str->len : 18, str->val, str->len <= 18 ? 0 : '+'); - } break; - case IS_CONSTANT: - decode = zend_strndup(ZEND_STRL("")); - break; - case IS_CONSTANT_AST: - decode = zend_strndup(ZEND_STRL("")); - break; - default: - asprintf(&decode, "unknown type: %d", Z_TYPE_P(literal)); - break; - } + decode = phpdbg_short_zval_print(literal, 20); } break; - - case IS_UNUSED: - return NULL; } return decode; } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c index 4cd8ce2782..0d03c3cdd4 100644 --- a/sapi/phpdbg/phpdbg_utils.c +++ b/sapi/phpdbg/phpdbg_utils.c @@ -24,6 +24,7 @@ #include "phpdbg.h" #include "phpdbg_opcode.h" #include "phpdbg_utils.h" +#include "ext/standard/php_string.h" #if defined(HAVE_SYS_IOCTL_H) # include "sys/ioctl.h" @@ -756,3 +757,62 @@ PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zen return op->opcode == ZEND_CATCH; } + +char *phpdbg_short_zval_print(zval *zv, int maxlen) /* {{{ */ +{ + char *decode = NULL; + + switch (Z_TYPE_P(zv)) { + case IS_UNDEF: + decode = zend_strndup("", 0); + break; + case IS_NULL: + decode = zend_strndup(ZEND_STRL("null")); + break; + case IS_FALSE: + decode = zend_strndup(ZEND_STRL("false")); + break; + case IS_TRUE: + decode = zend_strndup(ZEND_STRL("true")); + break; + case IS_LONG: + asprintf(&decode, ZEND_ULONG_FMT, Z_LVAL_P(zv)); + break; + case IS_DOUBLE: + asprintf(&decode, "%.*G", 14, Z_DVAL_P(zv)); + break; + case IS_STRING: { + int i; + zend_string *str = php_addcslashes(Z_STR_P(zv), 0, "\\\"", 2); + for (i = 0; i < str->len; i++) { + if (str->val[i] < 32) { + str->val[i] = ' '; + } + } + asprintf(&decode, "\"%.*s\"%c", str->len <= maxlen - 2 ? (int) str->len : (maxlen - 3), str->val, str->len <= maxlen - 2 ? 0 : '+'); + zend_string_release(str); + } break; + case IS_RESOURCE: + asprintf(&decode, "Rsrc #%d", Z_RES_HANDLE_P(zv)); + break; + case IS_ARRAY: + asprintf(&decode, "array(%d)", zend_hash_num_elements(Z_ARR_P(zv))); + break; + case IS_OBJECT: { + zend_string *str = Z_OBJCE_P(zv)->name; + asprintf(&decode, "%.*s%c", str->len <= maxlen ? (int) str->len : maxlen - 1, str->val, str->len <= maxlen ? 0 : '+'); + break; + } + case IS_CONSTANT: + decode = zend_strndup(ZEND_STRL("")); + break; + case IS_CONSTANT_AST: + decode = zend_strndup(ZEND_STRL("")); + break; + default: + asprintf(&decode, "unknown type: %d", Z_TYPE_P(zv)); + break; + } + + return decode; +} /* }}} */ diff --git a/sapi/phpdbg/phpdbg_utils.h b/sapi/phpdbg/phpdbg_utils.h index dcf713e05b..d4fd352cd4 100644 --- a/sapi/phpdbg/phpdbg_utils.h +++ b/sapi/phpdbg/phpdbg_utils.h @@ -94,6 +94,8 @@ int phpdbg_is_auto_global(char *name, int len); PHPDBG_API void phpdbg_xml_var_dump(zval *zv); +char *phpdbg_short_zval_print(zval *zv, int maxlen); + PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception); #ifdef ZTS -- 2.40.0