TweetFollow Us on Twitter

June 95 - Balance of Power: MacsBug for PowerPC

Balance of Power: MacsBug for PowerPC

Dave Evans and Jim Murphy

Where would we be without our venerable friend MacsBug? Those long debugging sessions, with soda cans piling up, would be so lonely. Like a trusted buddy, only a key press away, MacsBug has helped us solve the toughest problems and has taken us into the very core of the Macintosh.

Yet now the core has changed. The Macintosh has transmuted into a RISC powerhouse, and its new runtime environment is a foreign place to the old MacsBug. But instead of leaving our friend in the past, Apple is developing a next-generation MacsBug. The next MacsBug, version 6.5, supports PowerPC debugging with the same commands that you already know. An early release of the new MacsBug is provided on this issue's CD.

A QUICK LOOK

When we're confronted with a MacsBug display that heralds the beginning of a new debugging challenge, our first questions are "Where are we?" and "How did we get here?" MacsBug has always provided tools and information to help us quickly answer these questions. The stack crawl commands, for example, show not only what code you're executing but also how you got there. On a Power Macintosh, however, the old MacsBug often failed at tasks like the stack crawl. The PowerPC architecture changes fundamental structures -- such as stack frame formats -- and introduces new hurdles like mixed-mode switches and native code. The key goal of the new MacsBug is to restore the functionality you need in order to debug on a Power Macintosh.

The new MacsBug adds many features to satisfy this goal. It lets you disassemble, trace, and step through PowerPC code. You can set breakpoints in PowerPC code, and easily find out what code fragment you've interrupted and what native symbol is closest. And you can display a stack crawl that includes both PowerPC and 680x0 stack frames. Let's take a closer look at these and other new features.

DISASSEMBLING POWERPC CODE

The new MacsBug will disassemble both PowerPC and 680x0 code. Some commands are now sensitive to which type of code is executing. The td (total display) command will show the PowerPC register set during execution of native code, and the 680x0 emulated registers during execution of 680x0 code. When used without an address, the il and ip commands will disassemble the code currently being executed, whether PowerPC or 680x0; however, when an address is specified with il and ip, MacsBug will disassemble 680x0 code at the specified address.

We've introduced a few new commands to force disassembly of PowerPC native code. They include the following:

  • ilp: Instruction list of PowerPC code

  • ipp: Instruction half-page list of PowerPC code

  • idp: Instruction display one word as PowerPC code

  • dhp: Disassemble hex as PowerPC code

  • brp: Set breakpoint in PowerPC code
To demonstrate, we'll set a native breakpoint in the Memory Manager with brp __SetHandleSize. After we type g and wait for a second, MacsBug interrupts with this display:
PowerPC breakpoint at 000A06C4 __SetHandleSize
We type the il command and see the following (notice the familiar breakpoint bullet and the asterisk showing the current program counter location):
Disassembling PowerPC code from 000A06C4
  __SetHandleSize
     +00000 000A06C4 **mflr    r0
     +00004 000A06C8   stmw    r26,-0x0018(SP)
     +00008 000A06CC   stw     r0,0x0008(SP)
     +0000C 000A06D0   stwu    SP,-0x0170(SP)
     +00010 000A06D4   lwz     r30,0x0000(RTOC)
     +00014 000A06D8   addic   r7,SP,72
     +00018 000A06DC   lwz     r26,0x0000(r30)
     +0001C 000A06E0   ori     r31,r4,0x0000
     +00020 000A06E4   stw     r7,0x0000(r30)
     +00024 000A06E8   ori     r29,r5,0x0000
     +00028 000A06EC   lwz     r3,0x0004(RTOC)
     +0002C 000A06F0   bl      __HSetStateQ+013C
     +00030 000A06F4   lwz     RTOC,0x0014(SP)
     +00034 000A06F8   ori     r28,r3,0x0000
     +00038 000A06FC   addic   r3,SP,72
From here we can display any PowerPC register, step or trace through the code, or ask for our location using the improved wh command. The wh command now lists which code fragment contains the address, using the code fragment export symbols to display the nearest earlier symbol. In this example, we interrupted at __SetHandleSize in the MemoryMgr code fragment, so wwh produces this:
Address 000A06C4 is in the System heap at
    00002800 at __SetHandleSize
This address is within the code fragment
    named "MemoryMgr".
It is 000021D4 bytes into this heap block:
  Start    Length       Tag  Mstr Ptr  Lock
* 0009E4F0 00009050+04   R   00002BF0   L       

CRAWLING AROUND TOGETHER

