Exit Wiki

Tools and tricks for using Carbon with GDB

(Apple) Toolbox Helper Functions

From GDB section of Carbon Tips And Tricks from Apple:

"From gdb you can call functions from both within your application or in the Toolbox. Over time many helpful debugging routines have been added to the Toolbox."

for a list of these enter:

(gdb) call GDB*
(gdb) call Debug*
(gdb) call Is* (or IsValid*)

(hit tab for autocomplete/list)

To use some of you'll have to call them like this:

(gdb) call (void) DebugPrintMenu(inMenuRef)
(gdb) call (void) DebugPrintMenuList()

(if you forget the void you'll get an error about not being able to determine the return type. Yes, you have to manually specify it).

The downside is that sometimes GDB can't find these functions (bummer!)

There's also

(gdb) call HIObjectPrintDebugInfo(hiObjectBasedThing)

You can combine these functions in useful ways, as in this example

(gdb) call (void) DebugPrintMenuList()
(Will give you a list of menus and their IDs)

(gdb) call (MenuHandle) GetMenuHandle( ID OF ONE OF THE MENUS )
$5 = (struct OpaqueMenuRef *) 0xa34ccc0

(gdb) call (void) DebugPrintMenu($5)
(Will print out the menu for you)

Apple also provides /usr/share/gdb/carbon.gdb to source in your .gdbinit, or /usr/share/gdb/macsbugs.gdb if you prefer MacsBug style commands.

In GDB Hacks

Printing C-String formatted Handles

print handle[0]@handleLen

Debugging Functions

Sometimes you need a little help, and can't do it all from the GDB command line. Here are some functions for you

Print Path for a FSSpec

   1 void PrintFSSpec(FSSpec in)
   2 {
   3         OSErr err = noErr;
   4         FSRef asRef;
   5         CFURLRef asURL = NULL;
   6         CFStringRef thePath = NULL;
   7         
   8         err = FSpMakeFSRef(&in,&asRef);
   9         if (err == noErr)
  10         {
  11                 asURL = CFURLCreateFromFSRef(NULL,&asRef);
  12                 
  13                 thePath = CFURLCopyFileSystemPath(asURL, kCFURLPOSIXPathStyle);
  14                 if (thePath)
  15                 {
  16                         CFShow(thePath);
  17                         CFRelease(thePath);
  18                 }
  19                 CFRelease(asURL);
  20         }
  21         else
  22         {
  23                 CFShow( CFSTR("Could not transform FSSpec into FSRef") );
  24         }
  25 }

Comments:

Add comments by visiting: GDB/Carbon/Comments

GDB/Carbon (last edited 2007-11-26 14:56:34 by RyanWilcox)