Initial support for built-in backtracing.

There are still a few problems such as includes and calling other functions
from internal functions which aren't seen (will have to think if and how to
fix this).
Also the main scripts filename isn't available. Need to think about that.
This commit is contained in:
Andi Gutmans 2002-05-02 17:20:48 +00:00
parent 7a64b2b7e5
commit 7e5ec2d761
6 changed files with 85 additions and 52 deletions

View file

@ -65,6 +65,7 @@ static ZEND_FUNCTION(get_loaded_extensions);
static ZEND_FUNCTION(extension_loaded);
static ZEND_FUNCTION(get_extension_funcs);
static ZEND_FUNCTION(get_defined_constants);
static ZEND_FUNCTION(debug_backtrace);
#if ZEND_DEBUG
static ZEND_FUNCTION(zend_test_func);
#endif
@ -116,6 +117,7 @@ static zend_function_entry builtin_functions[] = {
ZEND_FE(extension_loaded, NULL)
ZEND_FE(get_extension_funcs, NULL)
ZEND_FE(get_defined_constants, NULL)
ZEND_FE(debug_backtrace, NULL)
#if ZEND_DEBUG
ZEND_FE(zend_test_func, NULL)
#endif
@ -1180,6 +1182,33 @@ ZEND_FUNCTION(get_defined_constants)
}
/* {{{ proto void debug_backtrace(void)
Prints out a backtrace */
ZEND_FUNCTION(debug_backtrace)
{
zend_execute_data *ptr;
int lineno;
ptr = EG(current_execute_data);
lineno = ptr->opline->lineno;
ptr = ptr->prev_execute_data;
while (ptr) {
if (ptr->object) {
printf("%s::", Z_OBJCE(*ptr->object)->name);
}
printf("%s() [%s:%d]\n", ptr->function_state.function->common.function_name, ptr->function_state.function->op_array.filename, lineno);
lineno = ptr->opline->lineno;
ptr = ptr->prev_execute_data;
}
printf("main() [...:%d]\n", lineno);
RETURN_TRUE;
}
/* {{{ proto bool extension_loaded(string extension_name)
Returns true if the named extension is loaded */
ZEND_FUNCTION(extension_loaded)