home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13955 < prev    next >
Encoding:
Text File  |  1992-08-13  |  3.6 KB  |  81 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!gatech!destroyer!gumby!kzoo!k044477
  3. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  4. Subject: Musings on the Think C Debugger
  5. Message-ID: <1992Aug13.191622.15902@hobbes.kzoo.edu>
  6. Organization: Kalamazoo College
  7. Date: Thu, 13 Aug 1992 19:16:22 GMT
  8. Lines: 71
  9.  
  10. I often wonder, while I use this way-cool debugger, exactly how it
  11. works.  I'm not a really-low-level Mac hacker, so I have to make a lot
  12. of guesses, and it'd be nice if someone could point out my mistakes.
  13.  
  14.  
  15. The source-level debugger works great with my low-level debugger, which
  16. happens to be Macsbug.  There's this kind of separation of levels:  the
  17. debugger switch gets intercepted by Macsbug, as does cmd-power (via
  18. Programmer's Key).  Yet _Debugger, _DebugStr, etc. traps drop me into
  19. Think Debugger.  I'm presuming that the Think Debugger simply patches
  20. those traps, in the context of my app's heap.
  21.  
  22. But the debugger switch thing confuses me a little.  It's a high-level
  23. interrupt, right?--that's what the NMI means--and so gets routed through
  24. the interrupt vector table that starts at $0000 (or should I say
  25. $0008?).  Bus errors go through the same table.  So the Think Debugger
  26. sets a hook to its own routines at $0008, the bus error vector, and lets
  27. Macsbug keep _its_ hook at the rest of the vectors.  Right?
  28.  
  29. What other vectors get replaced?  I've seen bus errors, address errors,
  30. and illegal instruction errors get trapped by "ThD", but e.g.
  31. stack-collided-with-heap errors still drop into Macsbug.
  32.  
  33.  
  34. Context switching.  If I set a breakpoint, I guess ThD drops a
  35. _Debugger_ trap at that word, and makes sure to flush the instruction
  36. cache and so forth.  When it hits it, it figures out where it came from,
  37. loads in the appropriate source file, and puts the arrow in the right
  38. place.  Ok so far?
  39.  
  40. Now, as far as the PM is concerned, it's still running _my_app_--last
  41. it knew, it returned from a WaitNextEvent call in my app's event loop,
  42. and you'd think it would expect to get another WaitNextEvent from
  43. _my_app_ again.  Doesn't it get confused when ThD suddenly starts
  44. calling WNE?
  45.  
  46. OK, I step one instruction.  I guess ThD writes in a _Debugger_ trap,
  47. jumps to my code, executes it, it hits the trap, and the handler
  48. restores the old code that was there.  But how does it do the context
  49. switch?  How does it bring my app's windows to the front?
  50.  
  51. While my app's sitting at a breakpoint, I flip into ZTerm and check on
  52. my download.  (I can download while doing source-level debugging;  I
  53. love it!)  Now, ZTerm's calling WNE, and each time it does so, the
  54. Process Manager code sends a null event to one background app.  What
  55. happens when my app gets one?  Has the ThD put in code around my event
  56. loop that catches those null events before they get passed on to the
  57. rest of my app, and simply ignores them?  What happens if I have more
  58. than one place where I call WNE?
  59.  
  60. I'm still sitting at a breakpoint.  When my windows need updating,
  61. doesn't the system "return" from my app's WNE call (which was never
  62. really made in the first place) with an update event?
  63.  
  64.  
  65. How does ThD redraw my windows for me!?
  66.  
  67.  
  68. Is there some automatic way that the ThD knows what lo-mem globals etc.
  69. to swap in and out when it hits a breakpoint?  Or do the programmers at
  70. Symantec know about some undocumented system call that'll do a context
  71. switch for you?
  72.  
  73.  
  74. That's all I can think of now.  Sorry to ramble but it's such a
  75. confusing beast, and I'd like to think that I have _some_ clue about
  76. what's going on behind the scenes.
  77. -- 
  78.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  79.  Pull down the monuments, and send a postcard back
  80.  For nineteen-ninety-five, I will have the starter pack      - Gang of Four
  81.