Changeset 113

Show
Ignore:
Timestamp:
07/06/05 16:52:36 (3 years ago)
Author:
zoeloelip
Message:

* Documented namespace option
* New debug/log code. Make the code a lot cleaner and easier

for the user to debug eaccelerator.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r112 r113  
     12005-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 
    162005-06-27 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
    27        * Fixed a buffer overflow in eaccelerator.c and cache.c. A string longer 
  • eaccelerator/trunk/config.m4

    r101 r113  
    9393]) 
    9494 
     95AC_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 
    95102dnl PHP_BUILD_SHARED 
    96103if test "$PHP_EACCELERATOR" != "no"; then 
     
    130137  if test "$eaccelerator_inode" = "yes"; then 
    131138    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]) 
    132142  fi 
    133143 
  • eaccelerator/trunk/debug.c

    r64 r113  
    44   +----------------------------------------------------------------------+ 
    55   | Copyright (c) 2004 - 2005 eAccelerator                               | 
    6    | http://eaccelerator.net                                                     | 
     6   | http://eaccelerator.net                                              | 
    77   +----------------------------------------------------------------------+ 
    88   | This program is free software; you can redistribute it and/or        | 
     
    2424   +----------------------------------------------------------------------+ 
    2525   | Author(s): Dmitry Stogov <dstogov@users.sourceforge.net>             | 
     26   |            Bart Vanbrabant <zoeloelip@users.sourceforge.net>         | 
    2627   +----------------------------------------------------------------------+ 
    2728   $Id$ 
     
    2930 
    3031#include "eaccelerator.h" 
     32 
     33#ifdef HAVE_EACCELERATOR 
     34 
    3135#include "debug.h" 
    3236#include <ctype.h> 
    3337#include <stdio.h> 
    3438 
    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); 
     39FILE *F_fp = NULL; 
     40long eaccelerator_debug = 0; 
     41 
     42/** 
     43 * Init the debug system. This must be called before any debug 
     44 * functions are used. 
     45 */ 
     46void 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 */ 
     66void 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 */ 
     78void 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); 
    10587 
    10688#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 */ 
     101void 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 
     128void 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 
     143void ea_debug_printf (long debug_level, char *format, ...) 
     144
     145
     146#endif 
     147 
     148/** 
     149 * Put a debug message 
     150 */ 
     151#ifdef DEBUG 
     152void 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 
     160void ea_debug_put (long debug_level, char *message) 
     161
     162
     163#endif 
     164 
     165/** 
     166 * Print a binary message 
     167 */ 
     168#ifdef DEBUG 
     169void 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 
     180void 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 
     189void 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 
     209void 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 
     218void 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 
     228void ea_debug_pad (long debug_level TSRMLS_DC) 
     229
     230
     231#endif 
     232 
     233void ea_debug_start_time (struct timeval *tvstart) 
     234
     235    gettimeofday (tvstart, NULL); 
     236
     237 
     238long 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  
    44   +----------------------------------------------------------------------+ 
    55   | Copyright (c) 2004 - 2005 eAccelerator                               | 
    6    | http://eaccelerator.net                                                     | 
     6   | http://eaccelerator.net                                              | 
    77   +----------------------------------------------------------------------+ 
    88   | This program is free software; you can redistribute it and/or        | 
     
    2323   | A copy is availble at http://www.gnu.org/copyleft/gpl.txt            | 
    2424   +----------------------------------------------------------------------+ 
    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>                 | 
    2627   +----------------------------------------------------------------------+ 
    2728   $Id$ 
     
    3536#include "zend_extensions.h" 
    3637 
    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 
     58void ea_debug_init (TSRMLS_D); 
     59void ea_debug_shutdown (); 
     60void ea_debug_error (char *format, ...); 
     61void ea_debug_pad (long debug_level TSRMLS_DC); 
     62void ea_debug_log (char *format, ...); 
     63void ea_debug_binary_print (long debug_level, char *p, int len); 
     64void ea_debug_put (long debug_level, char *message); 
     65void ea_debug_log_hashkeys (char *p, HashTable * ht); 
     66 
     67void ea_debug_start_time (struct timeval *tvstart); 
     68long ea_debug_elapsed_time (struct timeval *tvstart); 
    4369 
    4470#endif /* INCLUDED_DEBUG_H */ 
  • eaccelerator/trunk/eaccelerator.c

    r112 r113  
    44   +----------------------------------------------------------------------+ 
    55   | Copyright (c) 2004 - 2005 eAccelerator                               | 
    6    | http://eaccelerator.net                                                     | 
     6   | http://eaccelerator.net                                              | 
    77   +----------------------------------------------------------------------+ 
    88   | This program is free software; you can redistribute it and/or        | 
     
    6565#endif 
    6666 
    67 /*??? 
    68 #ifdef HAVE_SCHED_H 
    69 #  include <sched.h> 
    70 #endif 
    71 */ 
    72  
    7367#include "php.h" 
    7468#include "php_ini.h" 
     
    9892static long eaccelerator_shm_ttl = 0; 
    9993static long eaccelerator_shm_prune_period = 0; 
    100 static long eaccelerator_debug = 0
     94extern long eaccelerator_debug
    10195static zend_bool eaccelerator_check_mtime = 1; 
    10296static zend_bool eaccelerator_scripts_shm_only = 0; 
     
    114108int binary_zend_version; 
    115109 
    116 FILE *F_fp; 
    117  
    118110#ifdef ZEND_ENGINE_2 
    119111/* pointer to the properties_info hashtable destructor */ 
     
    124116static zend_op_array *(*mm_saved_zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC); 
    125117 
    126 #if defined(PROFILE_OPCODES) || defined(WITH_EACCELERATOR_EXECUTOR) 
     118#if defined(DEBUG) || defined(WITH_EACCELERATOR_EXECUTOR) 
    127119static void (*mm_saved_zend_execute)(zend_op_array *op_array TSRMLS_DC); 
    128120#endif 
     
    290282    return FAILURE; 
    291283  } 
    292 #ifdef DEBUG 
    293284#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()); 
    299288#endif 
    300289#ifdef ZTS 
     
    332321#endif 
    333322      MM *mm = eaccelerator_mm_instance->mm; 
    334 #ifdef DEBUG 
    335323#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()); 
    341327#endif 
    342328#ifdef ZTS 
     
    352338 
    353339/******************************************************************************/ 
    354 /* Prepare values to cache them                                                                                          */ 
     340/* Prepare values to cache them                                               */ 
    355341/******************************************************************************/ 
    356342 
     
    936922/******************************************************************************/ 
    937923/* Functions to calculate the size of different structure that a compiled php */ 
    938 /* script contains.                                                                                                                      */ 
     924/* script contains.                                                           */ 
    939925/******************************************************************************/ 
    940926 
     
    10301016        zend_class_entry *ce = zv->value.obj.ce; 
    10311017        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()); 
    10331019          zend_bailout(); 
    10341020        } 
    10351021        while (ce != NULL) { 
    10361022          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()); 
    10381024            zend_bailout(); 
    10391025          } 
     
    10501036      return; 
    10511037    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()); 
    10531039      zend_bailout(); 
    10541040    default: 
     
    10691055    MMCG(mem) += sizeof(eaccelerator_op_array); 
    10701056  } 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); 
    10721058    zend_bailout(); 
    10731059  } 
     
    11591145/* Calculate the size of a class entry */ 
    11601146static void calc_class_entry(zend_class_entry* from TSRMLS_DC) { 
    1161 /*  int i; */ 
    1162  
    11631147  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); 
    11651149    zend_bailout(); 
    11661150  } 
    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 */ 
    11741151  EACCELERATOR_ALIGN(MMCG(mem)); 
    11751152  MMCG(mem) += sizeof(eaccelerator_class_entry); 
     
    14441421  zend_op *end; 
    14451422 
    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(), 
    14491425    from->function_name ? from->function_name : "(top)", from->scope ? from->scope->name : "NULL"); 
    1450   fflush(F_fp); 
    1451 #endif 
    14521426 
    14531427  if (from->type == ZEND_INTERNAL_FUNCTION) { 
     
    15181492        to->scope_name = store_string(q->arKey, q->nKeyLength TSRMLS_CC); 
    15191493        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); 
    15241498        break; 
    15251499      } 
     
    15281502    if (to->scope_name == NULL) 
    15291503    { 
    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"); 
    15331507    } 
    15341508  } 
     
    16321606static eaccelerator_class_entry* store_class_entry(zend_class_entry* from TSRMLS_DC) { 
    16331607  eaccelerator_class_entry *to; 
    1634 /*  int i; */ 
    1635  
    16361608  EACCELERATOR_ALIGN(MMCG(mem)); 
    16371609  to = (eaccelerator_class_entry*)MMCG(mem); 
     
    16581630#endif 
    16591631 
     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"); 
    16601635#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); 
    16641636  MMCG(xpad)++; 
    16651637#endif 
     
    17301702  char *x; 
    17311703 
    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); 
    17351706 
    17361707  MMCG(compress) = 1; 
     
    17501721  q = NULL; 
    17511722  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 
    17551727    EACCELERATOR_ALIGN(MMCG(mem)); 
    17561728    fc = (mm_fc_entry*)MMCG(mem); 
     
    17771749  q = NULL; 
    17781750  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 
    17821754    EACCELERATOR_ALIGN(MMCG(mem)); 
    17831755    fc = (mm_fc_entry*)MMCG(mem); 
     
    20622034#endif 
    20632035 
    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(), 
    20672038    from->function_name? from->function_name : "(top)"); 
    2068   fflush(F_fp); 
    2069 #endif 
    20702039 
    20712040  if (from->type == ZEND_INTERNAL_FUNCTION) { 
     
    21562125  if (from->scope_name != NULL) 
    21572126  { 
    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) 
    21602129    { 
    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); 
    21652133    } 
    21662134    else 
    21672135    { 
    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); 
    21712138      to->scope = *(zend_class_entry **)(to->scope); 
    21722139    } 
     
    21752142  else 
    21762143  { 
    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()); 
    21802145    if (MMCG(class_entry)) 
    21812146    { 
     
    21842149      for (p = MMCG(class_entry)->parent; p; p = p->parent) 
    21852150      { 
    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) 
    21902154        { 
    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); 
    21942158          to->scope = function->common.scope; 
    21952159          break; 
     
    22012165  } 
    22022166 
    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(), 
    22062169    from->function_name ? from->function_name : "(top)", to->scope ? to->scope->name : "NULL"); 
    2207   fflush(F_fp); 
    2208 #endif 
    2209 #if 0 
    2210         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 if 
    2218                  * 0) it doesn't exists yet, 
    2219                  * or, if the constructor is inherited from the parent: 
    2220                  * A) the constructor is internal function 
    2221                  * B) the constructor's scope name doesn't match the oparray's scope name 
    2222                  * 
    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 DEBUG 
    2235   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 #endif 
    2240                 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) != 0 
    2248                                 ) 
    2249                         ) 
    2250                 { 
    2251 #ifdef DEBUG 
    2252   pad(TSRMLS_C); 
    2253   fprintf(F_fp, "------>    matched\n"); 
    2254   fflush(F_fp); 
    2255 #endif 
    2256                         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 #endif 
    22962170#endif 
    22972171  if (from->type == ZEND_INTERNAL_FUNCTION) 
    22982172  { 
    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); 
    23022177    if (ce) 
    23032178    { 
    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    } 
    23072183    if (ce != NULL && 
    23082184                ce->parent != NULL && 
     
    23162192                function->type == ZEND_INTERNAL_FUNCTION) 
    23172193        { 
    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    { 
    23252200      /*??? FIXME. I don't know how to fix handler. */ 
    23262201                /* 
     
    23282203                 * damaged structure... 
    23292204                 */ 
    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()); 
    23332207    } 
    23342208    return to; 
     
    24052279#endif 
    24062280 
     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)"); 
    24072283#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); 
    24112284  MMCG(xpad)++; 
    24122285#endif 
     
    24652338#endif 
    24662339    { 
    2467       debug_printf("[%d] EACCELERATOR can't restore parent class " 
     2340      ea_debug_error("[%d] EACCELERATOR can't restore parent class " 
    24682341          "\"%s\" of class \"%s\"\n", getpid(), (char*)from->parent, to->name); 
    24692342      to->parent = NULL; 
     
    25002373  else 
    25012374  { 
    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()); 
    25052377    to->parent = NULL; 
    25062378  } 
     
    29862858  realname[0] = '\000'; 
    29872859#endif 
    2988 #if defined(DEBUG) || defined(TEST_PERFORMANCE) 
    2989 #ifdef TEST_PERFORMANCE 
     2860 
    29902861  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 
    29962867  MMCG(xpad)+=2; 
    29972868#endif 
    29982869  compile_time = time(0); 
    29992870  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",  
    30012872                getpid(), file_handle->filename); 
    30022873  } 
     
    30132884      !eaccelerator_ok_to_cache(realname TSRMLS_CC)) { 
    30142885#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()); 
    30182887    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 
    30252891    MMCG(xpad)-=2; 
    30262892#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()); 
    30302894    return t; 
    30312895  } 
     
    30452909#endif 
    30462910  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); 
    30502912    /* restored from cache */ 
    30512913 
     
    30662928*/ 
    30672929    } 
    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 
    30742933    MMCG(xpad)-=2; 
    30752934#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()); 
    30802936    return t; 
    30812937  } else { 
     
    30922948    int bailout; 
    30932949 
    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()); 
    30962951    if (CG(class_table) != EG(class_table)) 
    30972952    { 
    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    } 
    31062961 
    31072962    zend_hash_init_ex(&tmp_function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1, 0); 
     
    31242979    class_table_tail = CG(class_table)->pListTail; 
    31252980 
    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); 
    31332984    if (MMCG(optimizer_enabled) && eaccelerator_mm_instance->optimizer_enabled) {