September 94 - KON & BAL'S PUZZLE PAGE
KON & BAL'S PUZZLE PAGE
Heaps of Fun
KONSTANTIN OTHMER, BRUCE LEAK, AND Steve
NEWMAN
See if you can solve this programming puzzle, presented in the form of a dialog
between Konstantin Othmer (KON) and Bruce Leak (BAL) -- and a special guest,
developer Steve Newman. The dialog gives clues to help you. Keep guessing until you're
done; your score is the number to the left of the clue that gave you the correct answer.
Even if you never run into the particular problems being solved here, you'll learn
some valuable debugging techniques that will help you solve your own programming
conundrums. And you'll also learn interesting Macintosh trivia.
Steve I've got a machine that crashed into MacsBug. I think it's this bug that some of
our beta testers have been reporting; it's really intermittent, so I may not get it to
happen again. I've got to find it just by looking at this one crash.
KON It's not reproducible?
Steve Not if it's the bug I've been hearing about. The reports are always the same: The
machine crashes while saving a file. Afterward the file is unreadable. If they go back to
an older copy of the file, the problem doesn't recur. No single user seems to have had
this crash happen more than twice, and no one has been able to associate it with
something they were doing in the program before they told it to save.
BAL What does this program do?
Steve It's a PIM -- personal information manager. Data entry and dialog boxes and
stuff. It's a pretty big program, but very vanilla in its use of the ROM -- strictly
Volume I stuff, plus the Memory Manager and File Manager, of course.
KON You've tried stress testing? Heap scramble, low-memory conditions, MemHell,
QC, all of that?
Steve Yeah. It was a war zone, and we couldn't bring out the bug. But it just happened to
one of our tech support people, Stephanie. I've taken over her machine until I can
figure out what's going on. She closed a file, it asked her if she wanted to save changes,
she clicked Yes, and it crashed into MacsBug with an illegal instruction.
BAL Illegal instruction? Sounds like you've branched off into the middle of nowhere.
Where's the program counter?
100 Steve wh pc says we're in CODE segment 44, $017C bytes into a routine called
Preflush. According to a link map I can look at on another machine, segment 44 has the
file-saving code.
KON Is the heap trashed?
95 Steve MacsBug says the heap is fine.
BAL Perhaps some random memory-trashing bug has overwritten part of the code
segment. Disassemble around the program counter.
90 Steve It looks like valid code, but the PC is in the middle of an instruction.
KON Do you have any purgeable code segments?
85 Steve We have a fairly complicated code segment management scheme based on
reference counting. We're pretty careful about it, though; it's been a long time since
we've had any problems there. As it happens, segment 44 is purgeable, but it has too
many entry points to do reference counting, so we just unload it from our event loop.
BAL Sounds like code right out of the Finder. Let's try to find out how we managed to
branch into the middle of an instruction. Do a stack crawl and see where we came from.