Skip to content

Commit 5e16722

Browse files
committed
Show exception source in phpdbg
1 parent 79b1832 commit 5e16722

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

Zend/zend_exceptions.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ static int zend_implement_throwable(zend_class_entry *interface, zend_class_entr
5555
}
5656
/* }}} */
5757

58-
static inline zend_class_entry *zend_get_exception_base(zval *object)
58+
static inline zend_class_entry *i_get_exception_base(zval *object)
5959
{
6060
return instanceof_function(Z_OBJCE_P(object), default_exception_ce) ? default_exception_ce : error_ce;
6161
}
6262

63+
ZEND_API zend_class_entry *zend_get_exception_base(zval *object)
64+
{
65+
return i_get_exception_base(object);
66+
}
67+
6368
void zend_exception_set_previous(zend_object *exception, zend_object *add_previous)
6469
{
6570
zval tmp, *previous, zv, *pzv, rv;
@@ -76,7 +81,7 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
7681
ZVAL_OBJ(&zv, exception);
7782
pzv = &zv;
7883
do {
79-
base_ce = zend_get_exception_base(pzv);
84+
base_ce = i_get_exception_base(pzv);
8085
previous = zend_read_property(base_ce, pzv, "previous", sizeof("previous")-1, 1, &rv);
8186
if (Z_TYPE_P(previous) == IS_NULL) {
8287
zend_update_property(base_ce, pzv, "previous", sizeof("previous")-1, &tmp);
@@ -196,7 +201,7 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type,
196201
}
197202
Z_SET_REFCOUNT(trace, 0);
198203

199-
base_ce = zend_get_exception_base(&obj);
204+
base_ce = i_get_exception_base(&obj);
200205

201206
if (EXPECTED(class_type != parse_error_ce || !(filename = zend_get_compiled_filename()))) {
202207
zend_update_property_string(base_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename());
@@ -243,7 +248,7 @@ ZEND_METHOD(exception, __construct)
243248
int argc = ZEND_NUM_ARGS();
244249

245250
object = getThis();
246-
base_ce = zend_get_exception_base(object);
251+
base_ce = i_get_exception_base(object);
247252

248253
if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
249254
zend_class_entry *ce;
@@ -325,9 +330,9 @@ ZEND_METHOD(error_exception, __construct)
325330
}
326331

327332
#define GET_PROPERTY(object, name) \
328-
zend_read_property(zend_get_exception_base(object), (object), name, sizeof(name) - 1, 0, &rv)
333+
zend_read_property(i_get_exception_base(object), (object), name, sizeof(name) - 1, 0, &rv)
329334
#define GET_PROPERTY_SILENT(object, name) \
330-
zend_read_property(zend_get_exception_base(object), (object), name, sizeof(name) - 1, 1, &rv)
335+
zend_read_property(i_get_exception_base(object), (object), name, sizeof(name) - 1, 1, &rv)
331336

332337
/* {{{ proto string Exception|Error::getFile()
333338
Get the file in which the exception occurred */
@@ -602,7 +607,7 @@ ZEND_METHOD(exception, getTraceAsString)
602607
DEFAULT_0_PARAMS;
603608

604609
object = getThis();
605-
base_ce = zend_get_exception_base(object);
610+
base_ce = i_get_exception_base(object);
606611

607612
trace = zend_read_property(base_ce, object, "trace", sizeof("trace")-1, 1, &rv);
608613
if (Z_TYPE_P(trace) != IS_ARRAY) {
@@ -731,7 +736,7 @@ ZEND_METHOD(exception, __toString)
731736
zval_dtor(&fname);
732737

733738
exception = getThis();
734-
base_ce = zend_get_exception_base(exception);
739+
base_ce = i_get_exception_base(exception);
735740

736741
/* We store the result in the private property string so we can access
737742
* the result in uncaught exception handlers without memleaks. */
@@ -982,7 +987,7 @@ ZEND_API void zend_exception_error(zend_object *ex, int severity) /* {{{ */
982987
if (Z_TYPE(tmp) != IS_STRING) {
983988
zend_error(E_WARNING, "%s::__toString() must return a string", ce_exception->name->val);
984989
} else {
985-
zend_update_property_string(zend_get_exception_base(&exception), &exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name->val : Z_STRVAL(tmp));
990+
zend_update_property_string(i_get_exception_base(&exception), &exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name->val : Z_STRVAL(tmp));
986991
}
987992
}
988993
zval_ptr_dtor(&tmp);

Zend/zend_exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ZEND_API void zend_throw_exception_internal(zval *exception);
3636

3737
void zend_register_default_exception(void);
3838

39+
ZEND_API zend_class_entry *zend_get_exception_base(zval *object);
3940
ZEND_API zend_class_entry *zend_exception_get_default(void);
4041
ZEND_API zend_class_entry *zend_get_error_exception(void);
4142
ZEND_API zend_class_entry *zend_get_error(void);

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,9 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
14431443
/* check for uncaught exceptions */
14441444
if (exception && PHPDBG_G(handled_exception) != exception) {
14451445
zend_execute_data *prev_ex = execute_data;
1446+
zval zv, rv;
1447+
zend_string *file;
1448+
zend_long line;
14461449

14471450
do {
14481451
prev_ex = zend_generator_check_placeholder_frame(prev_ex);
@@ -1457,7 +1460,13 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
14571460
} while ((prev_ex = prev_ex->prev_execute_data));
14581461

14591462
PHPDBG_G(handled_exception) = exception;
1460-
phpdbg_error("exception", "name=\"%s\"", "Uncaught exception %s", exception->ce->name->val);
1463+
1464+
ZVAL_OBJ(&zv, exception);
1465+
file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv));
1466+
line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv));
1467+
1468+
phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"%lld\"", "Uncaught exception %s in %s on line %lld", exception->ce->name->val, file->val, line);
1469+
zend_string_release(file);
14611470
DO_INTERACTIVE(1);
14621471
}
14631472
ex_is_caught:

0 commit comments

Comments
 (0)