![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/all/themes/custom_front/images/you_are_here_red.gif)
![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/default/files/beta-site.gif)
|
Volume Number: | 10 | |
Issue Number: | 11 | |
Column Tag: | Tips &Tidbits |
Tips &Tidbits
By Scott T Boyd, Editor
Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.
Send us your tips! We’ll send you money, and developers all over the world will marvel at your insight, your wisdom, or the simple fact that you’ve got enough extra time to write and send a little bit of e-mail to make their lives a little bit better.
We pay $25 for every tip we use, and $50 for Tip of the Month. You can take your award in orders or subscriptions if you prefer. Make sure code compiles, and send tips by e-mail; editorial@xplain.com is a great address. See page two for our other addresses.
Tip Of The Month
Trapping Non-Trap Vector Calls
The Debugger has certain limitations in its ability to trace A-Line traps and such. As an example, suppose we’re interested in breaking on calls to CacheFlush. It’s a trap vector which is usually referenced by a JSR ([xx]) instead of the usual A-Line Trap vector. Because it doesn’t go through the normal A-line dispatcher, we can’t break on references to it with the Trap Intercept mechanism.
Here’s some example code that creates a dummy procedure in an application, and an initialization proc that patches the low-memory trap vector so that it points to the dummy procedure. I modify the dummy procedure to make it a JMP to the original value of the low memory vector [Remember, this is for debugging, not for shipping code. Shipping code should generally not modify code it’s about to execute - Ed stb]. Finally, the doPatch proc undoes the patch and restores the system to its previous state.
To use this, set a breakpoint at my_doPatch_Proc. When you drop into your debugger, look at the stack to see who’s calling. After some looking, you can automate the process by observing where the interesting return addresses are on the stack with an action clause (such as the one shown here) that would list them in the -Notes- window:
?ra := (ra7)^; { return addr is contents of A7 }
{ In the next line we check PC for an address in the Quadra 900 ROM }
if ?pc = 40887824 then ?ra := (ra7+#46+#28)^-2; { # = decimal } writeln(?ra:ProcPtr); { display the address as a proc name + offset }
resume;
/* 1 */ procedure my_doPatch_Proc; { make it at least 6 bytes long } begin end; procedure doPatch(doit:Boolean); CONST jCacheFlush = $6f4; type jmpL = record opc:integer; addr:Longint; end; VAR q:^jmpL; p:^Longint; begin p := pointer(jCacheFlush);{$06F4 is the low-mem global jCacheFlush} q := @my_doPatch_Proc; if doit then begin with q^ do begin opc := $4EF9; {JMP.L} addr := p^; end; p^ := Ord(q); end else begin p^ := q^.addr; { undo patch } end; end;
- Steve Jasik, Menlo Park, CA
Even Better Data Gathering
The September issue’s tip-of-the-month recommended a way to log standard information during crashes using the EveryTime MacsBug macro. This technique is particularly useful for beta sites to report bugs, but there’s an even easier way. Many versions of MacsBug already have a built-in macro called StdLog that does almost the same thing. Beta-sites can just use stdlog to supply you with information and it doesn’t require them to muck with their “Debugger Prefs” file.
- Harold Ekstrom, Walnut Creek, CA
![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/all/themes/custom_front/img/search_text.gif)
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine