home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-05 | 34.7 KB | 908 lines | [TEXT/EDIT] |
- MacsBug with MultiFinder: a practical example by Carol Crews
-
-
- Introduction
-
- This document covers the basic MacsBug commands, and is intended for testers who have a
- fairly good understanding of the Macintosh but are not necessarily programmers. It is designed
- both to develop a familiarity with MacsBug and to explain the changes in the heap structure which
- are the result of the new MultiFinder environment.
-
-
- There are five major sections: the tutorial, the MacsBug command section, a discussion of
- heaps in general, a discussion of the MultiFinder heap, and a list of information to include in bug
- reports. In addition, there is a list of further MacsBug reference materials, and a chart of the
- Macintosh character set (ASCII). For those who have never used MacsBug before, the tutorial
- will be helpful. For others, the list of commands will serve as a more complete reference than
- documents such as the MPW MacsBug section. For those who are expert at MacsBug, the section
- on the MultiFinder heap will be an introduction to the changes under MultiFinder. Testers should
- use the command list (section VII) as a starting point for deciding what to include in their bug
- reports; their software engineers may have modifications to this list.
-
-
- In order to follow this tutorial, you need: MacsBug 5.5, System 4.2, Finder 6.0,
- MultiFinder 1.0, MacWrite 4.6, and MacDraw 1.9.5. If any of the terms in this document are
- unfamiliar to you, check the glossary at the end of the document. It is assumed that you are
- experienced at working under MultiFinder.
-
-
-
- To get into MacsBug, make sure you have both MacsBug and a programmer's switch
- installed on your Mac. Press the interrupt switch (the one at the very back; the one towards the
- front will reboot the system), and you will drop into MacsBug.
-
-
- If you have any comments or recommendations for this document, please address them to me at
- M/S 27AQ, x6677.
-
-
-
- I. The goal
-
- With a basic understanding of MacsBug, you will not only have a better idea of what has
- happened when you crash during a testing session, but you will be better able to provide the software
- engineers with information which may help them isolate and fix a bug. The goal of the tutorial is to
- provide you with a basic understanding of both MacsBug and the MultiFinder heap.
-
-
- The tutorial covers the most commonly used MacsBug commands, including:
-
- 1. PC
-
- 2. WH
-
- 3. DM
-
- 4. IL
-
- 5. HC
-
- 6. HT
-
- 7. HX
-
- 8. HD
-
- 9. CV
-
- 10. TD
-
- 11. DV
-
- 12. G
-
- 13. RB
-
- 14. ES
-
- 15. `
-
- In addition, it will explain how to examine the MultiFinder (Juggler) heap to find other
- application heaps, and how to look at those heaps for more information.
-
-
-
- II. The tutorial session
-
- (Note: this tutorial was written for an SE with 2.5 mgs. Although you may not have this
- configuration, you should still be able to follow all of the examples. The important difference is that
- the addresses listed in MacsBug will be different numbers; compare what you see on your screen to
- what is listed in this document.)
-
-
- 1. Boot your Mac with MultiFinder on. Make sure that you have MacsBug 5.5 loaded in
- your system file. (You can do this by pressing the programmer's interrupt switch and
- then typing DV, for Display Version. Type G to return to the normal screen.)
-
- 2. Get info on the MacWrite application; set the size resource to 224K.
-
- 3. Get info on the MacDraw application; set the size resource to 192K.
-
- 4. Launch MacWrite.
-
- 5. Open the Alarm Clock.
-
- 6. Return to the Finder and launch MacDraw.
-
- 7. Press the programmer's interrupt switch to get into MacsBug.
-
-
- Note: you are now set up to follow the tutorial; the following sections are intended to
-
-
- III. What to look at in MacsBug
-
- When you drop into MacsBug, you will see a display of registers that looks similar to this:
-
-
-
- PC=00261C1C SR=00002000 tSii xnZvc Ti=0000C4C0
-
- D0=00000000 D1=00000210 D2=00000004 D3=00000001
-
- D4=0000FFFF D5=00000000 D6=001FDC9A D7=00000000
-
- A0=0026C0CE A1=00261B1A A2=00000000 A3=0040B5CC
-
- A4=00000000 A5=0026E108 A6=001FCEAE A7=001FCE8E
-
- RA6 1FCE8E 001F CEF4 0026 5A2E A000 085A 0000 0000 .....&Z....Z....
-
- RA7 1FCE8E 0000 0000 0026 1B96 0000 0000 0000 0001 .....&..........
-
-
- 261C1C: 3002 0C400021 MOVE.W D2,D0
-
-
-
-
-
- This is called the Total Display; you can get it onscreen whenever you are in
- MacsBug by typing TD.
-
- PC is the Program Counter; this register contains the address of the next instruction
- to be executed.
-
- SR is the Status Register; it contains information about the status of the 68000 chip
- and interrupt levels.
-
- A0, A1, A2, A3, A4, A5, A6, and A7 are 8 Address registers (lines 4 and 5
- above), and D0, D1, D2, D3, D4, D5, D6, and D7 are 8 Data registers (lines 2 and 3
- above). Address registers are used to manipulate addresses, and data registers are used to
- manipulate data.
-
-
- As you can see above, the last line of the display starts with the address of the
- program counter ("261C1C:" refers to the same address as "PC=00261C1C", from the
- first line of the display). "MOVE.W" (at the end of this line) is the instruction which was
- about to be carried out when you dropped into MacsBug. Thus, you can see where the
- program counter was (the address) and what it was going to do (the instruction MOVE.W).
- You can include this information in your bug report, e.g. "PC=261C1C MOVE.W
- D2,D0". This may help the engineers figure out what was happening when you crashed or
- hung.
-
-
- At this point, you can type a number of commands to get more information about
- what was happening when you dropped into MacsBug:
-
-
- IV. MacsBug Command Section
-
-
- 1. PC (program counter)
-
- Although this information is usually shown in the total display (as demonstrated
- above), it may not be displayed if you have crashed. In order to get the information on the
- program counter, just type PC. MacsBug will then tell you where the program counter is
- and what it was doing. In this example, it says:
-
- 261C1C: 3002 0C400021 MOVE.W D2,D0
-
-
- 2. WH PC (or WH; where pc)
-
- This command displays the location of the first named routine it finds, working back
- through memory from the PC. Ex:
-
- In RAM Jug heap: 00261C1C
-
- WH PC may not give the same address as PC; check both PC and WH PC and include the
- results of both in your bug report. If the current routine did not have a name, MacsBug
- may go back a long way to find one; often, the first named routine it finds turns out to have
- been the last ROM call made, which may have nothing to do with what was happening
- when you crashed. That's why it's important to include the info from both PC and WH in
- your bug report. (Note: This command may crash MacsBug if heaps are in inconsistent
- states. You may want to do this command last.)
-
-
- 3. DM 910 (display memory 910)
-
- Memory location 910 always contains the name of the currently active application; in
- this example, it says:
-
- 000910 0D54D 6163 4472 6177 2031 2E35 8100 .MacDraw 1.9.5..
-
- "00910" tells you what memory location this is; ".MacDraw 1.9.5.." tells you what
- application is active (for example, you may have crashed when trying to switch between
- applications in MultiFinder; this can help you determine which application crashed). DM
- can be used to display many memory locations other than 910 (which is a system global);
- other system globals are listed on pages 481-488 of Scott Knaster's book, How to Write
- Software for a Macintosh.
-
-
- 4. IL PC-20 (instruction list, starting 20 bytes before the program counter address)
-
- This command disassembles (i.e. translates) assembly code into something readable
- - if you read 68000 code! It can be helpful to the programmers to look at this, and you
- may be able to learn it through osmosis. You can disassemble any number of lines and
- from any address.
-
- The address is the value right after IL; in this case it's "PC", which has the value of
- 261C1C because that's where the Program Counter is (see above). You could use the
- actual value " 261C1C", as in "IL 261C1C-20", but it's usually easier to type PC than
- figure out its location and type that in.
-
- The number of bytes is your choice; it indicates how many bytes before the
- program counter MacsBug should begin disassembling. In general, the program counter is
- not shown at exactly the right place, so if you look back a few lines from the PC you are
- more likely to discover the correct line. This is because the program counter is sometimes
- advanced before the previous instruction was completed; if the Mac crashes on an
- instruction after advancing the program counter, the program counter is in the wrong place.
- That's why you need to look at 10 or 20 bytes before the PC. Note: MacsBug displays 14
- lines of disassembled code at once. If you press return, MacsBug will give you the next
- 14 lines; you can do this over and over to go through a long instruction list. (Normally,
- when you press return, MacsBug repeats your last command exactly; this is one of the few
- cases where pressing return gives you additional information instead of repeating the last
- information it gave. ) Another thing to notice is how the addresses are listed: they are all
- even numbers. This is because the instructions for the 68000 chip are an even number of
- bytes, and they should always start at an even number. If you notice that the address for
- the PC is an odd address, you probably crashed with an address error (it couldn't do
- anything at that address).
-
-
- 5. HC (Heap Check)
-
- Heap check tells you the location of the current heap. It's a good idea to do this as
- soon as you drop into MacsBug, so that you will know if your heap is corrupted. If the
- heap is ok (i.e. not trashed or corrupted), MacsBug will say something like "Current heap
- is at 001CE8AA." If the heap is corrupted, MacsBug says something like "Heap?
- @0001BE0A 00427076" (this is an imaginary heap location, just used for example.) The
- question mark after Heap indicates that the heap has been corrupted. If the heap is not ok,
- Do Not Use Any Heap Command Other Than HX if you have a bad heap (HX
- exchanges you away to another heap; for more info, see below). If you try to get a heap
- dump or heap total from a bad heap, you may cause your machine to be rebooted or create
- an address error - and then any useful information you were trying to get out of the
- MacsBug session will be lost! You can use HC at any point to see what heap you are
- currently set to.
-
-
- 6. HT (Heap Total)
-
- HT will get you information on the status of the memory within the current heap.
- When you dropped into MacsBug above, the current heap was the application heap (for
- MacDraw). To check that you are still looking at this heap, type HC; if the heap address
- isn't 1600 (on an SE, or 1400 on a Mac+, or 1E00 on a MacII - these are the locations of
- the system heap on each machine), then you are in the application heap (see "A Discussion
- of Heaps", below, for more information on system and application heaps.) Then type HT;
- it should look something like this:
-
- Current heap is at 001CE8AA
-
- Ptrs: 0003 Hand: 0045 Locked: 0003 Purgeable: 0007
-
- Heap Sze: 0002C636 Free: 0001C09C Purge Sp: 00003014
-
- This tells you:
-
- • the location of the heap (1CE8AA)
-
- • the number of pointers (there are 3 pointers in this heap)
-
- • the number of handles (45 is hex for 69, so there are 69 handles in this heap)
-
- • the number of locked blocks in the heap (3)
-
- • the number of purgeable blocks (7)
-
- • the size of the heap (2C636 hex bytes)
-
- • the amount of free space (1C09C is hex for 114844, which is about 112K)
-
- • the amount of purgeable space (3014 is hex for 12308, which is about 12K)
-
- When you have little free or purgeable space, you may have crashed because you ran out of
- memory; use HT to give you a better idea of how tight memory was. (Note: see below
- "CV", for information about converting hex numbers to decimal.)
-
-
- WARNING: Do not use HT when the heap may be corrupted; first, type HC to see that it
- is ok. If you don't get a question mark, it's probably ok to get a heap total or a heap
- dump.
-
-
- 7. HX (Heap eXchange)
-
- HX stands for Heap eXchange; it lets you switch around between the various heaps.
- For a more in depth explanation of heaps, including how to look at the MultiFinder
- (Juggler) heap, see "A discussion of heaps", below. You can use HX to toggle between
- the two primary heaps: the current application heap and the system heap. When you drop
- into MacsBug, you are usually in the application heap; if you type HX, you will exchange
- to the system heap. If you type HX again, you will exchange back to the application heap.
- You can always use HC to check which heap you are in, and whether or not the heap has
- been corrupted. You can exchange to other heaps such as the MultiFinder heap or any of
- the applications within the MultiFinder heap; this is covered in depth below.
-
-
- 8. HD (Heap Display)
-
- This command displays the current heap. A heap display looks like this:
-
- >HD
-
- 0001C3A0 h 0000000C 00269E60 02F2 CDEF 0101
-
- 0001C3AC h 00000046 00269E9C 02F2 DITL 0103
-
- 0001C3F2 h 0000000E p 00269E98 02F2 STR# 0100 (see ex. below)
-
- 0001C400 h 000002D0 00269E90 02F2 DITL 0105
-
- 0001C6D0 h 000002D0 00269E58 02F2 CNTL 0100
-
- 0001C9A0 h 00000092 00269E54 02F2 MENU 0400
-
- 0001CA32 h 0000000C 00269E50 02F2 MENU 0700
-
- 0001CA3E h 0000000C 00269E4C 02F2 MENU 0800
-
- 0001CA4A h 0000000C 00269E48 02F2 MENU 0600
-
- 0001CA56 h 0000000C 00269E44 02F2 MENU 0300
-
- 0001CA62 h 000002D0 00269E3C 02F2 MENU 0A00
-
- 0001CD32 h 00000092 00269E38 02F2 MENU 0500
-
- 0001CDC4 h 0000000C 00269E34 02F2 MENU 0200
-
- 0001CDD0 h 0000000C 00269E30
-
- 0001CDDC h 0000000C 00269E2C 02F2 CURS 010E
-
- 0001CDE8 h 0000000C p 00269E28 02F2 fcod 00FD
-
- 0001CDF4 h 0000001C p 00269E68 02F2 fcod 00FB
-
- 0001CE10 h 00000012 00269EA8
-
-
-
-
-
- Each line of the display contains information about a block in the current heap zone. The
- columns contain the following information (the line used for the example is the third line
- in the display above; the numbers above each column refer to the names listed below):
-
-
- 1 2 3 4 5 6 7 8 9
-
- 0001C3F2 h 0000000E p 00269E98 (*) 02F2 STR# 0100
-
-
-
- 1: Block address (0001C3F2)
-
- 2: Type (h)
-
- 3: Size (0000000E)
-
- 4: Flag (p)
-
- 5: Master pointer location (00269E98)
-
- 6: Locked (*)
-
- 7: Refnum (02F2)
-
- 8: Res type (STR#)
-
- 9: ID# (0100)
-
-
-
- Block address points to the start of the block of memory. The first 8 bytes of each
- block is the header, which is used for the memory manager, so that space doesn't contain
- information you are likely to be interested in. This means that you have to account for
- that space when you are looking at the block; more about this later, in the section about
- the MultiFinder heap.
-
-
- Type is one of three letters, indicating:
-
- f - free block
-
- p - pointer
-
- h - handle to a relocatable block.
-
-
- Size is the physical size of the block, in hex; the size includes the contents of the block,
- the header, and any unused bytes at the end of the block.
-
-
- Flag - this column is used when the type column contains an h (for handle). If there is a
- p in the flag column, then the handle is purgeable. If there is no p, then this handle is not
- purgeable. Note: pointers are not purgeable, so there is never a "p" flag for a pointer
- block.
-
-
- The master pointer location is used when the block is a handle. The master pointer
- location is the address of the master pointer block (which is usually in a non-relocatable
- block). You can use this to find the block by dereferencing it, which means using an @
- at the front of the address. Again, more about this later, in the section on MultiFinder
- heaps.
-
-
- An asterisk in the 6th column indicates that this block is locked; if there is no asterisk,
- then the block isn't locked (this is only used with non-purgeable blocks that are handles).
- An unlocked block can be relocated, and a locked block can't. Note: pointers blocks are
- always non-purgeable and locked, by definition: you don't want to relocate a pointer.
- Because pointers are always locked, MacsBug does not include an asterisk in the sixth
- column; it might be considered redundant. Conclusion: when you see an asterisk in the
- sizth column, you know that you are looking at a non-purgeable, non-relocatable handle
- block.
-
-
- The last three columns are used when a block is a resource file block. They are the
- resource file's reference number (file refnum), its ID number, and the resource
- type.
-
-
- You can terminate or interrupt a heap dump by pressing the backspace key; you can pause
- it and restart it by pressing the space key.
-
-
- 9. CV (ConVert)
-
- CV means ConVert; MacsBug will convert any value into unsigned hexidecimal,
- signed hexidecimal, decimal, and binary for you. This is very useful in checking sizes,
- which are generally expressed in hex. For example, if you type "CV 151515", MacsBug
- returns:
-
- $00151515 00151515 #1381653 '....' 00000000 00010101 00010101 00010101
-
- The first number, preceeded by $, is the unsigned hex representation; the second number is
- the signed hex representation. The third number, preceeded by #, is the decimal
- representation; the 0's and 1's at the end are, of course, binary. The section in the middle,
- '....', is the text version, i.e. the ASCII representation (this number does not have an
- ASCII equivalent.) You can also get it to convert text to an ASCII code, or vice versa. For
- example, "CV 'M" (preceed the text you want to convert with an apostrophe) would get
- you:
-
- $0000004D 0000004D #77 '...M' 00000000 00000000 00000000 01001101
-
- This shows that the ASCII code for M is 77 (the decimal version, since the ASCII chart is
- written in decimal, not hex or binary.) See if you can spell your name in ASCII
- equivalents! The Macintosh character set, which includes both the ASCII character set and
- some special characters, can be found on page 247 of volume one of Inside Mac; a copy is
- attached to the end of this document.
-
-
- 10. TD (Total Display)
-
- As mentioned above, this allows you to see the total display. This is usually
- displayed when you first enter MacsBug, but it may scroll off. You can get it back again
- by typing TD.
-
-
- 11. DV (Display Version)
-
- Display Version simply tells you which version of MacsBug you are using; you
- should be using Macsbug 5.5 June 17th, 1987 or later.
-
-
- 12. G (G0)
-
- Go can be used to return you to the point you were at when you dropped into
- Macsbug. For this tutorial session, you dropped into Macsbug by pressing the interrupt
- switch; this means that there probably wasn't anything wrong with your system, and if you
- return to where you left off, you can continue to work. HOWEVER, if you crashed into
- Macsbug or were hung and interrupted into it, your Mac is probably not in a workable
- state. If you use G at this point, you may crash again, it may hang, it may reboot... To be
- safe, only use this command when you know the machine is "clean".
-
-
- 13. RB (ReBoot)
-
- You can always reboot from Macsbug - which you will often need to do when the
- machine is really messed up and you've had an address or bus error. When you need to
- reboot, you can do so by using this command, the restart switch on the programmer's
- button, or the power switch.
-
-
- 14. ES (Escape Shell)
-
- Sometimes, your application heap may be messed up, but other things are still
- running ok. If you type ES, the Mac will attempt to return to the Finder (after quitting the
- application you were in). This may allow you to go into other applications and save data.
- However, anytime you've been forcefully dropped into Macsbug, you must restart the
- system before doing any serious work, because there may be other unknown conditions in
- the machine. So use ES to get back to the Finder (when possible), clean things up, save
- what you can, and restart to try again. It is extremely important that you reboot after using
- ES and before continuing with your testing, or your results will be invalid.
-
-
- 15. ` (toggle between screen and MacsBug)
-
- This strange key, the back apostrophe, lets you toggle between looking at the
- Macsbug screen and at the Mac screen as it was just before you crashed. This sometimes
- lets you get an idea of what was happening when you crashed.
-
-
- V. A discussion of heaps
-
- The Macintosh divides memory up into a number of heaps, each of which has a different
- function. Before MultiFinder, there were only two heaps: the application heap and the
- system heap. The application heap contains the application's code and its resources, and the
- system heap contains operating system data structures.
-
- You can look at both of these heaps in Macsbug, and can toggle between them by typing
- HX, or heap exchange. When you drop into MacsBug, you are set at the application heap; if
- you type HC for heap check, MacsBug will tell you about the application heap. When you type
- HX you toggle (exchange) to the system heap (and if you type it again, you toggle back to the
- application heap). You can tell which heap you are looking at because the system heap begins at
- a specific location for each machine:
-
- On the Mac+, it begins at 1400.
-
- On the SE, it begins at 1600;
-
- On the Mac II, it begins at 1E00;
-
-
- If the heap starts at a location other than one of these, you are looking at an application
- heap. To see what the heap location is, type HC or HX; MacsBug will tell you the current heap
- location (if the heap is not corrupted), i.e. "Current heap is at 00001600."
-
- The application heap contains the code and resources for your current application. In this
- example, the current application is MacDraw, because that is where you were when you pressed
- the programmer's interrupt switch. You can tell the name of the current application by typing
- "DM 910"; this memory location holds a string containing the application's name. If you were in
- the Finder when you pressed the interrupt switch, the Finder would be the current application;
- you would be looking at the Finder's heap when you dropped into MacsBug, and DM 910
- would return "Finder".
-
-
-
- VI. The MultiFinder heap
-
- With MultiFinder, the heaps work differently. You still have a system heap, and it still
- starts at the standard location. You also still have a current application heap, and you can toggle
- between the two using HX. The difference with MultiFinder is that you may have more than one
- application loaded at once; although only one of these can be the current application, the other
- applications have their own heaps. You have to work a bit harder to get to them, but it is
- possible to examine the heap for each application.
-
- When MultiFinder is running, it takes over the space previously used as the application
- heap and uses it as its own heap. It then subdivides this fairly large space into separate heaps for
- each application.
-
- To exchange to the MultiFinder heap, type "HX @@2A6+C." ("@@2A6+C" refers to
- the MultiFinder heap - that's the place you need to get to in order to look at the MultiFinder
- heap.) To make sure that the heap is ok, type HC before doing anything else. (If you've
- crashed while using MultiFinder, there's a chance that the MultiFinder heap is trashed.) If the
- heap is ok, you can display the heap by typing HD, and then look at the last few lines of the heap
- to find the locations of the other application heaps. In our example, we have MacWrite and
- MacDraw loaded, and we dropped into MacsBug while MacDraw was the active (current)
- application. This means that when we use HX alone (i.e. without an address such as
- "@@2A6+C"), we will switch back and forth between the system heap and the MacDraw heap.
- In addition, there is a MultiFinder heap, and within the MultiFinder heap, a MacWrite heap. As
- a matter of fact, the MacDraw heap is also inside the MultiFinder heap. And that's not all! The
- Finder has a heap inside the MultiFinder heap (this allows you to switch back to the Finder
- whenever you want while you're running MultiFinder). A few other small applications, such as
- Backgrounder, also have small heaps; this makes it possible for you to print in the background
- while you do other things in the foreground.
-
-
- Let's look at the MultiFinder heap (this will only include the last lines of the heap display):
-
-
-
- >HX @@2A6+C (exchange to the MultiFinder heap)
-
- Current heap is at 0026048
-
- >HC (make sure the MultiFinder heap is ok)
-
- Current heap is at 0026048
-
- >HD (display the MultiFinder heap -this shows
-
- just the last screenful)
-
- 0002665C h 00000012 0026A080
-
- 0002666E h 0000000C 0026A078
-
- 0002667A h 00000046 0026A0AC
-
- 000266C0 h 0000000E 0026A0A8
-
- 000266CE h 000002E8 0026A0A0
-
- 000269B6 h 000002E8 0026A074
-
- 00026C9E h 000000CE 0026A070
-
- 00026D6C h 0000000C 0026A068
-
- 00026D78 h 0000000C 0026A064
-
- 00026D84 h 0000000C 0026A06C
-
- 00026D90 h 00000012 0026A0B8
-
- 00026DA2 h 000002E8 0026A058
-
- 0002708A h 000000CE 0026A054
-
- 00027158 h 0000000C 0026A050
-
- 00027164 h 0000000C 0026A04C
-
- 00027170 h 0000000C 0026A048
-
- 0002717C f 001A770A
-
- 001CAA1A h 00003E88 0026A044 *
-
- 001CE8A2 h 00030008 0026A05C *
-
- 001FE8AA h 00038008 0026A060 *
-
- 002368B2 h 00028008 0026A08C *
-
- 0025E8BA h 00002208 0026A0A4 *
-
- 00260AC2 h 00000034 0026A0B0 *
-
- 00260AF6 h 0000003A 0026A0B4 *
-
- 00260B30 h 0000253A p 0026A0C0 *
-
- 0026306A h 0000064A p 0026A0C4 *
-
- 00169C1C p 000004B0 *
-
- Ptrs: 0002 Hand: 0021 Locked: 0009 Purgeable: 0000
-
- Heap Sze: 00244084 Free: 001A7726 Purge Sp: 00000000
-
-
-
- We can look at the last few lines of this display and learn a great deal about the various
- applications which are loaded: the lines which are marked as handles (h's in the 2nd column),
- not purgeable (p's in the 4th column), and locked (asterisks in the 6th column) are potential
- application heaps. Seven of the last ten lines meet these qualifications (each line represents a
- block in memory). We know that open applications include DA Handler (so that Alarm Clock
- can be open), MacWrite, MacDraw, the Finder, and perhaps Backgrounder. (Note:
- Backgrounder is a small application which sits around waiting for a print job to be spooled.
- When a spooled file is present, Backgrounder launches PrintMonitor which can then print the file
- in the background.) The third column is the size, in hex; if we convert these sizes and then
- divide by 1024, we see that, of the seven potential heaps, the top five lines (blocks) are sizes
- 15.5K, 192K, 224K, 160K, and 16K, respectively (use the calculator to divide the number of
- bytes by 1024, to get the number of K). Before we launched MacDraw and MacWrite, we set
- the size resources to 192K and 224K. If you check the Finder, you will see that it likes to have
- 160K for its heap. The first one, 15.5K, is likely to be the DA Handler, and the last one, 8.5K,
- is likely to be the Backgrounder heap. Because these applications don't let you change their
- resource sizes, you have to look at their size resources in ResEdit. DA Handler 1.0 has a size
- resource of 15.5K, and Backgrounder 5.0 has a size resource of 8.5K. Thus, we can account
- for the top five application heaps. The last two, with sizes of 34 and 3A (in hex) are resident
- whenever MultiFinder is running, but are of no interest to us.
-
- The best way to tell which application heap is which is to keep a list of the size resources
- you set for each application, so that you can compare them to the heap sizes shown in MacsBug.
- Try to set a unique size for each, to give your detective work a better chance to succeed.
-
- However, you can't take it for granted that if the heap size is about the same as the size
- resource, you've found the right heap; you should look at it a bit more. In order to examine the
- actual application heaps, we use the HX command again, and specify an address. How do we
- know what address to look at? From the explanation of heap displays (above), we know that the
- first column is the block address, and that the address given includes the 8-byte header used for
- the memory manager. Therefore, if we use the block address and add 8 bytes, we'll get to the
- beginning of the supposed application heap.
-
- Try it. Refer to the previous pages for the entire MacsBug dump; only the necessary lines
- will be included here. Compare what you see to what is shown in the document. First, look at
- the MacDraw heap. This one will be easy to verify, because it is the current application heap,
- and you know you can always get to it by typing HX one or two times. Remember, MacDraw
- has a size resource of 192K, which is 30008 bytes in hex. Look at your MultiFinder heap
- display, and find the line with an asterisk at the end, which has the number 30008 in the 3rd
- column. Take the number in the first column (in this case, the number in the first column is
- 001CE8A2), and substitute it in these commands:
-
-
- >HX 1CE8A2+8
-
- >HC
-
- Current Heap is at 001CE8AA
-
- >HX
-
- Current Heap is at 00001600 (that's the system heap on an SE)
-
- >HX
-
- Current Heap is at 001CE8AA
-
-
- It works! By adding 8 to the block address on the line you're interested in and
- exchanging to that heap, you've found one of the application heaps. Using HX twice made you
- switch between the system heap and the application heap, and proved that the heap you're
- looking at was the same application heap we'd been looking at earlier, MacDraw. It's important
- to type HC, to check that you've switched to a valid heap.
-
- Now try to look at the MacWrite heap. First, you have to switch back to the MultiFinder
- heap and dump it, so that you can look for the blocks which contain the other application heaps.
- Next, find the line containing the size 38008, which is 224K, the size resource for MacWrite
- (this block is underlined in the example below). Add 8 to that, exchange to it, and check the
- heap to make sure it's valid:
-
-
-
- >HX @@2A6+C (exchange to the MultiFinder heap)
-
- Current heap is at 0026048
-
- >HC (make sure the MultiFinder heap is ok)
-
- Current heap is at 0026048
-
- >HD (display the MultiFinder heap -this shows
-
- just the last screenful)
-
- 0002665C h 00000012 0026A080
-
- 0002666E h 0000000C 0026A078
-
- 0002667A h 00000046 0026A0AC
-
- 000266C0 h 0000000E 0026A0A8
-
- 000266CE h 000002E8 0026A0A0
-
- 000269B6 h 000002E8 0026A074
-
- 00026C9E h 000000CE 0026A070
-
- 00026D6C h 0000000C 0026A068
-
- 00026D78 h 0000000C 0026A064
-
- 00026D84 h 0000000C 0026A06C
-
- 00026D90 h 00000012 0026A0B8
-
- 00026DA2 h 000002E8 0026A058
-
- 0002708A h 000000CE 0026A054
-
- 00027158 h 0000000C 0026A050
-
- 00027164 h 0000000C 0026A04C
-
- 00027170 h 0000000C 0026A048
-
- 0002717C f 001A770A
-
- 001CAA1A h 00003E88 0026A044 *
-
- 001CE8A2 h 00030008 0026A05C *
-
- 001FE8AA h 00038008 0026A060 *
-
- 002368B2 h 00028008 0026A08C *
-
- 0025E8BA h 00002208 0026A0A4 *
-
- 00260AC2 h 00000034 0026A0B0 *
-
- 00260AF6 h 0000003A 0026A0B4 *
-
- 00260B30 h 0000253A p 0026A0C0 *
-
- 0026306A h 0000064A p 0026A0C4 *
-
- 00169C1C p 000004B0 *
-
- Ptrs: 0002 Hand: 0021 Locked: 0009 Purgeable: 0000
-
- Heap Sze: 00244084 Free: 001A7726 Purge Sp: 00000000
-
- >HX 1FE8AA+8
-
- Current heap is at 001FE8B2
-
- >HC
-
- Current heap is at 001FE8B2
-
-
-
- This is more than likely the MacWrite heap; there isn't much more you can do to verify
- this, however, without learning a great deal more about MacsBug and assembly language. It is
- still useful to be able to exchange to all of the applications heaps and check that they are not
- corrupted. Another thing you can do is display memory for the size of the heap and see if it
- contains any recognizable character strings. To do this, you look again at the block and its size
- as listed in the MultiFinder heap, and use the DM command. The format is "DM (block
- address+8) (Size-8)." This means "display what's in memory at the beginning of the
- application heap (accounting for the 8-byte header) for an amount equal to the size of the
- application heap, minus the 8-byte header". Remember that you can use the space bar to pause
- and continue scrolling. Try it, using the correct block address from your MultiFinder heap:
-
-
- >DM 1FE8AA+8 38008-8
-
-
- You can also use the DM command to look at DAs. The DA Handler is an application
- which is loaded into the MultiFinder heap, but the DAs themselves are drivers which are loaded
- in the system heap. To look for a DA, you switch to the system heap, dump a list of the drivers,
- and then display the first bytes of the driver:
-
- >HX
-
- Current Heap is at 001CE8AA (the MacDraw heap)
-
- >HX
-
- Current Heap is at 00001600 (the system heap on an SE)
-
- >HD 'DRVR (dump the drivers in this heap)
-
- Current heap is at 00001600
-
- 00018170 h 00000F7E p 0000D944 0002 DRVR 000D
-
- Cnt ### 0001 0000349C
-
- >DM 18170 F7E
-
-
- "HD 'DRVR" tells MacsBug to give you a list of all the drivers in the system heap. Each
- DA has its own drivers; other drivers may also be included. The command "DM 18170 F7E"
- tells MacsBug to display memory starting at the address of the driver for the entire size of the
- driver. Usually, the driver's name is included in the first two or three lines; use the space bar to
- stop the scrolling display, and the delete key to exit the command. If you have other drivers
- listed, you can look at them also. It is sometimes helpful to be able to find out what DAs were
- loaded when you have crashed and can't remember what you had open.
-
-
-
-
- VII. What to write down in your bug report
-
- This tutorial has covered a lot of commands; how can you use this information in your
- bug reports? The engineer on your project will have his or her own needs for specific
- information; have your team leader find out what they are, and include that information in your
- report.
-
-
- Here is a general list; include both the commands and the results in your report:
-
- 1. HC - report the heap location and its condition
-
- 2. HX - exchange to the other heap
-
- 3. HC - report the location of the other heap and its condition
-
- 4. DM 910 - report the current application
-
- 5. PC - the address of the PC
-
- 6. WH PC - the previous named routine
-
- 7. IL PC-20 - if you have time and room, write down the lines preceeding and following the
- PC
-
- 8. DM RA7 30 - Display the first 30 bytes of the stack
-
- 9. TD - write down the information from the total display, including the lines for RA6 and RA7
-
- 10. HX @@2A6+C - if you're running under MultiFinder
-
- 11. HC - report how the MultiFinder heap is
-
- 12. Look at other application heaps and their condition
-
- 13. HT - check the amount of free and purgeable space for each heap you examine
-
-
-
- VIII. Other sources of information on MacsBug
-
- 1. Appendix D, How to Write Software for the Macintosh, Scott Knaster.
-
- 2. Debugging with MacsBug (chapter 8), MPW manual, Apple Computer.
-