diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/Makefile | 5 | ||||
-rw-r--r-- | macosx/tkMacOSXCarbonEvents.c | 52 | ||||
-rw-r--r-- | macosx/tkMacOSXDebug.c | 134 | ||||
-rw-r--r-- | macosx/tkMacOSXDebug.h | 11 | ||||
-rw-r--r-- | macosx/tkMacOSXDraw.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXFont.c | 3 | ||||
-rw-r--r-- | macosx/tkMacOSXInit.c | 6 | ||||
-rw-r--r-- | macosx/tkMacOSXMenu.c | 20 |
8 files changed, 195 insertions, 39 deletions
diff --git a/macosx/Makefile b/macosx/Makefile index b4f77f7..e73780c 100644 --- a/macosx/Makefile +++ b/macosx/Makefile @@ -4,7 +4,7 @@ # uses the standard unix build system in tk/unix (which can be used directly instead of this # if you are not using the tk/macosx projects). # -# RCS: @(#) $Id: Makefile,v 1.7.2.12 2005/11/27 02:36:46 das Exp $ +# RCS: @(#) $Id: Makefile,v 1.7.2.13 2006/01/10 05:38:19 das Exp $ # ######################################################################################################## @@ -186,7 +186,8 @@ build-${PROJECT}: ${OBJ_DIR}/Makefile rm -rf ./${LIBDIR} ./${BINDIR} && ln -fs ${SYMROOT} ./${LIBDIR} && \ ln -fs ${SYMROOT} ./${BINDIR} && ln -fs ${OBJ_DIR}/tktest ${SYMROOT} ifeq (${TK_X11},) - @rm -f ${OBJ_DIR}/${BINDIR} + @rm -f ${OBJ_DIR}/${BINDIR} && \ + ln -fs Wish.app/Contents/MacOS/Wish ${SYMROOT}/${WISH} endif # Create symbolic link to Tcl.framework in ${SYMROOT}if necessary @cd ${SYMROOT} && if [ ! -e Tcl.framework -o -L Tcl.framework ]; then \ diff --git a/macosx/tkMacOSXCarbonEvents.c b/macosx/tkMacOSXCarbonEvents.c index 45be898..d903636 100644 --- a/macosx/tkMacOSXCarbonEvents.c +++ b/macosx/tkMacOSXCarbonEvents.c @@ -60,7 +60,7 @@ * software in accordance with the terms specified in this * license. * - * RCS: @(#) $Id: tkMacOSXCarbonEvents.c,v 1.3.2.8 2005/12/13 03:44:42 das Exp $ + * RCS: @(#) $Id: tkMacOSXCarbonEvents.c,v 1.3.2.9 2006/01/10 05:38:20 das Exp $ */ #include "tkInt.h" @@ -125,7 +125,7 @@ CarbonEventHandlerProc ( macEvent.eKind != kEventMouseDragged) { CarbonEventToAscii(event, buf); fprintf(stderr, "CarbonEventHandlerProc started handling %s\n", buf); - TkMacOSXInitNamedSymbol(HIToolbox, void, _DebugPrintEvent, + TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _DebugPrintEvent, EventRef inEvent); if (_DebugPrintEvent) { /* Carbon-internal event debugging (c.f. Technote 2124) */ @@ -226,31 +226,31 @@ TkMacOSXInitCarbonEvents ( } #ifdef TK_MAC_DEBUG_CARBON_EVENTS - TkMacOSXInitNamedSymbol(HIToolbox, void, _TraceEventByName, CFStringRef); - if (_TraceEventByName) { + TkMacOSXInitNamedDebugSymbol(HIToolbox, void, TraceEventByName, char*); + if (TraceEventByName) { /* Carbon-internal event debugging (c.f. Technote 2124) */ - _TraceEventByName(CFSTR("kEventMouseDown")); - _TraceEventByName(CFSTR("kEventMouseUp")); - _TraceEventByName(CFSTR("kEventMouseWheelMoved")); - _TraceEventByName(CFSTR("kEventMouseScroll")); - _TraceEventByName(CFSTR("kEventWindowUpdate")); - _TraceEventByName(CFSTR("kEventWindowActivated")); - _TraceEventByName(CFSTR("kEventWindowDeactivated")); - _TraceEventByName(CFSTR("kEventRawKeyDown")); - _TraceEventByName(CFSTR("kEventRawKeyRepeat")); - _TraceEventByName(CFSTR("kEventRawKeyUp")); - _TraceEventByName(CFSTR("kEventRawKeyModifiersChanged")); - _TraceEventByName(CFSTR("kEventRawKeyRepeat")); - _TraceEventByName(CFSTR("kEventAppActivated")); - _TraceEventByName(CFSTR("kEventAppDeactivated")); - _TraceEventByName(CFSTR("kEventAppQuit")); - _TraceEventByName(CFSTR("kEventMenuBeginTracking")); - _TraceEventByName(CFSTR("kEventMenuEndTracking")); - _TraceEventByName(CFSTR("kEventCommandProcess")); - _TraceEventByName(CFSTR("kEventWindowExpanded")); - _TraceEventByName(CFSTR("kEventAppHidden")); - _TraceEventByName(CFSTR("kEventAppShown")); - _TraceEventByName(CFSTR("kEventAppAvailableWindowBoundsChanged")); + TraceEventByName("kEventMouseDown"); + TraceEventByName("kEventMouseUp"); + TraceEventByName("kEventMouseWheelMoved"); + TraceEventByName("kEventMouseScroll"); + TraceEventByName("kEventWindowUpdate"); + TraceEventByName("kEventWindowActivated"); + TraceEventByName("kEventWindowDeactivated"); + TraceEventByName("kEventRawKeyDown"); + TraceEventByName("kEventRawKeyRepeat"); + TraceEventByName("kEventRawKeyUp"); + TraceEventByName("kEventRawKeyModifiersChanged"); + TraceEventByName("kEventRawKeyRepeat"); + TraceEventByName("kEventAppActivated"); + TraceEventByName("kEventAppDeactivated"); + TraceEventByName("kEventAppQuit"); + TraceEventByName("kEventMenuBeginTracking"); + TraceEventByName("kEventMenuEndTracking"); + TraceEventByName("kEventCommandProcess"); + TraceEventByName("kEventWindowExpanded"); + TraceEventByName("kEventAppHidden"); + TraceEventByName("kEventAppShown"); + TraceEventByName("kEventAppAvailableWindowBoundsChanged"); } #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ } diff --git a/macosx/tkMacOSXDebug.c b/macosx/tkMacOSXDebug.c index 77d700d..37d2750 100644 --- a/macosx/tkMacOSXDebug.c +++ b/macosx/tkMacOSXDebug.c @@ -50,13 +50,17 @@ * software in accordance with the terms specified in this * license. * - * RCS: @(#) $Id: tkMacOSXDebug.c,v 1.2.2.4 2005/11/27 02:36:46 das Exp $ + * RCS: @(#) $Id: tkMacOSXDebug.c,v 1.2.2.5 2006/01/10 05:38:20 das Exp $ */ +#include "tkMacOSXInt.h" #include "tkMacOSXDebug.h" #ifdef TK_MAC_DEBUG +#include <mach-o/dyld.h> +#include <mach-o/nlist.h> + typedef struct { EventKind kind; char * name; @@ -447,5 +451,133 @@ MouseTrackingResultToAscii(MouseTrackingResult r, char * buf) sprintf(buf, "Unknown mouse tracking result : %d", r); return buf; } + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXGetNamedDebugSymbol -- + * + * + * Dynamically acquire address of a named symbol from a loaded + * dynamic library, so that we can use API that may not be + * available on all OS versions. + * For debugging purposes, if we cannot find the symbol with the + * usual dynamic library APIs, we manually walk the symbol table + * of the loaded library. This allows access to unexported + * symbols such as private_extern internal debugging functions. + * If module is NULL or the empty string, search all loaded + * libraries (could be very expensive and should be avoided). + * + * THIS FUCTION IS ONLY TO BE USED FOR DEBUGGING PURPOSES, IT MAY + * BREAK UNEXPECTEDLY IN THE FUTURE ! + * + * Results: + * Address of given symbol or NULL if unavailable. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +void * +TkMacOSXGetNamedDebugSymbol(const char* module, const char* symbol) +{ + void* addr = TkMacOSXGetNamedSymbol(module, symbol); +#ifndef __LP64__ + if (!addr) { + const struct mach_header *mh = NULL; + uint32_t i, n = _dyld_image_count(); + + for (i = 0; i < n; i++) { + if (module && *module) { + /* Find image with given module name */ + char *name; + const char *path = _dyld_get_image_name(i); + + if (!path) { + continue; + } + name = strrchr(path, '/') + 1; + if (strncmp(name, module, strlen(name)) != 0) { + continue; + } + } + mh = _dyld_get_image_header(i); + if (mh) { + struct load_command *lc; + struct symtab_command *st = NULL; + struct segment_command *sg = NULL; + uint32_t j, m, nsect = 0, txtsectx = 0; + + lc = (struct load_command*)((char *) mh + + sizeof(struct mach_header)); + m = mh->ncmds; + for (j = 0; j < m; j++) { + /* Find symbol table and index of __text section */ + if (lc->cmd == LC_SEGMENT) { + /* Find last segment before symbol table */ + sg = (struct segment_command*) lc; + if (!txtsectx) { + /* Count total sections until (__TEXT, __text) */ + uint32_t k, ns = sg->nsects; + + if (strcmp(sg->segname, SEG_TEXT) == 0) { + struct section *s = (struct section *)( + (char *)sg + + sizeof(struct segment_command)); + + for(k = 0; k < ns; k++) { + if (strcmp(s->sectname, SECT_TEXT) == 0) { + txtsectx = nsect+k+1; + break; + } + s++; + } + } + nsect += ns; + } + } else if (!st && lc->cmd == LC_SYMTAB) { + st = (struct symtab_command*) lc; + break; + } + lc = (struct load_command *)((char *) lc + lc->cmdsize); + } + if (st && sg && txtsectx) { + intptr_t base, slide = _dyld_get_image_vmaddr_slide(i); + char *strings; + struct nlist *sym; + uint32_t strsize = st->strsize; + int32_t strx; + + /* Offset file positions by difference to actual position + in memory of last segment before symbol table: */ + base = (intptr_t) sg->vmaddr + slide - sg->fileoff; + strings = (char*)(base + st->stroff); + sym = (struct nlist*)(base + st->symoff); + m = st->nsyms; + for (j = 0; j < m; j++) { + /* Find symbol with given name in __text section */ + strx = sym->n_un.n_strx; + if ((sym->n_type & N_TYPE) == N_SECT && + sym->n_sect == txtsectx && + strx > 0 && strx < strsize && + strcmp(strings + strx, symbol) == 0) { + addr = (void*) sym->n_value + slide; + break; + } + sym++; + } + } + } + if (module && *module) { + /* If given a module name, only search corresponding image */ + break; + } + } + } +#endif /* __LP64__ */ + return addr; +} #endif /* TK_MAC_DEBUG */ diff --git a/macosx/tkMacOSXDebug.h b/macosx/tkMacOSXDebug.h index f57fc71..df3c00c 100644 --- a/macosx/tkMacOSXDebug.h +++ b/macosx/tkMacOSXDebug.h @@ -50,7 +50,7 @@ * software in accordance with the terms specified in this * license. * - * RCS: @(#) $Id: tkMacOSXDebug.h,v 1.2.2.4 2005/11/27 02:36:46 das Exp $ + * RCS: @(#) $Id: tkMacOSXDebug.h,v 1.2.2.5 2006/01/10 05:38:20 das Exp $ */ #ifndef _TKMACDEBUG @@ -79,6 +79,15 @@ char * TkMacOSXMenuMessageToAscii(int msg, char * s); char * MouseTrackingResultToAscii(MouseTrackingResult r, char * buf ); +void * TkMacOSXGetNamedDebugSymbol(const char* module, const char* symbol); + +/* Macro to abstract common use of TkMacOSXGetNamedDebugSymbol to initialize named symbols */ +#define TkMacOSXInitNamedDebugSymbol(module, ret, symbol, ...) \ + static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \ + if (symbol == (void*)(-1L)) { \ + symbol = TkMacOSXGetNamedDebugSymbol(STRINGIFY(module), STRINGIFY(_##symbol));\ + } + #endif #endif diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c index 5722057..cfdfc22 100644 --- a/macosx/tkMacOSXDraw.c +++ b/macosx/tkMacOSXDraw.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.2.2.9 2005/12/08 07:50:30 das Exp $ + * RCS: @(#) $Id: tkMacOSXDraw.c,v 1.2.2.10 2006/01/10 05:38:20 das Exp $ */ #include "tkInt.h" @@ -23,6 +23,7 @@ #include "tkMacOSXInt.h" #include "tkPort.h" #include "tkMacOSXDebug.h" +#include "tclInt.h" /* for Tcl_CreateNamespace() */ #ifndef PI # define PI 3.14159265358979323846 diff --git a/macosx/tkMacOSXFont.c b/macosx/tkMacOSXFont.c index 2a2466e..e27650e 100644 --- a/macosx/tkMacOSXFont.c +++ b/macosx/tkMacOSXFont.c @@ -11,12 +11,13 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXFont.c,v 1.3.2.6 2005/12/08 07:50:30 das Exp $ + * RCS: @(#) $Id: tkMacOSXFont.c,v 1.3.2.7 2006/01/10 05:38:20 das Exp $ */ #include <Carbon/Carbon.h> #include "tkMacOSXInt.h" #include "tkFont.h" +#include "tclInt.h" /* for Tcl_CreateNamespace() */ /* * For doing things with Mac strings and Fixed numbers. This probably should move diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index a1ee640..d0f5a5a 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXInit.c,v 1.3.2.12 2005/12/08 07:50:30 das Exp $ + * RCS: @(#) $Id: tkMacOSXInit.c,v 1.3.2.13 2006/01/10 05:38:20 das Exp $ */ #include "tkInt.h" @@ -170,12 +170,13 @@ TkpInit(interp) if (rsrc) { ReleaseResource(rsrc); } else { +#ifndef __LP64__ const struct mach_header *image; char *data = NULL; uint32_t size; int fd = -1; char fileName[L_tmpnam + 15]; - int i, n; + uint32_t i, n; /* Get resource data from __tk_rsrc section of tk library file */ n = _dyld_image_count(); @@ -216,6 +217,7 @@ TkpInit(interp) unlink(fileName); close(fd); } +#endif /* __LP64__ */ } } diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c index 275846d..797e7ab 100644 --- a/macosx/tkMacOSXMenu.c +++ b/macosx/tkMacOSXMenu.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.6.2.14 2005/11/27 06:53:36 das Exp $ + * RCS: @(#) $Id: tkMacOSXMenu.c,v 1.6.2.15 2006/01/10 05:38:20 das Exp $ */ #include "tkMacOSXInt.h" #include "tkMenubutton.h" @@ -25,6 +25,12 @@ #include "tkMacOSXDebug.h" #include <CoreFoundation/CFString.h> +/* +#ifdef TK_MAC_DEBUG +#define TK_MAC_DEBUG_MENUS +#endif +*/ + #if !defined(MAC_OS_X_VERSION_10_3) || \ (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_3) /* Define constants only available on Mac OS X 10.3 or later */ @@ -1066,6 +1072,14 @@ ReconfigureIndividualMenu( TkMenuEntry *mePtr; int parentDisabled = 0; +#ifdef TK_MAC_DEBUG_MENUS + /* Carbon-internal menu debugging (c.f. Technote 2124) */ + TkMacOSXInitNamedDebugSymbol(HIToolbox, void, DebugPrintMenu, MenuRef menu); + if (DebugPrintMenu) { + DebugPrintMenu(macMenuHdl); + } +#endif + for (mePtr = menuPtr->menuRefPtr->parentEntryPtr; mePtr != NULL; mePtr = mePtr->nextCascadePtr) { char *name = (mePtr->namePtr == NULL) ? "" @@ -1150,10 +1164,6 @@ ReconfigureIndividualMenu( ((MacMenu *) mePtr->childMenuRefPtr ->menuPtr->platformData)->menuHdl; - if (childMenuHdl == NULL) { - childMenuHdl = ((MacMenu *) mePtr->childMenuRefPtr - ->menuPtr->platformData)->menuHdl; - } if (childMenuHdl != NULL) { { SetMenuItemHierarchicalID(macMenuHdl, base + index, |