MacsBug version 6.5 distinguishes between PowerPC and 680x0 stack frames but will display them as a unified stack crawl. This makes it very easy to determine where you are and where you've been. Since the PowerPC version of the Mac OS still contains a substantial amount of 680x0 code, you'll often see references to 680x0 callers in the stack crawl. Otherwise, expect to see the nearest earlier code fragment symbol to each caller. A sample stack crawl, displayed with the sc command, would look like this:
Frame     Caller    ISA
01D87FB2  00013CA0  PPC  'MyApp'+1A0
01D87F4A  00043050  PPC  'MyApp'+2F450
01D87EF0  4085FF06  68K  ComponentDispatch+26
01D87EC8  4085FFE6  68K  ComponentDispatch+106
01D87E50  00063144  PPC  'NativeComponent'+40
Here you can see that we're executing a native application with the exported main symbol MyApp. The application calls a subroutine at MyApp+1A0, leaving the first stack frame that we see here. Then at MyApp+2F450 the subroutine appears to call the 680x0-based Component Manager. We assume this because the next two stack frames are marked "68K" and appear within the ComponentDispatch code. The Component Manager then calls native code with the symbol NativeComponent. The last frame is generated when NativeComponent calls a subroutine.

EVEN MORE NEW FEATURES

Besides support for native Power Macintosh debugging, the new MacsBug adds other exciting new features, including:
  • multiple debugger preferences files

  • better ROM symbols using ROM map files

  • an improved dcmd format

  • significant performance improvements on 68040-based Macintosh computers
We once used ResEdit to construct a single MacsBug preferences file with all our favorite dcmds and templates. Those days are over: the new MacsBug version will load up to 32 preferences files that you provide. And if you haven't discarded the ROM list files provided with MPW, you can build them and use the resulting ROM map files with the new MacsBug. Put the map files in the new MacsBug preferences folder to use the map's symbol information. When disassembling or displaying addresses in the ROM, MacsBug will then display better symbols.

The improved dcmd format adds new action calls and an expanded parameter block structure, which provides full access to the PowerPC register set and machine state. Although this doesn't give you special support for developing PowerPC-native dcmds, you now have access to valuable internal state information. With this new information, your dcmds can do things that were previously reserved for Apple dcmds, such as tdp (total dump PowerPC), which was introduced in the article "Debugging on PowerPC" in develop Issue 17. This dcmd, among others from Apple, has intimate knowledge of how the PowerPC system software works. With the new dcmd format, this intimate knowledge is no longer necessary since MacsBug provides access to everything you'll need.

The new dcmd format has been designed with maximum flexibility in mind. Your dcmds can check at run time for the availability of MacsBug features. When new callbacks are defined, you can check whether MacsBug supports the calls, rather than being tied to a specific MacsBug version.

On 68040-based Macintosh computers, MacsBug will perform most tasks much faster, and with an important side effect. The new MacsBug doesn't flush the 68040 processor cache nearly as often, greatly improving performance for most commands. The key side effect is for bugs related to cache flushing: in the past, MacsBug would flush the cache frequently enough to make these bugs hard to reproduce when you're stepping or using breakpoints; the new MacsBug, with its selective flushing, should allow you to more readily reproduce this type of problem.

IT'S LOG, LOG, LOG!

Here at Apple, bugs are usually found by test engineers using automated scripts and manual testing. When they find a bug in our code, we're rarely nearby to analyze it immediately. Therefore, they collect key information so that we can later reproduce the problem. One useful piece of information they collect is called a standard log.

The standard log is a sequence of MacsBug commands that are run after a crash or interrupt -- for example, a register display and stack crawl. These commands are logged in a text file, and the result is copied into a report that describes the problem. Having this information in the problem report saves significant time and sometimes provides enough detail to resolve the problem immediately. MacsBug version 6.5 makes this log useful on the Power Macintosh. Its improved stack crawl, native disassembly, and PowerPC register display provide key information for later analysis. We recommend that you incorporate a standard log into your testing process; you'll find ours included as the StdLog macro.

DON'T HESITATE

You can read the release notes provided on the CD for detailed descriptions of these and other improvements. We hope you'll install the new version of MacsBug without delay!

DAVE EVANS denies rumors that he modeled for the Mac OS logo. Although he works in the Mac OS team at Apple and does perpetually smile -- and his favorite color is blue -- Dave could never sit still long enough for the pose. You're more likely to spot him racing off in his hunter green Jeep Sahara. He'll probably be late, after fitting too many activities into his day, and he'll certainly be en route to some new adventure.

