com php-src: Shorten opline dump lines and show literals: sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg.h sapi/phpdbg/phpdbg_ help.c
sapi/phpdbg/phpdbg_opcode.c sapi/phpdbg/phpdbg _print.c
| From: | Bob Weinand | Date: | Mon, 20 Apr 2015 10:23:11 +0000 |
| Subject: | com php-src: Shorten opline dump lines and show literals: sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg.h sapi/phpdbg/phpdbg_ help.c sapi/phpdbg/phpdbg_opcode.c sapi/phpdbg/phpdbg _print.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86398@lists.php.net to get a copy of this message | ||
Commit: 1a249bd6745131cc68f72b2cfc9b8ca789b221ee
Author: Bob Weinand <bobwei9@hotmail.com> Mon, 20 Apr 2015 12:22:55 +0200
Parents: 1c3b99c4ff20bdce1c589318c39e7fd20d6f9ee2
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1a249bd6745131cc68f72b2cfc9b8ca789b221ee
Log:
Shorten opline dump lines and show literals
Changed paths:
M sapi/phpdbg/phpdbg.c
M sapi/phpdbg/phpdbg.h
M sapi/phpdbg/phpdbg_help.c
M sapi/phpdbg/phpdbg_opcode.c
M sapi/phpdbg/phpdbg_print.c
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index a1af1e0..a93a062 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -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); diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index c636a7c..c76e460 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -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) diff --git a/sapi/phpdbg/phpdbg_help.c b/sapi/phpdbg/phpdbg_help.c index 6b10551..022a919 100644 --- a/sapi/phpdbg/phpdbg_help.c +++ b/sapi/phpdbg/phpdbg_help.c @@ -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 " diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 76f3cf3..9622fd6 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -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]) diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 052ac12..ffdf325 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -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);
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index a1af1e0..a93a062 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -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); diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h index c636a7c..c76e460 100644 --- a/sapi/phpdbg/phpdbg.h +++ b/sapi/phpdbg/phpdbg.h @@ -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) diff --git a/sapi/phpdbg/phpdbg_help.c b/sapi/phpdbg/phpdbg_help.c index 6b10551..022a919 100644 --- a/sapi/phpdbg/phpdbg_help.c +++ b/sapi/phpdbg/phpdbg_help.c @@ -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 " diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 76f3cf3..9622fd6 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -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]) diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c index 052ac12..ffdf325 100644 --- a/sapi/phpdbg/phpdbg_print.c +++ b/sapi/phpdbg/phpdbg_print.c @@ -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);