Changeset 113
- Timestamp:
- 07/06/05 16:52:36 (3 years ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/config.m4 (modified) (2 diffs)
- eaccelerator/trunk/debug.c (modified) (3 diffs)
- eaccelerator/trunk/debug.h (modified) (3 diffs)
- eaccelerator/trunk/eaccelerator.c (modified) (55 diffs)
- eaccelerator/trunk/eaccelerator.h (modified) (3 diffs)
- eaccelerator/trunk/eaccelerator.ini (modified) (1 diff)
- eaccelerator/trunk/loader.c (modified) (1 diff)
- eaccelerator/trunk/shm.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r112 r113 1 2005-07-06 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 * Documented namespace option 3 * New debug/log code. Make the code a lot cleaner and easier 4 for the user to debug eaccelerator. 5 1 6 2005-06-27 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 2 7 * Fixed a buffer overflow in eaccelerator.c and cache.c. A string longer eaccelerator/trunk/config.m4
r101 r113 93 93 ]) 94 94 95 AC_ARG_WITH(eaccelerator-debug, 96 [ --with-eaccelerator-debug Enable the debug code so eaccelerator logs verbose.],[ 97 eaccelerator_debug=$withval 98 ],[ 99 eaccelerator_debug=no 100 ]) 101 95 102 dnl PHP_BUILD_SHARED 96 103 if test "$PHP_EACCELERATOR" != "no"; then … … 130 137 if test "$eaccelerator_inode" = "yes"; then 131 138 AC_DEFINE(WITH_EACCELERATOR_USE_INODE, 1, [Undef if you don't wan't to use inodes to determine hash keys]) 139 fi 140 if test "$eaccelerator_debug" = "yes"; then 141 AC_DEFINE(DEBUG, 1, [Undef when you want to enable eaccelerator debug code]) 132 142 fi 133 143 eaccelerator/trunk/debug.c
r64 r113 4 4 +----------------------------------------------------------------------+ 5 5 | Copyright (c) 2004 - 2005 eAccelerator | 6 | http://eaccelerator.net |6 | http://eaccelerator.net | 7 7 +----------------------------------------------------------------------+ 8 8 | This program is free software; you can redistribute it and/or | … … 24 24 +----------------------------------------------------------------------+ 25 25 | Author(s): Dmitry Stogov <dstogov@users.sourceforge.net> | 26 | Bart Vanbrabant <zoeloelip@users.sourceforge.net> | 26 27 +----------------------------------------------------------------------+ 27 28 $Id$ … … 29 30 30 31 #include "eaccelerator.h" 32 33 #ifdef HAVE_EACCELERATOR 34 31 35 #include "debug.h" 32 36 #include <ctype.h> 33 37 #include <stdio.h> 34 38 35 #if defined(DEBUG) || defined(TEST_PERFORMANCE) || defined(PROFILE_OPCODES) 36 37 extern FILE *F_fp; 38 39 void 40 binary_print (char *p, int len) 41 { 42 while (len--) 43 { 44 fputc (*p++, F_fp); 45 } 46 fputc ('\n', F_fp); 47 } 48 49 void 50 log_hashkeys (char *p, HashTable * ht) 51 { 52 Bucket *b; 53 int i = 0; 54 55 b = ht->pListHead; 56 57 fputs (p, F_fp); 58 while (b) 59 { 60 fprintf (F_fp, "[%d] ", i); 61 binary_print (b->arKey, b->nKeyLength); 62 63 b = b->pListNext; 64 i++; 65 } 66 } 67 68 void 69 pad (TSRMLS_D) 70 { 71 int i = MMCG (xpad); 72 while (i-- > 0) 73 { 74 fputc ('\t', F_fp); 75 } 76 } 77 78 void 79 start_time (struct timeval *tvstart) 80 { 81 gettimeofday (tvstart, NULL); 82 } 83 84 long 85 elapsed_time (struct timeval *tvstart) 86 { 87 struct timeval tvend; 88 int sec, usec; 89 gettimeofday (&tvend, NULL); 90 sec = tvend.tv_sec - tvstart->tv_sec; 91 usec = tvend.tv_usec - tvstart->tv_usec; 92 return sec * 1000000 + usec; 93 } 94 #endif /* #if defined(DEBUG) || defined(TEST_PERFORMANCE) || defined(PROFILE_OPCODES) */ 95 96 void 97 debug_printf (char *format, ...) 98 { 99 char output_buf[512]; 100 va_list args; 101 102 va_start (args, format); 103 vsnprintf (output_buf, sizeof (output_buf), format, args); 104 va_end (args); 39 FILE *F_fp = NULL; 40 long eaccelerator_debug = 0; 41 42 /** 43 * Init the debug system. This must be called before any debug 44 * functions are used. 45 */ 46 void ea_debug_init (TSRMLS_D) 47 { 48 /* register ini entries */ 49 REGISTER_MAIN_LONG_CONSTANT ("EA_LOG", EA_LOG, CONST_PERSISTENT | CONST_CS); 50 REGISTER_MAIN_LONG_CONSTANT ("EA_DEBUG", EA_DEBUG, CONST_PERSISTENT | CONST_CS); 51 REGISTER_MAIN_LONG_CONSTANT ("EA_PROFILE_OPCODES", EA_PROFILE_OPCODES, 52 CONST_PERSISTENT | CONST_CS); 53 REGISTER_MAIN_LONG_CONSTANT ("EA_TEST_PERFORMANCE", EA_TEST_PERFORMANCE, 54 CONST_PERSISTENT | CONST_CS); 55 REGISTER_MAIN_LONG_CONSTANT ("EA_LOG_HASHKEYS", EA_LOG_HASHKEYS, 56 CONST_PERSISTENT | CONST_CS); 57 58 F_fp = fopen (MMCG (eaccelerator_log_file), "a"); 59 if (!F_fp) 60 F_fp = stderr; 61 } 62 63 /** 64 * Close the debug system. 65 */ 66 void ea_debug_shutdown () 67 { 68 fflush (F_fp); 69 fclose (F_fp); 70 F_fp = NULL; 71 } 72 73 /** 74 * Print a log message that will be print when the debug level is 75 * equal to EA_LOG. This function is always called even if ea isn't 76 * compiled with DEBUG and the log level is not equal to EA_LOG. 77 */ 78 void ea_debug_log (char *format, ...) 79 { 80 if (eaccelerator_debug & EA_LOG) { 81 char output_buf[512]; 82 va_list args; 83 84 va_start (args, format); 85 vsnprintf (output_buf, sizeof (output_buf), format, args); 86 va_end (args); 105 87 106 88 #ifdef ZEND_WIN32 107 OutputDebugString (output_buf); 108 /* zend_printf("EACCELERATOR: %s<br>\n",output_buf);*/ 109 #else 110 fputs (output_buf, stderr); 111 #endif 112 } 89 OutputDebugString (*output_buf); 90 #else 91 fputs (output_buf, F_fp); 92 fflush (F_fp); 93 #endif 94 } 95 } 96 97 /** 98 * Output an error message to stderr. This message are always printed 99 * no matter what log level is used. 100 */ 101 void ea_debug_error (char *format, ...) 102 { 103 char output_buf[512]; 104 va_list args; 105 106 va_start (args, format); 107 vsnprintf (output_buf, sizeof (output_buf), format, args); 108 va_end (args); 109 110 #ifdef ZEND_WIN32 111 OutputDebugString (*buffer); 112 #else 113 fputs (output_buf, stderr); 114 fflush (stderr); 115 #endif 116 } 117 118 /* 119 * All these functions aren't compiled when eA isn't compiled with DEBUG. They 120 * are replaced with function with no body, so it's optimized away by the compiler. 121 * Even if the debug level is ok. 122 */ 123 124 /** 125 * Print a debug message 126 */ 127 #ifdef DEBUG 128 void ea_debug_printf (long debug_level, char *format, ...) 129 { 130 if (eaccelerator_debug & debug_level) { 131 char output_buf[512]; 132 va_list args; 133 134 va_start (args, format); 135 vsnprintf (output_buf, sizeof (output_buf), format, args); 136 va_end (args); 137 138 fputs (output_buf, F_fp); 139 fflush (F_fp); 140 } 141 } 142 #else 143 void ea_debug_printf (long debug_level, char *format, ...) 144 { 145 } 146 #endif 147 148 /** 149 * Put a debug message 150 */ 151 #ifdef DEBUG 152 void ea_debug_put (long debug_level, char *message) 153 { 154 if (debug_level & eaccelerator_debug) { 155 fputs (message, F_fp); 156 fflush (F_fp); 157 } 158 } 159 #else 160 void ea_debug_put (long debug_level, char *message) 161 { 162 } 163 #endif 164 165 /** 166 * Print a binary message 167 */ 168 #ifdef DEBUG 169 void ea_debug_binary_print (long debug_level, char *p, int len) 170 { 171 if (eaccelerator_debug & debug_level) { 172 while (len--) { 173 fputc (*p++, F_fp); 174 } 175 fputc ('\n', F_fp); 176 fflush (F_fp); 177 } 178 } 179 #else 180 void ea_debug_binary_print (long debug_level, char *p, int len) 181 { 182 } 183 #endif 184 185 /** 186 * Log a hashkey 187 */ 188 #ifdef DEBUG 189 void ea_debug_log_hashkeys (char *p, HashTable * ht) 190 { 191 if (eaccelerator_debug & EA_LOG_HASHKEYS) { 192 Bucket *b; 193 int i = 0; 194 195 b = ht->pListHead; 196 197 fputs (p, F_fp); 198 while (b) { 199 fprintf (F_fp, "[%d] ", i); 200 ea_debug_binary_print (EA_LOG_HASHKEYS, b->arKey, b->nKeyLength); 201 202 b = b->pListNext; 203 i++; 204 } 205 fflush (F_fp); 206 } 207 } 208 #else 209 void ea_debug_log_hashkeys (char *p, HashTable * ht) 210 { 211 } 212 #endif 213 214 /** 215 * Pad the message with the current pad level. 216 */ 217 #ifdef DEBUG 218 void ea_debug_pad (long debug_level TSRMLS_DC) 219 { 220 if (eaccelerator_debug & debug_level) { 221 int i = MMCG (xpad); 222 while (i-- > 0) { 223 fputc ('\t', F_fp); 224 } 225 } 226 } 227 #else 228 void ea_debug_pad (long debug_level TSRMLS_DC) 229 { 230 } 231 #endif 232 233 void ea_debug_start_time (struct timeval *tvstart) 234 { 235 gettimeofday (tvstart, NULL); 236 } 237 238 long ea_debug_elapsed_time (struct timeval *tvstart) 239 { 240 struct timeval tvend; 241 int sec, usec; 242 gettimeofday (&tvend, NULL); 243 sec = tvend.tv_sec - tvstart->tv_sec; 244 usec = tvend.tv_usec - tvstart->tv_usec; 245 return sec * 1000000 + usec; 246 } 247 248 #endif /* #ifdef HAVE_EACCELERATOR */ eaccelerator/trunk/debug.h
r64 r113 4 4 +----------------------------------------------------------------------+ 5 5 | Copyright (c) 2004 - 2005 eAccelerator | 6 | http://eaccelerator.net |6 | http://eaccelerator.net | 7 7 +----------------------------------------------------------------------+ 8 8 | This program is free software; you can redistribute it and/or | … … 23 23 | A copy is availble at http://www.gnu.org/copyleft/gpl.txt | 24 24 +----------------------------------------------------------------------+ 25 | Author(s): Dmitry Stogov <dstogov@users.sourceforge.net> | 25 | Author(s): Dmitry Stogov <dstogov@users.sourceforge.net> | 26 | Bart Vanbrabant <zoeloelip@users.sourceforge.net> | 26 27 +----------------------------------------------------------------------+ 27 28 $Id$ … … 35 36 #include "zend_extensions.h" 36 37 37 void debug_printf (char *format, ...); 38 void binary_print (char *p, int len); 39 void log_hashkeys (char *p, HashTable * ht); 40 void pad (TSRMLS_D); 41 void start_time (struct timeval *tvstart); 42 long elapsed_time (struct timeval *tvstart); 38 39 /* print information about the file that's loaded or cached */ 40 #define EA_LOG (1<<0L) 41 42 /* print debugging information, mostly about the storing and restoring of a 43 * script's data structures. Gives you detailed information about what eA is 44 * doing 45 */ 46 #define EA_DEBUG (1<<1L) 47 48 /* profile php opcodes */ 49 #define EA_PROFILE_OPCODES (1<<2L) 50 51 /* print out performance data (start - end time) */ 52 53 #define EA_TEST_PERFORMANCE (1<<3L) 54 55 /* log the hashkeys used to cache scripts */ 56 #define EA_LOG_HASHKEYS (1<<4L) 57 58 void ea_debug_init (TSRMLS_D); 59 void ea_debug_shutdown (); 60 void ea_debug_error (char *format, ...); 61 void ea_debug_pad (long debug_level TSRMLS_DC); 62 void ea_debug_log (char *format, ...); 63 void ea_debug_binary_print (long debug_level, char *p, int len); 64 void ea_debug_put (long debug_level, char *message); 65 void ea_debug_log_hashkeys (char *p, HashTable * ht); 66 67 void ea_debug_start_time (struct timeval *tvstart); 68 long ea_debug_elapsed_time (struct timeval *tvstart); 43 69 44 70 #endif /* INCLUDED_DEBUG_H */ eaccelerator/trunk/eaccelerator.c
r112 r113 4 4 +----------------------------------------------------------------------+ 5 5 | Copyright (c) 2004 - 2005 eAccelerator | 6 | http://eaccelerator.net |6 | http://eaccelerator.net | 7 7 +----------------------------------------------------------------------+ 8 8 | This program is free software; you can redistribute it and/or | … … 65 65 #endif 66 66 67 /*???68 #ifdef HAVE_SCHED_H69 # include <sched.h>70 #endif71 */72 73 67 #include "php.h" 74 68 #include "php_ini.h" … … 98 92 static long eaccelerator_shm_ttl = 0; 99 93 static long eaccelerator_shm_prune_period = 0; 100 static long eaccelerator_debug = 0;94 extern long eaccelerator_debug; 101 95 static zend_bool eaccelerator_check_mtime = 1; 102 96 static zend_bool eaccelerator_scripts_shm_only = 0; … … 114 108 int binary_zend_version; 115 109 116 FILE *F_fp;117 118 110 #ifdef ZEND_ENGINE_2 119 111 /* pointer to the properties_info hashtable destructor */ … … 124 116 static zend_op_array *(*mm_saved_zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC); 125 117 126 #if defined( PROFILE_OPCODES) || defined(WITH_EACCELERATOR_EXECUTOR)118 #if defined(DEBUG) || defined(WITH_EACCELERATOR_EXECUTOR) 127 119 static void (*mm_saved_zend_execute)(zend_op_array *op_array TSRMLS_DC); 128 120 #endif … … 290 282 return FAILURE; 291 283 } 292 #ifdef DEBUG293 284 #ifdef ZEND_WIN32 294 fprintf(F_fp, "init_mm [%d]\n", getpid()); 295 #else 296 fprintf(F_fp, "init_mm [%d,%d]\n", getpid(), getppid()); 297 #endif 298 fflush(F_fp); 285 ea_debug_printf(EA_DEBUG, "init_mm [%d]\n", getpid()); 286 #else 287 ea_debug_printf(EA_DEBUG, "init_mm [%d,%d]\n", getpid(), getppid()); 299 288 #endif 300 289 #ifdef ZTS … … 332 321 #endif 333 322 MM *mm = eaccelerator_mm_instance->mm; 334 #ifdef DEBUG335 323 #ifdef ZEND_WIN32 336 fprintf(F_fp, "shutdown_mm [%d]\n", getpid()); 337 #else 338 fprintf(F_fp, "shutdown_mm [%d,%d]\n", getpid(), getppid()); 339 #endif 340 fflush(F_fp); 324 ea_debug_printf(EA_DEBUG, "shutdown_mm [%d]\n", getpid()); 325 #else 326 ea_debug_printf(EA_DEBUG, "shutdown_mm [%d,%d]\n", getpid(), getppid()); 341 327 #endif 342 328 #ifdef ZTS … … 352 338 353 339 /******************************************************************************/ 354 /* Prepare values to cache them */340 /* Prepare values to cache them */ 355 341 /******************************************************************************/ 356 342 … … 936 922 /******************************************************************************/ 937 923 /* Functions to calculate the size of different structure that a compiled php */ 938 /* script contains. */924 /* script contains. */ 939 925 /******************************************************************************/ 940 926 … … 1030 1016 zend_class_entry *ce = zv->value.obj.ce; 1031 1017 if (!MMCG(compress)) { 1032 debug_printf("[%d] EACCELERATOR can't cache objects\n", getpid());1018 ea_debug_error("[%d] EACCELERATOR can't cache objects\n", getpid()); 1033 1019 zend_bailout(); 1034 1020 } 1035 1021 while (ce != NULL) { 1036 1022 if (ce->type != ZEND_USER_CLASS && strcmp(ce->name,"stdClass") != 0) { 1037 debug_printf("[%d] EACCELERATOR can't cache objects\n", getpid());1023 ea_debug_error("[%d] EACCELERATOR can't cache objects\n", getpid()); 1038 1024 zend_bailout(); 1039 1025 } … … 1050 1036 return; 1051 1037 case IS_RESOURCE: 1052 debug_printf("[%d] EACCELERATOR can't cache resources\n", getpid());1038 ea_debug_error("[%d] EACCELERATOR can't cache resources\n", getpid()); 1053 1039 zend_bailout(); 1054 1040 default: … … 1069 1055 MMCG(mem) += sizeof(eaccelerator_op_array); 1070 1056 } else { 1071 debug_printf("[%d] EACCELERATOR can't cache function \"%s\"\n", getpid(), from->function_name);1057 ea_debug_error("[%d] EACCELERATOR can't cache function \"%s\"\n", getpid(), from->function_name); 1072 1058 zend_bailout(); 1073 1059 } … … 1159 1145 /* Calculate the size of a class entry */ 1160 1146 static void calc_class_entry(zend_class_entry* from TSRMLS_DC) { 1161 /* int i; */1162 1163 1147 if (from->type != ZEND_USER_CLASS) { 1164 debug_printf("[%d] EACCELERATOR can't cache internal class \"%s\"\n", getpid(), from->name);1148 ea_debug_error("[%d] EACCELERATOR can't cache internal class \"%s\"\n", getpid(), from->name); 1165 1149 zend_bailout(); 1166 1150 } 1167 /*1168 if (from->builtin_functions) {1169 debug_printf("[%d] EACCELERATOR can't cache class \"%s\" because of it has "1170 "some builtin_functions\n", getpid(), from->name);1171 zend_bailout();1172 }1173 */1174 1151 EACCELERATOR_ALIGN(MMCG(mem)); 1175 1152 MMCG(mem) += sizeof(eaccelerator_class_entry); … … 1444 1421 zend_op *end; 1445 1422 1446 #ifdef DEBUG 1447 pad(TSRMLS_C); 1448 fprintf(F_fp, "[%d] store_op_array: %s [scope=%s]\n", getpid(), 1423 ea_debug_pad(EA_DEBUG TSRMLS_C); 1424 ea_debug_printf(EA_DEBUG, "[%d] store_op_array: %s [scope=%s]\n", getpid(), 1449 1425 from->function_name ? from->function_name : "(top)", from->scope ? from->scope->name : "NULL"); 1450 fflush(F_fp);1451 #endif1452 1426 1453 1427 if (from->type == ZEND_INTERNAL_FUNCTION) { … … 1518 1492 to->scope_name = store_string(q->arKey, q->nKeyLength TSRMLS_CC); 1519 1493 to->scope_name_len = q->nKeyLength - 1; 1520 #ifdef DEBUG 1521 pad(TSRMLS_C); fprintf(F_fp, "[%d] find scope '%s' in CG(class_table) save hashkey '%s' [%08x] as to->scope_name\n",1522 getpid(), from->scope->name ? from->scope->name : "NULL", q->arKey, to->scope_name); fflush(F_fp);1523 #endif 1494 1495 ea_debug_pad(EA_DEBUG TSRMLS_C); 1496 ea_debug_printf(EA_DEBUG, "[%d] find scope '%s' in CG(class_table) save hashkey '%s' [%08x] as to->scope_name\n", 1497 getpid(), from->scope->name ? from->scope->name : "NULL", q->arKey, to->scope_name); 1524 1498 break; 1525 1499 } … … 1528 1502 if (to->scope_name == NULL) 1529 1503 { 1530 #ifdef DEBUG 1531 pad(TSRMLS_C); fprintf(F_fp, "[%d] could not find scope '%s' in CG(class_table), saving it to NULL\n", getpid(), from->scope->name ? from->scope->name : "NULL"); fflush(F_fp);1532 #endif 1504 ea_debug_pad(EA_DEBUG TSRMLS_C); 1505 ea_debug_printf(EA_DEBUG, "[%d] could not find scope '%s' in CG(class_table), saving it to NULL\n", 1506 getpid(), from->scope->name ? from->scope->name : "NULL"); 1533 1507 } 1534 1508 } … … 1632 1606 static eaccelerator_class_entry* store_class_entry(zend_class_entry* from TSRMLS_DC) { 1633 1607 eaccelerator_class_entry *to; 1634 /* int i; */1635 1636 1608 EACCELERATOR_ALIGN(MMCG(mem)); 1637 1609 to = (eaccelerator_class_entry*)MMCG(mem); … … 1658 1630 #endif 1659 1631 1632 ea_debug_pad(EA_DEBUG TSRMLS_C); 1633 ea_debug_printf(EA_DEBUG, "[%d] store_class_entry: %s parent was '%s'\n", 1634 getpid(), from->name? from->name : "(top)", from->parent ? from->parent->name : "NULL"); 1660 1635 #ifdef DEBUG 1661 pad(TSRMLS_C);1662 fprintf(F_fp, "[%d] store_class_entry: %s parent was '%s'\n", getpid(), from->name? from->name : "(top)", from->parent ? from->parent->name : "NULL");1663 fflush(F_fp);1664 1636 MMCG(xpad)++; 1665 1637 #endif … … 1730 1702 char *x; 1731 1703 1732 #ifdef DEBUG 1733 pad(TSRMLS_C); fprintf(F_fp, "[%d] eaccelerator_store_int: key='%s'\n", getpid(), key); fflush(F_fp); 1734 #endif 1704 ea_debug_pad(EA_DEBUG TSRMLS_C); 1705 ea_debug_printf(EA_DEBUG, "[%d] eaccelerator_store_int: key='%s'\n", getpid(), key); 1735 1706 1736 1707 MMCG(compress) = 1; … … 1750 1721 q = NULL; 1751 1722 while (c != NULL) { 1752 #ifdef DEBUG 1753 pad(TSRMLS_C); fprintf(F_fp, "[%d] eaccelerator_store_int: class hashkey=", getpid()); binary_print(c->arKey, c->nKeyLength); fflush(F_fp); 1754 #endif 1723 ea_debug_pad(EA_DEBUG TSRMLS_C); 1724 ea_debug_printf(EA_DEBUG, "[%d] eaccelerator_store_int: class hashkey=", getpid()); 1725 ea_debug_binary_print(EA_DEBUG, c->arKey, c->nKeyLength); 1726 1755 1727 EACCELERATOR_ALIGN(MMCG(mem)); 1756 1728 fc = (mm_fc_entry*)MMCG(mem); … … 1777 1749 q = NULL; 1778 1750 while (f != NULL) { 1779 #ifdef DEBUG 1780 pad(TSRMLS_C); fprintf(F_fp, "[%d] eaccelerator_store_int: function hashkey='%s'\n", getpid(), f->arKey); fflush(F_fp);1781 #endif 1751 ea_debug_pad(EA_DEBUG TSRMLS_C); 1752 ea_debug_printf(EA_DEBUG, "[%d] eaccelerator_store_int: function hashkey='%s'\n", getpid(), f->arKey); 1753 1782 1754 EACCELERATOR_ALIGN(MMCG(mem)); 1783 1755 fc = (mm_fc_entry*)MMCG(mem); … … 2062 2034 #endif 2063 2035 2064 #ifdef DEBUG 2065 pad(TSRMLS_C); 2066 fprintf(F_fp, "[%d] restore_op_array: %s\n", getpid(), 2036 ea_debug_pad(EA_DEBUG TSRMLS_C); 2037 ea_debug_printf(EA_DEBUG, "[%d] restore_op_array: %s\n", getpid(), 2067 2038 from->function_name? from->function_name : "(top)"); 2068 fflush(F_fp);2069 #endif2070 2039 2071 2040 if (from->type == ZEND_INTERNAL_FUNCTION) { … … 2156 2125 if (from->scope_name != NULL) 2157 2126 { 2158 char *from_scope_lc = zend_str_tolower_dup(from->scope_name, from->scope_name_len);2159 if (zend_hash_find(CG(class_table), (void *)from_scope_lc, from->scope_name_len+1, (void **)&to->scope) != SUCCESS)2127 char *from_scope_lc = zend_str_tolower_dup(from->scope_name, from->scope_name_len); 2128 if (zend_hash_find(CG(class_table), (void *)from_scope_lc, from->scope_name_len+1, (void **)&to->scope) != SUCCESS) 2160 2129 { 2161 #ifdef DEBUG 2162 pad(TSRMLS_C); fprintf(F_fp, "[%d] can't find '%s' in hash. use MMCG(class_entry).\n", getpid(), from_scope_lc); fflush(F_fp); 2163 #endif 2164 to->scope = MMCG(class_entry); 2130 ea_debug_pad(EA_DEBUG TSRMLS_C); 2131 ea_debug_printf(EA_DEBUG, "[%d] can't find '%s' in hash. use MMCG(class_entry).\n", getpid(), from_scope_lc); 2132 to->scope = MMCG(class_entry); 2165 2133 } 2166 2134 else 2167 2135 { 2168 #ifdef DEBUG 2169 pad(TSRMLS_C); fprintf(F_fp, "[%d] found '%s' in hash\n", getpid(), from_scope_lc); fflush(F_fp); 2170 #endif 2136 ea_debug_pad(EA_DEBUG TSRMLS_C); 2137 ea_debug_printf(EA_DEBUG, "[%d] found '%s' in hash\n", getpid(), from_scope_lc); 2171 2138 to->scope = *(zend_class_entry **)(to->scope); 2172 2139 } … … 2175 2142 else 2176 2143 { 2177 #ifdef DEBUG 2178 pad(TSRMLS_C); fprintf(F_fp, "[%d] from is NULL\n", getpid()); fflush(F_fp); 2179 #endif 2144 ea_debug_pad(EA_DEBUG TSRMLS_C); ea_debug_printf(EA_DEBUG, "[%d] from is NULL\n", getpid()); 2180 2145 if (MMCG(class_entry)) 2181 2146 { … … 2184 2149 for (p = MMCG(class_entry)->parent; p; p = p->parent) 2185 2150 { 2186 #ifdef DEBUG 2187 pad(TSRMLS_C); fprintf(F_fp, "[%d] checking parent '%s' have '%s'\n", getpid(), p->name, fname_lc); fflush(F_fp); 2188 #endif 2189 if (zend_hash_find(&p->function_table, fname_lc, fname_len+1, (void **) &function)==SUCCESS) 2151 ea_debug_pad(EA_DEBUG TSRMLS_C); 2152 ea_debug_printf(EA_DEBUG, "[%d] checking parent '%s' have '%s'\n", getpid(), p->name, fname_lc); 2153 if (zend_hash_find(&p->function_table, fname_lc, fname_len+1, (void **) &function)==SUCCESS) 2190 2154 { 2191 #ifdef DEBUG 2192 pad(TSRMLS_C); fprintf(F_fp, "[%d] '%s' has '%s' of scope '%s'\n", getpid(), p->name, fname_lc, function->common.scope->name); fflush(F_fp);2193 #endif 2155 ea_debug_pad(EA_DEBUG TSRMLS_C); 2156 ea_debug_printf(EA_DEBUG, "[%d] '%s' has '%s' of scope '%s'\n", 2157 getpid(), p->name, fname_lc, function->common.scope->name); 2194 2158 to->scope = function->common.scope; 2195 2159 break; … … 2201 2165 } 2202 2166 2203 #ifdef DEBUG 2204 pad(TSRMLS_C); 2205 fprintf(F_fp, "[%d] %s's scope is '%s'\n", getpid(), 2167 ea_debug_pad(EA_DEBUG TSRMLS_C); 2168 ea_debug_printf(EA_DEBUG, "[%d] %s's scope is '%s'\n", getpid(), 2206 2169 from->function_name ? from->function_name : "(top)", to->scope ? to->scope->name : "NULL"); 2207 fflush(F_fp);2208 #endif2209 #if 02210 if (to->scope != NULL)2211 {2212 unsigned int len = strlen(to->function_name);2213 char *lcname = zend_str_tolower_dup(to->function_name, len);2214 char *lc_to_name = zend_str_tolower_dup(to->scope->name, to->scope->name_length);2215 /*2216 * HOESH: this one probably the old style constructor,2217 * so we set this as the constructor for the scope if2218 * 0) it doesn't exists yet,2219 * or, if the constructor is inherited from the parent:2220 * A) the constructor is internal function2221 * B) the constructor's scope name doesn't match the oparray's scope name2222 *2223 * remember lcname & len can be used as scope name info after the match!2224 */2225 2226 /* segv74: I got a question.2227 *2228 * I think that, this code is reconstructing zend_class_entry thing.2229 * is it right doing this here?2230 *2231 * IMHO, we can do this job in restore_class_entry().2232 * it's not good for readablity, and dosen't have performace gain.2233 */2234 #ifdef DEBUG2235 pad(TSRMLS_C);2236 fprintf(F_fp, " scope: %s[%d], method name: %s[%d] (%d) : to->scope->constructor=0x%08x\n",2237 lcname, to->scope->name_length, lc_to_name, len, memcmp(lc_to_name, lcname, len), to->scope->constructor);2238 fflush(F_fp);2239 #endif2240 if (2241 to->scope->name_length == len &&2242 memcmp(lc_to_name, lcname, len) == 0 &&2243 (2244 to->scope->constructor == NULL || // case 0)2245 to->scope->constructor->type == ZEND_INTERNAL_FUNCTION || // case A)2246 to->scope->constructor->op_array.scope->name_length != len || // case B)2247 memcmp(to->scope->constructor->op_array.scope->name, lcname, len) != 02248 )2249 )2250 {2251 #ifdef DEBUG2252 pad(TSRMLS_C);2253 fprintf(F_fp, "------> matched\n");2254 fflush(F_fp);2255 #endif2256 to->scope->constructor = (zend_function*)to;2257 }2258 /* HOESH: To avoid unnecessary lookups */2259 else if (*lcname == '_' && *(lcname+1) == '_')2260 {2261 if (len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1 &&2262 memcmp(lcname, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)) == 0)2263 {2264 to->scope->constructor = (zend_function*)to;2265 }2266 else if (len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1 &&2267 memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) == 0)2268 {2269 to->scope->destructor = (zend_function*)to;2270 }2271 else if (len == sizeof(ZEND_CLONE_FUNC_NAME)-1 &&2272 memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) == 0)2273 {2274 to->scope->clone = (zend_function*)to;2275 }2276 else if (len == sizeof(ZEND_GET_FUNC_NAME)-1 &&2277 memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)) == 0)2278 {2279 to->scope->__get = (zend_function*)to;2280 }2281 else if (len == sizeof(ZEND_SET_FUNC_NAME)-1 &&2282 memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)) == 0)2283 {2284 to->scope->__set = (zend_function*)to;2285 }2286 else if (len == sizeof(ZEND_CALL_FUNC_NAME)-1 &&2287 memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)) == 0)2288 {2289 to->scope->__call = (zend_function*)to;2290 }2291 }2292 efree(lcname);2293 efree(lc_to_name);2294 }2295 #endif2296 2170 #endif 2297 2171 if (from->type == ZEND_INTERNAL_FUNCTION) 2298 2172 { 2299 zend_class_entry* ce = MMCG(class_entry); 2300 #ifdef DEBUG 2301 pad(TSRMLS_C); fprintf(F_fp, "[%d] [internal function from=%08x,to=%08x] ce='%s' [%08x]\n", getpid(), from, to, ce->name, ce); fflush(F_fp); 2173 zend_class_entry* ce = MMCG(class_entry); 2174 ea_debug_pad(EA_DEBUG TSRMLS_C); 2175 ea_debug_printf(EA_DEBUG, "[%d] [internal function from=%08x,to=%08x] ce='%s' [%08x]\n", 2176 getpid(), from, to, ce->name, ce); 2302 2177 if (ce) 2303 2178 { 2304 pad(TSRMLS_C); fprintf(F_fp, "[%d] ce->parent='%s' [%08x]\n", getpid(), ce->parent->name, ce->parent); fflush(F_fp); 2305 } 2306 #endif 2179 ea_debug_pad(EA_DEBUG TSRMLS_C); 2180 ea_debug_printf(EA_DEBUG, "[%d] ce->parent='%s' [%08x]\n", 2181 getpid(), ce->parent->name, ce->parent); 2182 } 2307 2183 if (ce != NULL && 2308 2184 ce->parent != NULL && … … 2316 2192 function->type == ZEND_INTERNAL_FUNCTION) 2317 2193 { 2318 #ifdef DEBUG 2319 pad(TSRMLS_C); fprintf(F_fp, "[%d] found in function table\n", getpid()); fflush(F_fp); 2320 #endif 2321 ((zend_internal_function*)(to))->handler = ((zend_internal_function*) function)->handler; 2322 } 2323 else 2324 { 2194 ea_debug_pad(EA_DEBUG TSRMLS_C); 2195 ea_debug_printf(EA_DEBUG, "[%d] found in function table\n", getpid()); 2196 ((zend_internal_function*)(to))->handler = ((zend_internal_function*) function)->handler; 2197 } 2198 else 2199 { 2325 2200 /*??? FIXME. I don't know how to fix handler. */ 2326 2201 /* … … 2328 2203 * damaged structure... 2329 2204 */ 2330 #ifdef DEBUG 2331 pad(TSRMLS_C); fprintf(F_fp, "[%d] can't find\n", getpid()); fflush(F_fp); 2332 #endif 2205 ea_debug_pad(EA_DEBUG TSRMLS_C); 2206 ea_debug_printf(EA_DEBUG, "[%d] can't find\n", getpid()); 2333 2207 } 2334 2208 return to; … … 2405 2279 #endif 2406 2280 2281 ea_debug_pad(EA_DEBUG TSRMLS_C); 2282 ea_debug_printf(EA_DEBUG, "[%d] retore_class_entry: %s\n", getpid(), from->name? from->name : "(top)"); 2407 2283 #ifdef DEBUG 2408 pad(TSRMLS_C);2409 fprintf(F_fp, "[%d] retore_class_entry: %s\n", getpid(), from->name? from->name : "(top)");2410 fflush(F_fp);2411 2284 MMCG(xpad)++; 2412 2285 #endif … … 2465 2338 #endif 2466 2339 { 2467 debug_printf("[%d] EACCELERATOR can't restore parent class "2340 ea_debug_error("[%d] EACCELERATOR can't restore parent class " 2468 2341 "\"%s\" of class \"%s\"\n", getpid(), (char*)from->parent, to->name); 2469 2342 to->parent = NULL; … … 2500 2373 else 2501 2374 { 2502 #ifdef DEBUG 2503 pad(TSRMLS_C); fprintf(F_fp, "[%d] parent = NULL\n", getpid()); fflush(F_fp); 2504 #endif 2375 ea_debug_pad(EA_DEBUG TSRMLS_C); 2376 ea_debug_printf(EA_DEBUG, "[%d] parent = NULL\n", getpid()); 2505 2377 to->parent = NULL; 2506 2378 } … … 2986 2858 realname[0] = '\000'; 2987 2859 #endif 2988 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 2989 #ifdef TEST_PERFORMANCE 2860 2990 2861 struct timeval tv_start; 2991 fprintf(F_fp, "[%d] Enter COMPILE\n",getpid()); fflush(F_fp);2992 start_time(&tv_start);2993 #endif 2994 fprintf(F_fp, "[%d] Enter COMPILE\n",getpid()); fflush(F_fp);2995 fprintf(F_fp, "[%d] compile_file: \"%s\"\n",getpid(), file_handle->filename); fflush(F_fp); 2862 ea_debug_printf(EA_TEST_PERFORMANCE, "[%d] Enter COMPILE\n",getpid()); 2863 ea_debug_start_time(&tv_start); 2864 ea_debug_printf(EA_DEBUG, "[%d] Enter COMPILE\n",getpid()); 2865 ea_debug_printf(EA_DEBUG, "[%d] compile_file: \"%s\"\n",getpid(), file_handle->filename); 2866 #ifdef DEBUG 2996 2867 MMCG(xpad)+=2; 2997 2868 #endif 2998 2869 compile_time = time(0); 2999 2870 if (buf.st_mtime >= compile_time && eaccelerator_debug > 0) { 3000 debug_printf("[%d] EACCELERATOR: Warning: \"%s\" is cached but it's mtime is in the future.\n",2871 ea_debug_log("[%d] EACCELERATOR: Warning: \"%s\" is cached but it's mtime is in the future.\n", 3001 2872 getpid(), file_handle->filename); 3002 2873 } … … 3013 2884 !eaccelerator_ok_to_cache(realname TSRMLS_CC)) { 3014 2885 #endif 3015 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 3016 fprintf(F_fp, "\t[%d] compile_file: compiling\n",getpid()); fflush(F_fp); 3017 #endif 2886 ea_debug_printf(EA_DEBUG, "\t[%d] compile_file: compiling\n", getpid()); 3018 2887 t = mm_saved_zend_compile_file(file_handle, type TSRMLS_CC); 3019 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 3020 #ifdef TEST_PERFORMANCE 3021 fprintf(F_fp, "\t[%d] compile_file: end (%ld)\n",getpid(),elapsed_time(&tv_start)); fflush(F_fp); 3022 #else 3023 fprintf(F_fp, "\t[%d] compile_file: end\n",getpid()); fflush(F_fp); 3024 #endif 2888 ea_debug_printf(EA_TEST_PERFORMANCE, "\t[%d] compile_file: end (%ld)\n", getpid(), ea_debug_elapsed_time(&tv_start)); 2889 ea_debug_printf(EA_DEBUG, "\t[%d] compile_file: end\n", getpid()); 2890 #ifdef DEBUG 3025 2891 MMCG(xpad)-=2; 3026 2892 #endif 3027 #if defined(DEBUG) 3028 fprintf(F_fp, "[%d] Leave COMPILE\n",getpid()); fflush(F_fp); 3029 #endif 2893 ea_debug_printf(EA_DEBUG, "[%d] Leave COMPILE\n", getpid()); 3030 2894 return t; 3031 2895 } … … 3045 2909 #endif 3046 2910 if (t != NULL) { 3047 if (eaccelerator_debug > 0) { 3048 debug_printf("[%d] EACCELERATOR hit: \"%s\"\n", getpid(), t->filename); 3049 } 2911 ea_debug_log("[%d] EACCELERATOR hit: \"%s\"\n", getpid(), t->filename); 3050 2912 /* restored from cache */ 3051 2913 … … 3066 2928 */ 3067 2929 } 3068 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 3069 #ifdef TEST_PERFORMANCE 3070 fprintf(F_fp, "\t[%d] compile_file: restored (%ld)\n",getpid(),elapsed_time(&tv_start)); fflush(F_fp); 3071 #else 3072 fprintf(F_fp, "\t[%d] compile_file: restored\n",getpid()); fflush(F_fp); 3073 #endif 2930 ea_debug_printf(EA_TEST_PERFORMANCE, "\t[%d] compile_file: restored (%ld)\n", getpid(), ea_debug_elapsed_time(&tv_start)); 2931 ea_debug_printf(EA_DEBUG, "\t[%d] compile_file: restored\n", getpid()); 2932 #ifdef DEBUG 3074 2933 MMCG(xpad)-=2; 3075 2934 #endif 3076 #if defined(DEBUG) 3077 fprintf(F_fp, "[%d] Leave COMPILE\n",getpid()); fflush(F_fp); 3078 //dprint_compiler_retval(t, 1); 3079 #endif 2935 ea_debug_printf(EA_DEBUG, "[%d] Leave COMPILE\n", getpid()); 3080 2936 return t; 3081 2937 } else { … … 3092 2948 int bailout; 3093 2949 3094 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 3095 fprintf(F_fp, "\t[%d] compile_file: marking\n",getpid()); fflush(F_fp); 2950 ea_debug_printf(EA_DEBUG, "\t[%d] compile_file: marking\n", getpid()); 3096 2951 if (CG(class_table) != EG(class_table)) 3097 2952 { 3098 fprintf(F_fp, "\t[%d] oops, CG(class_table)[%08x] != EG(class_table)[%08x]\n", getpid(), CG(class_table), EG(class_table));3099 //log_hashkeys("CG(class_table)\n", CG(class_table));3100 //log_hashkeys("EG(class_table)\n", EG(class_table));3101 } 3102 else 3103 fprintf(F_fp, "\t[%d] OKAY. That what I thought, CG(class_table)[%08x] == EG(class_table)[%08x]\n", getpid(), CG(class_table), EG(class_table));3104 //log_hashkeys("CG(class_table)\n", CG(class_table));3105 #endif 2953 ea_debug_printf(EA_DEBUG, "\t[%d] oops, CG(class_table)[%08x] != EG(class_table)[%08x]\n", getpid(), CG(class_table), EG(class_table)); 2954 ea_debug_log_hashkeys("CG(class_table)\n", CG(class_table)); 2955 ea_debug_log_hashkeys("EG(class_table)\n", EG(class_table)); 2956 } 2957 else { 2958 ea_debug_printf(EA_DEBUG, "\t[%d] OKAY. That what I thought, CG(class_table)[%08x] == EG(class_table)[%08x]\n", getpid(), CG(class_table), EG(class_table)); 2959 ea_debug_log_hashkeys("CG(class_table)\n", CG(class_table)); 2960 } 3106 2961 3107 2962 zend_hash_init_ex(&tmp_function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); … … 3124 2979 class_table_tail = CG(class_table)->pListTail; 3125 2980 3126 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 3127 #ifdef TEST_PERFORMANCE 3128 fprintf(F_fp, "\t[%d] compile_file: compiling (%ld)\n",getpid(),elapsed_time(&tv_start)); fflush(F_fp); 3129 #else 3130 fprintf(F_fp, "\t[%d] compile_file: compiling tmp_class_table=%d class_table=%d\n", getpid(), tmp_class_table.nNumOfElements, orig_class_table->nNumOfElements); fflush(F_fp); 3131 #endif 3132 #endif 2981 ea_debug_printf(EA_TEST_PERFORMANCE, "\t[%d] compile_file: compiling (%ld)\n",getpid(),ea_debug_elapsed_time(&tv_start)); 2982 ea_debug_printf(EA_DEBUG, "\t[%d] compile_file: compiling tmp_class_table=%d class_table=%d\n", 2983 getpid(), tmp_class_table.nNumOfElements, orig_class_table->nNumOfElements); 3133 2984 if (MMCG(optimizer_enabled) && eaccelerator_mm_instance->optimizer_enabled) {