]> granicus.if.org Git - php/commitdiff
Make backtraces *much* more readable
authorBob Weinand <bobwei9@hotmail.com>
Mon, 29 Jun 2015 00:51:10 +0000 (02:51 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Mon, 29 Jun 2015 00:51:10 +0000 (02:51 +0200)
sapi/phpdbg/phpdbg_frame.c
sapi/phpdbg/phpdbg_opcode.c
sapi/phpdbg/phpdbg_utils.c
sapi/phpdbg/phpdbg_utils.h

index 584052ee0b65d1ed529618e1da0422a908cfc1e6..c2a995dd4ad79a88296a9e677d4ad9e50da40773 100644 (file)
@@ -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();
index ffc5db04d4669684f34dba08ef1fa837e04ed53d..75009108a29e8c5e6fec039e5a27eb56b808bce9 100644 (file)
@@ -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;
 } /* }}} */
index 4cd8ce2782b531eae604e477cbd478a2477fd968..0d03c3cdd4d9f9bc7e1997cb7d1165c9ccbc7067 100644 (file)
@@ -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;
+} /* }}} */
index dcf713e05ba85fa3244be28761991e06a704919e..d4fd352cd4cc74736f9c1b66b806031bbe2d6510 100644 (file)
@@ -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