From: krakjoe Date: Mon, 18 Nov 2013 17:00:26 +0000 (+0000) Subject: improve uncaught exception handler X-Git-Tag: php-5.6.0alpha1~110^2~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a30a79fd4c507c91a11a1c362758ce34cbabd56;p=php improve uncaught exception handler --- diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c index e6d4a0ca73..88d03dc06f 100644 --- a/phpdbg_prompt.c +++ b/phpdbg_prompt.c @@ -390,6 +390,56 @@ static PHPDBG_COMMAND(leave) /* {{{ */ return PHPDBG_LEAVE; } /* }}} */ +static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */ +{ + zend_fcall_info fci; + + zval fname, + *trace, + exception; + + /* get filename and linenumber before unsetting exception */ + const char *filename = zend_get_executed_filename(TSRMLS_C); + zend_uint lineno = zend_get_executed_lineno(TSRMLS_C); + + /* copy exception */ + exception = *EG(exception); + zval_copy_ctor(&exception); + EG(exception) = NULL; + + phpdbg_error( + "Uncaught %s !", + Z_OBJCE(exception)->name); + + /* call __toString */ + ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring")-1, 1); + fci.size = sizeof(fci); + fci.function_table = &Z_OBJCE(exception)->function_table; + fci.function_name = &fname; + fci.symbol_table = NULL; + fci.object_ptr = &exception; + fci.retval_ptr_ptr = &trace; + fci.param_count = 0; + fci.params = NULL; + fci.no_separation = 1; + zend_call_function(&fci, NULL TSRMLS_CC); + + if (trace) { + phpdbg_writeln( + "Uncaught %s", Z_STRVAL_P(trace)); + /* remember to dtor trace */ + zval_ptr_dtor(&trace); + } + + /* output useful information about address */ + phpdbg_writeln( + "Stacked entered at %p in %s on line %lu", + EG(active_op_array)->opcodes, filename, lineno); + + zval_dtor(&fname); + zval_dtor(&exception); +} /* }}} */ + static PHPDBG_COMMAND(run) /* {{{ */ { if (EG(in_execution)) { @@ -441,16 +491,7 @@ static PHPDBG_COMMAND(run) /* {{{ */ } zend_end_try(); if (EG(exception)) { - phpdbg_error("Uncaught Exception !"); - /* - * @TODO(anyone) something better !! - */ - zend_print_zval_r( - EG(exception), 0 TSRMLS_CC); - - /* make sure this is dtor'd and reset */ - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; + phpdbg_handle_exception(TSRMLS_C); } EG(active_op_array) = orig_op_array; diff --git a/test.php b/test.php index 2266d157d5..7e3a96c87d 100644 --- a/test.php +++ b/test.php @@ -1,4 +1,15 @@