mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-24 01:11:01 +00:00
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:
parent
fb41cc45d4
commit
6d55a1db69
4 changed files with 176 additions and 82 deletions
|
@ -1,3 +1,9 @@
|
|||
Thu Mar 11 10:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSDebug.m: Added two new functions for logging messags.
|
||||
* Source/include/NSDebug.h: Added four new logging macros.
|
||||
* Source/NSBundle.m: Updated to use new NSDebugMLLog() macro.
|
||||
|
||||
Wed Mar 10 09:54:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/FastMap.x: FastMapNodeForKey() - special case for empty map
|
||||
|
|
|
@ -48,7 +48,7 @@ extern int errno;
|
|||
*
|
||||
* GSDebugAllocationList()
|
||||
* Returns a newline separated list of the classes which
|
||||
* have nstances allocated, and the instance counts.
|
||||
* have instances allocated, and the instance counts.
|
||||
* If 'changeFlag' is YES then the list gives the number
|
||||
* of instances allocated/deallocated sine the function
|
||||
* was last called.
|
||||
|
@ -61,6 +61,11 @@ extern void GSDebugAllocationRemove(Class c);
|
|||
extern BOOL GSDebugAllocationActive(BOOL active);
|
||||
extern int GSDebugAllocationCount(Class c);
|
||||
extern const char* GSDebugAllocationList(BOOL changeFlag);
|
||||
|
||||
extern NSString* GSDebugFunctionMsg(const char *func, const char *file,
|
||||
int line, NSString *fmt);
|
||||
extern NSString* GSDebugMethodMsg(id obj, SEL sel, const char *file,
|
||||
int line, NSString *fmt);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -90,6 +95,13 @@ extern const char* GSDebugAllocationList(BOOL changeFlag);
|
|||
You can also change the active debug levels under your programs control -
|
||||
NSProcessInfo has a [-debugSet] method that returns the mutable set that
|
||||
contains the active debug levels - your program can modify this set.
|
||||
|
||||
As a convenience, there are four more logging macros you can use -
|
||||
NSDebugFLog(), NSDebugFLLog(), NSDebugMLog() and NSDebugMLLog().
|
||||
These are the same as the other macros, but are specifically for use in
|
||||
either functions or methods and prepend information about the file, line
|
||||
and either function or class/method in which the message was generated.
|
||||
|
||||
*/
|
||||
#ifdef DEBUG
|
||||
#include <Foundation/NSObjCRuntime.h>
|
||||
|
@ -100,9 +112,33 @@ extern const char* GSDebugAllocationList(BOOL changeFlag);
|
|||
#define NSDebugLog(format, args...) \
|
||||
do { if (GSDebugSet(@"dflt") == YES) \
|
||||
NSLog(format, ## args); } while (0)
|
||||
#define NSDebugFLLog(level, format, args...) \
|
||||
do { if (GSDebugSet(level) == YES) { \
|
||||
NSString *fmt = GSDebugFunctionMsg( \
|
||||
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
|
||||
NSLog(fmt, ## args); }} while (0)
|
||||
#define NSDebugFLog(format, args...) \
|
||||
do { if (GSDebugSet(@"dflt") == YES) { \
|
||||
NSString *fmt = GSDebugFunctionMsg( \
|
||||
__PRETTY_FUNCTION__, __FILE__, __LINE__, format); \
|
||||
NSLog(fmt, ## args); }} while (0)
|
||||
#define NSDebugMLLog(level, format, args...) \
|
||||
do { if (GSDebugSet(level) == YES) { \
|
||||
NSString *fmt = GSDebugMethodMsg( \
|
||||
self, _cmd, __FILE__, __LINE__, format); \
|
||||
NSLog(fmt, ## args); }} while (0)
|
||||
#define NSDebugMLog(format, args...) \
|
||||
do { if (GSDebugSet(@"dflt") == YES) { \
|
||||
NSString *fmt = GSDebugMethodMsg( \
|
||||
self, _cmd, __FILE__, __LINE__, format); \
|
||||
NSLog(fmt, ## args); }} while (0)
|
||||
#else
|
||||
#define NSDebugLLog(level, format, args...)
|
||||
#define NSDebugLog(format, args...)
|
||||
#define NSDebugFLLog(level, format, args...)
|
||||
#define NSDebugFLog(format, args...)
|
||||
#define NSDebugMLLog(level, format, args...)
|
||||
#define NSDebugMLog(format, args...)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -294,7 +294,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
|||
if ([s hasSuffix: @"_obj"])
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
|
||||
NSDebugLLog(@"NSBundle", @"(NSBundle): Found main in %@\n", path);
|
||||
NSDebugMLLog(@"NSBundle", @"Found main in %@\n", path);
|
||||
/* We do alloc and init separately so initWithPath: knows
|
||||
we are the _mainBundle */
|
||||
_mainBundle = [NSBundle alloc];
|
||||
|
@ -377,7 +377,7 @@ _bundle_load_callback(Class theClass, Category *theCategory)
|
|||
|
||||
if (stat([path cString], &statbuf) != 0)
|
||||
{
|
||||
NSDebugLLog(@"NSBundle", @"Could not access path %s for bundle", [path cString]);
|
||||
NSDebugMLLog(@"NSBundle", @"Could not access path %s for bundle", [path cString]);
|
||||
//[self dealloc];
|
||||
//return nil;
|
||||
}
|
||||
|
|
210
Source/NSDebug.m
210
Source/NSDebug.m
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue