Improve stack trace when tracking

This commit is contained in:
rfm 2024-12-04 11:00:42 +00:00
parent 815a0d7b20
commit a82e358248

View file

@ -453,6 +453,18 @@ enable()
}
static inline const char *
stackTrace(unsigned skip)
{
NSArray *a = [NSThread callStackSymbols];
if ([a count] > skip)
{
a = [a subarrayWithRange: NSMakeRange(skip, [a count] - skip)];
}
return [[a description] UTF8String];
}
static inline struct trackLink *
find(id o)
@ -530,8 +542,8 @@ findMethods(id o, IMP *dea, IMP *rel, IMP *ret)
GS_MUTEX_UNLOCK(trackLock);
fprintf(stderr, "Tracking ownership - unable to find entry for"
" instance %p of '%s'\n", o, class_getName(c));
NSLog(@"Tracking ownership %p problem at %@",
o, [NSThread callStackSymbols]);
NSLog(@"Tracking ownership %p problem at %s",
o, stackTrace(1));
/* Should never happen because we don't remove class entries, but I suppose
* someone could call the replacement methods directly. The best we can do
@ -586,8 +598,8 @@ findMethods(id o, IMP *dea, IMP *rel, IMP *ret)
}
}
GS_MUTEX_UNLOCK(trackLock);
NSLog(@"Tracking ownership -[%p dealloc] at %@",
self, [NSThread callStackSymbols]);
NSLog(@"Tracking ownership -[%p dealloc] at %s",
self, stackTrace(2));
(*dealloc)(self, _cmd);
}
}
@ -608,8 +620,8 @@ findMethods(id o, IMP *dea, IMP *rel, IMP *ret)
unsigned rc;
rc = (unsigned)[self retainCount];
NSLog(@"Tracking ownership -[%p release] %u->%u at %@",
self, rc, rc-1, [NSThread callStackSymbols]);
NSLog(@"Tracking ownership -[%p release] %u->%u at %s",
self, rc, rc-1, stackTrace(2));
(*release)(self, _cmd);
}
}
@ -632,8 +644,8 @@ findMethods(id o, IMP *dea, IMP *rel, IMP *ret)
rc = (unsigned)[self retainCount];
result = (*retain)(self, _cmd);
NSLog(@"Tracking ownership -[%p retain] %u->%u at %@",
self, rc, (unsigned)[self retainCount], [NSThread callStackSymbols]);
NSLog(@"Tracking ownership -[%p retain] %u->%u at %s",
self, rc, (unsigned)[self retainCount], stackTrace(2));
}
return result;
}
@ -743,8 +755,8 @@ makeLinkForClass(Class c)
l->next = tracked;
tracked = l;
GS_MUTEX_UNLOCK(trackLock);
NSLog(@"Tracking ownership started for class %p at %@",
self, [NSThread callStackSymbols]);
NSLog(@"Tracking ownership started for class %p at %s",
self, stackTrace(1));
}
- (void) trackOwnership
@ -811,8 +823,8 @@ makeLinkForClass(Class c)
li->next = tracked;
tracked = li;
GS_MUTEX_UNLOCK(trackLock);
NSLog(@"Tracking ownership started for instance %p at %@",
self, [NSThread callStackSymbols]);
NSLog(@"Tracking ownership started for instance %p at %s",
self, stackTrace(1));
}
@end