Tuesday, April 18, 2006

MacBook Pro

I got my work supplied MacBook Pro last week, and I've got two words... AWE-SOME! It's waaaay fast. On my dual 2GHz G5, Firefox bounces the dock icon about 5-8 times before opening. With the new universal Firefox binary, it bounces 1-2x on my MBP! That's friggin' fast! Now, I don't actually use Firefox (mostly because it's historically been too slow to start), but it's still an interesting measure.

Here's a few other interesting little tid-bits I came across on my first run through the new system:

  • You can tell if an application is universal by looking at the "Get Info" window in the Finder, or by using the file command from the Terminal. And you can tell if a process is actually running under Rosetta at runtime because /usr/libexec/oah/translate will be mapped into its address space. Just
    lsof -p PID | grep translate

  • You can run an application under Rosetta from the command line by using the command /usr/libexec/oah/translate. For example:
    /usr/libexec/oah/translate /bin/ls

  • On PPC functions arguments are passed in CPU registers starting with $r3. So, the function call foo(1, 2, 3) would have 0x1 in $r3, 0x2 in $r4, etc. On Intel function arguments are passed on the stack, so the function call foo(1, 2, 3) would have 0x1 at $ebp+8, 0x2 at $ebp+12, etc.

  • In Objective-C, a method call like [foo add:5] actually gets compiled into a C function call like
    objc_msgSend(self, @selector(add:), 5)
    And as we just saw, Intel Macs pass function arguments on the stack. So, the standard way to print "self" in gdb on a PPC Mac is
    po $r3
    (remember, $r3 has the first argument on PPC -- "self"), but on Intel it turns into
    po *(int *)($ebp+8)
    (po is print-object).

  • If you need to debug (using gdb) a PPC binary on an Intel Mac, you can do some basic stuff by setting the OAH_GDB environment variable to YES, then starting the application. Then in a new window, start gdb like
    gdb --oah
    then use gdb's attach command to attach to the running process like normal. This will even show you PPC style registers and stuff in gdb. Pretty cool for basic debugging.

Saturday, April 08, 2006

Fantastic Darwin Code Browser Online

The source for Darwin is available online here, but there's not a good way to browse and search the code. Until now. Enter the OpenGrok source browser for Darwin. It's friggin' sweet and "wicked fast".

Thursday, April 06, 2006

The little hidden built-in calculator

I just learned this little trick a few days ago, but I guess it's not really all that new. Almost all Cocoa text areas can perform calculations right inline. You just have to type a calculation, highlight it, hit Command-Shift-8, then the calculation will be evaluated and replaced by the answer. Pretty cool. For example, if I type 3^(2*pi), then highlight it and hit Command-Shift-8, it will be replaced with 995.041644892855.

You'll probably notice that the Sript Editor application opens when you do this. That's because the feature is implemented as a Service provided by the Script Editor. What's really happening is that the highlighted text is being executed as AppleScript. So, as I sit here typing into this text area in Safari, I could highlight and execute

tell application "Safari" to display dialog "Hello"
(don't ask me why I'd want to run that AppleScript from right here).

I'm sure there's much cooler stuff you can do wit this trick, but regardless it's pretty cool.