com php-src: improve uncaught exception handler: phpdbg_promp t.c test.php
| From: | Bob Weinand | Date: | Mon, 18 Nov 2013 17:00:26 +0000 |
| Subject: | com php-src: improve uncaught exception handler: phpdbg_promp t.c test.php | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-74835@lists.php.net to get a copy of this message | ||
Commit: 7a30a79fd4c507c91a11a1c362758ce34cbabd56
Author: krakjoe <joe.watkins@live.co.uk> Mon, 18 Nov 2013 17:00:26 +0000
Parents: e02c26d1f502a28103e1b2367547ed188c5ab4c5
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7a30a79fd4c507c91a11a1c362758ce34cbabd56
Log:
improve uncaught exception handler
Changed paths:
M phpdbg_prompt.c
M test.php
Diff:
diff --git a/phpdbg_prompt.c b/phpdbg_prompt.c
index e6d4a0c..88d03dc 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 2266d15..7e3a96c 100644
--- a/test.php
+++ b/test.php
@@ -1,4 +1,15 @@
<?php
+
+function outer() {
+ mine();
+}
+
+function mine() {
+ throw new Exception();
+}
+
+outer();
+
if (isset($include))
include (sprintf("%s/web-bootstrap.php", dirname(__FILE__)));