JIM MURPHY (AppleLink MURPH, Internet murph@apple.com) dislikes one thing more than the Pittsburgh Penguins hockey club without superstar center Mario Lemieux, and that's a Macintosh without MacsBug. When he's not dodging a tedious meeting at Apple, blearily staring at a logic analyzer, or hacking the Mac OS boot process, he can be found plying the backroads of the Santa Cruz mountains in his trusty Miata.

Thanks to Brian Bechtel, Dave Lyons, and Greg Robbins for reviewing this column.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Notability 4.0.1 - Note-taking and annot...
Notability is a powerful note-taker to annotate documents, sketch ideas, record lectures, take notes and more. It combines, typing, handwriting, audio recording, and photos so you can create notes... Read more
Notability 4.0.1 - Note-taking and annot...
Notability is a powerful note-taker to annotate documents, sketch ideas, record lectures, take notes and more. It combines, typing, handwriting, audio recording, and photos so you can create notes... Read more
NetShade 8.0 - Browse privately using an...
NetShade is an anonymous proxy and VPN app+service for Mac. Unblock your Internet through NetShade's high-speed proxy and VPN servers spanning seven countries. NetShade masks your IP address as you... Read more
Thunderbird 60.7.1 - Email client from M...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
Coda 2.7.3 - One-window Web development...
Coda is a powerful Web editor that puts everything in one place. An editor. Terminal. CSS. Files. With Coda 2, we went beyond expectations. With loads of new, much-requested features, a few surprises... Read more
Logic Pro X 10.4.5 - Music creation and...
Logic Pro X is the most advanced version of Logic ever. Sophisticated new tools for professional songwriting, editing, and mixing are built around a modern interface that's designed to get creative... Read more
Coda 2.7.3 - One-window Web development...
Coda is a powerful Web editor that puts everything in one place. An editor. Terminal. CSS. Files. With Coda 2, we went beyond expectations. With loads of new, much-requested features, a few surprises... Read more
Thunderbird 60.7.1 - Email client from M...
As of July 2012, Thunderbird has transitioned to a new governance model, with new features being developed by the broader free software and open source community, and security fixes and improvements... Read more
NetShade 8.0 - Browse privately using an...
NetShade is an anonymous proxy and VPN app+service for Mac. Unblock your Internet through NetShade's high-speed proxy and VPN servers spanning seven countries. NetShade masks your IP address as you... Read more
Logic Pro X 10.4.5 - Music creation and...
Logic Pro X is the most advanced version of Logic ever. Sophisticated new tools for professional songwriting, editing, and mixing are built around a modern interface that's designed to get creative... Read more

Latest Forum Discussions

See All

Marvel Super War Beta Impressions
Marvel Super War is the latest MOBA from Netease, but it’s not something you can just go and download on the App Store now. The game is in a closed beta, meaning you have to download it from a special linkhere and the developers are still ironing... | Read more »
Wild Bullets guide - Tips and tricks for...
Wild Bullets offers up fast and fun wild west action, but it has a good amount of strange mechanics to navigate. Between the game’s unique movement and all of its unlocks, there’s quite a bit to take in. With that said, we put in a good amount of... | Read more »
Superhero-themed runner Talking Tom Hero...
After a massively popular pre-registration period, Outfit7’s runner, Talking Tom Hero Dash, has now landed on iOS and Android. This latest game in the beloved Talking Tom and Friends franchise sees the Talking Tom Heroes team taking on a band of... | Read more »
Infectonator 3: Apocalypse guide - Tips...
When I first booted up Infectonator 3: Apocalypse, I was surprised by the sheer amount of stuff going on it. From crafting and leveling zombies to the intricacies of managing a wandering horde of braindead zombies, it can be overwhelming. | Read more »
A beginner’s guide to MU Origin 2
Webzen’s acclaimed MU Origin 2 recently launched on iOS and Android, shaking up the MMORPG genre in the process. It’s a huge game with a lot of different systems and modes to learn, so we’ve put together a handy beginner’s guide to give you a head... | Read more »
Q&A with the creator of Flappy Fight...
Earlier this month, a little game called Flappy Fighter hit the App Store and seemingly surprised everyone. What looked like a simple Flappy Bird send-up actually turned into the little mobile fighting game that could. | Read more »
MU Origin 2, Webzen’s highly anticipated...
Having successfully left its closed beta phase, MU Origin 2 is no longer available for pre-registration – because it’s now entered its full release. It’s a fully-fledged 3D MMORPG and the second spin-off based on the Webzen’s popular MU universe,... | Read more »
AFK Arena guide - Everything you need to...
Ok, so if you're like me, you've been playing (and sometimes waiting) your way through AFK Arena, only to learn there's a lot more to it than there appears on the surface. There's guilds, a PvP arena, and all sorts of other systems and game modes... | Read more »
Explore an epic fantasy world in MMORPG...
Webzen have just announced the official launch date for its stunning MMORPG ‘MU Origin 2’ which will arrive for iOS and Android on May 28th. It will be the second spinoff from the classic PC-based MU Online, and it looks to further refine the... | Read more »
Solar Explorer: New Dawn guide - Tips an...
Solar Explorer: New Dawn is a lunar lander game that really ratchets the intensity up to 11. With all of the asteroids flying around as you fly around at seemingly breakneck speeds, it can be easy to feel overwhelmed bythe whole thing. | Read more »

