]> granicus.if.org Git - php/commitdiff
Shorten opline dump lines and show literals
authorBob Weinand <bobwei9@hotmail.com>
Mon, 20 Apr 2015 10:22:55 +0000 (12:22 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Mon, 20 Apr 2015 10:23:11 +0000 (12:23 +0200)
sapi/phpdbg/phpdbg.c
sapi/phpdbg/phpdbg.h
sapi/phpdbg/phpdbg_help.c
sapi/phpdbg/phpdbg_opcode.c
sapi/phpdbg/phpdbg_print.c

index a1af1e0ea967c06cde2314d7c62fb7fb127fffa1..a93a062d2ec050bf9fc9de2969b05daedb9354bf 100644 (file)
@@ -763,6 +763,7 @@ const opt_struct OPTIONS[] = { /* {{{ */
 #endif
        {'x', 0, "xml output"},
        {'p', 2, "show opcodes"},
+       {'o', 0, "display opline addresses"},
        {'h', 0, "help"},
        {'V', 0, "version"},
        {'-', 0, NULL}
@@ -1192,7 +1193,7 @@ phpdbg_main:
                                if (sscanf(php_optarg, "%d", &listen) != 1) {
                                        listen = 8000;
                                }
-                               break;
+                       break;
 
                        case 'a': { /* set bind address */
                                free(address);
@@ -1213,6 +1214,10 @@ phpdbg_main:
                                settings = (void *) 0x1;
                        } break;
 
+                       case 'o':
+                               flags |= PHPDBG_PRINT_OPLINE_ADDR;
+                       break;
+
                        case 'h': {
                                sapi_startup(phpdbg);
                                phpdbg->startup(phpdbg);
index c636a7c791cf99e0b9a74b8e29a309de7ced82df..c76e460495567bf8b608149c746097f766e1d53a 100644 (file)
@@ -187,10 +187,11 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
 #define PHPDBG_WRITE_XML              (1ULL<<31)
 
 #define PHPDBG_SHOW_REFCOUNTS         (1ULL<<32)
+#define PHPDBG_PRINT_OPLINE_ADDR      (1ULL<<33)
 
-#define PHPDBG_IN_SIGNAL_HANDLER      (1ULL<<33)
+#define PHPDBG_IN_SIGNAL_HANDLER      (1ULL<<34)
 
-#define PHPDBG_DISCARD_OUTPUT         (1ULL<<34)
+#define PHPDBG_DISCARD_OUTPUT         (1ULL<<35)
 
 #define PHPDBG_SEEK_MASK              (PHPDBG_IN_UNTIL | PHPDBG_IN_FINISH | PHPDBG_IN_LEAVE)
 #define PHPDBG_BP_RESOLVE_MASK       (PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP)
index 6b105511924326ce0c48b38acbb798eabb0a2af2..022a919f5200758855cc48cd8b4a06f3a49223f5 100644 (file)
@@ -390,6 +390,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
 "  **-a**      **-a**192.168.0.3       Setup remote console bind address" CR
 "  **-x**                          Enable xml output (instead of normal text output)" CR
 "  **-p**      **-p**, **-p=func**, **-p* **   Output opcodes and quit" CR
+"  **-o**                          Display opline addresses in opline dumps" CR
 "  **-h**                          Print the help overview" CR
 "  **-V**                          Print version number" CR
 "  **--**      **--** arg1 arg2        Use to delimit phpdbg arguments and php $argv; append any $argv "
index 76f3cf3a4bb29bac5b2b74bd4d7f23f717509a05..9622fd661b85fc86d5fbdac774a0d9884ffaf9cb 100644 (file)
@@ -23,6 +23,7 @@
 #include "zend_compile.h"
 #include "phpdbg_opcode.h"
 #include "phpdbg_utils.h"
+#include "ext/standard/php_string.h"
 
 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
 
@@ -63,9 +64,59 @@ static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t
                        asprintf(&decode, "@" ZEND_ULONG_FMT, id);
                } break;
 
-               case IS_CONST:
-                       asprintf(&decode, "C%u", phpdbg_decode_literal(ops, RT_CONSTANT(ops, *op)));
-               break;
+               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, "%lld", 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;
+                       }
+               } break;
 
                case IS_UNUSED:
                        asprintf(&decode, "<unused>");
