com php-src: Make backtraces *much* more readable: sapi/phpdbg/ phpdbg_frame.c sapi/phpdbg/phpdbg_opcode.c sapi/php dbg/phpdbg_utils.c
sapi/phpdbg/phpdbg_utils.h
| From: | Bob Weinand | Date: | Mon, 29 Jun 2015 00:51:10 +0000 |
| Subject: | com php-src: Make backtraces *much* more readable: sapi/phpdbg/ phpdbg_frame.c sapi/phpdbg/phpdbg_opcode.c sapi/php dbg/phpdbg_utils.c sapi/phpdbg/phpdbg_utils.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87585@lists.php.net to get a copy of this message | ||
Commit: 088f589f7d5aa24a8c42fea582dc53b8cb7232c2
Author: Bob Weinand <bobwei9@hotmail.com> Mon, 29 Jun 2015 02:51:10 +0200
Parents: f500471e8c27af61e3c213d183e583b49d8b42ee
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=088f589f7d5aa24a8c42fea582dc53b8cb7232c2
Log:
Make backtraces *much* more readable
Changed paths:
M sapi/phpdbg/phpdbg_frame.c
M sapi/phpdbg/phpdbg_opcode.c
M sapi/phpdbg/phpdbg_utils.c
M sapi/phpdbg/phpdbg_utils.h
Diff:
diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c
index 584052e..c2a995d 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("</arg>");
} ZEND_HASH_FOREACH_END();
diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c
index ffc5db0..7500910 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("<constant>"));
- break;
- case IS_CONSTANT_AST:
- decode = zend_strndup(ZEND_STRL("<ast>"));
- 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 4cd8ce2..0d03c3c 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("<constant>"));
+ break;
+ case IS_CONSTANT_AST:
+ decode = zend_strndup(ZEND_STRL("<ast>"));
+ 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 dcf713e...d4fd352 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