home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Night of the Living Disc / Night of the Living Disc.2mg / Dev.CD.5 / Utilities / GSBug / GSBug.Tutorial < prev    next >
Encoding:
Text File  |  1990-06-19  |  28.6 KB  |  605 lines  |  [04] ASCII Text (0x0000)

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                              GSBug is Your Friend
  10.  
  11.                            (a quick intro to GSBug)
  12.                                by:  Tim Swihart
  13.  
  14.  
  15.  
  16. So, you just got GSBug installed for the first time and don't have a clue how
  17. to use it.  Sure, you could call APDA (1-800-282-2732) and order the complete
  18. package (part #A0037LL/A, price $30), but you're not sure if GSBug will really
  19. help you find those nasty bugs in the Apple IIGS software you're developing.
  20. Well, from the next paragraph until the end of this file, I'll present a quick
  21. introduction to some of the reasons why GSBug is a "MUST HAVE" tool for all
  22. IIGS developers.  It doesn't matter what language you program in, or which
  23. environment you use, GSBug is the key to tracking down and exterminating those
  24. nasty bugs that make your software look shabby.
  25.  
  26.  
  27. Installation:
  28.  
  29. Before we can really get into it, you need to install GSBug and the
  30. GSBug.Templates file and reboot your IIGS.  If you only have one computer,
  31. then print this file and continue reading from the printout.  GSBug is an INIT
  32. with the file name "GSBug.INIT" - install it by copying this file into your
  33. boot disk's SYSTEM/SYSTEM.SETUP folder.  Copy the "GSBug.Templates" file into
  34. the same folder.
  35.  
  36.  
  37. Care & Feeding of GSBug:
  38.  
  39. Now that everything is installed, reboot your computer.  No need to launch any
  40. particular application just yet, I have to explain the various parts of
  41. GSBug's screen and I want to cover a few basic GSBug commands before we go bug
  42. hunting.  I'll assume you're running the Finder right now, but it really
  43. doesn't matter a whole lot what application is running, as long as it is a
  44. 16-bit application (i.e.:  a true IIGS desktop application).
  45.  
  46. You can pop into GSBug at any time (assuming interrupts aren't disabled) by
  47. pressing OPEN APPLE-OPTION-CONTROL-ESC  (if you're having troubles remembering
  48. all of those keys at once, just think of it as the same keys that you use to
  49. get to the built-in control panel plus the OPTION key).  You'll be presented
  50. with a rather busy-looking 80-column text screen.  (there's a screen dump
  51. right below this paragraph - I told you it was busy-looking screen)
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. ------ cut here to start the screen dump ------
  63.  
  64. KEY BRK  DebugD  K/PC   B   D    S    A    X    Y    M   Q   L  P  nvmxdizc e d
  65. 00  o d   9500  FD/688D FD 2500 1FE0 0000 4D95 0044  0C  BE  1  03 00000011 0 0
  66.  
  67. 1FF2:60  00/0000:  BE '>'  00/0000-00-00
  68. 1FF1:43  00/0000:  BE '>'  00/0000-00-00
  69. 1FF0:FE  00/0000:  BE '>'  00/0000-00-00
  70. 1FEF:01  00/0000:  BE '>'  00/0000-00-00
  71. 1FEE:37  00/0000:  BE '>'  00/0000-00-00
  72. 1FED:0C  00/0000:  BE '>'  00/0000-00-00
  73. 1FEC:00  00/0000:  BE '>'  00/0000-00-00
  74. 1FEB:4D  00/0000:  BE '>'  00/0000-00-00
  75. 1FEA:7A  00/0000:  BE '>'  00/0000-00-00
  76. 1FE9:C0  00/0000:  BE '>'
  77. 1FE8:00  00/0000:  BE '>'  E1/0000.000F-T
  78. 1FE7:2C  00/0000:  BE '>'  00/0000.0000-?
  79. 1FE6:00  00/0000:  BE '>'  00/0000.0000-?
  80. 1FE5:E0  00/0000:  BE '>'  00/0000.0000-?
  81. 1FE4:6A  00/0000:  BE '>'  00/0000.0000-?
  82. 1FE3:B4  00/0000:  BE '>'  00/0000.0000-?
  83. 1FE2:62  00/0000:  BE '>'  00/0000.0000-?
  84. 1FE1:DA  00/0000:  BE '>'  00/0000.0000-?
  85. 1FE0:FD  00/0000:  BE '>'  00/0000.0000-?
  86.  
  87. :GSBug V1.5b9 w/Glue Support -(C)1986-90 Apple Computer,Inc.
  88.  
  89. ------ cut here to end the screen dump ------
  90.  
  91.  
  92. Top Two Lines:
  93.  
  94. The first two lines of the screen show the contents of various registers.  The
  95. top line of the screen starts off with "KEY  BRK  DebugD" - those are headings
  96. for the items in the second line of the screen.  The meanings of those headings
  97. (and the items under them) are:
  98.  
  99. Heading     Meaning
  100. -------     -------------------------------------------
  101. KEY         Modifiers used to separate debugger keys from application keys
  102. BRK         (beyond the scope of this quick intro - see the manual)
  103.  
  104. DebugD      Debugger's direct page (1K in size) - in bank $00
  105. K/PC        K=program bank, PC=program counter 
  106.  
  107. B           app's data bank
  108. D           current direct page in bank zero 
  109.  
  110. S           current stack pointer
  111. A           accumulator's value
  112.  
  113. X           X register's value
  114. Y           Y register's value
  115.  
  116. M           machine state register's value
  117. Q           quagmire register's value
  118.  
  119. L           Language card bank
  120. P           processor-status register's value
  121.  
  122. nvmxdizc    bits that make up "P" (n=negative, c=carry, etc)
  123. e           emulation mode flag
  124. d           disassembly mode flag (0=recognize SEP & REP during "L"isting)
  125.  
  126.  
  127. If you want more information on a specific register's meaning then look it up
  128. in the IIGS Hardware reference manual, the GSBug manual, or any good book that
  129. covers the IIGS's internal hardware.  Any of these register's values can be
  130. changed - we'll show how to do that in a few paragraphs or so...
  131.  
  132.  
  133. The Left-Hand Side:
  134.  
  135. The next major area of the screen is the 4-digit column of numbers running
  136. down the far left side.  There is a colon on each line after the fourth
  137. digit, and then there is a column (two digits wide) of numbers.  All of these
  138. numbers are in hex and this area is the stack.  The four digit column, the
  139. colons, and the two digit column are collectively known as the "stack
  140. subdisplay area" - remember that, there's a test at the end of this file.
  141. The column on the left of the colon is the address of the stack and the
  142. column on the right (the two digit column) are the values on the stack.
  143. The bottom-most four digit stack address is the "top" of the stack (i.e.:
  144. if your app pushes anything on the stack, that's the address it would wind
  145. up at).  As you step through your application (we'll show how in a minute,
  146. patience...) the stack will scroll upwards as things are pushed onto it and
  147. downwards as things are pulled off of it.
  148.  
  149.  
  150. The Not-So-Left-Hand Side:
  151.  
  152. The next major area should be a column of "00/0000:  BE '>'" known as the
  153. "RAM subdisplay area".  This area is used to display any 19 memory locations
  154. that you want to keep an eye on.  The value at each of those locations is
  155. shown in hex (that's what the "10" means - location 00/0000 contains hex "BE"
  156. when I wrote this) and in ASCII (the ASCII version is between the single quote
  157. marks, i.e.:  the "'>").  It is possible to have this subdisplay show a
  158. two-byte or a three-byte value instead of the one-byte value.  You lose the
  159. ASCII display if you opt for the 2 or 3 byte values.
  160.  
  161. After I finish explaining the rest of the screen, I'll come back and describe
  162. how to change these 19 "windows on memory" to look at what you want to monitor.
  163.  
  164.  
  165. The Center Part:
  166.  
  167. The next major area of the screen is the 9 lines of "00/0000-00-00", better
  168. known as the "Breakpoint subdisplay" (they're on the top half of the screen).
  169. GSBug lets you set up to 17 breakpoints in your program (not counting BRK
  170. instructions you imbed in your program yourself).  Curious about how you set
  171. 17 break points when there are only 9 lines in this section?  Did I mention
  172. that APDA stocks the manual (which has full details)? <grin>  Seriously, you
  173. can "extend" the breakpoint subdisplay by shrinking the section under it
  174. (which we haven't described yet).  For the purposes of this quick intro, I'm
  175. not going to show how to do this (you need some kind of reason to get the
  176. manual).  I'll just describe this area and later show how to set up to 9 break
  177. points.
  178.  
  179. The "00/0000" part of the breakpoint subdisplay is obviously an address - in
  180. fact, it's the address you want to break on.  The next part "-00-" is the
  181. trigger value.  GSBug is smart enough to count how many times an address has
  182. been executed and break on a certain number (i.e.:  put a "03" here and GSBug
  183. will break the third time that address is executed).  The last part of this
  184. area is the running count - this is how GSBug lets you know how many times
  185. that area has been executed (rather than leave you wondering, it tells you and
  186. you can be ready for the break).  You set the address and trigger portions and
  187. GSBug sets the count portion.
  188.  
  189.  
  190. The Bottom Part of the Center Part:
  191.  
  192. The bottom half of the center of the screen is known as the "Memory
  193. Protection Subdisplay" and looks starts off with "E1/0000.000F-T".  This
  194. area can be expanded (or shrunk) by trading lines of this area for lines of
  195. the one above it (the "Breakpoint subdisplay").  If you want to know how to
  196. do this, read the manual from APDA, it's big (roughly 150 pages) and I'm not
  197. retyping all of it here!  <grin>
  198.  
  199. The "E1/0000.000F" is the address range starting at E1/0000 and ending at
  200. E1/000F.  The "T" at the end means that this range of memory is protected from
  201. code tracing.  If you're tracing through your code and it jumps (JSR's, JSL,
  202. whatever) into this range of memory, then the code in this range will NOT be
  203. traced - it will be executed at full speed instead.
  204.  
  205. There are two other options for code protection ("W" and "H").  They are beyond
  206. the scope of this quick tutorial (c'mon, I'm only trying to cover the basics
  207. here).
  208.  
  209.  
  210. Where You Type Commands:
  211.  
  212. The bottom line on the screen is the command line subdisplay (catchy name,
  213. eh?).  When you first enter GSBug, this line will contain the copyright
  214. message and version number for GSBug (unless you've used the DebugStr or
  215. SetMileStone "tool" calls to change this string).  As soon as you press a
  216. key, the copyright message vanishes and your keypress shows up next to the
  217. blinking cursor.  This is where you'll type various commands to make GSBug
  218. help you get the kinks out of your software.
  219.  
  220.  
  221. What's the Big Blank Spot For?:
  222.  
  223. The big blank area towards the far right of the screen is officially known as
  224. the "disassembly subdisplay" (it's one of the big reasons you're using GSBug -
  225. even if you don't know it yet).  As you single-step through your software,
  226. trace through it, or just list areas of memory this area will show you the
  227. disassembled version of your program.  One of the really slick things about
  228. this area is that it's smart enough to know about the names of GS/OS calls and
  229. Toolbox calls - so you see things like "_CheckUpdate" instead of "JSL E10000".
  230. That makes if VERY easy to line up pieces of your source with the disassembly
  231. if you're working in a high-level language.  It also makes it a LOT easier to
  232. see what you're doing!
  233.  
  234. GSBug also knows about the alternate Toolbox entry point (E10004) and will
  235. display those as tool calls also.  The leading underscore ("_") lets you know
  236. that GSBug is substituting the tool's name for you.  If the tool call is being
  237. made through "glue", then the underscore is preceded by an asterisk ("*").
  238.  
  239. If you've ever used the built in "monitor" (I'm not talking about your RGB
  240. monitor, I'm talking about the disassembler that's been built into Apple II's
  241. for a LONGGGGGGG time now), then you'll be able to quickly figure out that the
  242. left-most part of the disassembly subdisplay is the address, the inside column
  243. are the hex byte making up the code about to be disassembled, and the
  244. right-most part is the disassembled version of your software.
  245.  
  246.  
  247. Your First GSBug Command:
  248.  
  249. OK, you now know what all of the various areas of this rather busy-looking
  250. screen are for, so let's get down to business!  The first thing to do is press
  251. the "L" key (upper or lower case work the same these days) and then press
  252. RETURN.  This will fill the disassembly subdisplay with 19 lines of
  253. disassembled code (which 19 lines were disassembled really don't matter yet).
  254. Study it until you can tell at a glance which parts are the address, which
  255. parts are the hex bytes, and which parts are the disassembled code.
  256.  
  257. Type "L" and press RETURN again - you get the next 19 lines of memory (see,
  258. told you it was a lot like the built-in monitor).
  259.  
  260. Now, let's do something a tad more useful...  Press the "S" key and RETURN
  261. (you just told GSBug to start single-stepping through your application).  Be
  262. careful what keys you press while in the single step mode - lots of
  263. weird-looking things can happen (they're all normal, but if you don't expect
  264. them you can get confused).  For now, ONLY press the keys this tutorial tells
  265. you to.  If you can't wait and just HAVE to bang on all of the various keys,
  266. then go ahead - reboot once you've totally confused yourself, pop back into
  267. GSBug and catch up with the rest of the folks reading this.
  268.  
  269. To tell GSBug to execute the highlighted instruction, press the SPACE BAR one
  270. time.  Heck, press it several times so that you get a bunch of lines of
  271. disassembled code on the screen.  Notice that the code scrolls up and the
  272. "highlighted" area stays in the same place?  Notice it's kind of close to the
  273. bottom of the screen?  Later I'll tell you how to move it up higher.
  274.  
  275. Press the ESC key.  That takes you out of single-step and returns you to the
  276. command line.  Press "S" and RETURN again to restart single stepping.  Notice
  277. that the lines ABOVE the highlighted area have been erased?  Remember that -
  278. if you halt single-stepping and need some piece of info above the highlighted
  279. area, then write it down because it'll be wiped out when you restart
  280. single-stepping (or when you do any of a bunch of different things).  If you
  281. have your printer connected to slot 1, then you can print GSBug's screen using
  282. the "P" command (press "P" and RETURN - be sure you're NOT single-stepping
  283. when you do this, "P" only prints from the command line).
  284.  
  285.  
  286. Lock a Tractor Beam onto Them Sulu!:
  287.  
  288. Want an easy way to have the computer step through source for you without
  289. having to bang again and again on the SPACE BAR?  Start single-stepping
  290. ("S" and RETURN), then press RETURN again.  VRRRROOOOMMMMMM!  Can't read all
  291. the stuff flying by?  No sweat, press SPACE BAR and you'll be back to
  292. single-stepping.  Pressing the RETURN key a second time kicked GSBug into
  293. "Trace" mode.
  294.  
  295. Trace actually has two speeds, the default is fast (we like to test
  296. developers' speed reading skills).  To kick TRACE into low gear, press the
  297. left arrow key.  If you're in single-step mode, then you won't see the speed
  298. change (after all, it affects TRACE, not SINGLE-STEP), but fear not brave
  299. developer, the speed change has been made.  Press RETURN again (to be sure
  300. you're in TRACE mode) and press the left arrow key (if you didn't a few lines
  301. ago) to kick TRACE into low gear.  Want to get back into high gear?  Press the
  302. right arrow key (sneaky, eh?).
  303.  
  304.  
  305. RED ALERT!:
  306.  
  307. Do _NOT_ press the down arrow key while TRACING or single-stepping (unless
  308. you know what you're doing).  The down arrow key tells GSBug to SKIP the
  309. highlighted instruction!  This is a great way to step over BRK instructions,
  310. but it's not a real smart thing to do at random while TRACING through an
  311. application (randomly skipping an instruction generally results in a crash).
  312.  
  313.  
  314. Move That Line Up:
  315.  
  316. If you want to raise the highlighted line within the disassembly subdisplay,
  317. then press ESC (to get back to the command line) and type "SET"  (don't type
  318. the quotes, ok?) and press RETURN.  The up and down arrows now control the
  319. vertical position of the highlighted bar within the disassembly subdisplay.
  320. Position the bar where you want  it and press ESC.  That position will be
  321. remembered until the next time you move it or until you reboot (then it goes
  322. back to the default position).  The manual for GSBug tells you how to save
  323. this new position to a configuration file (it also tells you that pressing the
  324. left and right arrow will move the stack subdisplay up and down, and that
  325. pressing a number less than eight will change the slot used to print the
  326. screen).
  327.  
  328.  
  329. Reaching the Breaking Point:
  330.  
  331. Alright, time for some fancy stuff!  The next couple of sections will assume
  332. you were running the IIGS Finder when you popped into GSBug (other apps will
  333. work just fine, but why be difficult?).  GSBug will let you break on any tool
  334. call (or calls) that you specify, so let's set a few tool breaks and learn how
  335. to use this feature.
  336.  
  337. From GSBug's command line (press ESC if you're still stepping or tracing),
  338. type "settbrk _sysbeep" and press RETURN.  If GSBug beeps at you instead of
  339. accepting this line, then you didn't type it right (there are two t's in
  340. "settbrk" and don't type the quotes).  Type "settbrk #090E" and press RETURN.
  341. You just added two tool calls to GSBug's list of tools to break on.  The first
  342. one was added by naming the tool to break on ("_sysbeep") and the second one
  343. was added by specifying the tool's number ("#090E").  This lets you set tool
  344. breaks regardless of whether you know the tool's name or number.
  345.  
  346. Type "showbrks" and press RETURN to see the complete list of tool breaks that
  347. GSBug has been told about.  Notice that the left hand side of the screen now
  348. implies that you can set breaks on GS/OS calls?  That's because you can!
  349. GS/OS breaks have to be set by number (not by name).
  350.  
  351. All we've done so far is make a list of tools for GSBug to break on.  We
  352. haven't actually told GSBug to break on them, that requires a separate
  353. command.  Type "tbrkin" to tell GSBug to break on all of the tool calls in
  354. its list.  Now, when either a call to SysBeep or a call to NewWindow
  355. (tool $090E is NewWindow) is made, we'll be dropped back into GSBug.
  356.  
  357.  
  358. Oh Yeah?  Prove It!:
  359.  
  360. Make sure you're at GSBug's command line (press ESC if you aren't).  Type "R"
  361. and RETURN.  This resumes full execution of your application.  To test the
  362. tool breaks we just set, we need to force the Finder (or whatever app you
  363. stubborn folks decided to use instead of the Finder) to make a call to
  364. NewWindow and/or to SysBeep.  Double click on a disk icon, get info on a file,
  365. open a folder, open a desk accessory, etc to get the Finder to open a new
  366. window.  Notice that you land in GSBug?
  367.  
  368. Press "S" and RETURN to enter single-stepping.  Notice that the highlighted
  369. instruction is "NewWindow".  Ah, the tool break works.  Now, press SPACE BAR
  370. to execute the NewWindow call, press ESC to stop single-stepping, and type "R"
  371. and RETURN to resume running the Finder.  (if we didn't bother to single step
  372. across the NewWindow call, we would just fall right back into the debugger
  373. since we have a break point set on that call).
  374.  
  375.  
  376. Take it Out, Wise Guy!;
  377.  
  378. Tired of falling into GSBug everything a new window is opened?  There are
  379. several ways to remove tool breaks.  The easiest way is to type "tbrkout" to
  380. stop breaking on the listed tool calls without trashing the list.  Typing
  381. "tbrkin" makes GSBug start breaking on them again.
  382.  
  383. To clear the list of tool breaks, either type "clrtbrk _sysbeep" (to remove
  384. the sysbeep break we put in earlier) and repeat that for "_newwindow" or wipe
  385. the all out with "clralltbrks".  I'll let you decide...
  386.  
  387.  
  388. Cheap Trick #1:
  389.  
  390. Being able to break into the debugger based on a tool call is VERY handy!  But
  391. what if you want to see the stack being set up BEFORE your code gets all the
  392. way down to the tool call itself?  After all, if you're not putting enough
  393. parameters on the stack (or too many), then breaking on the tool call itself
  394. is too late to watch the stack being built.  There's an easy solution for
  395. this - stick a SysBeep call in your source ABOVE the tool call you really
  396. want to break on and set a tool break on SysBeep.  This will let you
  397. single-step through the stack setup for the call you're really interested in.
  398. OK, so it's a cheap trick, but it's darned effective...
  399.  
  400.  
  401. I Don't Like My Registers:
  402.  
  403. Remember earlier I mentioned that you can change the values of the various
  404. registers from within GSBug?  This lets you change values that are about to be
  405. pushed on the stack and do all kinds of neat things.  You're sharp, so I won't
  406. bore you with all the things this lets you do, I'll just cut right to the
  407. description of HOW to do it...
  408.  
  409. To change the accumulator's value, type "a=value" on the command line.
  410. Replace "value" with the hex value you want  to stuff into the accumulator.
  411. Type "x=value" to set the x register, "y=value" to set the y register, etc.
  412. You can't type "a=x" to set the accumulator to the value in the x register,
  413. but since you can see the x register's value, this isn't that big of a loss.
  414.  
  415.  
  416. Cheap Trick #2:
  417.  
  418. If you accidently SKIP an instruction that you didn't mean to (and you haven't
  419. executed any more since then), you can "unskip" it by exiting single-step
  420. mode, then type "pc=value" where "value" is the address (all three bytes just
  421. to be safe) that the skipped instruction is at.  Press RETURN and then resume
  422. single-stepping (notice that you're back at the skipped instruction now).
  423.  
  424.  
  425. Cheap Trick #3:
  426.  
  427. Fudging the program counter (pc=value) will let you push extra info on the
  428. stack in cases where you didn't push enough for a call.  Be careful with
  429. this - you may need to set the accumulator before re-executing an
  430. already-executed PHA and you could totally trash the stack if you're not
  431. paying attention.  One place this is handy is to compensate for passing a
  432. WORD instead of a LONG (easy to do with C when you're dealing with resource
  433. ID's).  If you don't understand this trick, don't use it!
  434.  
  435. A minor modification on this stunt is (obviously) to pull extra bytes OFF of
  436. the stack in cases where you left something on there that shouldn't have been
  437. left on.  Once you spot problems like too much or too little data on the
  438. stack,  FIX YOUR SOURCE CODE AND RECOMPILE IT!!!!  You don't really want to
  439. have to find this bug a second time do you?
  440.  
  441.  
  442. Cheap Trick #4:
  443.  
  444. GSBug is a lot like the monitor in certain respects.  That means many of the
  445. commands you're used to from the monitor will work under GSBug.  Setting
  446. values in memory under GSBug is done just like it is under the monitor
  447. (i.e.:  address : value1 value2 value3 value4 ...).   addressT and RETURN
  448. starts tracing at the memory location specified by "address".  addressS and
  449. RETURN starts single-stepping at the memory location specified by "address".
  450. addressL and RETURN lists 19 lines of disassemby starting at the memory
  451. location specific by "address".  You can even use the built-in mini assembler
  452. if you want (type "asm" and RETURN).
  453.  
  454.  
  455. Peering Into Memory:
  456.  
  457. The 19 "windows on memory" can be used by typing "mem" and RETURN on the
  458. command line.  This puts the cursor on the far right of the first line in the
  459. RAM subdisplay area.  Type the address you want to watch and press RETURN.
  460. That will move you to the next line (so you can set the address for the second
  461. memory location).  If you want to see two bytes starting at that address,
  462. press "P".  To see three bytes, press "L".  "Z" toggles between direct-page
  463. and absolute addressing, ":" toggles between direct, 2-byte indirect, and
  464. 3-byte indirect addressing.  Press "?" for more info.
  465.  
  466. This provides a nice way to look at variables in memory, dereference
  467. pointers/handles, etc.  When the contents of any "peered into" location
  468. changes, the corresponding line on GSBug's screen will change also.
  469.  
  470.  
  471. Cheap Trick #5:
  472.  
  473. (this one's actually not cheap, it's pretty danged useful!)  While
  474. single-stepping or tracing, you can see other "screens" by pressing various
  475. keys (this accounts for the weird effects I alluded to earlier).  Press "S" to
  476. see the SHR screen (i.e.:  your desktop application's desktop), "D" to see the
  477. double hi-res screen, "T" to see the text screen, "8" to see 80-column
  478. display, "4" to see 40-column display, "H" to see the Hi-Res screen, "L" for
  479. the Lo-Res screen, and ESC to exit single-stepping.  This lets you see your
  480. application's screen instead of GSBug's screen (makes it a LOT easier to
  481. debug your apps when you can see their screens...).
  482.  
  483.  
  484. Study For The Test:
  485.  
  486. I told you earlier that there would be a test at the end of this tutorial, so
  487. now's your chance to kick back and study a bit.  So far, we've covered what
  488. the various parts of GSBug's screen mean, how to disassemble pieces of memory
  489. (using "L"), how to single-step and trace (at different speeds) through your
  490. application, how to set, use, and clear breakpoints, how to display various
  491. screens, and how to set up the RAM subdisplay area.
  492.  
  493.  
  494. Don't Touch That Dial!:
  495.  
  496. The material covered so far gives you a decent foundation to draw upon as you
  497. hunt bugs in your own software.  We've only lightly touched on what GSBug can
  498. really do (I'm not typing all 150 or so pages of the manual into this
  499. "introduction" to GSBug).  GSBug offers a lot of power and capabilities that
  500. should be learned by all developers.
  501.  
  502. Before I wrap up this tutorial I want to cover the use of templates and
  503. describe some of the new features in GSBug v.1.5b9 that aren't described in
  504. the APDA documentation (because we just added the features and haven't
  505. replaced APDA's master manual yet).
  506.  
  507.  
  508. Templates By Jim:
  509.  
  510. GSBug provides an easy way for you to view portions of memory through
  511. templates.  This allows you to "see" the data structures in memory just
  512. like they appear in the documentation (i.e.: see them divided into the
  513. various fields).  The GSBug.Templates file that you were supposed to
  514. have placed in the SYSTEM/SYSTEM.SETUP folder of your boot disk contains
  515. a complete set of templates for our latest interface files.  One of the
  516. Apple II Developer Technical Support Engineers put these templates together
  517. (and came up with a pretty neat way to build in a "help system" - so tell
  518. Jim "thanks" next time a template bails you out of a jam).
  519.  
  520. GSBug does NOT automatically load those templates (boy, that would sure eat
  521. memory - having the template auto-loaded!).  You have to tell GSBug to load
  522. them (and you can unload them later).  To load these templates, just type
  523. "loadtemp */system/system.setup/gsbug.templates" and press RETURN.  Keep
  524. trying until you get it right - it does work (watch out for typos, etc).
  525.  
  526. To view a piece of memory with a template simply determine the starting
  527. address of the template.  The starting address can be found in a number of
  528. ways - you can dereference a pointer that you just pushed on the stack, etc.
  529. Then, type an underscore, the type of structure you want used, a blank space,
  530. and the starting address (don't forget the bank).  (i.e.:  if you know you
  531. have a graf port starting at location 06/15E4, then type:  "_grafport 06/15E4"
  532. and press RETURN.
  533.  
  534. To use the built-in template help system that Jim came up with (thanks Jim!),
  535. just type: "_template 0" and press return.  This will give you a list of all
  536. the categories of help you can get more info on (such as ADB, FONTS, etc).
  537. The categories are grouped by toolbox manager.  To get details on a particular
  538. toolbox manager's tool calls, type "_toolmgrname 0" and press RETURN
  539. (replace "_toolmgrname" with the name of any tool manager - lead with an
  540. underscore or it won't work).  (i.e.: "_quickdraw 0" for details on QuickDraw
  541. data structures)  For more details, read the separate documentation file on
  542. using the templates.
  543.  
  544. If you want to create your own custom templates, then read the GSBug manual
  545. (pages 86-88) or decipher the templates in the GSBug.Templates file.  To
  546. unload the templates (and free up the memory they're eating), type "killtemp"
  547. and press RETURN from GSBug's command line.
  548.  
  549.  
  550. The New Stuff:
  551.  
  552. As if all of this weren't reason enough to use GSBug, the man behind this
  553. jewel recently added a couple more reasons (he calls them features).  The two
  554. most important ones (in my opinion) are "SetMileStone" and "DebugStr".  Both
  555. of these are fake tool calls that the debugger sees, intercepts, and acts on.  
  556.  
  557. SetMileStone simply changes the copyright message to be a string of your
  558. choice.  If you're having a problem figuring out where your code was last at
  559. before it jumped off into the weeds, then sprinkle SetMileStone calls into
  560. your source code (with different strings on each of course).  Then, when your
  561. app chokes and dies, you'll be presented with the text from the last
  562. SetMileStone that was executed.
  563.  
  564.  
  565. Cheap (and short) Trick #6:
  566.  
  567. If you get really fancy, you can build the strings on the fly and imbed the
  568. values of key variables into them to further simplify locating the bug.
  569.  
  570.  
  571. Calling all Debuggers:
  572.  
  573. Several "tool calls" have been added to GSBug.  These are called just like a
  574. regular tool call, except they're intercepted (and acted on) by the debugger.
  575. Do _NOT_ leave calls to these debugger tools in your software when you ship it
  576. to customers!  Why?  Because making these calls on a system that doesn't have
  577. GSBug installed makes a real mess...
  578.  
  579. The new calls are SetMileStone, DebugStr, DebugVersion, and DebugStatus.
  580. SetMileStone simply changes the debugger's string and lets your app keep
  581. running.  DebugStr works like SetMileStone (i.e.: changes the copyright string
  582. to something with info about your application) except it dumps you immediately
  583. into GSBug.  DebugVersion and DebugStatus act just like normal version and
  584. status calls for regular tool sets - they simply allow you to verify what
  585. version of the debugger is running before you try to make any debugger tool
  586. calls.
  587.  
  588. The tool numbers and parameter lists for these calls are:
  589.  
  590. Name            Tool #  Parameter (returns)
  591. --------------  ------  ---------------------------------------------------
  592. DebugStatus     $06FF   (non-zero = true, ToolLocator error it not loaded)
  593. DebugStr        $09FF   pointer to Pascal-style string
  594. DebugVersion    $04FF   ($159F for v.1.5B9)
  595. SetMileStone    $0AFF   pointer to Pascal-style string
  596.  
  597.  
  598. Want More Info?
  599.  
  600. Contact APDA and order the full package (you have a newer version of GSBug
  601. with this file, but APDA has the full manual).  You could also try to
  602. persuade me to add more detail to this file in the future (it's long enough
  603. for the first release).  Order it by calling APDA (1- 800-282-2732) and
  604. asking for part #A0037LL/A (the price is $30).
  605.