You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.3 KiB

12 years ago
Fixed bug #72213 (Finally leaks on nested exceptions). Squashed commit of the following: commit 8461b0407fc9eab0869d43b84e6a92ba2fe06997 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed May 25 00:34:42 2016 +0300 Rmoved zend_try_catch_element.parent and walk through op_array.try_catch_array backward from the current try_cacth_offset. commit 0c71e249649bed178bfbef30bb3e63c57f07af05 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed May 25 00:04:53 2016 +0300 Move SAVE_OPLINE() to its original place commit 111432a4df738fcd65878a42f23194dc3c4983a2 Author: Dmitry Stogov <dmitry@zend.com> Date: Wed May 25 00:01:10 2016 +0300 Separate the common part of ZEND_HANDLE_EXCEPTION and FAST_RET into zend_dispatch_try_catch_finally_helper. commit 4f21c06c2ec17819a708bc037f318784554a6ecd Author: Nikita Popov <nikic@php.net> Date: Tue May 24 14:55:27 2016 +0200 Improve finally fix commit da5c7274997b8308e682b5bf280124e3a1483086 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue May 24 10:36:08 2016 +0300 Fixed Zend/tests/try/bug70228_3.phpt and Zend/tests/try/bug70228_4.phpt commit cfcedf2fb4f4fc1f7de9f7d53a3037fed7795f19 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue May 24 02:59:27 2016 +0300 Added test commit 4c6aa93d43da941eb4fda15b48154bfb104bdc04 Author: Dmitry Stogov <dmitry@zend.com> Date: Tue May 24 00:38:20 2016 +0300 Added tests commit 8a8f4704b0eca2e460d42c1f253a363b0db8e510 Author: Dmitry Stogov <dmitry@zend.com> Date: Mon May 23 23:27:34 2016 +0300 Fixed bug #72213 (Finally leaks on nested exceptions)
10 years ago
11 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Felipe Pena <felipe@php.net> |
  16. | Authors: Joe Watkins <joe.watkins@live.co.uk> |
  17. | Authors: Bob Weinand <bwoebi@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #include "phpdbg.h"
  21. #include "zend_vm_opcodes.h"
  22. #include "zend_compile.h"
  23. #include "phpdbg_opcode.h"
  24. #include "phpdbg_utils.h"
  25. #include "ext/standard/php_string.h"
  26. ZEND_EXTERN_MODULE_GLOBALS(phpdbg)
  27. static inline const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */
  28. {
  29. const char *ret = zend_get_opcode_name(opcode);
  30. if (ret) {
  31. return ret + 5; /* Skip ZEND_ prefix */
  32. }
  33. return "UNKNOWN";
  34. } /* }}} */
  35. static inline char *phpdbg_decode_op(
  36. zend_op_array *ops, const znode_op *op, uint32_t type) /* {{{ */
  37. {
  38. char *decode = NULL;
  39. switch (type) {
  40. case IS_CV: {
  41. zend_string *var = ops->vars[EX_VAR_TO_NUM(op->var)];
  42. spprintf(&decode, 0, "$%.*s%c",
  43. ZSTR_LEN(var) <= 19 ? (int) ZSTR_LEN(var) : 18,
  44. ZSTR_VAL(var), ZSTR_LEN(var) <= 19 ? 0 : '+');
  45. } break;
  46. case IS_VAR:
  47. spprintf(&decode, 0, "@%u", EX_VAR_TO_NUM(op->var) - ops->last_var);
  48. break;
  49. case IS_TMP_VAR:
  50. spprintf(&decode, 0, "~%u", EX_VAR_TO_NUM(op->var) - ops->last_var);
  51. break;
  52. case IS_CONST: {
  53. zval *literal = RT_CONSTANT(ops, *op);
  54. decode = phpdbg_short_zval_print(literal, 20);
  55. } break;
  56. }
  57. return decode;
  58. } /* }}} */
  59. char *phpdbg_decode_input_op(
  60. zend_op_array *ops, const zend_op *opline, znode_op op, zend_uchar op_type,
  61. uint32_t flags) {
  62. char *result = NULL;
  63. if (op_type != IS_UNUSED) {
  64. result = phpdbg_decode_op(ops, &op, op_type);
  65. } else if (ZEND_VM_OP_JMP_ADDR == (flags & ZEND_VM_OP_MASK)) {
  66. spprintf(&result, 0, "J%td", OP_JMP_ADDR(opline, op) - ops->opcodes);
  67. } else if (ZEND_VM_OP_NUM == (flags & ZEND_VM_OP_MASK)) {
  68. spprintf(&result, 0, "%" PRIu32, op.num);
  69. } else if (ZEND_VM_OP_TRY_CATCH == (flags & ZEND_VM_OP_MASK)) {
  70. if (op.num != (uint32_t)-1) {
  71. spprintf(&result, 0, "try-catch(%" PRIu32 ")", op.num);
  72. }
  73. } else if (ZEND_VM_OP_LIVE_RANGE == (flags & ZEND_VM_OP_MASK)) {
  74. if (opline->extended_value & ZEND_FREE_ON_RETURN) {
  75. spprintf(&result, 0, "live-range(%" PRIu32 ")", op.num);
  76. }
  77. } else if (ZEND_VM_OP_THIS == (flags & ZEND_VM_OP_MASK)) {
  78. result = estrdup("THIS");
  79. } else if (ZEND_VM_OP_NEXT == (flags & ZEND_VM_OP_MASK)) {
  80. result = estrdup("NEXT");
  81. } else if (ZEND_VM_OP_CLASS_FETCH == (flags & ZEND_VM_OP_MASK)) {
  82. //zend_dump_class_fetch_type(op.num);
  83. } else if (ZEND_VM_OP_CONSTRUCTOR == (flags & ZEND_VM_OP_MASK)) {
  84. result = estrdup("CONSTRUCTOR");
  85. }
  86. return result;
  87. }
  88. char *phpdbg_decode_opline(zend_op_array *ops, zend_op *opline) /*{{{ */
  89. {
  90. const char *opcode_name = phpdbg_decode_opcode(opline->opcode);
  91. uint32_t flags = zend_get_opcode_flags(opline->opcode);
  92. char *result, *decode[4] = {NULL, NULL, NULL, NULL};
  93. /* OP1 */
  94. decode[1] = phpdbg_decode_input_op(
  95. ops, opline, opline->op1, opline->op1_type, ZEND_VM_OP1_FLAGS(flags));
  96. /* OP2 */
  97. decode[2] = phpdbg_decode_input_op(
  98. ops, opline, opline->op2, opline->op2_type, ZEND_VM_OP2_FLAGS(flags));
  99. /* RESULT */
  100. switch (opline->opcode) {
  101. case ZEND_CATCH:
  102. spprintf(&decode[3], 0, "%" PRIu32, opline->result.num);
  103. break;
  104. default:
  105. decode[3] = phpdbg_decode_op(ops, &opline->result, opline->result_type);
  106. break;
  107. }
  108. spprintf(&result, 0,
  109. "%-23s %-20s %-20s %-20s",
  110. decode[0] ? decode[0] : opcode_name,
  111. decode[1] ? decode[1] : "",
  112. decode[2] ? decode[2] : "",
  113. decode[3] ? decode[3] : "");
  114. if (decode[0])
  115. efree(decode[0]);
  116. if (decode[1])
  117. efree(decode[1]);
  118. if (decode[2])
  119. efree(decode[2]);
  120. if (decode[3])
  121. efree(decode[3]);
  122. return result;
  123. } /* }}} */
  124. void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_flags) /* {{{ */
  125. {
  126. /* force out a line while stepping so the user knows what is happening */
  127. if (ignore_flags ||
  128. (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) ||
  129. (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ||
  130. (PHPDBG_G(oplog)))) {
  131. zend_op *opline = (zend_op *) execute_data->opline;
  132. char *decode = phpdbg_decode_opline(&execute_data->func->op_array, opline);
  133. if (ignore_flags || (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) {
  134. /* output line info */
  135. phpdbg_notice("opline", "line=\"%u\" opline=\"%p\" op=\"%s\" file=\"%s\"", "L%-5u %16p %s %s",
  136. opline->lineno,
  137. opline,
  138. decode,
  139. execute_data->func->op_array.filename ? ZSTR_VAL(execute_data->func->op_array.filename) : "unknown");
  140. }
  141. if (!ignore_flags && PHPDBG_G(oplog)) {
  142. phpdbg_log_ex(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
  143. opline->lineno,
  144. opline,
  145. decode,
  146. execute_data->func->op_array.filename ? ZSTR_VAL(execute_data->func->op_array.filename) : "unknown");
  147. }
  148. efree(decode);
  149. }
  150. if (PHPDBG_G(oplog_list)) {
  151. phpdbg_oplog_entry *cur = zend_arena_alloc(&PHPDBG_G(oplog_arena), sizeof(phpdbg_oplog_entry));
  152. zend_op_array *op_array = &execute_data->func->op_array;
  153. cur->op = (zend_op *) execute_data->opline;
  154. cur->opcodes = op_array->opcodes;
  155. cur->filename = op_array->filename;
  156. cur->scope = op_array->scope;
  157. cur->function_name = op_array->function_name;
  158. cur->next = NULL;
  159. PHPDBG_G(oplog_cur)->next = cur;
  160. PHPDBG_G(oplog_cur) = cur;
  161. }
  162. } /* }}} */
  163. void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags) /* {{{ */
  164. {
  165. phpdbg_print_opline_ex(execute_data, ignore_flags);
  166. } /* }}} */