home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / mac / programm / 20795 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.5 KB  |  66 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!mcsun!sunic!kth.se!dront.nada.kth.se!d88-jwa
  3. From: d88-jwa@dront.nada.kth.se (Jon WΣtte)
  4. Subject: Re: Help for a new programmer (CDEF's & Debuging Resource Code)
  5. Message-ID: <1993Jan6.145605.28930@kth.se>
  6. Keywords: CDEF,Debug,Controls,Resource 
  7. Sender: usenet@kth.se (Usenet)
  8. Nntp-Posting-Host: dront.nada.kth.se
  9. Organization: Royal Institute of Technology, Stockholm, Sweden
  10. References: <1993Jan6.045539.29232@engr.LaTech.edu>
  11. Date: Wed, 6 Jan 1993 14:56:05 GMT
  12. Lines: 52
  13.  
  14. > How to debug CDEF in Think C
  15.  
  16. Well, you could try and create a CDEF that's only 6 bytes,
  17. load it in, make it contain a JMP instruction and the
  18. address of a function in your application, and flush the
  19. cache (after locking the resource)
  20.  
  21. Something like:
  22.  
  23. typedef struct cdef {
  24.  
  25.     unsigned short jmp ;
  26.     short * ( addr ) ( ) ;
  27.  
  28. } cdefStub ;
  29.  
  30.  
  31. pascal short
  32. MyRealCDEF ( whatever )
  33. {
  34.     Do the stuff
  35. }
  36.  
  37.  
  38. /* DO this before creating any controls */
  39.  
  40.     cdefStub stub ;
  41.     Handle h = GetReosurce ( 'CDEF' , 4711 ) ;
  42.  
  43.     stub . jmp = 0x4000 ; /* Have to look this up, JMP Immediate */
  44.     stub . addr = MyRealCDEF ;
  45.  
  46.     HLockHi ( h ) ; /* Top of heap to avoid fragmentation */
  47.  
  48.     * ( cdefStub * ) * h = stub ;
  49.  
  50.     if ( TrapAvailable ( _HWTrap ) ) {
  51.  
  52.  
  53.         FlushInstructionCache ( ) ;
  54.     }
  55.  
  56.  
  57. Now anything going to CDEF 4711 in your program will go to
  58. the function MyRealCDEF, and you can use the source debugger
  59. on it, and reference globals even! Cool!
  60.  
  61.  
  62. -- 
  63.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  64.  
  65.    Cookie Jar: Vanilla Yoghurt with Crushed Oreos.
  66.