Added new debugging macros.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3897 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-11 11:07:21 +00:00
parent fb41cc45d4
commit 6d55a1db69
4 changed files with 176 additions and 82 deletions

View file

@ -1,5 +1,5 @@
/* Debugging utilities for GNUStep and OpenStep
Copyright (C) 1997 Free Software Foundation, Inc.
Copyright (C) 1997,1999 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: August 1997
@ -28,20 +28,21 @@
const char*
strerror(int eno)
{
extern char* sys_errlist[];
extern int sys_nerr;
extern char* sys_errlist[];
extern int sys_nerr;
if (eno < 0 || eno >= sys_nerr) {
return("unknown error number");
if (eno < 0 || eno >= sys_nerr)
{
return("unknown error number");
}
return(sys_errlist[eno]);
return(sys_errlist[eno]);
}
#endif
typedef struct {
Class class;
int count;
int lastc;
Class class;
int count;
int lastc;
} table_entry;
static int num_classes = 0;
@ -54,55 +55,63 @@ static BOOL debug_allocation = NO;
BOOL
GSDebugAllocationActive(BOOL active)
{
BOOL old = debug_allocation;
BOOL old = debug_allocation;
debug_allocation = active;
return old;
debug_allocation = active;
return old;
}
void
GSDebugAllocationAdd(Class c)
{
if (debug_allocation) {
int i;
if (debug_allocation)
{
int i;
for (i = 0; i < num_classes; i++) {
if (the_table[i].class == c) {
the_table[i].count++;
return;
for (i = 0; i < num_classes; i++)
{
if (the_table[i].class == c)
{
the_table[i].count++;
return;
}
}
if (num_classes >= table_size) {
int more = table_size + 128;
table_entry* tmp = objc_malloc(more * sizeof(table_entry));
if (num_classes >= table_size)
{
int more = table_size + 128;
table_entry* tmp = objc_malloc(more * sizeof(table_entry));
if (tmp == 0) {
return; /* Argh */
if (tmp == 0)
{
return; /* Argh */
}
if (the_table) {
memcpy(tmp, the_table, num_classes * sizeof(table_entry));
objc_free(the_table);
if (the_table)
{
memcpy(tmp, the_table, num_classes * sizeof(table_entry));
objc_free(the_table);
}
the_table = tmp;
the_table = tmp;
}
the_table[num_classes].class = c;
the_table[num_classes].count = 1;
the_table[num_classes].lastc = 0;
num_classes++;
the_table[num_classes].class = c;
the_table[num_classes].count = 1;
the_table[num_classes].lastc = 0;
num_classes++;
}
}
int
GSDebugAllocationCount(Class c)
{
int i;
int i;
for (i = 0; i < num_classes; i++) {
if (the_table[i].class == c) {
return the_table[i].count;
for (i = 0; i < num_classes; i++)
{
if (the_table[i].class == c)
{
return the_table[i].count;
}
}
return 0;
return 0;
}
/*
@ -114,77 +123,120 @@ GSDebugAllocationCount(Class c)
const char*
GSDebugAllocationList(BOOL difference)
{
int pos = 0;
int i;
static int siz = 0;
static char* buf = 0;
int pos = 0;
int i;
static int siz = 0;
static char *buf = 0;
if (debug_allocation == NO) {
return "Debug allocation system is not active!\n";
if (debug_allocation == NO)
{
return "Debug allocation system is not active!\n";
}
for (i = 0; i < num_classes; i++) {
int val = the_table[i].count;
for (i = 0; i < num_classes; i++)
{
int val = the_table[i].count;
if (difference) {
val -= the_table[i].lastc;
if (difference)
{
val -= the_table[i].lastc;
}
if (val != 0) {
pos += 11 + strlen(the_table[i].class->name);
if (val != 0)
{
pos += 11 + strlen(the_table[i].class->name);
}
}
if (pos == 0) {
if (difference) {
return "There are NO newly allocated or deallocated object!\n";
if (pos == 0)
{
if (difference)
{
return "There are NO newly allocated or deallocated object!\n";
}
else {
return "I can find NO allocated object!\n";
else
{
return "I can find NO allocated object!\n";
}
}
pos++;
pos++;
if (pos > siz) {
if (pos & 0xff) {
pos = ((pos >> 8) + 1) << 8;
if (pos > siz)
{
if (pos & 0xff)
{
pos = ((pos >> 8) + 1) << 8;
}
siz = pos;
if (buf) {
objc_free(buf);
siz = pos;
if (buf)
{
objc_free(buf);
}
buf = objc_malloc(siz);
buf = objc_malloc(siz);
}
if (buf) {
pos = 0;
for (i = 0; i < num_classes; i++) {
int val = the_table[i].count;
if (buf)
{
pos = 0;
for (i = 0; i < num_classes; i++)
{
int val = the_table[i].count;
if (difference) {
val -= the_table[i].lastc;
if (difference)
{
val -= the_table[i].lastc;
}
the_table[i].lastc = the_table[i].count;
the_table[i].lastc = the_table[i].count;
if (val != 0) {
sprintf(&buf[pos], "%s\t%d\n", the_table[i].class->name, val);
pos += strlen(&buf[pos]);
if (val != 0)
{
sprintf(&buf[pos], "%s\t%d\n", the_table[i].class->name, val);
pos += strlen(&buf[pos]);
}
}
}
}
return buf;
return buf;
}
void
GSDebugAllocationRemove(Class c)
{
if (debug_allocation) {
int i;
if (debug_allocation)
{
int i;
for (i = 0; i < num_classes; i++) {
if (the_table[i].class == c) {
the_table[i].count--;
return;
for (i = 0; i < num_classes; i++)
{
if (the_table[i].class == c)
{
the_table[i].count--;
return;
}
}
}
}
NSString*
GSDebugFunctionMsg(const char *func, const char *file, int line, NSString *fmt)
{
NSString *message;
message = [NSString stringWithFormat: @"File %s: %d. In %s %@",
file, line, func, fmt];
return message;
}
NSString*
GSDebugMethodMsg(id obj, SEL sel, const char *file, int line, NSString *fmt)
{
NSString *message;
Class cls = (Class)obj;
char c = '+';
if ([obj isInstance] == YES)
{
c = '-';
cls = [obj class];
}
message = [NSString stringWithFormat: @"File %s: %d. In [%@ %c%@] %@",
file, line, NSStringFromClass(cls), c, NSStringFromSelector(sel), fmt];
return message;
}