Stacktrace in errormessages

From: Date: Sun, 29 Oct 2000 07:34:22 +0000
Subject: Stacktrace in errormessages
Groups: php.dev 
Request: Send a blank email to php-dev+get-36334@lists.php.net to get a copy of this message
Hi I would like to have php include a stacktrace in errormessages to easy debugging. I've tried modifying zend to do this, but it didn't work :( I would appreciate it if anyone with more (read any) experience with this could take a look. My humble attemt at a patch is attached. It was supposed to loop through the function_call stack and add the name of each function to a string. This string should be passed to the users error-handler instad of the error-message. Thanks -- Ragnar Kjørstad Modus Media

--- php-4.0.3pl1-orig/Zend/zend.c Mon Sep 25 20:10:45 2000 +++ php-4.0.3pl1/Zend/zend.c Sun Oct 29 08:06:03 2000 @@ -540,12 +540,23 @@ #define ZEND_ERROR_BUFFER_SIZE 1024 +void zend_create_stacktrace(void *element, void *arg) { + zval *stacktrace=(zval *)arg; + Z_STRLEN_P(stacktrace)=Z_STRLEN_P(stacktrace)+ + strlen(((zend_function *)element)->common.function_name); + Z_STRVAL_P(stacktrace)=(char *)erealloc(Z_STRVAL_P(stacktrace), + Z_STRLEN_P(stacktrace)); + strcat(Z_STRVAL_P(stacktrace), + ((zend_function *)element)->common.function_name); +} + ZEND_API void zend_error(int type, const char *format, ...) { va_list args; zval ***params; zval *retval; zval *z_error_type, *z_error_message, *z_error_filename, *z_error_lineno, *z_context; + zval *z_error_stacktrace; char *error_filename; uint error_lineno; zval *orig_user_error_handler; @@ -611,6 +622,14 @@ ALLOC_INIT_ZVAL(z_error_filename); ALLOC_INIT_ZVAL(z_error_lineno); ALLOC_INIT_ZVAL(z_context); + ALLOC_INIT_ZVAL(z_error_stacktrace); + z_error_stacktrace->value.str.val = (char *) emalloc(1); + z_error_stacktrace->value.str.len = 1; + z_error_stacktrace->type = IS_STRING; + z_error_stacktrace->value.str.val[0]='\0'; + + zend_stack_apply_with_argument(&CG(function_call_stack), ZEND_STACK_APPLY_BOTTOMUP, (int (*)(void *element, void *))zend_create_stacktrace, (void *)z_error_stacktrace); + z_error_message->value.str.val = (char *) emalloc(ZEND_ERROR_BUFFER_SIZE); #ifdef HAVE_VSNPRINTF @@ -643,7 +662,8 @@ params = (zval ***) emalloc(sizeof(zval **)*5); params[0] = &z_error_type; - params[1] = &z_error_message; + // params[1] = &z_error_message; + params[1] = &z_error_stacktrace; params[2] = &z_error_filename; params[3] = &z_error_lineno; params[4] = &z_context;
« previous php.dev (#36334) next »