Resolve symbols using dladdr() if it exists.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31263 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
theraven 2010-09-09 14:22:45 +00:00
parent c4159475b4
commit 9c0b83c8a9

View file

@ -39,6 +39,9 @@
#else #else
# include <objc/objc-load.h> # include <objc/objc-load.h>
#endif #endif
#ifdef __GNUSTEP_RUNTIME__
# include <objc/hooks.h>
#endif
#include "objc-load.h" #include "objc-load.h"
#import "Foundation/NSException.h" #import "Foundation/NSException.h"
@ -249,6 +252,9 @@ GSPrivateUnloadModule(FILE *errorStream,
#ifdef __MINGW__ #ifdef __MINGW__
// FIXME: We can probably get rid of this now - MinGW should include a working
// dladdr() wrapping this function, so we no longer need a Windows-only code
// path
NSString * NSString *
GSPrivateSymbolPath(Class theClass, Category *theCategory) GSPrivateSymbolPath(Class theClass, Category *theCategory)
{ {
@ -264,13 +270,27 @@ GSPrivateSymbolPath(Class theClass, Category *theCategory)
} }
return s; return s;
} }
#elif LINKER_GETSYMBOL
NSString *GSPrivateSymbolPath(Class theClass, Category *theCategory)
{
void *addr = (NULL == theCategory) ? (void*)theClass : (void*)theCategory;
Dl_info info;
// This is correct: dladdr() does the opposite thing to all other UNIX
// functions.
if (0 == dladdr(addr, &info))
{
return nil;
}
return [NSString stringWithUTF8String: info.dli_fname];
}
#else #else
NSString * NSString *
GSPrivateSymbolPath(Class theClass, Category *theCategory) GSPrivateSymbolPath(Class theClass, Category *theCategory)
{ {
const char *ret; const char *ret;
char buf[125], *p = buf; char buf[125], *p = buf;
int len = strlen(theClass->name); const char *className = class_getName(theClass);
int len = strlen(className);
if (theCategory == NULL) if (theCategory == NULL)
{ {
@ -286,8 +306,7 @@ GSPrivateSymbolPath(Class theClass, Category *theCategory)
} }
memcpy(p, "__objc_class_name_", sizeof(char)*18); memcpy(p, "__objc_class_name_", sizeof(char)*18);
memcpy(&p[18*sizeof(char)], theClass->name, memcpy(&p[18*sizeof(char)], className, strlen(className) + 1);
strlen(theClass->name) + 1);
} }
else else
{ {