Price Scanner via MacPrices.net

Amazon is offering Apple’s new 2019 15″ MacBo...
Amazon has the new 2019 15″ 6-Core and 8-Core MacBook Pros on sale today for $200 off Apple’s MSRP. Shipping is free: – 2019 15″ 2.3GHz 8-Core MacBook Pro Space Gray or Silver: $2599.99 $200 off MSRP... Read more
Our exclusive MacBook Price Trackers show you...
Our Apple award-winning MacBook price trackers are the best place to look for the best sales and lowest prices on MacBooks, MacBook Airs, and MacBook Pros. Scan our price trackers for the latest... Read more
Sprint is offering iPhone 8 Plus pre-owned le...
Sprint is offering the 64GB iPhone 8 Plus, preowned, for $10 per month when combined with a Sprint 18 month Flex lease. Offer is valid from 6/14/19 to 6/30/19. Upgrade to a 256GB model for $12 per... Read more
Amazon is offering a 50% discount on Apple Sm...
Amazon has Apple Smart Keyboards for current-generation 10″ iPad Airs and previous-generation 10″ iPad Pros on sale today for $79.50 shipped. That’s a 50% discount over Apple’s regular MSRP of $159... Read more
Roundup of the best 13″ MacBook Air sales...
Amazon has new 2018 13″ MacBook Airs on sale for $100-$150 off Apple’s MSRP, with prices starting at $1099, each including free shipping. Be sure to select Amazon as the seller during checkout,... Read more
Sale! New 2019 15″ & 13″ MacBook Pros now...
B&H Photo has the new 2019 15″ and 13″ MacBook Pros now on sale for up to $200 off Apple’s MSRP. Overnight shipping is free to many addressed in the US. B&H’s prices are currently the lowest... Read more
New 2019 15″ 2.6GHz 6-Core MacBook Pro on sal...
Adorama has the new 2019 15″ 2.6GHz 6-Core Space Gray MacBook Pro on sale today for $2244 shipped. Their price is $155 off Apple’s MSRP, and Adorama charges sales tax for NY & NJ residents only... Read more
12″ 1.2GHz Space Gray MacBook on sale today f...
Amazon has the 12″ 1.2GHz Space Gray Retina MacBook on sale today for $300 off Apple’s MSRP, only $999. Shipping is free: – 12″ 1.2GHz Space Gray MacBook (8GB RAM/256GB SSD): $999.99 $300 off MSRP... Read more
Clearance 27″ 5K iMacs on sale for up to $600...
B&H Photo has clearance, previous-generation, 27″ 5K Apple iMacs available for up to $600 off original MSRP. These are the same models offered by Apple in their retail and online stores. B&H... Read more
Apple’s new 15″ 2.3GHz 8-Core MacBook Pro is...
B&H Photo has the new 2019 15″ 2.3GHz Silver 8-Core MacBook Pro in stock today and on sale for $2599 including free shipping. That’s $200 off Apple’s MSRP, and it’s currently the lowest price... Read more

Jobs Board

Field Business Development Manager, *Apple*...
Field Business Development Manager, Apple Chicago, IL, USEden Prairie, MN, US Requisition Number:73320 As an Apple Business Development Manager at Insight, you Read more
Geek Squad *Apple* Master Consultation Agen...
**702908BR** **Job Title:** Geek Squad Apple Master Consultation Agent **Job Category:** Services/Installation/Repair **Location Number:** 000360-Williston-Store Read more
*Apple* Mobile Master - Best Buy (United Sta...
**699587BR** **Job Title:** Apple Mobile Master **Job Category:** Store Associates **Location Number:** 000394-Western Hills-Store **Job Description:** **What does a Read more
Best Buy *Apple* Computing Master - Best Bu...
**702927BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 001224-Lakewood-Store **Job Description:** **What does a Read more
Sr Merch Planner - *Apple* Hardware, *Appl...
…data-job-id="12210719" data-google-job-id="" data-apply-click-url="/job/ApplyClick">Sr Merch Planner - Apple Hardware, Apple Accessories, WearablesApply Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.