Skip to content

Commit

Permalink
Improve stack trace when tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Dec 4, 2024
1 parent 815a0d7 commit a82e358
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Source/Additions/NSObject+GNUstepBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,18 @@ + (BOOL) shouldCleanUp
}


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)
Expand Down Expand Up @@ -530,8 +542,8 @@ + (BOOL) shouldCleanUp
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
Expand Down Expand Up @@ -586,8 +598,8 @@ - (void) _replacementDealloc
}
}
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);
}
}
Expand All @@ -608,8 +620,8 @@ - (void) _replacementRelease
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);
}
}
Expand All @@ -632,8 +644,8 @@ - (id) _replacementRetain

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;
}
Expand Down Expand Up @@ -743,8 +755,8 @@ + (void) trackOwnership
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
Expand Down Expand Up @@ -811,8 +823,8 @@ - (void) trackOwnership
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
Expand Down

0 comments on commit a82e358

Please sign in to comment.