I attached to a program with gdb in OSX and I want to use CFShow
in the gdb console etc. However, nothing shows up. printf
shows nothing as well:
(gdb) call (int) printf("Hello\n")
$10 = 6
(gdb) call (int) printf("Hello World!\n")
$11 = 13
Apple suggests the following tip for when attaching with gdb, to make the output appear in the gdb console:
(gdb) call (void) close(1)
(gdb) call (void) close(2)
(gdb) shell tty
/dev/ttyp1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$2 = 2
In xcode's gdb console tty
gives "not a tty
", so I tried it in gdb in a terminal. There tty
does work but after redirecting stdout there's still no output. Also no output if I direct stdout to a file.. :/
Any salvation?
Update/More-details:
On some programs (like TextMate) this method does work. The application I was trying to debug is Update: seems the real explanation is rather:/Developer/Applications/Audio/AU\ Lab.app
. For some reason this trick does not work there..
If after attaching I redirect stdout before calling printf
for the first time, it works! If I first printf
and only then redirect output, output shows up only after doing printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n")
and then pressing enter (to repeat last command) 327 times.
So I guess redirecting stdout somehow makes libc confused and makes it use a buffer of 2**14
bytes for some reason?