@@ -80,47 +131,39 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars) /*{
 
        switch (op->opcode) {
        case ZEND_JMP:
-#ifdef ZEND_GOTO
        case ZEND_GOTO:
-#endif
-#ifdef ZEND_FAST_CALL
        case ZEND_FAST_CALL:
-#endif
-                       asprintf(&decode[1], "J%ld", OP_JMP_ADDR(op, op->op1) - ops->opcodes);
+               asprintf(&decode[1], "J%ld", OP_JMP_ADDR(op, op->op1) - ops->opcodes);
                goto format;
 
        case ZEND_JMPZNZ:
-                       decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars);
-                       asprintf(&decode[2], "J%u or J%" PRIu32, op->op2.opline_num, op->extended_value);
+               decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars);
+               asprintf(&decode[2], "J%u or J%" PRIu32, op->op2.opline_num, op->extended_value);
                goto result;
 
        case ZEND_JMPZ:
        case ZEND_JMPNZ:
        case ZEND_JMPZ_EX:
        case ZEND_JMPNZ_EX:
-
-#ifdef ZEND_JMP_SET
        case ZEND_JMP_SET:
-#endif
                decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars);
                asprintf(&decode[2], "J%ld", OP_JMP_ADDR(op, op->op2) - ops->opcodes);
-       goto result;
+               goto result;
 
        case ZEND_RECV_INIT:
                goto result;
 
-               default: {
-                       decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars);
-                       decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars);
+       default:
+               decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars);
+               decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars);
 result:
-                       decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars);
+               decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars);
 format:
-                       asprintf(&decode[0],
-                               "%-20s %-20s %-20s",
-                               decode[1] ? decode[1] : "",
-                               decode[2] ? decode[2] : "",
-                               decode[3] ? decode[3] : "");
-               }
+               asprintf(&decode[0],
+                       "%-20s %-20s %-20s",
+                       decode[1] ? decode[1] : "",
+                       decode[2] ? decode[2] : "",
+                       decode[3] ? decode[3] : "");
        }
 
        if (decode[1])
index 052ac12884bad99ebbff88b5e0337f5ac2b3db6d..ffdf325b5b564fb60df271797d1900426102b0e7 100644 (file)
@@ -63,14 +63,14 @@ static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */
                                end = op_array->last-1;
 
                                if (method->common.scope) {
-                                       phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" method=\"%s::%s\" file=\"%s\"", "\tL%d-%d %s::%s() %s",
+                                       phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" method=\"%s::%s\" file=\"%s\"", "L%d-%d %s::%s() %s",
                                                op_array->line_start,
                                                op_array->line_end,
                                                method->common.scope->name->val,
                                                method->common.function_name->val,
                                                op_array->filename ? op_array->filename->val : "unknown");
                                } else {
-                                       phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" function=\"%s\" file=\"%s\"", "\tL%d-%d %s() %s",
+                                       phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" function=\"%s\" file=\"%s\"", "L%d-%d %s() %s",
                                                method->common.function_name ? op_array->line_start : 0,
                                                method->common.function_name ? op_array->line_end : 0,
                                                method->common.function_name ? method->common.function_name->val : "{main}",
@@ -81,14 +81,21 @@ static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */
                                do {
                                        char *decode = phpdbg_decode_opline(op_array, opline, &vars);
                                        if (decode != NULL) {
-                                               phpdbg_writeln("print", "line=\"%u\" opline=\"%p\" opcode=\"%s\" op=\"%s\"", "\t\tL%u\t%p %-30s %s",
-                                                       opline->lineno,
-                                                       opline,
-                                                       phpdbg_decode_opcode(opline->opcode),
-                                                       decode);
+                                               if (PHPDBG_G(flags) & PHPDBG_PRINT_OPLINE_ADDR) {
+                                                       phpdbg_writeln("print", "line=\"%u\" opline=\"%p\" opcode=\"%s\" op=\"%s\"", " L%-5u %p %-36s %s",
+                                                               opline->lineno,
+                                                               opline,
+                                                               phpdbg_decode_opcode(opline->opcode),
+                                                               decode);
+                                               } else {
+                                                       phpdbg_writeln("print", "line=\"%u\" opcode=\"%s\" op=\"%s\"", " L%-5u %-36s %s",
+                                                               opline->lineno,
+                                                               phpdbg_decode_opcode(opline->opcode),
+                                                               decode);
+                                               }
                                                free(decode);
                                        } else {
-                                               phpdbg_error("print", "type=\"decodefailure\" opline=\"%16p\"", "\tFailed to decode opline %16p", opline);
+                                               phpdbg_error("print", "type=\"decodefailure\" opline=\"%16p\"", "Failed to decode opline %16p", opline);
                                        }
                                        opline++;
                                } while (opcode++ < end);