debug.cpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.21 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 #include "incls/_precompiled.incl"
00025 #include "incls/_debug.cpp.incl"
00026 
00027 
00028 // definition of boolean flags
00029 
00030 #define MATERIALIZE_BOOLEAN_FLAG(name,value,doc) \
00031   bool name = value; 
00032 
00033 APPLY_TO_BOOLEAN_FLAGS(MATERIALIZE_BOOLEAN_FLAG,MATERIALIZE_BOOLEAN_FLAG)
00034 
00035 
00036 // definition of integer flags
00037 
00038 #define MATERIALIZE_INTEGER_FLAG(name,value,doc) \
00039   int name = value; 
00040 
00041 APPLY_TO_INTEGER_FLAGS(MATERIALIZE_INTEGER_FLAG,MATERIALIZE_INTEGER_FLAG)
00042 
00043 
00044 // boolean flag table
00045 
00046 struct boolFlag {
00047   char* name;
00048   bool* value_ptr;
00049   bool  default_value;
00050   char* doc;
00051 };
00052 
00053 
00054 #ifdef PRODUCT
00055 #define MATERIALIZE_BOOLEAN_FLAG_STRUCT_FOR_DEVELOP(name,value,doc) \
00056   // do nothing - flag doesn't show up in table in product version
00057 #else
00058 #define MATERIALIZE_BOOLEAN_FLAG_STRUCT_FOR_DEVELOP(name,value,doc) \
00059   { XSTR(name), &name, value, doc },
00060 #endif
00061 
00062 #define MATERIALIZE_BOOLEAN_FLAG_STRUCT_FOR_PRODUCT(name,value,doc) \
00063   { XSTR(name), &name, value, doc },
00064 
00065 static boolFlag boolTable[] = {
00066   APPLY_TO_BOOLEAN_FLAGS(MATERIALIZE_BOOLEAN_FLAG_STRUCT_FOR_DEVELOP,MATERIALIZE_BOOLEAN_FLAG_STRUCT_FOR_PRODUCT) 
00067   {0, NULL, false, NULL } // indicates end of table
00068 };
00069 
00070 
00071 inline bool str_equal(char* s, char* q, int len) {
00072   // s is null terminated, q is not!
00073   if (strlen(s) != (unsigned int) len) return false;
00074   return strncmp(s, q, len) == 0;
00075 }
00076 
00077 
00078 bool debugFlags::boolAt(char* name, int len, bool* value) {
00079   for (boolFlag* current = &boolTable[0]; current->name; current++) {
00080     if (str_equal(current->name, name, len)) {
00081       *value = *current->value_ptr;
00082       return true;
00083     }
00084   }
00085   return false;
00086 }
00087 
00088 
00089 bool debugFlags::boolAtPut(char* name, int len, bool* value) {
00090   if (str_equal("TracePrims", name, len)) {
00091     TraceOopPrims             = *value;
00092     TraceDoublePrims          = *value;
00093     TraceByteArrayPrims       = *value;
00094     TraceDoubleByteArrayPrims = *value;
00095     TraceObjArrayPrims        = *value;
00096     TraceSmiPrims             = *value;
00097     TraceProxyPrims           = *value;
00098     TraceBehaviorPrims        = *value;
00099     TraceBlockPrims           = *value;
00100     TraceDebugPrims           = *value;
00101     TraceSystemPrims          = *value;
00102     TraceProcessPrims         = *value;
00103     TraceCallBackPrims        = *value;
00104     TraceMethodPrims          = *value;
00105     TraceMixinPrims           = *value;
00106     *value = !*value;
00107     return true;
00108   }
00109   for (boolFlag* current = &boolTable[0]; current->name; current++) {
00110     if (str_equal(current->name, name, len)) {
00111       bool old_value = *current->value_ptr;
00112       *current->value_ptr = *value; 
00113       *value = old_value;
00114       return true;
00115     }
00116   }
00117   return false;
00118 }
00119 
00120 
00121 // integer flag table
00122 
00123 struct intFlag {
00124   char* name;
00125   int*  value_ptr;
00126   int   default_value;
00127   char* doc;
00128 };
00129 
00130 
00131 #ifdef PRODUCT
00132 #define MATERIALIZE_INTEGER_FLAG_STRUCT_FOR_DEVELOP(name,value,doc) \
00133   // do nothing - flag doesn't show up in table in product version
00134 #else
00135 #define MATERIALIZE_INTEGER_FLAG_STRUCT_FOR_DEVELOP(name,value,doc) \
00136   { XSTR(name), &name, value, doc },
00137 #endif
00138 
00139 #define MATERIALIZE_INTEGER_FLAG_STRUCT_FOR_PRODUCT(name,value,doc) \
00140   { XSTR(name), &name, value, doc },
00141 
00142 static intFlag intTable[] = {
00143   APPLY_TO_INTEGER_FLAGS(MATERIALIZE_INTEGER_FLAG_STRUCT_FOR_DEVELOP,MATERIALIZE_INTEGER_FLAG_STRUCT_FOR_PRODUCT) 
00144   {0, NULL, 0, NULL } // indicates end of table
00145 };
00146 
00147 
00148 bool debugFlags::intAt(char* name, int len, int* value) {
00149   for (intFlag* current = &intTable[0]; current->name; current++) {
00150     if (str_equal(current->name, name, len)) {
00151       *value = *current->value_ptr;
00152       return true;
00153     }
00154   }
00155   return false;
00156 }
00157 
00158 
00159 bool debugFlags::intAtPut(char* name, int len, int* value) {
00160   for (intFlag* current = &intTable[0]; current->name; current++) {
00161     if (str_equal(current->name, name, len)) {
00162       int old_value = *current->value_ptr;
00163       *current->value_ptr = *value; 
00164       *value = old_value;
00165       return true;
00166     }
00167   }
00168   return false;  
00169 }
00170 
00171 
00172 // printing
00173 
00174 void debugFlags::printFlags() {
00175   for (boolFlag* b = &boolTable[0]; b->name; b++)
00176     lprintf("%30s = %s\n", b->name, *b->value_ptr ? "true" : "false");
00177   for (intFlag* i = &intTable[0]; i->name; i++)
00178     lprintf("%30s = %d\n", i->name, *i->value_ptr);
00179 }
00180 
00181 
00182 void debugFlags::print_on(outputStream* st) {
00183   // Boolean flags
00184   for (boolFlag* b = &boolTable[0]; b->name; b++)
00185     st->print_cr("%s%s",  *b->value_ptr ? "+" : "-");
00186 
00187   // Integer flags
00188   for (intFlag* i = &intTable[0]; i->name; i++)
00189     st->print_cr("%s=%d",  i->name, *b->value_ptr);
00190 }
00191 
00192 
00193 void print_diff_on(outputStream* st) {
00194   // Boolean flags
00195   for (boolFlag* b = &boolTable[0]; b->name; b++) {
00196     if (*b->value_ptr != b->default_value)
00197       st->print_cr("%s%s",  *b->value_ptr ? "+" : "-");
00198   }
00199 
00200   // Integer flags
00201   for (intFlag* i = &intTable[0]; i->name; i++) {
00202     if (*b->value_ptr != b->default_value)
00203       st->print_cr("%s=%d",  i->name, *b->value_ptr);
00204   }
00205 }
00206 
00207 
00208 bool BeingDebugged = false;

Generated on Mon Oct 9 13:37:08 2006 for Strongtalk VM by  doxygen 1.4.7