Improve debug

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29874 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-03-08 09:27:48 +00:00
parent ef0c9453f8
commit 42db2fdf50
5 changed files with 62 additions and 15 deletions

View file

@ -1,3 +1,13 @@
2010-03-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSObject.m:
* Source/Additions/GSObjCRuntime.m:
* Documentation/Base.gsdoc:
* Headers/Additions/GNUstepBase/GSObjCRuntime.h:
Add GNUSTEP_BEHAVIOR_DEBUG enovironment variable to turn on logging
of the use of behaviors/overrides of class methds by a list of
methods from another class.
2010-03-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSArray.m: Re-remove [GSMutableArray count] (GSMutableArray

View file

@ -388,6 +388,13 @@ notice and this notice are preserved.
or you want to use an alternative config file for some reason.
</p>
</desc>
<term>GNUSTEP_BEHAVIOR_DEBUG</term>
<desc>
A boolean (YES or NO) which can be used to turn on debug
logging (to stderr) of the GSObjCRuntime functions to
add/override methods in a class using a list of methods
from another class.
</desc>
<term>HOMEDRIVE</term>
<desc>
<p>

View file

@ -176,6 +176,10 @@ GSObjCAddClassBehavior(Class receiver, Class behavior);
GS_EXPORT void
GSObjCAddClassOverride(Class receiver, Class override);
/** Turn on (YES), off (NO) or test (-1) behavior debugging.
*/
GS_EXPORT BOOL GSObjCBehaviorDebug(int setget);
GS_EXPORT NSValue *
GSObjCMakeClass(NSString *name, NSString *superName, NSDictionary *iVars);

View file

@ -477,24 +477,36 @@ GSObjCAddClasses(NSArray *classes)
static int behavior_debug = 0;
static BOOL behavior_debug = NO;
void
BOOL
GSObjCBehaviorDebug(int i)
{
behavior_debug = i;
BOOL old = behavior_debug;
if (i == YES)
{
behavior_debug = YES;
}
else if (i == NO)
{
behavior_debug = NO;
}
return old;
}
void
GSObjCAddMethods(Class cls, Method *list, BOOL replace)
{
unsigned int index = 0;
char c;
Method m;
if (cls == 0 || list == 0)
{
return;
}
c = class_isMetaClass(cls) ? '+' : '-';
while ((m = list[index++]) != NULL)
{
@ -507,15 +519,19 @@ GSObjCAddMethods(Class cls, Method *list, BOOL replace)
*/
if (YES == class_addMethod(cls, n, i, t))
{
BDBGPrintf(" added %s\n", sel_getName(n));
BDBGPrintf(" added %c%s\n", c, sel_getName(n));
}
else if (YES == replace)
{
/* If we want to replace an existing implemetation ...
*/
method_setImplementation(class_getInstanceMethod(cls, n), i);
BDBGPrintf(" replaced %s\n", sel_getName(n));
BDBGPrintf(" replaced %c%s\n", c, sel_getName(n));
}
else
{
BDBGPrintf(" skipped %c%s\n", c, sel_getName(n));
}
}
}
@ -806,13 +822,13 @@ GSObjCAddClassBehavior(Class receiver, Class behavior)
}
BDBGPrintf("Adding behavior to class %s\n", class_getName(receiver));
BDBGPrintf(" instance methods from %s\n", class_getName(behavior));
/* Add instance methods */
methods = class_copyMethodList(behavior, &count);
BDBGPrintf(" instance methods from %s %u\n", class_getName(behavior), count);
if (methods == NULL)
{
BDBGPrintf(" none.\n");
BDBGPrintf(" none.\n");
}
else
{
@ -821,11 +837,11 @@ GSObjCAddClassBehavior(Class receiver, Class behavior)
}
/* Add class methods */
BDBGPrintf(" class methods from %s\n", class_getName(behavior));
methods = class_copyMethodList(object_getClass(behavior), &count);
BDBGPrintf(" class methods from %s %u\n", class_getName(behavior), count);
if (methods == NULL)
{
BDBGPrintf(" none.\n");
BDBGPrintf(" none.\n");
}
else
{
@ -868,21 +884,28 @@ GSObjCAddClassOverride(Class receiver, Class override)
}
BDBGPrintf("Adding override to class %s\n", class_getName(receiver));
BDBGPrintf(" instance methods from %s\n", class_getName(override));
/* Add instance methods */
methods = class_copyMethodList(override, &count);
if (methods != NULL)
BDBGPrintf(" instance methods from %s %u\n", class_getName(override), count);
if (methods == NULL)
{
BDBGPrintf(" none.\n");
}
else
{
GSObjCAddMethods (receiver, methods, YES);
free(methods);
}
/* Add class methods */
BDBGPrintf("Adding class methods from %s\n",
class_getName(object_getClass(override)));
methods = class_copyMethodList(object_getClass(override), &count);
if (methods != NULL)
BDBGPrintf(" class methods from %s %u\n", class_getName(override), count);
if (methods == NULL)
{
BDBGPrintf(" none.\n");
}
else
{
GSObjCAddMethods (object_getClass(receiver), methods, YES);
free(methods);

View file

@ -995,7 +995,6 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
fedisableexcept(FE_INVALID);
#endif
#ifdef HAVE_LOCALE_H
GSSetLocaleC(LC_ALL, ""); // Set up locale from environment.
#endif
@ -1003,6 +1002,10 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak));
// Create the global lock
gnustep_global_lock = [NSRecursiveLock new];
// Behavior debugging
GSObjCBehaviorDebug(GSPrivateEnvironmentFlag("GNUSTEP_BEHAVIOR_DEBUG",
GSObjCBehaviorDebug(-1)));
// Zombie management stuff.
zombieMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSNonOwnedPointerMapValueCallBacks, 0);