Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Display all defaults for any Cocoa app Apps
For any Cocoa app that uses the defaults system in the 'standard' fashion, the app will register defaults as it launches. If you launch the application using gdb (included with OS X), you can easily display all registered defaults.

Read the rest of the article for the how-to...

Start a terminal session, and launch the application to be viewed via the command line:
gdb /Applications/
This brings up gdb, ready to launch mail, so just type (at the gdb prompt), 'r' and then hit enter, and will launch. You'll see a bunch of text go by, and eventually, will show up on your screen.

Once the app is launched, go to the terminal window and type a ctrl-c. This will pause the app and give you a prompt. Then do this, entering each line below as a new line in gdb:
p $o = (unsigned int) objc_getClass("NSUserDefaults")
p $s = (unsigned int) sel_getUid("standardUserDefaults")
p $o = (unsigned int) objc_msgSend($o, $s)
p $s = (unsigned int) sel_getUid("dictionaryRepresentation")
p $o = (unsigned int) objc_msgSend($o, $s)
p $s = (unsigned int) sel_getUid("description")
p $o = (unsigned int) objc_msgSend($o, $s)
p (void) NSLog($o)
This will cause all of the registered defaults and their current values to be printed out.

[Editor's note: I just tried this with TextEdit, and it worked just as described - a very neat trick!]
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)

Display all defaults for any Cocoa app | 9 comments | Create New Account
Click here to return to the 'Display all defaults for any Cocoa app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
a bunch of warnings
Authored by: beastie on Dec 27, '01 07:14:20PM

I just tried to launch TextEdit as well via gdb and got a bunch of warnings like:

unable to open symbol file: CFMPriv_CoreFoundation: No such file or directory.
warning: Unable to read symbols from "CFMPriv_CoreFoundation"; reading from memory.

unable to open symbol file: CFMPriv_HTMLRendering: No such file or directory.
warning: Unable to read symbols from "CFMPriv_HTMLRendering"; reading from memory.

anyone else got the same? what could be the cause for this?

[ Reply to This | # ]
Worked fine here...
Authored by: robg on Dec 27, '01 08:15:41PM

"gdb /Applications/" followed by 'r' worked just as expected.

Wish I could tell you why yours isn't working.


[ Reply to This | # ]
Re:Worked fine here...
Authored by: beastie on Dec 28, '01 03:48:51AM

No dewd, you didnt understand, mine is working too.. but before it launched it gave me thaaaaat lots of warnings... TextEdit has opened after that as expected, but my terminal was flooded with those warnings... So i'm just worried if it's normal and if not, what can i do about it..?


[ Reply to This | # ]
Authored by: robg on Dec 28, '01 09:58:01AM

Sorry for the misunderstanding. I just repeated the experiment, and there were no warnings. Instead, I see that it "read symbols for shared libraries" twice and "done" after each one.

Hopefully someone with more knowledge of either gdb or the core OS can tell us what's going on with your machine.


[ Reply to This | # ]
I could be wrong...
Authored by: madmizzen on Dec 28, '01 03:51:10AM

as i don't have the gdb binary that is mentioned in the article, maybe it is on the developers cd?. But to find the defaults for Cocoa apps i have been just using the defaults reader/writer that is included in OSX.

[term prompt]% defaults read

man defaults for all the details.

Of course since i don't have gdb, i may very well be mistaken.

[ Reply to This | # ]
I could be wrong...
Authored by: Anonymous on Dec 28, '01 02:34:07PM

That won't tell you *all* the defaults; only the ones that the app has explicitly changed.

A properly written Cocoa application will register a set of default values that effectively provide the "default" defaults to be used by the app. These values are not written into the defaults database. When the app changes a particular default's value, that new value will be written and will be accessible in the manner described.

(Yes, gdb is on the developer CD)

However, defaults do not have to be registered, either. To truly find all of the defaults an application ever looks for, you need to modify the defaults subsystem to log every default as it is accessed. This will catch *all* defaults, including ones that are never registered.

It isn't hard to do-- but you do need to compile a small hunk of code to make it work. If anyone is interested, send email and I can write up a brief article on how it is done.

[ Reply to This | # ]
Authored by: almond on Dec 31, '01 11:34:59AM

I tried this and I got (after the NSLog($o)) a EXC_BAD_ACCESS error
I was running on just like the sample.

(gdb) p $o = (unsigned int) objc_msgSend($o, $s)
$7 = 41072272
(gdb) p (void) NSLog($o)

Program received signal EXC_BAD_ACCESS, Could not access memory.
0x7016a130 in _CFStringAppendFormatAndArgumentsAux ()
The program being debugged was signaled while in a function called from GDB.

Any ideas about what was going on?

I was really looking forward to being able to set extra default headers
in (I use a forwarding email service, so I need to set the
reply-to header in my email; having to do it manually each time is
just a pain.)

[ Reply to This | # ]
Authored by: hagbard on Feb 03, '02 10:53:38AM

here's why you can't access the memory, it's because of protected memory. Try sudo gdb instead of gdb, now you can acces any process' memory !

(the only problem, with mail, is that it will open with root as the user, and probably not your personal mailbox, but this won't be a problem with other apps...)

[ Reply to This | # ]
Display all defaults for any Cocoa app
Authored by: Hes Nikke on Mar 09, '03 03:14:33AM
it didn't work for XHints chat, a proprly written cocoa app (admitntly i can just look at the sourcefor OpenMac)

Program received signal SIGINT, Interrupt.
0x90073c48 in mach_msg_trap ()
(gdb) p $o = (unsigned int) objc_getClass("NSUserdefaults")
$1 = 0
(gdb) p $s = (unsigned int) sel_getUid("standardUserdefaults")
$2 = 2039392
(gdb) p $o = (unsigned int) objc_msgSend($o, $s)
$3 = 0
(gdb) p $s = (unsigned int) sel_getUid("dictionaryRepresentation")
$4 = 2422935564
(gdb) p $o = (unsigned int) objc_msgSend($o, $s)
$5 = 0
(gdb) p $s = (unsigned int) sel_getUid("description")
$6 = 2422933484
(gdb) p $o = (unsigned int) objc_msgSend($o, $s)
$7 = 0
(gdb) p (void) NSLog($o)
$8 = void

vacuums do not suck. they merely provide an absence that allows other objects to take the place of what becomes absent.

[ Reply to This | # ]